:root {
  color-scheme: light;
  --ink: #17314a;
  --muted: #577087;
  --paper: rgba(255, 255, 255, 0.82);
  --paper-strong: rgba(255, 255, 255, 0.94);
  --line: rgba(23, 49, 74, 0.15);
  --teal: #13b9ad;
  --coral: #ff786a;
  --gold: #ffc84e;
  --leaf: #77c65d;
  --sky: #4ab8ff;
  --font-round: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", ui-rounded, system-ui, sans-serif;
  font-family: var(--font-round);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: linear-gradient(135deg, #dff7ff 0%, #e8fff7 52%, #fff1e8 100%);
  color: var(--ink);
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.hud {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(280px, 460px) auto minmax(190px, 1fr);
  align-items: start;
  gap: 16px;
  pointer-events: none;
}

.brand,
.question-card,
.hud-actions,
.best,
.timer,
.lives,
.player-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand {
  height: 44px;
  width: fit-content;
  min-width: 170px;
  padding: 0 16px 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 18px 48px rgba(34, 91, 124, 0.16);
  backdrop-filter: blur(16px);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  width: 16px;
  height: 16px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--sky), var(--teal));
  box-shadow: 8px 8px 0 rgba(255, 200, 78, 0.75);
  transform: rotate(45deg) translate(-3px, -3px);
}

.brand-copy {
  display: grid;
  gap: 1px;
  line-height: 1;
}

.brand-copy strong {
  font-size: 14px;
}

.brand-copy em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.question-card {
  justify-self: center;
  display: grid;
  min-height: 88px;
  width: 100%;
  padding: 12px 18px 13px;
  border: 2px solid rgba(255, 200, 78, 0.45);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 250, 224, 0.9)),
    var(--paper-strong);
  box-shadow: 0 22px 60px rgba(34, 91, 124, 0.18);
  backdrop-filter: blur(18px);
  text-align: center;
}

.level {
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
}

.question {
  min-height: 34px;
  color: #ff7a3d;
  font-family: var(--font-round);
  font-size: clamp(28px, 4vw, 40px);
  line-height: 0.98;
  letter-spacing: 0;
  text-shadow:
    0 3px 0 #fff3cf,
    0 10px 22px rgba(255, 120, 106, 0.2);
}

.feedback {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: none;
}

.feedback.good {
  color: var(--teal);
}

.feedback.bad {
  color: var(--coral);
}

.score-stack {
  min-width: 112px;
  text-align: center;
  justify-self: center;
}

.score {
  display: block;
  height: 68px;
  font-size: clamp(48px, 7vw, 72px);
  line-height: 0.92;
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: 0 10px 30px rgba(49, 81, 103, 0.22);
}

.combo {
  display: block;
  min-height: 20px;
  color: var(--coral);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.combo.show {
  opacity: 1;
  transform: translateY(0);
}

.hud-actions {
  justify-self: end;
  pointer-events: auto;
}

.player-badge {
  min-height: 44px;
  max-width: 140px;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid rgba(19, 185, 173, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 18px 48px rgba(34, 91, 124, 0.16);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(16px);
}

.lives {
  min-height: 44px;
  min-width: 82px;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid rgba(255, 120, 106, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 18px 48px rgba(34, 91, 124, 0.16);
  color: var(--coral);
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 1px;
  backdrop-filter: blur(16px);
}

.best,
.timer {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 18px 48px rgba(34, 91, 124, 0.16);
  backdrop-filter: blur(16px);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.best b,
.timer b {
  color: var(--ink);
  font-size: 16px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 18px 48px rgba(34, 91, 124, 0.16);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  backdrop-filter: blur(16px);
  cursor: pointer;
}

.icon-button:active,
.home-card button:active,
.leaderboard-close:active {
  transform: translateY(1px);
}

.power-wrap {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(360px, calc(100vw - 48px));
  transform: translateX(-50%);
  opacity: 0.9;
  pointer-events: none;
}

.power-track {
  position: relative;
  height: 30px;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  overflow: hidden;
  background:
    linear-gradient(90deg,
      rgba(19, 185, 173, 0.2) 0 36%,
      rgba(255, 200, 78, 0.22) 36% 70%,
      rgba(255, 120, 106, 0.22) 70% 100%);
  box-shadow:
    inset 0 1px 2px rgba(32, 49, 66, 0.14),
    0 12px 28px rgba(23, 49, 74, 0.14);
}

.power-track::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 36%, rgba(255, 255, 255, 0.92) 36% 37%, transparent 37% 70%, rgba(255, 255, 255, 0.92) 70% 71%, transparent 71%);
  pointer-events: none;
}

.power {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--coral));
  box-shadow: 0 0 20px rgba(255, 127, 112, 0.45);
  transition: width 40ms linear;
}

