:root {
  color-scheme: dark;
  --ink: #fff8ee;
  --muted: #b9c4d8;
  --line: rgba(255, 255, 255, 0.18);
  --panel: rgba(12, 21, 42, 0.94);
  --blue: #54c7ff;
  --green: #42d97b;
  --red: #ff5d73;
  --gold: #ffd166;
  --felt: #0b6b4b;
  --card-w: clamp(42px, 12.2vw, 70px);
  --card-h: calc(var(--card-w) * 1.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 209, 102, 0.16), transparent 27%),
    radial-gradient(circle at 82% 10%, rgba(84, 199, 255, 0.22), transparent 30%),
    linear-gradient(155deg, #08122d 0%, #12335d 52%, #090f1f 100%);
  color: var(--ink);
  touch-action: manipulation;
  user-select: none;
}

button {
  font: inherit;
}

.shell {
  display: grid;
  width: 100vw;
  height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  place-items: center;
}

.game {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1.15dvh, 10px);
  width: min(100%, 640px);
  height: min(100%, 920px);
  min-height: 0;
}

.brand-header {
  display: grid;
  min-height: clamp(42px, 8dvh, 58px);
  place-items: center;
  text-align: center;
}

.solitaire-logo {
  color: transparent;
  font-size: clamp(1.45rem, min(6.5dvw, 5.4dvh), 2.8rem);
  font-weight: 1000;
  line-height: 0.9;
  background: linear-gradient(90deg, #ffd166 0%, #fff8ee 34%, #54c7ff 68%, #42d97b 100%);
  background-clip: text;
  -webkit-background-clip: text;
  filter: drop-shadow(0 5px 0 rgba(5, 10, 24, 0.48)) drop-shadow(0 0 16px rgba(84, 199, 255, 0.34));
  letter-spacing: 0;
  text-transform: uppercase;
}

.site-tag {
  margin-top: 3px;
  color: rgba(255, 248, 238, 0.78);
  font-size: clamp(0.62rem, min(2.2dvw, 1.9dvh), 0.88rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.topbar,
.bottombar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: center;
  gap: clamp(4px, 1.1vw, 8px);
}

.topbar {
  grid-template-columns: 1fr 1fr 1fr;
}

.metric {
  min-width: 0;
  padding: clamp(5px, 1dvh, 8px) 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
}

.metric.center {
  text-align: center;
}

.metric.right {
  text-align: right;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(0.95rem, 2.6dvh, 1.12rem);
}

.table {
  position: relative;
  display: grid;
  min-height: 0;
  gap: clamp(8px, 1.4dvh, 12px);
  padding: clamp(8px, 1.5dvh, 12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0)),
    radial-gradient(circle at 50% 10%, rgba(84,199,255,0.12), transparent 34%),
    var(--felt);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18), 0 18px 48px rgba(0, 0, 0, 0.24);
}

.table::before {
  content: "Bleeping Solitaire!";
  position: absolute;
  inset: 45% 0 auto;
  color: rgba(255, 248, 238, 0.09);
  font-size: clamp(2rem, 9vw, 4rem);
  font-weight: 1000;
  line-height: 0.9;
  pointer-events: none;
  text-align: center;
  text-transform: uppercase;
}

.top-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, var(--card-w)) 1fr var(--card-w) var(--card-w);
  gap: clamp(5px, 1.1vw, 10px);
}

.tableau {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 0;
  grid-template-columns: repeat(7, minmax(0, var(--card-w)));
  gap: clamp(5px, 1.1vw, 10px);
  justify-content: space-between;
}

.column {
  position: relative;
  min-height: calc(var(--card-h) + 260px);
}

.pile,
.card,
.empty-slot {
  width: var(--card-w);
  min-width: 0;
  height: var(--card-h);
  border-radius: 8px;
}

.pile,
.empty-slot {
  display: grid;
  border: 2px dashed rgba(255, 255, 255, 0.28);
  place-items: center;
  background: rgba(0, 0, 0, 0.12);
  color: rgba(255, 248, 238, 0.42);
  font-size: clamp(1rem, 4.5vw, 1.7rem);
  font-weight: 950;
}

.pile {
  cursor: pointer;
}

.card {
  position: absolute;
  left: 0;
  display: grid;
  padding: 5px;
  border: 0;
  background: #fff8ee;
  color: #151314;
  cursor: pointer;
  font-weight: 950;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  text-align: left;
}

