:root {
  --sky: #57c3f2;
  --sky-deep: #1c7fb8;
  --sky-pale: #dcf1fb;
  --coral: #ff7454;
  --coral-deep: #e04c2c;
  --sun: #ffd166;
  --mint: #63d3b1;
  --paper: #f2f9fd;
  --card: #ffffff;
  --ink: #22404f;
  --muted: #6d8794;
  --focus: #e04c2c;
  --radius: 26px;
  --page-pad: clamp(12px, 2.5vw, 22px);
  --frame-pad: 0px;
  --frame-border: 0px;
  --gutter: 8px;
  --cell: 64px;
  --chip: 36px;
  --shadow: 0 12px 28px -16px rgba(28, 127, 184, 0.3), 0 1.5px 0 rgba(34, 64, 79, 0.05);
  --line: #e2eef4;
  --hot: #ffe4db;
  --hot-ink: var(--coral-deep);
  --cheer: var(--coral-deep);
  --dot: rgba(34, 64, 79, 0.055);
  --card-grain: rgba(28, 127, 184, 0.16);
  --card-sheen: rgba(255, 255, 255, 0.72);
  --blob-sky: rgba(220, 241, 251, 0.9);
  --blob-coral: rgba(255, 225, 216, 0.85);
  --blob-mint: rgba(227, 251, 243, 0.9);
  --font: "Figtree", "Segoe UI", sans-serif;
  --display: "Fredoka", "Trebuchet MS", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.5;
  background:
    radial-gradient(800px 380px at 88% -60px, rgba(87, 195, 242, 0.22), transparent 70%),
    radial-gradient(700px 420px at -200px 30%, rgba(255, 116, 84, 0.1), transparent 70%),
    radial-gradient(var(--dot) 1.6px, transparent 1.6px) 0 0 / 22px 22px,
    var(--paper);
}

button, a { font: inherit; }
button { cursor: pointer; }

::selection { background: var(--sky); color: #fff; }

.skip {
  position: absolute;
  left: 12px;
  top: 8px;
  z-index: 6;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--sky-deep);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-160%);
}

.skip:focus { transform: none; }

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(280px 280px at -40px 110%, var(--blob-sky), transparent 70%),
    radial-gradient(180px 180px at 96% 8%, var(--blob-coral), transparent 70%),
    radial-gradient(220px 220px at 40% 120%, var(--blob-mint), transparent 70%);
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: nowrap;
  max-width: 1140px;
  margin: 0 auto;
  padding: 14px 14px 14px 20px;
  background-color: var(--card);
  background-image:
    radial-gradient(120% 90% at 0% 0%, var(--card-sheen), transparent 48%),
    radial-gradient(var(--card-grain) 0.7px, transparent 0.85px);
  background-size: auto, 8px 8px;
  border-radius: 999px;
  box-shadow: 0 10px 26px -12px rgba(28, 127, 184, 0.25), 0 2px 0 rgba(34, 64, 79, 0.04);
  width: min(1140px, calc(100% - (2 * var(--page-pad))));
  margin-top: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.35rem, 3vw, 1.7rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
}

.brand h1 i {
  font-style: normal;
  color: var(--sky-deep);
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.medallion {
  margin: 0;
  min-width: 88px;
  padding: 8px 16px;
  text-align: center;
  background: var(--paper);
  border-radius: 18px;
}

.medallion span,
.medallion small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.medallion strong {
  display: block;
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
  color: var(--sky-deep);
}

.medallion small {
  margin-top: 2px;
  letter-spacing: 0.04em;
  text-transform: none;
  font-size: 12px;
}

.ghost,
.solid {
  border-radius: 999px;
  min-height: 44px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 14px;
}

.ghost {
  color: var(--ink);
  background: transparent;
  border: 0;
}

.ghost:hover { background: var(--sky-pale); }

.solid {
  color: #fff;
  background: var(--coral);
  border: 0;
  box-shadow: 0 6px 14px -4px rgba(224, 76, 44, 0.55), inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

.solid:hover { transform: translateY(-2px); }

.solid.is-armed {
  background: var(--sky-deep);
  color: #fff;
}

.play { display: contents; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  width: min(1140px, 100%);
  max-width: 1140px;
  margin: 18px auto 0;
  padding: 0 var(--page-pad) 28px;
}

.mode-field {
  grid-area: mode;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  min-width: 0;
  max-width: 100%;
}

.mode-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mode-options {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--paper);
}

.mode-option {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 40px;
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--ink);
  font: 600 14px var(--font);
  letter-spacing: 0;
  text-align: center;
  line-height: 1.2;
  cursor: pointer;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.mode-option:has(input:checked) {
  background: var(--ink);
  color: var(--paper);
}

.mode-option:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.boards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
}

@media (min-width: 721px) {
  body.is-dual .boards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.seat-label { display: none; }

body.is-dual .seat-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 0 4px 6px;
  font-size: 13px;
  font-weight: 700;
}

