:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: rgba(8, 14, 28, 0.72);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #eef3ff;
  --muted: #9fb0d1;
  --accent: #4de1a7;
  --accent2: #ffcb4d;
  --danger: #ff6d6d;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    linear-gradient(180deg, #101938 0%, #0b1020 100%);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1;
  touch-action: manipulation;
}

button.active {
  background: linear-gradient(180deg, rgba(77, 225, 167, 0.35), rgba(77, 225, 167, 0.15));
  border-color: rgba(77, 225, 167, 0.8);
}

#app {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  aspect-ratio: 9 / 16;
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
  background: #08101c;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  transform: translateY(18px);
}

.global-toolbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 20;
  pointer-events: auto;
}

.lang-btn {
  min-width: 48px;
  min-height: 38px;
  border-radius: 10px;
  font-weight: 900;
  color: var(--accent2);
  background: rgba(8, 14, 28, 0.72);
  backdrop-filter: blur(10px);
}

.home-toolbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 20;
  pointer-events: auto;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 26%, rgba(77, 225, 167, 0.20), transparent 30%),
    linear-gradient(180deg, rgba(9, 18, 38, 0.96), rgba(6, 10, 22, 0.98));
}

.screen.hidden {
  display: none;
}

.loading-screen {
  gap: 22px;
  align-content: center;
}

.brand, .home-title {
  font-size: 44px;
  line-height: 1;
  font-weight: 900;
  text-align: center;
  letter-spacing: 0;
  text-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.loading-card {
  width: min(320px, 84vw);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(10, 17, 32, 0.74);
  border-radius: 14px;
  padding: 18px;
  box-sizing: border-box;
}

.loading-title, .loading-text, .home-subtitle, .home-controls {
  color: var(--muted);
  text-align: center;
}

.loading-title {
  font-size: 15px;
  margin-bottom: 12px;
}

.progress-shell {
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4de1a7, #ffcb4d);
  transition: width 180ms ease;
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 18px auto 0;
  border-radius: 999px;
  border: 4px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--accent2);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  margin-top: 10px;
  font-size: 13px;
}

.home-screen {
  background:
    linear-gradient(rgba(5, 12, 26, 0.42), rgba(5, 12, 26, 0.78)),
    radial-gradient(circle at 50% 50%, rgba(77, 225, 167, 0.22), transparent 34%),
    linear-gradient(180deg, #15244a 0%, #07101f 100%);
}

.home-content {
  display: grid;
  gap: 12px;
  justify-items: center;
  width: min(360px, 88vw);
}

.profile-bar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  z-index: 1;
}

.name-btn {
  min-height: 38px;
  border-radius: 10px;
  color: var(--muted);
  background: rgba(8, 14, 28, 0.62);
}

.rank-score {
  color: var(--accent2);
  font-size: 18px;
  font-weight: 900;
}

.home-subtitle {
  font-size: 18px;
  margin-top: -6px;
}

.primary-btn {
  min-width: 184px;
  min-height: 52px;
  border-radius: 14px;
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(180deg, rgba(77, 225, 167, 0.9), rgba(31, 171, 124, 0.86));
  border-color: rgba(180, 255, 225, 0.72);
  color: #06131a;
  box-shadow: 0 12px 34px rgba(42, 220, 156, 0.22);
}

.secondary-btn {
  min-width: 184px;
  min-height: 46px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
}

#hud {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

#hud.menu-mode {
  display: none;
}

#hud.menu-mode .topbar,
#hud.menu-mode .message {
  display: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 10px;
  font-size: 22px;
  font-weight: 800;
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.scorebox, .status, .message, .bottom-ui {
  pointer-events: none;
}

.scorebox, .status, .message {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  color: var(--text);
}

.scorebox {
  padding: 10px 14px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
  min-width: 100px;
  text-align: center;
}

.scorebox .sep {
  opacity: 0.55;
  padding: 0 4px;
}

.status {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  align-items: center;
}

#gyroStatus {
  color: var(--accent2);
  font-weight: 800;
}

#gyroStatus.off {
  color: var(--danger);
}

.message {
  align-self: center;
  padding: 9px 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  max-width: 92%;
}

.message:empty {
  display: none;
}

.bottom-ui {
  position: absolute;
  inset: 0;
}

.rod-switch, .actions {
  position: absolute;
  bottom: max(6px, env(safe-area-inset-bottom));
  display: grid;
  grid-auto-flow: row;
  gap: 8px;
  pointer-events: auto;
}

.rod-switch {
  left: max(14px, calc(50% - 168px));
  grid-template-columns: repeat(2, 78px);
  grid-template-rows: repeat(2, 42px);
  grid-auto-flow: row;
}

.actions {
  right: max(14px, calc(50% - 168px));
}

.actions button,
.rod-switch button {
  width: 78px;
  min-height: 42px;
  padding: 10px 8px;
}

