:root {
  --bg: #070b16;
  --panel: #10182b;
  --line: rgba(232, 195, 106, 0.28);
  --gold: #e8c36a;
  --gold-2: #f6e3a8;
  --cyan: #5ee7ff;
  --pink: #ff7ad9;
  --text: #f4f1e8;
  --muted: #9aa6c2;
  --danger: #ff5d7a;
  --ok: #6dffb0;
  --cell: #161e33;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #05060a;
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  touch-action: none;
}

body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  width: 390px;
  height: 844px;
  max-width: 100vw;
  max-height: 100dvh;
  overflow: hidden;
  border-radius: 28px;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(94, 231, 255, 0.16), transparent 50%),
    radial-gradient(90% 50% at 100% 80%, rgba(232, 195, 106, 0.1), transparent 45%),
    var(--bg);
  box-shadow: 0 0 0 8px #141824, var(--shadow);
  touch-action: manipulation;
}

@media (max-width: 420px) {
  #stage {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
}

.aurora {
  pointer-events: none;
  position: absolute;
  inset: -20% -10% auto;
  height: 52%;
  background:
    radial-gradient(circle at 30% 40%, rgba(94, 231, 255, 0.18), transparent 42%),
    radial-gradient(circle at 72% 20%, rgba(232, 195, 106, 0.16), transparent 38%);
  filter: blur(8px);
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(22px + env(safe-area-inset-top)) 18px calc(16px + env(safe-area-inset-bottom));
  z-index: 1;
}

.screen.hidden,
.hidden {
  display: none !important;
}

.overlay {
  z-index: 5;
  background: rgba(5, 8, 16, 0.72);
  backdrop-filter: blur(10px);
  justify-content: center;
}

.home-head {
  text-align: center;
  padding: 18px 8px 8px;
}

.eyebrow {
  margin: 0 0 10px;
  letter-spacing: 0.22em;
  font-size: 12px;
  color: var(--gold);
}

.home-head h1 {
  margin: 0;
  font-size: 46px;
  letter-spacing: 0.12em;
  background: linear-gradient(180deg, var(--gold-2), var(--gold) 60%, #b8892d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 24px rgba(232, 195, 106, 0.2);
}

.tagline {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 22px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  min-height: 118px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(232, 195, 106, 0.08), rgba(16, 24, 43, 0.92));
  color: inherit;
  text-align: left;
  box-shadow: var(--shadow);
}

.mode-card:active {
  transform: scale(0.985);
}

.mode-kicker {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--cyan);
}

.mode-title {
  font-size: 24px;
  font-weight: 700;
}

.mode-desc {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.home-foot {
  margin-top: auto;
  padding-top: 16px;
}

.best-label {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.12em;
}

.best-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.best-row div {
  padding: 12px;
  border-radius: 14px;
  background: rgba(16, 24, 43, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.best-row span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.best-row strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

.play-hud {
  display: grid;
  grid-template-columns: 64px 1fr 72px;
  align-items: center;
  gap: 8px;
}

.hud-mid {
  text-align: center;
}

.hud-mid p {
  margin: 0;
}

#hud-level {
  font-size: 18px;
  font-weight: 700;
}

#hud-combo {
  margin-top: 2px;
  font-size: 12px;
  color: var(--gold);
}

.hud-time {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(94, 231, 255, 0.1);
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.hud-time.low {
  background: rgba(255, 93, 122, 0.16);
  color: var(--danger);
}

.phase-banner {
  margin: 12px 0 10px;
  min-height: 42px;
  text-align: center;
}

#phase-text {
  margin: 8px 0 0;
  font-size: 15px;
  color: var(--gold-2);
}

.flash-track {
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.flash-track i {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
}

.flash-track.running i {
  animation: drain 3s linear forwards;
}

@keyframes drain {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

.board {
  flex: 1;
  display: grid;
  place-content: center;
  gap: 8px;
  min-height: 0;
}

.board.shake {
  animation: shake 0.38s ease;
}

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

.cell {
  width: 100%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: var(--cell);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  position: relative;
}

.cell.lit,
.cell.picked {
  background: radial-gradient(circle at 40% 30%, #9af3ff, var(--cyan) 55%, #1c7f90);
  box-shadow: 0 0 18px rgba(94, 231, 255, 0.45);
  color: #042028;
}

.cell.picked {
  background: radial-gradient(circle at 40% 30%, #ffe9a8, var(--gold) 55%, #8a6918);
  box-shadow: 0 0 16px rgba(232, 195, 106, 0.4);
  color: #2a1d04;
}

.cell.seq-on {
  outline: 2px solid var(--gold-2);
}

.card {
  width: 100%;
  aspect-ratio: 0.86;
  perspective: 700px;
  border: 0;
  padding: 0;
  background: transparent;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
}

.card.open .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  backface-visibility: hidden;
  font-size: 28px;
}

.card-face.back {
  background: linear-gradient(160deg, #223056, #141c30);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--gold);
  font-size: 20px;
  letter-spacing: 0.2em;
}

.card-face.front {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #22324f, #172238);
  box-shadow: inset 0 0 0 1px rgba(94, 231, 255, 0.25);
}

.card.matched .card-face.front {
  box-shadow: inset 0 0 0 2px var(--ok);
}

.play-foot {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 8px;
}

#hint-text {
  margin: 0;
  min-height: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.primary-btn,
.ghost-btn {
  border: 0;
  min-height: 52px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  color: #1b1406;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
}

.primary-btn:active,
.mode-card:active,
.ghost-btn:active,
.cell:active,
.card:active {
  transform: scale(0.98);
}

.primary-btn:disabled {
  opacity: 0.4;
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-height: 40px;
  font-size: 14px;
}

.ghost-btn.wide {
  width: 100%;
  min-height: 48px;
}

.result-card {
  width: 100%;
  padding: 28px 20px 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(232, 195, 106, 0.12), var(--panel));
  border: 1px solid var(--line);
  text-align: center;
  box-shadow: var(--shadow);
}

.result-kicker {
  margin: 0;
  letter-spacing: 0.18em;
  color: var(--cyan);
  font-size: 12px;
}

.result-card h2 {
  margin: 8px 0 18px;
  font-size: 34px;
}

.result-score {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
}

.result-score strong {
  font-size: 40px;
  color: var(--gold-2);
}

.result-best,
.result-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#btn-retry {
  width: 100%;
  margin-top: 22px;
}

#btn-home {
  margin-top: 10px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 138px;
  transform: translateX(-50%);
  z-index: 8;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(16, 24, 43, 0.94);
  border: 1px solid var(--line);
  color: var(--gold-2);
  font-weight: 700;
  pointer-events: none;
}

.toast.hidden {
  display: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}