.power-zones {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 36fr 34fr 30fr;
  align-items: center;
  color: rgba(23, 49, 74, 0.72);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  pointer-events: none;
  z-index: 1;
}

.power-zones span {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.power-labels {
  display: grid;
  grid-template-columns: 36fr 34fr 30fr;
  gap: 4px;
  margin-top: 6px;
  color: rgba(23, 49, 74, 0.7);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.power-labels span {
  display: inline-grid;
  min-height: 20px;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 8px 20px rgba(23, 49, 74, 0.1);
}

.power-wrap[data-zone="0"] .power-labels span:nth-child(1),
.power-wrap[data-zone="1"] .power-labels span:nth-child(2),
.power-wrap[data-zone="2"] .power-labels span:nth-child(3),
.power-wrap[data-zone="0"] .power-zones span:nth-child(1),
.power-wrap[data-zone="1"] .power-zones span:nth-child(2),
.power-wrap[data-zone="2"] .power-zones span:nth-child(3) {
  background: rgba(255, 200, 78, 0.92);
  color: #17314a;
}

.power-wrap[data-zone="0"] .power-zones span:nth-child(1),
.power-wrap[data-zone="1"] .power-zones span:nth-child(2),
.power-wrap[data-zone="2"] .power-zones span:nth-child(3) {
  display: grid;
  height: 100%;
  place-items: center;
  background: rgba(255, 255, 255, 0.34);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(236, 250, 248, 0.48);
  backdrop-filter: blur(10px);
  transition: opacity 180ms ease;
}

.overlay.start-screen {
  place-items: start center;
  overflow-y: auto;
  padding: clamp(12px, 2.4vw, 28px);
  touch-action: pan-y;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.72) 0%, rgba(255, 255, 255, 0.34) 48%, rgba(255, 255, 255, 0.12) 100%),
    linear-gradient(180deg, rgba(12, 96, 146, 0.06), rgba(19, 185, 173, 0.08)),
    url("assets/math-island-bg.webp") center / cover no-repeat;
  backdrop-filter: none;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  position: relative;
  width: min(430px, calc(100vw - 40px));
  padding: 32px 30px 30px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 255, 251, 0.9)),
    rgba(255, 255, 255, 0.92);
  box-shadow: 0 34px 100px rgba(23, 49, 74, 0.26);
  text-align: center;
  overflow: hidden;
}

.modal.home-card {
  align-self: start;
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: min(760px, calc(100vw - 32px));
  max-height: none;
  margin: 0 auto;
  padding: 12px;
  background: rgba(255, 255, 255, 0.24);
  box-shadow: none;
  overflow: visible;
}

.modal::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 7px;
  background: linear-gradient(90deg, var(--sky), var(--teal), var(--gold), var(--coral));
}

.modal .eyebrow,
.modal p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.home-copy,
.leaderboard {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 24px 70px rgba(23, 49, 74, 0.22);
  backdrop-filter: blur(18px);
}

.home-copy {
  display: grid;
  grid-template-columns: minmax(270px, 1fr) minmax(280px, 1fr);
  gap: 16px;
  align-items: start;
  padding: 20px;
  text-align: left;
}

.home-main,
.home-picks {
  display: grid;
  gap: 9px;
}

.home-copy .eyebrow {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(19, 185, 173, 0.14);
  color: var(--teal);
  font-size: 12px;
}

.modal h1 {
  margin: 4px 0 6px;
  font-size: clamp(58px, 9vw, 80px);
  line-height: 0.95;
  letter-spacing: 0;
}

.modal h1.game-title {
  margin: 4px 0 0;
  color: var(--ink);
  font-size: clamp(40px, 4vw, 52px);
  line-height: 1.02;
  white-space: normal;
  text-shadow: 0 8px 22px rgba(23, 49, 74, 0.14);
}

.home-subtitle {
  color: var(--muted) !important;
  font-size: 14px !important;
  line-height: 1.45;
  text-transform: none !important;
}

.how-to {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 4px;
}

.how-to span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(19, 185, 173, 0.18);
  border-radius: 999px;
  background: rgba(236, 255, 250, 0.82);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.how-to span::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(255, 200, 78, 0.18);
}

.mode-chooser,
.avatar-chooser {
  display: grid;
  gap: 7px;
  margin: 0;
}

