:root {
  --night: #172c3b;
  --night-deep: #0d1d28;
  --porch: #b85d3e;
  --porch-dark: #793823;
  --lemon: #f6ce67;
  --cream: #fff4d5;
  --ink: #222a2b;
  --felt: #1f5a4a;
  --felt-deep: #123d34;
  --mint: #a8d9b7;
  --shadow: rgba(4, 13, 18, .42);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  color: var(--cream);
  background: var(--night-deep);
  font-family: Georgia, 'Times New Roman', serif;
  overscroll-behavior: none;
}
button, input { font: inherit; }
button { touch-action: manipulation; }
a { color: var(--lemon); }
.hidden { display: none !important; }
.screen { min-height: 100dvh; width: 100%; }

.porch-scene {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding: calc(56px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, transparent 0 74%, rgba(10, 22, 25, .5) 74%),
    repeating-linear-gradient(90deg, transparent 0 54px, rgba(255,255,255,.025) 54px 56px),
    linear-gradient(180deg, #203e51 0%, #172f3c 48%, #7e402c 48.2%, #a75338 100%);
}
.porch-scene::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 7%; height: 7px;
  background: rgba(74, 29, 20, .65);
  box-shadow: 0 20px 0 rgba(74,29,20,.5), 0 40px 0 rgba(74,29,20,.36);
}
.string-lights {
  position: absolute;
  z-index: 2;
  top: 10px; left: -3%; right: -3%; height: 48px;
  display: flex; justify-content: space-around;
  border-top: 2px solid #0a1318;
  border-radius: 50%;
  pointer-events: none;
}
.string-lights i {
  width: 10px; height: 15px; margin-top: 5px;
  border-radius: 50% 50% 45% 45%;
  background: var(--lemon);
  box-shadow: 0 0 7px 3px rgba(246,206,103,.54), 0 0 24px 8px rgba(246,206,103,.19);
}