.waste .card,
.foundation .card,
.stock .card {
  position: relative;
}

.card.face-down {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.12) 0 6px, transparent 6px 12px),
    linear-gradient(145deg, #1266ff, #0a2c80);
  color: transparent;
}

.stock-back {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.12) 0 6px, transparent 6px 12px),
    linear-gradient(145deg, #1266ff, #0a2c80);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.card.red {
  color: #d21f3c;
}

.card.black {
  color: #101725;
}

.card.selected {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  transform: translateY(-3px);
}

.flying-card {
  position: fixed !important;
  z-index: 30;
  margin: 0;
  pointer-events: none;
  transition: transform 280ms cubic-bezier(0.2, 0.85, 0.22, 1);
}

.card-rank {
  font-size: clamp(0.82rem, 3.1vw, 1.1rem);
}

.card-suit {
  display: grid;
  place-items: center;
  font-size: clamp(1.65rem, 7vw, 2.55rem);
  line-height: 1;
}

.card-small {
  justify-self: end;
  align-self: end;
  font-size: clamp(0.82rem, 3.1vw, 1.1rem);
  transform: rotate(180deg);
}

.stock-count {
  position: absolute;
  right: 6px;
  bottom: 5px;
  z-index: 1;
  color: rgba(255, 248, 238, 0.9);
  font-size: 0.78rem;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.small-button,
.secondary-button,
.primary-button,
.arcade-button,
.store-button {
  min-height: clamp(38px, 6.4dvh, 48px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  width: 100%;
  border: 0;
  background: var(--blue);
  color: #111314;
  box-shadow: 0 10px 28px rgba(84, 199, 255, 0.24);
}

.secondary-button,
.arcade-button,
.store-button {
  width: 100%;
  margin-top: 10px;
}

.arcade-button {
  border-color: rgba(84, 199, 255, 0.48);
  background: rgba(84, 199, 255, 0.34);
}

.store-button {
  border-color: rgba(84, 199, 255, 0.42);
  background: rgba(84, 199, 255, 0.14);
}

.buy-button {
  border-color: rgba(84, 199, 255, 0.62);
  background: rgba(84, 199, 255, 0.24);
}

.toast {
  position: absolute;
  left: 50%;
  top: 44%;
  z-index: 4;
  max-width: min(86%, 340px);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(8, 14, 30, 0.9);
  color: var(--ink);
  font-weight: 950;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -50%) scale(0.95);
}

.toast.pop {
  animation: toastPop 1400ms ease-out;
}

.toast.win {
  z-index: 31;
  max-width: min(92%, 520px);
  padding: 18px 20px;
  background: linear-gradient(145deg, rgba(255, 209, 102, 0.96), rgba(84, 199, 255, 0.92));
  color: #071225;
  font-size: clamp(1.45rem, 7.4vw, 3rem);
  line-height: 1.05;
  text-shadow: none;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.toast.win.pop {
  animation: winToastPop 3000ms ease-out;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  padding: 18px;
  place-items: center;
  background: rgba(5, 8, 18, 0.68);
  backdrop-filter: blur(10px);
}

.overlay.show {
  display: grid;
}

.panel {
  width: min(100%, 390px);
  max-height: min(92dvh, 760px);
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.kicker {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.panel h1 {
  margin: 0;
  font-size: clamp(2rem, 9dvw, 3.15rem);
  line-height: 0.95;
}

.panel p {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0 4px;
}

.stats-panel div {
  padding: 10px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.stats-panel span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stats-panel strong {
  display: block;
  margin-top: 4px;
  font-size: 1.3rem;
}

.secondary-button[hidden] {
  display: none;
}

@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.92); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  76% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.96); }
}

@keyframes winToastPop {
  0% { opacity: 0; transform: translate(-50%, -46%) scale(0.82); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.02); }
  82% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -56%) scale(0.96); }
}

@media (max-width: 460px) {
  :root {
    --card-w: min(12.4vw, 48px);
  }

  .table {
    padding: 6px;
  }

  .column {
    min-height: calc(var(--card-h) + 238px);
  }

  .card {
    padding: 4px;
  }

  .small-button {
    padding: 0 4px;
    font-size: 0.68rem;
  }
}

