:root {
  --bg: #090d22;
  --panel: rgba(19, 25, 61, .78);
  --panel-strong: rgba(17, 22, 54, .92);
  --panel-border: rgba(255, 255, 255, .13);
  --text: #f9f8ff;
  --muted: #aeb2d4;
  --cyan: #68e7f5;
  --yellow: #ffdc70;
  --pink: #ff75b7;
  --purple: #a18aff;
  --green: #76e6a6;
  --shadow: 0 24px 70px rgba(0, 0, 0, .32);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 4%, rgba(161, 138, 255, .2), transparent 28rem),
    radial-gradient(circle at 90% 17%, rgba(104, 231, 245, .12), transparent 24rem),
    var(--bg);
}

button { font: inherit; }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

.game-shell {
  width: min(100% - 32px, 720px);
  margin: 0 auto;
  padding: 28px 0 26px;
}

.topbar, .hud, .tip-row { position: relative; z-index: 2; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow, .mini-label {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .18em;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(27px, 6vw, 42px);
  line-height: 1;
  letter-spacing: -.06em;
}

.sound-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  color: var(--text);
  background: rgba(255, 255, 255, .07);
  cursor: pointer;
  transition: .2s ease;
}

.sound-button:hover { border-color: var(--cyan); transform: translateY(-2px); }

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-bottom: 12px;
}

.hud-card {
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 15px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hud-card span, .hud-card small {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .06em;
}

.hud-card span { display: block; }

.hud-card strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: clamp(18px, 4vw, 24px);
  letter-spacing: .02em;
}

.hud-card strong small { margin-left: 3px; font-weight: 700; }

.stage-wrap {
  position: relative;
  height: min(68vh, 620px);
  min-height: 470px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 26px;
  background: #111936;
  box-shadow: var(--shadow);
  isolation: isolate;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.play-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 34px clamp(18px, 6vw, 52px) 26px;
  opacity: 0;
  pointer-events: none;
  transform: scale(.98);
  transition: opacity .22s ease, transform .22s ease;
}

.play-layer.is-active { opacity: 1; pointer-events: auto; transform: scale(1); }

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

.mini-label { margin-bottom: 5px; color: var(--muted); letter-spacing: .1em; }

.challenge-head strong {
  display: block;
  font-size: clamp(27px, 8vw, 46px);
  line-height: .95;
  letter-spacing: -.06em;
}

.round-badge, .scope-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(104, 231, 245, .24);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(104, 231, 245, .08);
  font-size: 11px;
  white-space: nowrap;
}

.round-badge b { margin: 0 3px; color: var(--text); }

.color-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(9px, 2vw, 14px);
  width: min(100%, 440px);
  margin: 0 auto;
}

.color-tile {
  position: relative;
  display: grid;
  min-height: clamp(72px, 15vw, 108px);
  place-items: center;
  border: 2px solid rgba(255, 255, 255, .24);
  border-radius: 19px;
  box-shadow: inset 0 1px rgba(255, 255, 255, .22), 0 12px 24px rgba(0, 0, 0, .12);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .13s ease, filter .13s ease, border-color .13s ease;
}

.color-tile::after {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, .7);
  border-radius: 50%;
  content: "";
  opacity: .8;
}

.color-tile:hover { filter: brightness(1.08); transform: translateY(-3px); }
.color-tile:active { transform: scale(.94); }
.color-tile.is-correct { border-color: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, .15), 0 0 30px rgba(255, 255, 255, .22); }
.color-tile.is-wrong { border-color: var(--pink); animation: shake .22s ease; }

.feedback {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.feedback.is-good { color: var(--green); }
.feedback.is-bad { color: var(--pink); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-6px); }
  70% { transform: translateX(6px); }
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 9, 27, .48);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

.screen.is-visible { opacity: 1; pointer-events: auto; }

.screen-card {
  width: min(100%, 430px);
  padding: clamp(24px, 6vw, 42px);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 25px;
  background: var(--panel-strong);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  backdrop-filter: blur(18px);
}