.seat-label strong {
  font-family: var(--display);
  font-size: 1.2rem;
  color: var(--sky-deep);
}

body.is-dual .board-section.is-turn {
  box-shadow: 0 0 0 3px var(--sky), var(--shadow);
}

.deal-card,
.guide,
.board-section {
  background-color: var(--card);
  background-image:
    radial-gradient(120% 80% at 100% 0%, var(--card-sheen), transparent 42%),
    radial-gradient(var(--card-grain) 0.7px, transparent 0.85px);
  background-size: auto, 8px 8px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.deal-card,
.guide { padding: 20px 22px 18px; }

.deal-card {
  display: grid;
  min-width: 0;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "mode mode"
    "face kicker"
    "face caption"
    "face message"
    "cheer cheer";
  column-gap: 16px;
  row-gap: 2px;
  align-items: center;
}

.eyebrow,
.guide h2,
.rising-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.eyebrow { grid-area: kicker; }
#deal-caption { grid-area: caption; margin: 0; font-weight: 700; }
#message { grid-area: message; margin: 0; color: var(--ink); font-weight: 700; }
#cheer { grid-area: cheer; margin: 4px 0 0; }

.deal-btn {
  grid-area: face;
  display: grid;
  place-items: center;
  width: auto;
  min-width: 92px;
  margin: 0;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--sky-deep);
  cursor: default;
}

.deal-btn.is-over { cursor: pointer; }

#current {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(3.2rem, 7vw, 5.5rem);
  line-height: 0.9;
  letter-spacing: -0.03em;
  color: var(--sky-deep);
  white-space: nowrap;
}

.deal-btn.is-over #current { font-size: clamp(1.6rem, 4vw, 2.4rem); }

#cheer,
.note,
footer { color: var(--muted); }

#cheer {
  min-height: 0;
  width: 100%;
  text-align: center;
  font-family: var(--display);
  font-size: 1.15rem;
  color: var(--cheer);
}

#cheer:empty { display: none; }

.board-section {
  container-type: inline-size;
  width: 100%;
  min-width: 0;
  padding: 16px 16px 12px;
}

.table {
  --chip: clamp(32px, 12cqi, 44px);
  --cell: min(72px, calc((100cqi - 32px - (4 * var(--gutter)) - var(--chip) - 8px) / 5));
  display: grid;
  grid-template-columns: auto var(--chip);
  grid-template-areas:
    "rising rising"
    "frame rows"
    "cols falling";
  column-gap: 8px;
  row-gap: 8px;
  align-items: center;
  width: max-content;
  max-width: 100%;
  margin-inline: auto;
}

