:root {
  color-scheme: dark;
  --bg-0: #06150f;
  --bg-1: #0a2a1d;
  --bg-2: #0c4a32;
  --panel: rgba(7, 24, 18, 0.78);
  --panel-strong: rgba(5, 18, 14, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --line-bright: rgba(151, 255, 208, 0.36);
  --text: #f6fff9;
  --muted: #a8c6b6;
  --accent: #70f3ad;
  --accent-2: #24c978;
  --gold: #ffd978;
  --danger: #ff6d7a;
  --card-w: clamp(42px, 7vw, 92px);
  --card-h: calc(var(--card-w) * 1.42);
  --card-step: clamp(18px, 2.3vw, 31px);
  --radius: 20px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  --card-shadow: 0 8px 18px rgba(0, 0, 0, 0.28), 0 1px 0 rgba(255,255,255,.7) inset;
}

:root[data-theme="aurora"] {
  --bg-0: #081025;
  --bg-1: #12285c;
  --bg-2: #3057aa;
  --panel: rgba(8, 15, 38, 0.76);
  --panel-strong: rgba(7, 13, 30, 0.92);
  --line-bright: rgba(137, 195, 255, 0.42);
  --accent: #8ce4ff;
  --accent-2: #75a9ff;
  --muted: #b6c9ee;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 15%, rgba(89, 255, 171, .16), transparent 30%),
    radial-gradient(circle at 88% 8%, rgba(80, 210, 255, .12), transparent 28%),
    radial-gradient(circle at 80% 86%, rgba(255, 220, 118, .10), transparent 22%),
    linear-gradient(145deg, var(--bg-0), var(--bg-1) 55%, var(--bg-2));
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .38;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, #000, transparent 80%);
}

button, input, select { font: inherit; }
button { color: inherit; }

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app-shell {
  width: min(1240px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0 28px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.025));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-size: 21px;
  font-weight: 900;
  color: #062316;
  background: linear-gradient(145deg, #d9ffe9, var(--accent));
  box-shadow: 0 0 28px rgba(112, 243, 173, .22);
}

.brand-copy { line-height: 1.05; }
.brand-copy strong { display: block; font-size: 14px; letter-spacing: .14em; }
.brand-copy span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; letter-spacing: .09em; text-transform: uppercase; }

.stat-strip {
  display: flex;
  justify-content: center;
  gap: clamp(6px, 1.4vw, 18px);
  min-width: 0;
}

.stat {
  min-width: 72px;
  padding: 7px 10px;
  text-align: center;
  border-left: 1px solid var(--line);
}
.stat:first-child { border-left: 0; }
.stat small { display: block; color: var(--muted); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
.stat strong { display: block; margin-top: 2px; font-variant-numeric: tabular-nums; font-size: 15px; }

.icon-actions { display: flex; gap: 7px; }
.icon-btn, .action-btn, .mini-btn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, border-color .16s ease, opacity .16s ease;
}
.icon-btn:hover, .action-btn:hover, .mini-btn:hover { transform: translateY(-1px); border-color: var(--line-bright); background: rgba(255,255,255,.10); }
.icon-btn:active, .action-btn:active, .mini-btn:active { transform: translateY(0) scale(.98); }
.icon-btn:disabled, .action-btn:disabled { opacity: .34; cursor: not-allowed; transform: none; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  font-size: 16px;
}

.control-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(3, 17, 12, .40);
  backdrop-filter: blur(12px);
}

.control-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.action-btn, .mini-btn {
  min-height: 38px;
  border-radius: 11px;
  padding: 0 12px;
  font-size: 13px;
}
.action-btn.primary {
  border-color: rgba(112, 243, 173, .38);
  color: #062316;
  font-weight: 800;
  background: linear-gradient(135deg, #caffdf, var(--accent));
  box-shadow: 0 8px 24px rgba(37, 211, 119, .16);
}
.action-btn.primary:hover { background: linear-gradient(135deg, #e6fff0, #90f8bd); }

.level-picker {
  display: flex;
  align-items: center;
  overflow: hidden;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.055);
}
.level-picker button {
  width: 34px;
  height: 100%;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.level-picker button:hover { color: var(--text); background: rgba(255,255,255,.08); }
.level-picker input {
  width: 76px;
  height: 100%;
  padding: 0 5px;
  border: 0;
  border-inline: 1px solid var(--line);
  outline: 0;
  color: var(--text);
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: transparent;
}

.draw-select {
  height: 38px;
  padding: 0 30px 0 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: var(--panel-strong);
}

.game-surface {
  position: relative;
  min-height: clamp(560px, 76vh, 860px);
  overflow: hidden;
  padding: clamp(14px, 2.2vw, 26px);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 26px;
  background:
    radial-gradient(circle at 50% -20%, rgba(255,255,255,.10), transparent 42%),
    linear-gradient(160deg, rgba(18, 95, 62, .72), rgba(7, 54, 37, .82));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), var(--shadow);
}

:root[data-theme="aurora"] .game-surface {
  background:
    radial-gradient(circle at 45% -20%, rgba(120, 209, 255, .17), transparent 45%),
    linear-gradient(160deg, rgba(24, 59, 122, .74), rgba(11, 31, 74, .88));
}

.game-surface::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .16;
  background-image: radial-gradient(rgba(255,255,255,.75) .6px, transparent .7px);
  background-size: 12px 12px;
}

.board-top, .tableau {
  position: relative;
  z-index: 2;
}

.board-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.stock-zone, .foundation-zone { display: flex; gap: clamp(7px, 1.2vw, 14px); }
.foundation-wrap { width: var(--card-w); height: var(--card-h); }
.pile { width: var(--card-w); height: var(--card-h); }

.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  flex: 0 0 auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.18);
  border-radius: clamp(6px, .8vw, 11px);
  box-shadow: var(--card-shadow);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button.card { cursor: pointer; }