.color-mark {
  display: flex;
  gap: 7px;
  margin-bottom: 24px;
}

.color-mark i {
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, .44);
  border-radius: 6px;
  transform: rotate(12deg);
}

.color-mark i:nth-child(1) { background: #ff8066; }
.color-mark i:nth-child(2) { background: #68e7f5; transform: translateY(-5px) rotate(12deg); }
.color-mark i:nth-child(3) { background: #ffdc70; }

.screen-card h2 {
  margin-bottom: 18px;
  font-size: clamp(42px, 11vw, 70px);
  line-height: .92;
  letter-spacing: -.08em;
}

.screen-card h2 em { color: var(--yellow); font-style: normal; }

.screen-copy {
  max-width: 34ch;
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.primary-button, .secondary-button {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-radius: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: .2s ease;
}

.primary-button {
  width: 100%;
  border: 0;
  color: #161127;
  background: var(--yellow);
  box-shadow: 0 12px 30px rgba(255, 219, 110, .18);
}

.primary-button:hover, .primary-button:focus-visible { transform: translateY(-2px); box-shadow: 0 16px 34px rgba(255, 219, 110, .28); }

.secondary-button {
  width: 100%;
  border: 1px solid rgba(104, 231, 245, .34);
  color: var(--text);
  background: rgba(104, 231, 245, .1);
}

.secondary-button:hover, .secondary-button:focus-visible { border-color: var(--cyan); background: rgba(104, 231, 245, .16); }

.best-line { margin: 18px 0 0; color: var(--muted); font-size: 12px; }
.best-line strong { color: var(--yellow); }

.final-score {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin: 22px 0 12px;
  padding: 18px 0;
  border-top: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
  color: var(--muted);
  font-size: 13px;
}

.final-score strong { color: var(--yellow); font-size: 52px; line-height: .8; }

.result-stats {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 12px;
}

.result-stats b { margin-left: 3px; color: var(--text); }

.action-row { display: grid; gap: 9px; }
.share-status { min-height: 16px; margin: 10px 0 0; color: var(--green); font-size: 11px; text-align: center; }

.tip-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 18px 0 12px;
}

.tip-row p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; text-align: center; }
.tip-row p span { color: rgba(174, 178, 212, .68); }
.tip-icon { color: var(--yellow); font-size: 14px; }

.leaderboard-panel {
  margin-top: 7px;
  padding: 20px;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading .eyebrow { margin-bottom: 5px; }
.section-heading h2 { margin: 0; font-size: 23px; letter-spacing: -.06em; }
.scope-chip { min-height: 24px; color: var(--muted); border-color: var(--panel-border); background: rgba(255, 255, 255, .05); font-size: 10px; }

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

.leaderboard-item, .leaderboard-empty {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  min-height: 42px;
  padding: 0 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .05);
  font-size: 12px;
}

.leaderboard-item.is-top { background: rgba(255, 220, 112, .1); }
.leaderboard-rank { color: var(--yellow); font-weight: 800; }
.leaderboard-name { color: var(--text); }
.leaderboard-date { margin-left: 8px; color: var(--muted); font-size: 10px; }
.leaderboard-score { color: var(--cyan); font-size: 15px; font-weight: 800; }
.leaderboard-empty { display: block; padding: 13px; color: var(--muted); text-align: center; }
.leaderboard-note { margin: 12px 0 0; color: rgba(174, 178, 212, .68); font-size: 10px; line-height: 1.5; }

.footer-note { margin-top: 18px; color: rgba(174, 178, 212, .64); font-size: 11px; text-align: center; }

@media (max-width: 480px) {
  .game-shell { width: min(100% - 20px, 720px); padding-top: 18px; }
  .stage-wrap { min-height: 500px; border-radius: 21px; }
  .screen-card { padding: 25px 22px; }
  .play-layer { gap: 18px; padding: 30px 16px 22px; }
  .color-tile { min-height: 78px; border-radius: 15px; }
  .leaderboard-panel { padding: 17px; }
}
