* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  height: 100%;
}

body {
  background: linear-gradient(180deg, #2c3e50 0%, #1a242f 100%);
  color: #ecf0f1;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px;
  gap: 12px;
}

.hud {
  display: flex;
  gap: 18px;
  align-items: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.info {
  background: rgba(255, 255, 255, 0.08);
  padding: 6px 12px;
  border-radius: 7px;
}

.info span {
  color: #f1c40f;
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
}

button {
  background: #e74c3c;
  color: #fff;
  border: none;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.05s;
}

button:hover:not(:disabled) {
  background: #c0392b;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  background: #555c66;
  color: #99a0aa;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border: 2px solid #ecf0f1;
  color: #ecf0f1;
  padding: 5px 12px;
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.screen.hidden {
  display: none;
}

#start-screen {
  flex: 1;
  justify-content: center;
  min-height: 80vh;
}

.start-card {
  background: rgba(255, 255, 255, 0.08);
  padding: 40px 48px;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  min-width: 320px;
}

.start-card h1 {
  font-size: 36px;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.start-card label {
  font-size: 15px;
  color: #bdc3c7;
  margin-top: 4px;
}

.start-card input {
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.15);
  color: #ecf0f1;
  font-size: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}

.start-card input:focus {
  border-color: #e74c3c;
}

.start-card button {
  margin-top: 8px;
  padding: 12px;
  font-size: 18px;
  letter-spacing: 2px;
}

.start-card .btn-rank-link {
  margin-top: 0;
  font-size: 14px;
  letter-spacing: 0.5px;
  padding: 9px;
}

.download-section {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.download-section.hidden {
  display: none;
}

.download-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #7f8c8d;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.download-divider::before,
.download-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
}

.download-buttons {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.dl-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.dl-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  padding: 7px 10px;
  color: #ecf0f1;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.dl-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

.dl-btn:active {
  transform: translateY(1px);
}

.dl-icon {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.dl-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  text-align: left;
  min-width: 0;
  overflow: hidden;
}

.dl-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dl-sub {
  font-size: 10px;
  color: #95a5a6;
  letter-spacing: 0;
  margin-top: 1px;
}

.start-card .dl-help-link {
  background: transparent;
  border: none;
  color: #95a5a6;
  font-size: 10px;
  font-weight: 500;
  padding: 0 4px;
  margin: 0;
  letter-spacing: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(255, 255, 255, 0.15);
  align-self: center;
  cursor: pointer;
}

.start-card .dl-help-link:hover {
  color: #ecf0f1;
  background: transparent;
}

.help-body {
  font-size: 14px;
  line-height: 1.6;
  color: #ecf0f1;
}

.help-body p {
  margin-bottom: 12px;
}

.help-steps {
  padding-left: 22px;
  margin: 10px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-steps li {
  font-size: 13.5px;
}

.help-steps li b {
  color: #f1c40f;
  font-weight: 700;
}

.help-note {
  margin-top: 14px !important;
  font-size: 13px;
  color: #bdc3c7;
}

.help-code {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: #2ecc71;
  white-space: pre-wrap;
  word-break: break-all;
}

#mac-help-close {
  margin-top: 8px;
  align-self: center;
  padding: 9px 24px;
}

.hint {
  font-size: 13px;
  color: #95a5a6;
  min-height: 0;
  text-align: center;
}

.hint:empty {
  display: none;
}

.hint.error {
  color: #ff7062;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #2c3e50;
  border-radius: 14px;
  padding: 28px 32px;
  min-width: 360px;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  font-size: 24px;
  text-align: center;
  letter-spacing: 1px;
}

.tabs {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 4px;
}

.tab {
  flex: 1;
  background: transparent;
  color: #bdc3c7;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 7px;
  letter-spacing: 0;
}

.tab.active {
  background: #e74c3c;
  color: #fff;
}

.tab:hover:not(.active):not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: #ecf0f1;
}

.rank-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rank-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 7px;
  font-size: 15px;
}

.rank-list li.empty {
  justify-content: center;
  color: #7f8c8d;
  font-style: italic;
}

.rank-rank {
  width: 28px;
  font-weight: 700;
  color: #f1c40f;
  font-variant-numeric: tabular-nums;
}

.rank-list li:nth-child(1) .rank-rank { color: #ffd700; }
.rank-list li:nth-child(2) .rank-rank { color: #c0c0c0; }
.rank-list li:nth-child(3) .rank-rank { color: #cd7f32; }

.rank-name {
  flex: 1;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-score {
  font-weight: 700;
  color: #2ecc71;
  font-variant-numeric: tabular-nums;
}

#rank-close {
  margin-top: 4px;
  align-self: center;
  padding: 9px 24px;
}

.board-wrap {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

#board {
  background: #e8f5e0;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  cursor: crosshair;
  display: block;
}

.timer-bar {
  width: 18px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

#timer-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(180deg, #2ecc71 0%, #27ae60 100%);
  border-radius: 9px;
  transition: background 0.3s;
}

#timer-fill.warn {
  background: linear-gradient(180deg, #f1c40f 0%, #e67e22 100%);
}

#timer-fill.danger {
  background: linear-gradient(180deg, #e74c3c 0%, #c0392b 100%);
}