.menu-card, .handoff-card, .result-card {
  position: relative;
  z-index: 3;
  width: min(100%, 540px);
  text-align: center;
  border: 1px solid rgba(255,244,213,.2);
  border-radius: 24px;
  background: rgba(12, 31, 39, .82);
  box-shadow: 0 22px 60px var(--shadow), inset 0 1px rgba(255,255,255,.08);
  backdrop-filter: blur(8px);
}
.menu-card { padding: 24px 18px 22px; }
.eyebrow, .mode-label, label, .round-mark {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.eyebrow { color: var(--lemon); margin-bottom: 8px; }
h1 { margin: 0; font-size: clamp(34px, 11vw, 62px); line-height: .84; letter-spacing: -.045em; color: var(--cream); text-shadow: 0 4px 0 var(--porch-dark); }
h1 span { display: block; font: 900 .44em/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .23em; color: var(--lemon); text-shadow: none; margin: 0 0 6px .23em; }
.tagline { max-width: 410px; margin: 16px auto 18px; color: #d7e3dc; font-size: 15px; line-height: 1.45; }

button { color: inherit; }
.primary, .mode-btn, .bot-choice, .text-btn, .count-btn, .seat-btn, .icon-btn, .boneyard {
  border: 0;
  cursor: pointer;
}
.primary {
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--lemon);
  color: #352c17;
  box-shadow: 0 4px 0 #a77725;
  font: 900 13px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .05em;
}
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #a77725; }
.primary:disabled { filter: grayscale(.5); opacity: .52; cursor: default; }
.menu-card > .primary { width: 100%; margin-bottom: 14px; }
.mode-block { margin-top: 12px; }
.mode-block.compact { padding-top: 10px; border-top: 1px solid rgba(255,255,255,.1); }
.mode-label { margin-bottom: 7px; color: #a9c7bd; }
.bot-grid, .online-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bot-choice, .mode-btn {
  min-height: 62px;
  padding: 11px;
  border: 1px solid rgba(255,244,213,.22);
  border-radius: 13px;
  background: rgba(255,255,255,.07);
  text-align: left;
}
.bot-choice:hover, .mode-btn:hover { border-color: var(--lemon); background: rgba(246,206,103,.09); }
.bot-choice.sharper { background: rgba(184,93,62,.18); }
.mode-title, .mode-btn b { display: block; color: var(--cream); font: 800 13px/1.15 ui-sans-serif, system-ui, sans-serif; }
.mode-blurb, .mode-btn small { display: block; margin-top: 5px; color: #b9cdc6; font: 11px/1.25 ui-sans-serif, system-ui, sans-serif; }
#passBtn { width: 100%; min-height: 46px; text-align: center; font: 800 13px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .06em; }
.count-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; color: #b9cdc6; font: 800 10px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .08em; }
.count-buttons, .seat-btns { display: flex; gap: 7px; }
.count-btn, .seat-btn { width: 44px; min-height: 40px; border-radius: 9px; background: #e7eadf; color: var(--ink); font: 900 16px/1 ui-sans-serif, system-ui, sans-serif; }
.seat-btn.selected { background: var(--lemon); box-shadow: 0 0 0 2px #9b6f26; }
.text-btn { min-height: 42px; padding: 8px 12px; background: transparent; color: var(--lemon); font: 800 11px/1.2 ui-sans-serif, system-ui, sans-serif; letter-spacing: .06em; }
#rejoinBtn { margin-top: 6px; }
.rules { margin-top: 14px; color: #bdcec7; text-align: left; font-size: 12px; line-height: 1.45; }
.rules summary { color: var(--lemon); cursor: pointer; text-align: center; font: 800 11px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .06em; }
.rules p { margin: 8px 0 0; }
footer { position: relative; z-index: 3; margin-top: auto; padding: 22px 0 0; text-align: center; color: #d5c7b5; font: 10px/1.5 ui-sans-serif, system-ui, sans-serif; }

.overlay {
  position: fixed; z-index: 50; inset: 0;
  display: grid; place-items: center;
  padding: 18px;
  background: rgba(5, 14, 19, .79);
  backdrop-filter: blur(5px);
}
.dialog-card {
  width: min(100%, 390px);
  max-height: 90dvh;
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(255,244,213,.28);
  border-radius: 20px;
  background: #183644;
  box-shadow: 0 24px 70px #061015;
  text-align: center;
}
.dialog-card h2 { margin: 0 0 16px; color: var(--lemon); font-size: 24px; }
.dialog-card p { color: #ccdbd5; line-height: 1.5; font-size: 14px; }
.dialog-card label { display: block; margin: 13px 0 6px; color: #b6d0c7; text-align: left; }
.dialog-card input { width: 100%; min-height: 48px; padding: 10px 12px; border: 2px solid transparent; border-radius: 10px; outline: 0; color: #17262b; background: #f8f2df; font: 700 18px/1 ui-sans-serif, system-ui, sans-serif; }
.dialog-card input:focus { border-color: var(--lemon); }
.dialog-actions { display: flex; justify-content: center; gap: 8px; margin-top: 17px; }
.dialog-actions > * { flex: 1; }
.error { margin-top: 12px; color: #ffd1c1; font: 700 12px/1.4 ui-sans-serif, system-ui, sans-serif; }
#lobbyCode { margin: 10px 0; color: var(--lemon); font: 900 50px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .16em; text-indent: .16em; }
#lobbyNames { list-style: none; padding: 0; margin: 8px 0; color: #d8e6df; font: 700 13px/1.8 ui-sans-serif, system-ui, sans-serif; }

.handoff-card { margin: auto; padding: 32px 22px; }
.handoff-icon { font-size: 54px; }
.handoff-card h2 { margin: 6px 0 8px; font-size: 28px; }
.handoff-card p { color: #c8d8d1; }
.handoff-card .primary { width: 100%; margin-top: 14px; }

.game-screen {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background:
    radial-gradient(circle at 50% 18%, rgba(246,206,103,.16), transparent 25%),
    linear-gradient(180deg, var(--night) 0 18%, var(--felt-deep) 18% 100%);
  overflow: hidden;
}
.game-header { min-height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 5px 10px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.09); color: var(--cream); font: 900 20px/1 ui-sans-serif, system-ui, sans-serif; }
.round-mark { text-align: center; color: var(--lemon); }
.round-mark span, .round-mark b { display: block; }
.round-mark b { margin-top: 3px; color: #9bb9ae; font-size: 8px; letter-spacing: .13em; }
.scoreboard { display: flex; justify-content: center; gap: 5px; padding: 1px 8px 6px; overflow-x: auto; }
.score-chip { min-width: 62px; padding: 5px 8px; border-radius: 8px; background: rgba(5,18,22,.45); text-align: center; font: 700 9px/1 ui-sans-serif, system-ui, sans-serif; color: #a9c2b9; }
.score-chip b { display: block; margin-top: 3px; color: var(--cream); font-size: 16px; }
.score-chip.active { outline: 1px solid var(--lemon); color: var(--lemon); }
.opponents { min-height: 31px; display: flex; justify-content: center; gap: 6px; padding: 0 8px 5px; overflow-x: auto; }
.opp-chip { white-space: nowrap; padding: 5px 8px; border-radius: 999px; background: rgba(255,255,255,.08); color: #cad9d4; font: 700 10px/1 ui-sans-serif, system-ui, sans-serif; }
.opp-chip.active { background: var(--porch); color: white; }
.opp-chip b { margin-left: 4px; color: var(--lemon); }

.table-wrap { position: relative; min-height: 0; display: flex; flex-direction: column; overflow: hidden; border-top: 1px solid rgba(255,255,255,.07); border-bottom: 1px solid rgba(255,255,255,.07); }
.table-glow { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, rgba(255,255,255,.055), transparent 68%); }
.turn-notice { position: relative; z-index: 1; min-height: 28px; padding: 7px 10px 3px; color: var(--lemon); text-align: center; font: 900 10px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .1em; }
.chain-board { flex: 1; min-height: 135px; overflow-y: auto; padding: 6px 10px 10px; scrollbar-width: thin; }
.chain-empty { height: 100%; display: grid; place-items: center; color: #83aa9d; font-style: italic; font-size: 13px; }
.chain-row { position: relative; display: flex; min-height: 58px; align-items: center; justify-content: center; }
.chain-row.reverse { flex-direction: row-reverse; }
.chain-cell { position: relative; width: 56px; min-width: 56px; height: 58px; display: grid; place-items: center; }
.chain-row:not(:last-child) .chain-cell:last-child::after {
  content: '';
  position: absolute; z-index: -1; top: 27px; width: 40px; height: 58px;
  border: 3px solid rgba(246,206,103,.28); border-left: 0; border-radius: 0 24px 24px 0;
}
.chain-row:not(.reverse):not(:last-child) .chain-cell:last-child::after { left: 27px; }
.chain-row.reverse:not(:last-child) .chain-cell:last-child::after { right: 27px; transform: scaleX(-1); }

.domino {
  position: relative;
  width: 54px; height: 30px;
  display: flex;
  padding: 2px;
  border: 1px solid #c9c4b4;
  border-radius: 5px;
  background: #f5efdc;
  box-shadow: 0 3px 0 #aca593, 0 5px 8px rgba(0,0,0,.32);
  color: #1e2629;
}
.chain-row.reverse .domino:not(.double) { transform: rotate(180deg); }
.domino.double { width: 30px; height: 54px; flex-direction: column; }
.domino.double .face:first-child { border-right: 0; border-bottom: 1px solid #9c988b; }
.face { position: relative; flex: 1; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 1px; }
.face:first-child { border-right: 1px solid #9c988b; }
.dot { width: 4px; height: 4px; align-self: center; justify-self: center; border-radius: 50%; background: #253034; }
.hand-domino .dot { width: 5px; height: 5px; }

.table-controls { position: relative; z-index: 2; min-height: 54px; display: flex; justify-content: center; align-items: center; gap: 9px; padding: 2px 8px; }
.boneyard { min-width: 150px; min-height: 46px; display: grid; grid-template-columns: 38px auto; grid-template-rows: auto auto; align-items: center; padding: 5px 12px; border-radius: 12px; background: rgba(7,27,27,.58); color: var(--cream); text-align: left; }
.boneyard b { align-self: end; font: 900 11px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .08em; }
.boneyard small { align-self: start; color: #9fbbb2; font: 9px/1.4 ui-sans-serif, system-ui, sans-serif; }
.boneyard.ready { outline: 2px solid var(--lemon); animation: breathe 1.3s ease-in-out infinite; }
.boneyard:disabled { opacity: .44; cursor: default; }
.mini-stack { grid-row: 1 / 3; position: relative; width: 29px; height: 25px; }
.mini-stack i { position: absolute; inset: 5px 1px 0 4px; border: 1px solid #c8c3b3; border-radius: 3px; background: #eee7d4; box-shadow: 0 2px #8c887d; }
.mini-stack i:nth-child(2) { transform: translate(-3px,-3px); }
.mini-stack i:nth-child(3) { transform: translate(-6px,-6px); }
.narration { position: relative; z-index: 1; min-height: 23px; padding: 1px 10px 6px; text-align: center; color: #a9c3ba; font-size: 11px; font-style: italic; }
@keyframes breathe { 50% { box-shadow: 0 0 18px rgba(246,206,103,.35); } }

.hand-area { background: linear-gradient(180deg, #6e3324, #3d211b); padding: 7px 8px calc(9px + env(safe-area-inset-bottom)); box-shadow: 0 -7px 25px rgba(0,0,0,.3); }
.hand-heading { display: flex; justify-content: space-between; padding: 0 5px 5px; color: #e6c8ad; font: 800 9px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .09em; }
.hand { min-height: 72px; display: flex; align-items: center; justify-content: center; gap: 5px; overflow-x: auto; padding: 2px 4px 6px; }
.hand-tile { flex: 0 0 auto; min-width: 62px; min-height: 66px; display: grid; place-items: center; padding: 5px 4px 8px; border: 0; border-radius: 9px; background: rgba(255,255,255,.05); }
.hand-tile.playable { background: rgba(246,206,103,.15); box-shadow: inset 0 0 0 1px rgba(246,206,103,.48); transform: translateY(-2px); }
.hand-tile:disabled { opacity: .58; }
.hand-domino { width: 58px; height: 34px; }
.hand-domino.double { width: 58px; height: 34px; flex-direction: row; }
.hand-domino.double .face:first-child { border-right: 1px solid #9c988b; border-bottom: 0; }
.tile-pips { margin-top: 7px; color: #e6c8ad; font: 800 9px/1 ui-sans-serif, system-ui, sans-serif; }
.side-card .dialog-actions { flex-direction: row; }

.result-screen { display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top, #315462, #152b36 58%, #a95238 58.2%, #74351f); }
.result-card { padding: 28px 22px; }
.result-card h2 { margin: 4px 0 8px; color: var(--cream); font-size: clamp(30px, 9vw, 46px); line-height: 1; }
.result-card > p { color: #cadad4; font-size: 14px; line-height: 1.5; }
.lemonade { font-size: 48px; }
.porch-burst { font-size: 34px; margin-bottom: 8px; }
.result-scores { margin: 17px 0; padding: 10px; border-radius: 12px; background: rgba(255,255,255,.06); }
.result-score { display: flex; justify-content: space-between; padding: 6px 8px; color: #c9dbd4; font: 700 12px/1 ui-sans-serif, system-ui, sans-serif; }
.result-score b { color: var(--lemon); font-size: 16px; }
.result-card > button { width: 100%; margin-top: 8px; }
.brief-cta { display: block; margin-top: 17px; padding: 12px; border-radius: 10px; background: rgba(246,206,103,.1); text-decoration: none; font-size: 12px; line-height: 1.45; }

/* ---------------------------------------------------------- leaderboard */

#lb {
  margin: 14px 0 6px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.lb-tabs { display: flex; gap: 8px; }
.lb-chip {
  min-height: 34px;
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(246,206,103,.16);
  color: var(--lemon);
  font: 800 11px/1.2 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .06em;
  cursor: pointer;
}
.lb-tabs .lb-chip { opacity: .6; }
.lb-tabs .lb-chip.sel { opacity: 1; background: var(--porch); color: var(--cream); }
.lb-status {
  min-height: 15px;
  color: var(--mint);
  font: 700 12px/1.3 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .03em;
  text-align: center;
}
#lbList {
  list-style: none;
  width: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#lbList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  border-radius: 8px;
  color: #c9dbd4;
  font: 700 13px/1.4 ui-sans-serif, system-ui, sans-serif;
}
#lbList li.me { background: rgba(246,206,103,.16); color: var(--lemon); }
#lbList .rank { width: 26px; text-align: center; }
#lbList .nm {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#lbList .sc { font-variant-numeric: tabular-nums; white-space: nowrap; }
.lb-form { display: flex; gap: 8px; width: 100%; }
.lb-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  color: var(--cream);
  background: rgba(255,255,255,.1);
  border: 2px solid rgba(246,206,103,.35);
  border-radius: 10px;
  outline: none;
  font-size: 14px;
  font-weight: 700;
  user-select: text;
}
.lb-form input:focus { border-color: var(--lemon); }

@media (max-width: 430px) {
  .menu-card { padding: 19px 13px 16px; }
  .porch-scene { padding-left: 12px; padding-right: 12px; }
  .tagline { margin: 12px auto 14px; font-size: 13px; }
  .bot-choice { padding: 9px; }
  .mode-title { font-size: 12px; }
  .mode-blurb { font-size: 10px; }
}

@media (max-height: 700px) {
  .porch-scene { padding-top: calc(42px + env(safe-area-inset-top)); }
  .menu-card { padding-top: 16px; padding-bottom: 14px; }
  .tagline { margin: 9px auto 11px; }
  .mode-block { margin-top: 8px; }
  .rules { margin-top: 9px; }
  footer { padding-top: 12px; }
  .chain-row { min-height: 52px; }
  .chain-cell { height: 52px; }
  .hand { min-height: 65px; }
}

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