.result-modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 8, 18, 0.62);
  backdrop-filter: blur(6px);
  z-index: 7;
  pointer-events: auto;
}

.result-modal.hidden {
  display: none;
}

.modal-panel {
  width: min(320px, 86vw);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(12, 20, 36, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  padding: 24px 20px 20px;
  text-align: center;
  color: var(--text);
}

.modal-title {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.08;
  word-break: break-word;
}

#matchingTitle {
  font-size: 18px;
  letter-spacing: 0;
}

.modal-score {
  margin-top: 8px;
  font-size: 38px;
  font-weight: 900;
  color: var(--accent2);
}

.modal-copy {
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.result-modal .modal-panel {
  width: min(340px, 90vw);
}

.name-input {
  width: 100%;
  height: 46px;
  margin-top: 18px;
  box-sizing: border-box;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  font-weight: 800;
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.modal-actions button {
  min-width: 132px;
  background: linear-gradient(180deg, rgba(77, 225, 167, 0.42), rgba(77, 225, 167, 0.18));
  border-color: rgba(77, 225, 167, 0.8);
}

.difficulty-actions {
  margin-top: 22px;
  display: grid;
  gap: 10px;
}

.language-grid button.active {
  color: #06131a;
  background: linear-gradient(180deg, rgba(255, 203, 77, 0.96), rgba(255, 178, 52, 0.9));
  border-color: rgba(255, 230, 142, 0.9);
}

.difficulty-actions button {
  min-height: 48px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 800;
}

.settings-modal {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 20px;
  box-sizing: border-box;
  background: rgba(3, 8, 18, 0.68);
  backdrop-filter: blur(7px);
  pointer-events: auto;
}

.settings-modal.hidden {
  display: none;
}

.settings-panel {
  width: min(390px, 92vw);
  max-height: min(780px, 88vh);
  overflow: auto;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(12, 20, 36, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  padding: 16px;
  box-sizing: border-box;
  color: var(--text);
}

.leaderboard-panel {
  width: min(410px, 94vw);
  max-height: min(820px, 90vh);
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(12, 20, 36, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  padding: 16px;
  box-sizing: border-box;
  color: var(--text);
}

.leaderboard-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.leaderboard-list {
  margin-top: 14px;
  max-height: min(650px, 72vh);
  overflow: auto;
  display: grid;
  gap: 6px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 74px;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  font-size: 13px;
}

.leaderboard-row.player-row {
  border: 1px solid rgba(255, 203, 77, 0.9);
  background: rgba(255, 203, 77, 0.12);
}

.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-badge {
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  color: #08131a;
  background: #ffd24d;
  vertical-align: middle;
}

.leaderboard-badge.fake {
  background: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
}

.leaderboard-score {
  color: var(--accent2);
  font-weight: 900;
  text-align: right;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-title {
  font-size: 22px;
  font-weight: 900;
}

.settings-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.section-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent2);
}

.key-grid {
  display: grid;
  gap: 8px;
}

.rod-bind-grid {
  display: grid;
  gap: 8px;
}

.rod-bind-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 54px;
}

.rod-bind-row strong {
  display: block;
  color: var(--text);
  font-size: 14px;
}

.rod-bind-row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.key-grid label,
.range-row,
.toggle-row {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--muted);
  font-size: 14px;
}

.key-bind {
  min-width: 92px;
  border-radius: 8px;
  font-weight: 800;
  color: var(--text);
}

.rod-bind {
  min-width: 86px;
  border-radius: 8px;
  font-weight: 800;
  color: var(--text);
}

.key-bind.waiting,
.rod-bind.waiting {
  color: #06131a;
  background: linear-gradient(180deg, rgba(255, 203, 77, 0.96), rgba(255, 178, 52, 0.9));
  border-color: rgba(255, 230, 142, 0.9);
}

.range-row {
  grid-template-columns: 98px 1fr 42px;
}

.range-row input {
  width: 100%;
  accent-color: var(--accent);
}

.toggle-row input {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.reset-btn {
  width: 100%;
  min-height: 44px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 460px) {
  .scorebox {
    font-size: 22px;
    min-width: 76px;
    padding: 10px 10px;
  }
  .status {
    padding: 10px 9px;
    gap: 8px;
  }
  .icon-btn {
    width: 40px;
    height: 40px;
  }
  .rod-switch {
    grid-template-columns: repeat(2, 72px);
    grid-template-rows: repeat(2, 42px);
    left: 12px;
  }
  .actions {
    right: 12px;
  }
  .actions button,
  .rod-switch button {
    width: 72px;
    min-width: 0;
    min-height: 42px;
    font-size: 13px;
  }
  .difficulty-actions button {
    min-width: 0;
  }
  .global-toolbar {
    display: none;
  }
}