.card.face {
  color: #18201c;
  background:
    radial-gradient(circle at 50% 25%, rgba(255,255,255,.92), transparent 45%),
    linear-gradient(145deg, #ffffff, #eef4ef);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.card.face:hover { transform: translateY(-2px); box-shadow: 0 12px 24px rgba(0,0,0,.34); }
.card.face.red { color: #d72f45; }
.card.selected, .stack-selected .card {
  transform: translateY(-7px);
  box-shadow: 0 0 0 3px var(--gold), 0 14px 32px rgba(0,0,0,.35);
  filter: saturate(1.14);
}

.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: .92;
  font-size: clamp(10px, 1.25vw, 17px);
}
.corner b { font-weight: 850; }
.corner i { margin-top: 3px; font-style: normal; font-size: .92em; }
.corner.top { top: 7%; left: 8%; }
.corner.bottom { right: 8%; bottom: 7%; transform: rotate(180deg); }
.suit-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(19px, 3.1vw, 42px);
  opacity: .92;
}

.card-back {
  display: grid;
  place-items: center;
  border: 2px solid rgba(255,255,255,.84);
  background:
    linear-gradient(45deg, rgba(255,255,255,.10) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.10) 75%),
    linear-gradient(45deg, rgba(255,255,255,.10) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.10) 75%),
    linear-gradient(145deg, #143d31, #091d18);
  background-size: 14px 14px;
  background-position: 0 0, 7px 7px, 0 0;
  box-shadow: inset 0 0 0 3px rgba(8, 24, 19, .72), var(--card-shadow);
}
:root[data-theme="aurora"] .card-back { background-color: #142e67; background-image: linear-gradient(45deg, rgba(255,255,255,.10) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.10) 75%), linear-gradient(45deg, rgba(255,255,255,.10) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.10) 75%), linear-gradient(145deg, #244786, #0d214a); }

.card-back-emblem {
  display: grid;
  place-items: center;
  width: 45%;
  aspect-ratio: 1;
  border: 1px solid rgba(255,255,255,.42);
  border-radius: 50%;
  color: rgba(255,255,255,.90);
  font-size: clamp(13px, 2vw, 26px);
  font-weight: 900;
  text-shadow: 0 0 18px rgba(255,255,255,.25);
}
.stock-count {
  position: absolute;
  right: 6px;
  bottom: 5px;
  min-width: 20px;
  padding: 2px 5px;
  border-radius: 999px;
  color: #071c13;
  font-size: 10px;
  font-weight: 900;
  background: var(--accent);
}

.card.slot {
  display: grid;
  place-items: center;
  border: 1.5px dashed rgba(255,255,255,.22);
  box-shadow: inset 0 0 24px rgba(0,0,0,.10);
  background: rgba(0,0,0,.10);
}
button.card.slot:hover { border-color: rgba(255,255,255,.42); background: rgba(255,255,255,.04); }
.slot-icon { font-size: clamp(20px, 2.8vw, 34px); color: var(--accent); }
.slot-icon.muted { color: rgba(255,255,255,.15); }
.slot-suit { font-size: clamp(22px, 3vw, 39px); opacity: .32; }
.slot-suit.red { color: #ff8c98; }
.slot-label {
  position: absolute;
  bottom: 10%;
  left: 0;
  right: 0;
  color: rgba(255,255,255,.38);
  text-align: center;
  font-size: clamp(7px, .7vw, 10px);
  letter-spacing: .08em;
}

.tableau {
  display: grid;
  grid-template-columns: repeat(7, var(--card-w));
  justify-content: space-between;
  gap: clamp(4px, 1.15vw, 15px);
  margin-top: clamp(22px, 3.2vw, 38px);
}
.tableau-column {
  position: relative;
  width: var(--card-w);
  min-height: calc(var(--card-h) + 18 * var(--card-step));
}
.tableau-card {
  position: absolute;
  top: calc(var(--i) * var(--card-step));
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
}
.tableau-card .card { position: absolute; inset: 0; }

.hint-pulse {
  animation: hintPulse .72s ease-in-out 3;
  z-index: 120 !important;
}
@keyframes hintPulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255,217,120,0)); }
  50% { filter: drop-shadow(0 0 12px rgba(255,217,120,.95)); }
}