.chooser-title {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-option {
  display: grid;
  gap: 3px;
  min-height: 52px;
  padding: 8px 10px;
  border: 2px solid rgba(23, 49, 74, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.mode-option strong {
  font-size: 15px;
  font-weight: 900;
}

.mode-option span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.mode-option.selected {
  border-color: var(--teal);
  background: rgba(229, 255, 247, 0.9);
  box-shadow: 0 0 0 4px rgba(19, 185, 173, 0.13);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.avatar-option {
  display: grid;
  justify-items: center;
  gap: 5px;
  min-height: 80px;
  padding: 6px 6px 7px;
  border: 2px solid rgba(23, 49, 74, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.avatar-option img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 8px 18px rgba(23, 49, 74, 0.16);
}

.avatar-option.selected {
  border-color: var(--gold);
  background: rgba(255, 247, 209, 0.88);
  box-shadow: 0 0 0 4px rgba(255, 200, 78, 0.16);
}

.login-box {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.login-box input {
  width: 100%;
  height: 42px;
  border: 2px solid rgba(19, 185, 173, 0.28);
  border-radius: 8px;
  outline: none;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 900;
}

.login-box input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(19, 185, 173, 0.13);
}

.login-tip {
  min-height: 16px;
  margin-top: -3px !important;
  color: var(--muted) !important;
  font-size: 12px !important;
  text-transform: none !important;
}

.login-tip.error {
  color: var(--coral) !important;
}

.modal-hint {
  min-height: 16px;
  margin-top: -2px !important;
  color: var(--teal) !important;
  text-transform: none !important;
}

.home-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 0;
}

.primary-action,
.ghost-action {
  height: 44px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}

.primary-action {
  width: 100%;
  border: 0;
  background: linear-gradient(135deg, #17314a, #13b9ad);
  color: #fff;
  box-shadow: 0 14px 30px rgba(19, 185, 173, 0.25);
}

.ghost-action {
  min-width: 96px;
  padding: 0 16px;
  border: 2px solid rgba(23, 49, 74, 0.12);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  box-shadow: 0 12px 26px rgba(23, 49, 74, 0.1);
}

.leaderboard-panel {
  position: absolute;
  inset: 18px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(245, 253, 252, 0.68);
  backdrop-filter: blur(12px);
  z-index: 4;
}

.leaderboard-panel.hidden {
  display: none;
}

.leaderboard {
  width: min(320px, 100%);
  padding: 18px;
  text-align: left;
}

.leaderboard-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--ink);
  font-weight: 900;
}

.leaderboard-head span {
  font-size: 20px;
}

.leaderboard-head b {
  margin-left: auto;
  color: var(--teal);
  font-size: 12px;
}

.leaderboard-close {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(23, 49, 74, 0.1);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.leaderboard ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.leaderboard li.current-player {
  background: rgba(255, 200, 78, 0.24);
  outline: 2px solid rgba(255, 200, 78, 0.36);
}

.leaderboard .rank {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(23, 49, 74, 0.1);
  color: var(--muted);
  font-size: 12px;
}

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

.leaderboard .points {
  color: var(--coral);
}

.leaderboard .time {
  color: var(--muted);
  font-size: 12px;
}

.empty-rank {
  display: block !important;
  color: var(--muted) !important;
  text-align: center;
}

@media (max-width: 680px) {
  .game-shell {
    min-height: 0;
  }

  .hud {
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
  }

  .brand {
    display: none;
  }

  .question-card {
    grid-column: 1 / -1;
    grid-row: 2;
    min-height: 78px;
    margin-top: 2px;
    padding: 10px 14px 12px;
  }

  .question {
    font-size: 28px;
  }

  .score-stack {
    position: static;
    transform: none;
    justify-self: start;
    min-width: 74px;
    text-align: left;
  }

  .score {
    height: 40px;
    font-size: 42px;
  }

  .combo {
    min-height: 16px;
    font-size: 12px;
  }

  .hud-actions {
    grid-column: 2;
    gap: 6px;
  }

  .lives {
    min-width: 72px;
    min-height: 40px;
    padding: 0 10px;
    font-size: 15px;
  }

  .player-badge {
    display: none;
  }

  .best {
    display: none;
  }

  .timer {
    min-height: 40px;
    padding: 0 10px;
    font-size: 12px;
    gap: 5px;
  }

  .timer b {
    font-size: 13px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .overlay.start-screen {
    overflow-y: auto;
    padding: 16px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.88) 0%, rgba(255, 255, 255, 0.45) 52%, rgba(255, 255, 255, 0.12) 100%),
      url("assets/math-island-bg.webp") center / cover no-repeat;
  }

  .modal.home-card {
    align-self: start;
    justify-self: stretch;
    grid-template-columns: 1fr;
    width: 100%;
    max-height: none;
    margin-left: 0;
    padding: 0;
    gap: 12px;
    background: transparent;
  }

  .home-copy {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 22px 18px 20px;
  }

  .modal h1.game-title {
    font-size: 42px;
  }

  .leaderboard {
    padding: 15px;
  }

  .leaderboard-panel {
    inset: 0;
  }

  .home-actions {
    grid-template-columns: 1fr;
  }

  .ghost-action {
    width: 100%;
  }

  .avatar-grid {
    grid-template-columns: repeat(4, minmax(62px, 1fr));
    gap: 7px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .avatar-option {
    min-height: 86px;
  }

  .avatar-option img {
    width: 52px;
    height: 52px;
  }
}
