:root {
  --ink: #2a1c12;
  --navy: #1b2a4a;
  --navy-2: #243564;
  --cream: #fff6e8;
  --cream-2: #f3e2c2;
  --gold: #f0c14a;
  --gold-2: #c6862a;
  --jelly: #b42364;
  --leaf: #1f6b45;
  --line: #2a1c12;
  --shadow: 0 10px 24px rgba(20, 16, 8, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Nunito, "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--cream);
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(240, 193, 74, 0.18), transparent 60%),
    var(--navy);
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; max-width: 100%; height: auto; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.skip {
  position: absolute;
  left: 12px;
  top: 8px;
  transform: translateY(-140%);
  background: var(--gold);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 800;
  z-index: 5;
}
.skip:focus { transform: none; }

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

.table {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 14px 12px calc(92px + env(safe-area-inset-bottom));
}

.cloth {
  background:
    repeating-linear-gradient(90deg, var(--navy-2) 0 16px, #2c4078 16px 32px);
  border-radius: 28px;
  padding: 14px;
  box-shadow: 0 0 0 8px var(--cream-2), var(--shadow);
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 12px;
  min-width: 0;
}
.back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--navy);
  font-weight: 800;
  text-decoration: none;
}
.top-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.plaque {
  flex: 1 1 280px;
  min-width: 0;
  background: var(--cream);
  color: var(--ink);
  border-radius: 28px;
  padding: 10px 18px 8px;
  text-align: center;
  box-shadow: inset 0 0 0 3px #2a1c12;
}
.plaque h1 {
  font-family: Fraunces, "Iowan Old Style", Palatino, Georgia, serif;
  font-weight: 700;
  font-size: clamp(1.45rem, 4.6vw, 2.35rem);
  line-height: 1.05;
  margin: 0;
  letter-spacing: -0.03em;
}
.eyebrow, .fine {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.eyebrow { color: var(--jelly); text-transform: uppercase; }
.fine { margin-top: 4px; color: #5c4033; font-weight: 700; letter-spacing: 0; }
.text-button {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  margin-top: 2px;
  padding: 4px 8px;
  border: 0;
  background: transparent;
  color: #5c4033;
  font-weight: 800;
  text-align: center;
  white-space: normal;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.modes button, .actions button, .gate button, .banner button, .rules-card button {
  min-height: 44px;
  border-radius: 999px;
  border: 2px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}
.modes button {
  background: transparent;
  color: var(--cream);
  border-color: var(--cream-2);
}
.modes button[aria-checked="true"] {
  background: var(--gold);
  color: var(--ink);
  border-color: var(--gold);
}

.placemat {
  background: var(--cream);
  color: var(--ink);
  border-radius: 18px;
  padding: 10px 12px 12px;
  margin-top: 10px;
}
.who {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  justify-content: flex-start;
  padding-right: 8px;
}
.who h2 { margin: 0; font-size: 1.05rem; }
.score { margin: 0; font-weight: 800; }
.pips { display: flex; gap: 6px; }
.pip {
  width: 18px;
  height: 12px;
  border-radius: 8px 8px 4px 4px;
  border: 2px solid var(--ink);
  background: transparent;
}
.pip.on { background: var(--gold-2); }
.turn-flag {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--leaf);
}

.lunches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
button.lunch { font: inherit; appearance: none; }
.lunch, .plate {
  width: min(168px, 46vw);
  background: #fffaf3;
  border: 2px solid #ead7b8;
  border-radius: 16px;
  padding: 4px 4px 8px;
  color: var(--ink);
  text-align: center;
}
.lunch { border-color: var(--ink); }
.lunch.is-hot, .plate.is-hot {
  border-color: var(--gold-2);
  box-shadow: 0 0 0 3px var(--gold);
}
.lunch-caption, .plate span, .handcount {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
}
.handcount { margin: 8px 0 0; }
.frozen-note { color: var(--jelly); }

.piles {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}
.pile {
  width: auto;
  flex: 1 1 0;
  max-width: 140px;
  min-height: 108px;
  border-radius: 16px;
  background: rgba(255, 246, 232, 0.12);
  border: 2px dashed var(--cream-2);
  color: var(--cream);
  padding: 8px;
  text-align: center;
}
.pile strong, .pile span { display: block; overflow-wrap: anywhere; }
.pile strong { font-size: 0.82rem; }
.pile span { font-size: 0.72rem; font-weight: 700; color: #f3e2c2; }
.pile .mini { margin: 0 auto 6px; width: 72px; }
.pile .count-badge { color: var(--ink); }
.pile.draw {
  background: transparent;
  border-style: solid;
  padding: 0;
  border: 0;
}
.back-stack { position: relative; height: 78px; }
.back-stack .mini {
  position: absolute;
  left: 8px;
  width: 68px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
}
.back-stack .mini:nth-child(1) { top: 12px; left: 6px; }
.back-stack .mini:nth-child(2) { top: 6px; left: 12px; }
.back-stack .mini:nth-child(3) { top: 0; left: 18px; }
.count-badge {
  position: absolute;
  right: 6px;
  bottom: 0;
  background: var(--gold);
  color: var(--ink);
  border-radius: 999px;
  min-width: 28px;
  padding: 2px 6px;
  font-weight: 800;
  font-size: 0.78rem;
}

.status {
  margin: 12px 0 0;
  background: var(--cream);
  color: var(--ink);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 800;
  min-height: 44px;
}
.log {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 8px 2px 0;
  color: #f3e2c2;
  font-size: 0.82rem;
  font-weight: 700;
}
.log p { margin: 0; }

.hand {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 2px 8px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.pcard {
  flex: 0 0 auto;
  width: 108px;
  scroll-snap-align: start;
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 6px 6px 8px;
  text-align: center;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
  touch-action: manipulation;
}
.pcard svg { width: 100%; height: auto; }
.card-name, .card-flag {
  display: block;
  font-weight: 800;
}
.card-name { font-size: 0.86rem; line-height: 1.15; min-height: 2.3em; }
.card-flag { font-size: 0.72rem; color: var(--leaf); }
.pcard.is-legal { box-shadow: 0 0 0 3px var(--gold), 0 6px 0 rgba(0, 0, 0, 0.18); }
.pcard.is-selected { transform: translateY(-4px); }
.pcard.is-wait { background: #f4eadc; }
.pcard.is-wait .card-flag { color: #6b3a1f; }
.pcard.is-discard { box-shadow: 0 0 0 3px var(--jelly), 0 6px 0 rgba(0, 0, 0, 0.18); }
.pcard.is-discard .card-flag { color: var(--jelly); }
.pcard:disabled { cursor: default; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.actions button, .gate button, .banner button {
  background: var(--gold);
  color: var(--ink);
  border-color: var(--ink);
}
.actions button.ghost, .rules-card .ghost {
  background: transparent;
  color: var(--cream);
  border-color: var(--cream-2);
}
.actions button:disabled {
  background: #6d624f;
  color: #fff6e8;
  border-color: #6d624f;
  cursor: not-allowed;
}

.gate, .banner {
  margin-top: 12px;
  background: var(--cream);
  color: var(--ink);
  border-radius: 18px;
  padding: 16px;
  text-align: center;
}
.gate h2, .banner h2 { margin: 0 0 6px; font-family: Fraunces, Georgia, serif; }
.gate p, .banner p { margin: 0 0 12px; }

.grass {
  height: 22px;
  margin: 12px -14px -14px;
  border-radius: 0 0 20px 20px;
  background:
    radial-gradient(circle at 12px 0, transparent 9px, #217246 10px) 0 0 / 24px 22px repeat-x,
    #2f8a4e;
}

.rules-card {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--cream);
  width: min(560px, calc(100vw - 24px));
  max-height: min(88dvh, 760px);
}
.rules-card::backdrop { background: rgba(12, 16, 28, 0.72); }
.rules-card form, .rules-inner {
  background: var(--cream);
  color: var(--ink);
  border-radius: 18px;
  padding: 16px 16px 18px;
  overflow: auto;
  max-height: min(88dvh, 760px);
}
.rules-inner h2 { font-family: Fraunces, Georgia, serif; margin: 0 0 8px; }
.rules-inner h3 { margin: 16px 0 6px; font-size: 1rem; }
.rules-inner p, .rules-inner li { font-size: 0.95rem; line-height: 1.4; }
.rules-inner ul { margin: 0; padding-left: 1.1rem; }
.house-mark {
  display: inline-block;
  background: var(--gold);
  color: var(--ink);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 800;
}
.rules-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.rules-actions button {
  background: var(--navy);
  color: var(--cream);
  border: 2px solid var(--navy);
}

@media (max-width: 720px) {
  .top { flex-direction: column; align-items: stretch; }
  .plaque { flex: none; width: 100%; padding: 8px 14px 4px; }
  .placemat { padding: 8px 10px; margin-top: 8px; }
  .pcard { width: 100px; }
  .hand { padding-top: 8px; }
}
@media (min-width: 800px) {
  .table { padding-top: 22px; }
  .top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
  }
  .top-row { display: contents; }
  .back { grid-column: 1; }
  .plaque { grid-column: 2; }
  .modes { grid-column: 3; justify-content: flex-end; }
  .pcard { width: 120px; }
  .lunch, .plate { width: 180px; }
  .piles { gap: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .pcard.is-selected { transform: none; }
}