.rising {
  grid-area: rising;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.board-frame {
  grid-area: frame;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.row-scores {
  grid-area: rows;
  display: grid;
  grid-template-rows: repeat(5, var(--cell));
  gap: var(--gutter);
  align-items: center;
}

.col-scores {
  grid-area: cols;
  display: grid;
  grid-template-columns: repeat(5, var(--cell));
  gap: var(--gutter);
  justify-items: center;
}

.falling { grid-area: falling; justify-self: center; }

.board {
  display: grid;
  grid-template-columns: repeat(5, var(--cell));
  grid-template-rows: repeat(5, var(--cell));
  gap: var(--gutter);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  color: var(--sky-deep);
  background: var(--paper);
  box-shadow: none;
}

.cell.is-filled {
  border-color: transparent;
  background: var(--tile, var(--sky));
  color: var(--digit, #fff);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  cursor: default;
  animation: settle 0.28s ease;
}

.cell .digit,
.cell .peek {
  font-family: var(--display);
  font-size: calc(var(--cell) * 0.46);
  font-weight: 600;
  line-height: 1;
}

.cell .peek {
  position: absolute;
  color: var(--sky-deep);
  opacity: 0;
}

.cell.is-empty:hover .peek,
.cell.is-empty:focus-visible .peek { opacity: 1; }

.cell.on-main::before,
.cell.on-anti::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  border: 0;
}

.cell.on-main::before {
  top: 6px;
  left: 6px;
  border-radius: 99px;
  background: var(--sky-deep);
}

.cell.on-anti::after {
  top: 6px;
  right: 6px;
  border-radius: 2px;
  background: var(--coral);
}

.cell.is-filled.on-main::before,
.cell.is-filled.on-anti::after { background: rgba(255, 255, 255, 0.85); }

.cell.is-hot { box-shadow: inset 0 0 0 3px var(--sun); }

.chip {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  align-self: center;
  width: var(--chip);
  height: var(--chip);
  min-width: var(--chip);
  min-height: var(--chip);
  aspect-ratio: 1;
  border-radius: 50%;
  color: var(--sky-deep);
  font-weight: 700;
  background: var(--paper);
  border: 1.5px solid var(--line);
  box-shadow: none;
}

.chip .mark {
  position: absolute;
  top: 2px;
  left: 0;
  right: 0;
  font-size: 0.55rem;
  line-height: 1;
  text-align: center;
  pointer-events: none;
}

.chip .val {
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  color: var(--sky-deep);
}

.chip.is-hot {
  background: var(--hot);
  border-color: transparent;
}

.chip.is-hot .val,
.chip.is-hot .mark { color: var(--hot-ink); }

.guide h2 {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  margin-bottom: 8px;
}

.guide p { margin: 0 0 12px; }

.rules {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: grid;
  gap: 6px;
}

.rules li {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
}

.rules b {
  display: inline-grid;
  place-items: center;
  min-width: 2.4em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--sky-pale);
  color: var(--sky-deep);
  font-family: var(--display);
  font-weight: 600;
}

.note { font-size: 13px; }

footer {
  max-width: 1140px;
  margin: 8px auto 0;
  padding: 0 var(--page-pad) 28px;
  text-align: center;
  font-size: 13px;
}

footer p { margin: 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

@keyframes settle {
  from { transform: scale(0.86); }
  to { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cell.is-filled,
  .solid:hover { animation: none; transform: none; }
}

@media (max-width: 720px) {
  .top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "brand theme sound"
      "score new new";
    width: calc(100% - 20px);
    margin-top: 10px;
    padding: 12px 14px;
    gap: 10px 8px;
    border-radius: 28px;
    align-items: center;
  }

  .top-actions { display: contents; }

  .brand { grid-area: brand; }
  #theme { grid-area: theme; }
  #sound { grid-area: sound; }
  .medallion { grid-area: score; justify-self: start; margin-right: 0; }
  #restart { grid-area: new; justify-self: end; }

  .medallion {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 8px;
    min-height: 40px;
    padding: 8px 16px;
  }

  .medallion span { letter-spacing: 0.08em; }
  .medallion strong { font-size: 1.35rem; }
  .medallion small { margin-top: 0; }

  .brand p { display: none; }
  .brand h1 { font-size: 1.25rem; }
  .mark { width: 36px; height: 36px; }

  .ghost,
  .solid { min-height: 40px; padding: 8px 12px; }
  #restart { padding-inline: 16px; }

  main { margin-top: 10px; padding-bottom: 16px; gap: 12px; }

  .play {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .deal-card {
    padding: 10px 14px;
    grid-template-columns: 72px minmax(0, 1fr);
  }

  #current { font-size: 2.6rem; }
  .deal-btn.is-over #current { font-size: 1.2rem; }
  #deal-caption,
  #message { margin: 0; line-height: 1.25; }
  #cheer:empty { display: none; }

  .board-section { padding: 12px; }

  .table {
    --gutter: 5px;
    --chip: 30px;
    --cell: min(
      58px,
      calc((100cqi - 24px - (4 * var(--gutter)) - var(--chip) - 8px) / 5),
      calc((100svh - var(--header-h, 64px) - 168px) / 6.4)
    );
  }

  .guide { margin-top: 0; }
}

:root[data-theme="dark"] {
  --paper: #0e1c24;
  --card: #17303c;
  --ink: #e7f3f8;
  --muted: #9bb6c4;
  --sky-deep: #7ec8ef;
  --sky-pale: #1a3d4e;
  --line: #2c4a58;
  --hot: #4a2a24;
  --hot-ink: #ffb4a2;
  --cheer: #ffb4a2;
  --dot: rgba(231, 243, 248, 0.07);
  --card-grain: rgba(126, 200, 239, 0.2);
  --card-sheen: rgba(255, 255, 255, 0.05);
  --blob-sky: rgba(28, 127, 184, 0.28);
  --blob-coral: rgba(224, 76, 44, 0.16);
  --blob-mint: rgba(21, 122, 92, 0.2);
  --shadow: 0 14px 30px -16px rgba(0, 0, 0, 0.65);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1c24;
    --card: #17303c;
    --ink: #e7f3f8;
    --muted: #9bb6c4;
    --sky-deep: #7ec8ef;
    --sky-pale: #1a3d4e;
    --line: #2c4a58;
    --hot: #4a2a24;
    --hot-ink: #ffb4a2;
    --cheer: #ffb4a2;
    --dot: rgba(231, 243, 248, 0.07);
    --card-grain: rgba(126, 200, 239, 0.2);
    --card-sheen: rgba(255, 255, 255, 0.05);
    --blob-sky: rgba(28, 127, 184, 0.28);
    --blob-coral: rgba(224, 76, 44, 0.16);
    --blob-mint: rgba(21, 122, 92, 0.2);
    --shadow: 0 14px 30px -16px rgba(0, 0, 0, 0.65);
    color-scheme: dark;
  }
}

@media (forced-colors: active) {
  .cell,
  .chip,
  .deal-card,
  .guide,
  .board-section,
  .top,
  .solid {
    forced-color-adjust: none;
    background: Canvas;
    color: CanvasText;
    border: 1px solid CanvasText;
  }

  :focus-visible { outline: 3px solid Highlight; }
}