.pause-action-row {
  display: contents;
}

.pause-action-row:has(> button:not([hidden]) + button:not([hidden])) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.pause-action-row:has(> button:not([hidden]) + button:not([hidden])) > button {
  width: 100% !important;
  min-width: 0;
  margin-top: 0 !important;
  margin-right: 0 !important;
}
.arcade-store-arcade-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.22em;
  width: 100%;
  margin: 0 0 14px;
  border: 2px solid #1266ff;
  background: #ffffff;
  color: #071225;
  box-shadow: 0 0 0 2px rgba(18, 102, 255, 0.16), 0 8px 20px rgba(18, 102, 255, 0.2);
  text-transform: none;
}

.arcade-store-arcade-button span:nth-child(2) {
  color: #1266ff;
  text-transform: uppercase;
}

.arcade-store-arcade-button:hover,
.arcade-store-arcade-button:focus-visible {
  background: #ffffff;
  color: #071225;
  outline: 3px solid rgba(84, 199, 255, 0.55);
  outline-offset: 3px;
}
/* Shared 3D arcade button polish. */
.arcade-store-arcade-button {
  gap: 0;
  border: 2px solid #1266ff;
  background: linear-gradient(180deg, #ffffff 0%, #f2f8ff 44%, #d4e8ff 100%);
  color: #071225;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.95), inset 0 -4px 0 rgba(18,102,255,.2), 0 8px 20px rgba(18,102,255,.22);
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
}

.arcade-store-arcade-button .bleep-blue,
.arcade-store-arcade-button span:nth-child(2) {
  color: #1266ff;
  text-transform: uppercase;
}

.arcade-store-arcade-button:hover,
.arcade-store-arcade-button:focus-visible {
  background: linear-gradient(180deg, #ffffff 0%, #eaf4ff 42%, #bfdcff 100%);
  color: #071225;
  outline: 3px solid rgba(84,199,255,.58);
  outline-offset: 3px;
}

.primary-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--blue, #54c7ff) 34%, #fff) 0%, var(--blue, #54c7ff) 52%, color-mix(in srgb, var(--blue, #54c7ff) 72%, #071225) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.42), inset 0 -4px 0 rgba(5,10,24,.22), 0 8px 18px rgba(0,0,0,.26);
}

.secondary-button,
.small-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--yellow, #ffd166) 34%, #fff) 0%, var(--yellow, #ffd166) 54%, color-mix(in srgb, var(--yellow, #ffd166) 72%, #8a5a00) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.48), inset 0 -4px 0 rgba(89,51,0,.22), 0 7px 16px rgba(0,0,0,.24);
}

.store-button,
.buy-button {
  background: linear-gradient(180deg, rgba(255,255,255,.2) 0%, rgba(255,255,255,.1) 50%, rgba(5,10,24,.22) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.2), inset 0 -4px 0 rgba(5,10,24,.22), 0 7px 16px rgba(0,0,0,.22);
}
/* Compact high-score entry row: Initials, City, Save. */
.score-form {
  display: grid;
  grid-template-columns: minmax(4.2rem, 4.9rem) minmax(0, 1fr) auto;
  gap: 6px 8px;
  align-items: end;
}

.score-form label[for="initialsInput"] {
  grid-column: 1;
  grid-row: 1;
}

.score-form label[for="cityInput"] {
  grid-column: 2;
  grid-row: 1;
}

.initials-row {
  display: contents;
}

.initials-row input,
#initialsInput {
  grid-column: 1;
  grid-row: 2;
  width: 4.8rem;
  min-width: 0;
  text-align: center;
}

.city-input,
#cityInput {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
}

.initials-row button,
.score-form button[type="submit"] {
  grid-column: 3;
  grid-row: 2;
  min-width: 4.1rem;
  padding-inline: 10px;
}

.score-form datalist {
  display: none;
}

.score-form .high-score,
#highScoreText {
  grid-column: 1 / -1;
}
/* Keep the Arcade return button visible on initials/end-game overlays. */
.overlay {
  align-items: flex-start !important;
  overflow: auto !important;
  padding-top: max(10px, env(safe-area-inset-top)) !important;
  padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
}

.panel {
  max-height: calc(100dvh - 20px) !important;
}

.arcade-store-arcade-button {
  position: sticky;
  top: 0;
  z-index: 5;
}