.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 4px 0;
  color: var(--muted);
  font-size: 11px;
}
.game-footer kbd {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
  background: rgba(255,255,255,.06);
}

.toast {
  position: fixed;
  z-index: 500;
  left: 50%;
  bottom: 28px;
  max-width: min(90vw, 560px);
  padding: 11px 16px;
  border: 1px solid var(--line-bright);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 18px) scale(.96);
  color: var(--text);
  text-align: center;
  font-size: 13px;
  background: rgba(4, 18, 13, .92);
  box-shadow: 0 16px 45px rgba(0,0,0,.36);
  backdrop-filter: blur(16px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast[data-tone="error"] { border-color: rgba(255,109,122,.55); }
.toast[data-tone="hint"] { border-color: rgba(255,217,120,.62); }

.modal {
  position: fixed;
  z-index: 600;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  background: rgba(0, 8, 5, .58);
  backdrop-filter: blur(10px);
  transition: opacity .2s ease, visibility .2s ease;
}
.modal.open { opacity: 1; visibility: visible; }
.modal-card {
  width: min(94vw, 520px);
  padding: 28px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 24px;
  transform: translateY(12px) scale(.97);
  background: linear-gradient(155deg, rgba(18,48,36,.98), rgba(5,17,13,.98));
  box-shadow: 0 34px 90px rgba(0,0,0,.48);
  transition: transform .22s ease;
}
.modal.open .modal-card { transform: translateY(0) scale(1); }
.modal-badge {
  display: inline-flex;
  padding: 5px 9px;
  border: 1px solid rgba(112,243,173,.28);
  border-radius: 999px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.modal h2 { margin: 14px 0 8px; font-size: clamp(25px, 5vw, 38px); }
.modal p { margin: 0; color: var(--muted); line-height: 1.75; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.win-stats { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.win-stats span { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; background: rgba(255,255,255,.05); }

.rules {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
}
.rule {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: start;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.rule b {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--accent);
  background: rgba(255,255,255,.04);
}

.confetti-layer { position: fixed; z-index: 700; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-layer i {
  position: absolute;
  top: -40px;
  left: var(--x);
  font-style: normal;
  font-size: 20px;
  animation: confettiFall 3s var(--delay) cubic-bezier(.18,.7,.2,1) forwards;
}
@keyframes confettiFall {
  to { transform: translateY(112vh) rotate(var(--spin)); opacity: .05; }
}

@media (max-width: 860px) {
  :root { --card-w: clamp(40px, 11.1vw, 72px); --card-step: clamp(17px, 3.7vw, 25px); }
  .topbar { grid-template-columns: 1fr auto; }
  .stat-strip { grid-column: 1 / -1; grid-row: 2; order: 3; justify-content: stretch; }
  .stat { flex: 1; min-width: 0; }
  .control-panel { align-items: stretch; flex-direction: column; }
  .control-group { justify-content: center; }
  .board-top { gap: 14px; }
}

@media (max-width: 620px) {
  :root { --card-w: clamp(36px, 11.6vw, 58px); --card-step: clamp(17px, 4.4vw, 22px); }
  .app-shell { width: min(100% - 12px, 1240px); padding-top: 6px; }
  .topbar { padding: 8px; border-radius: 15px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .brand-copy strong { font-size: 12px; }
  .brand-copy span { font-size: 9px; }
  .icon-btn { width: 34px; height: 34px; }
  .stat { padding: 5px 3px; }
  .stat small { font-size: 8px; }
  .stat strong { font-size: 13px; }
  .control-panel { margin: 7px 0; padding: 8px; border-radius: 14px; }
  .control-group { gap: 5px; }
  .action-btn, .mini-btn, .draw-select { min-height: 34px; height: 34px; padding-inline: 9px; font-size: 11px; }
  .level-picker { height: 34px; }
  .level-picker input { width: 64px; font-size: 11px; }
  .game-surface { min-height: 70vh; padding: 10px 8px 18px; border-radius: 18px; }
  .board-top { gap: 6px; }
  .stock-zone, .foundation-zone { gap: 5px; }
  .tableau { gap: 4px; margin-top: 18px; }
  .corner.top { top: 6%; left: 7%; }
  .corner.bottom { right: 7%; bottom: 6%; }
  .slot-label { display: none; }
  .game-footer { font-size: 9px; }
  .desktop-only { display: none; }
}

@media (max-width: 390px) {
  :root { --card-w: clamp(36px, 10.6vw, 41px); --card-step: 18px; }
  .brand-copy span { display: none; }
  .action-btn[data-compact="true"] span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
