/* ==========================================================================
   Appearance: dark mode and text size.
   <html data-theme="dark|light"> and <html data-text="large|larger"> are set
   before first paint by the inline script in index.html (choices are kept on
   this device). With no saved choice the phone's own light/dark setting wins.
   ========================================================================== */

/* Dark palette: same brand yellow, warm near-black surfaces. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --cream: #121216;
  --cream-deep: #1a1a20;
  --surface: #1f1f26;
  --on-ink: #121216;
  --ink: #f4efe8;
  --ink-soft: #dcd6ce;
  --muted: #a4a9b5;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent-soft: #3a2f12;
  --danger: #f07a5a;
  --ok: #3ccf8e;
  --sq: #2a2a32;
  --dw: #b8655b;
  --dl: #5a87b4;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7);
}

/* Soft tints that were written as fixed light colours. */
:root[data-theme="dark"] .topbar { background: rgba(18, 18, 22, 0.9); }
:root[data-theme="dark"] .btn-primary:not(:disabled):hover { background: #ffc21f; }
:root[data-theme="dark"] .lvl, :root[data-theme="dark"] [class*="lvl-pill"] { color: var(--accent); }
:root[data-theme="dark"] .lv-cap { fill: var(--accent); }
:root[data-theme="dark"] .pill.ok,
:root[data-theme="dark"] .history .result-dot.won,
:root[data-theme="dark"] .t-status.running,
:root[data-theme="dark"] #push-btn[disabled] { background: rgba(60, 207, 142, 0.16); color: var(--ok); }
:root[data-theme="dark"] .pill.bad,
:root[data-theme="dark"] .warn-icon,
:root[data-theme="dark"] .c-danger { background: rgba(240, 122, 90, 0.16); color: var(--danger); }
:root[data-theme="dark"] .tone-mint { background: #183a33; }
:root[data-theme="dark"] .tone-blush { background: #3d2621; }
:root[data-theme="dark"] .team-0 { background: rgba(255, 184, 0, 0.16); color: #ffcf4d; }
:root[data-theme="dark"] .team-1 { background: rgba(240, 122, 90, 0.18); color: #ffb39e; }
:root[data-theme="dark"] .set-profile { background: linear-gradient(120deg, #2a2412, #2b1f14); }
:root[data-theme="dark"] .friends-hero { background: radial-gradient(rgba(255, 255, 255, 0.05) 1.2px, transparent 1.4px) 0 0 / 20px 20px, linear-gradient(120deg, #2a2412 0%, #2b1f14 100%); }
:root[data-theme="dark"] .seg-tabs button.is-active .count { background: rgba(0, 0, 0, 0.18); }
:root[data-theme="dark"] .modal { background: rgba(0, 0, 0, 0.6); }
:root[data-theme="dark"] input, :root[data-theme="dark"] textarea, :root[data-theme="dark"] select { color: var(--ink); }
:root[data-theme="dark"] input::placeholder { color: var(--muted); }
/* Warm glow backgrounds behind the welcome and intro art. */
:root[data-theme="dark"] .art { background: radial-gradient(120% 80% at 50% 42%, #2c2513 0%, #1d1a17 55%, var(--cream-deep) 100%); }
:root[data-theme="dark"] .hub-hero { background: radial-gradient(120% 90% at 50% 20%, #2c2513 0%, #1d1a17 60%, var(--cream-deep) 100%); }

/* Text size: rem-based text grows; the board and tiles keep their size. */
:root[data-text="large"] { font-size: 112.5%; }
:root[data-text="larger"] { font-size: 125%; }

/* Appearance controls in Settings */
.set-display { justify-content: space-between; cursor: default; }
.c-ink { background: #2a2a30; }
.mini-seg { display: inline-grid; grid-auto-flow: column; gap: 2px; padding: 3px; border-radius: 999px; background: var(--cream-deep); }
.mini-seg button { padding: 6px 9px; border-radius: 999px; font-size: 0.8125rem; font-weight: 700; color: var(--muted); line-height: 1; }
.mini-seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* Anything drawn on gold or yellow keeps dark lettering in both themes. */
:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .tone-accent,
:root[data-theme="dark"] .brand-tile,
:root[data-theme="dark"] .tile,
:root[data-theme="dark"] .confetti span,
:root[data-theme="dark"] .daily-mini i,
:root[data-theme="dark"] .letter-grid .tile,
:root[data-theme="dark"] .avatar,
:root[data-theme="dark"] .turn-banner.is-warn .turn-clock { color: #0e0e11; }
:root[data-theme="dark"] .btn-primary .hint, :root[data-theme="dark"] .tone-accent span { color: rgba(14, 14, 17, 0.7); }
/* The dark "Play solo" tile stays dark rather than flipping light. */
:root[data-theme="dark"] .tone-dark { background: #2a2a32; color: #fff; border-color: #2a2a32; }
@media (max-width: 400px) { .set-display .set-ic { display: none; } }

/* Offline mode */
.offline-pill { margin-right: auto; padding: 4px 10px; border-radius: 999px; background: var(--cream-deep); color: var(--muted); font-size: 0.75rem; font-weight: 800; }
body.is-offline #friends-open, body.is-offline #join-open, body.is-offline #daily-open, body.is-offline #score-open { opacity: 0.5; }

/* Offline dialog */
.offline-card { position: relative; width: min(340px, 100%); padding: 22px 22px 20px; gap: 8px; animation: sheet-up 0.3s var(--ease-out); }
.offline-card h2 { font-size: 1.25rem; margin-top: 2px; }
.offline-card .hint { margin: 0 0 8px; }
.offline-x { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%; background: var(--cream-deep); color: var(--ink); font-size: 1.3rem; line-height: 1; display: grid; place-items: center; }
.offline-art { width: 150px; justify-self: center; overflow: visible; }
.oa-shadow { fill: var(--line); }
.oa-cloud { fill: var(--accent-soft); stroke: var(--accent-deep); stroke-width: 3; animation: oa-float 3s ease-in-out infinite; }
.oa-wave { fill: none; stroke: var(--muted); stroke-width: 4; stroke-linecap: round; }
.oa-dot { fill: var(--muted); }
.oa-slash { stroke: var(--danger); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 60; stroke-dashoffset: 60; animation: oa-slash 0.5s 0.25s var(--ease-out) forwards; }
.oa-tile rect { fill: var(--tile); stroke: var(--tile-edge); stroke-width: 2; }
.oa-tile text { font: 800 18px var(--font); fill: #0e0e11; text-anchor: middle; }
.oa-tile { transform-origin: 127px 79px; animation: oa-bob 2.4s ease-in-out infinite; }
@keyframes oa-float { 50% { transform: translateY(-3px); } }
@keyframes oa-bob { 50% { transform: rotate(-8deg) translateY(-3px); } }
@keyframes oa-slash { to { stroke-dashoffset: 0; } }

/* Terms / privacy line under sign-in */
.legal-note { font-size: 0.72rem; color: var(--muted); text-align: center; margin: 2px 0 0; }
.legal-note a { color: inherit; text-underline-offset: 2px; }
a.set-row { text-decoration: none; }

/* Share-card buttons */
.share-card-btn { margin-top: 4px; }

/* Tiles left */
.bag-btn { background: none; border: 0; padding: 2px 6px; border-radius: 8px; cursor: pointer; }
.bag-btn:hover { background: var(--cream-deep); color: var(--ink); }
.bag-card { position: relative; width: min(380px, 100%); gap: 8px; }
.bag-card h2 { font-size: 1.2rem; }
.bag-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 4px; }
.bag-cell { position: relative; aspect-ratio: 1; border-radius: 9px; background: var(--tile); box-shadow: inset 0 -3px 0 var(--tile-edge); display: grid; place-items: center; color: #0e0e11; }
.bag-cell b { font-size: 1.05rem; line-height: 1; margin-top: -4px; }
.bag-cell i { position: absolute; right: 4px; bottom: 3px; font-style: normal; font-size: 0.66rem; font-weight: 800; }
.bag-cell.is-out { background: var(--cream-deep); box-shadow: none; color: var(--muted); opacity: 0.55; }
.bag-cell.is-hot:not(.is-out) { box-shadow: inset 0 -3px 0 var(--tile-edge), 0 0 0 2px var(--accent-deep); }
.small-note { font-size: 0.75rem; margin: 2px 0 0; }

/* Swapping tiles: the bag */
.swap-card { width: min(360px, 100%); gap: 10px; }
.swap-card h2 { font-size: 1.2rem; }
.swap-card .hint { margin: -4px 0 0; min-height: 1.3em; }
.swap-bag { justify-self: center; width: 170px; height: 170px; background: none; border: 0; padding: 0; cursor: default; transform-origin: 50% 85%; }
.swap-bag svg { width: 100%; height: 100%; overflow: visible; }
.swap-bag.is-ready { cursor: pointer; animation: bag-invite 1.4s ease-in-out infinite; }
.swap-bag.is-shaking { animation: bag-shake 0.32s ease-in-out infinite; }
.swap-bag.is-pop { animation: bag-pop 0.35s var(--ease-out); }
.sb-shadow { fill: var(--line); }
.sb-body { fill: #c99a52; stroke: #a77a37; stroke-width: 3; }
.sb-neck { fill: #b8873f; }
.sb-frill { fill: #d8ad66; stroke: #a77a37; stroke-width: 3; }
.sb-string { fill: none; stroke: #7a5600; stroke-width: 4; stroke-linecap: round; }
.sb-knot { fill: #7a5600; }
.sb-stamp rect { fill: #ffb800; stroke: #e0a200; stroke-width: 3; }
.sb-stamp text { font: 800 26px var(--font); fill: #0e0e11; text-anchor: middle; }
@keyframes bag-shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-7deg) translateY(-2px); } 75% { transform: rotate(7deg) translateY(-2px); } }
@keyframes bag-invite { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes bag-pop { 0% { transform: scale(1); } 40% { transform: scale(0.92, 1.06); } 100% { transform: scale(1); } }
.swap-row { display: flex; justify-content: center; gap: 6px; min-height: 0; }
.swap-row:empty { display: none; }
.swap-tile { width: 38px; height: 38px; font-size: 1.1rem; position: relative; flex: none; }
.swap-tile.is-slot { background: var(--cream-deep); box-shadow: inset 0 0 0 2px var(--line-strong); }
.swap-tile.is-picked { animation: tile-pick 0.55s var(--ease-out); }
@keyframes tile-pick { 0% { transform: translateY(-60px) rotateY(180deg) scale(0.6); opacity: 0; } 50% { transform: translateY(0) rotateY(90deg); opacity: 1; } 100% { transform: none; } }
.swap-row.is-old .swap-tile { opacity: 0.55; }
.swap-row.is-old.is-dropping .swap-tile { animation: tile-drop 0.6s ease-in forwards; }
.swap-row.is-old.is-dropping .swap-tile:nth-child(2) { animation-delay: 0.05s; } .swap-row.is-old.is-dropping .swap-tile:nth-child(3) { animation-delay: 0.1s; }
.swap-row.is-old.is-dropping .swap-tile:nth-child(n+4) { animation-delay: 0.15s; }
@keyframes tile-drop { to { transform: translateY(-120px) scale(0.3); opacity: 0; } }
/* Keep the new letters secret behind the dialog until they're picked. */
body.is-swapping #rack { visibility: hidden; }
#exchange-btn.is-muted { opacity: 0.55; }

/* Draw for first turn */
.draw-card { width: min(380px, 100%); gap: 10px; }
.draw-card h2 { font-size: 1.3rem; }
.draw-grid { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 6px 0 4px; }
.draw-seat { display: grid; justify-items: center; gap: 6px; width: 70px; }
.draw-seat b { font-size: 0.85rem; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draw-seat small { font-size: 0.72rem; font-weight: 800; color: var(--accent-deep); }
.draw-tile { position: relative; width: 50px; height: 50px; perspective: 600px; }
.draw-tile .back, .draw-tile .face { position: absolute; inset: 0; border-radius: 9px; display: grid; place-items: center; backface-visibility: hidden; font-weight: 800; font-size: 1.5rem; color: #0e0e11; }
.draw-tile .back { background: #c99a52; box-shadow: inset 0 -4px 0 #a77a37; animation: draw-back 0.5s calc(0.5s + var(--i) * 0.38s) var(--ease-out) forwards; }
.draw-tile .face { background: var(--tile); box-shadow: inset 0 -4px 0 var(--tile-edge); transform: rotateY(180deg); animation: draw-face 0.5s calc(0.5s + var(--i) * 0.38s) var(--ease-out) forwards; }
.draw-seat.is-first .draw-tile .face { box-shadow: inset 0 -4px 0 var(--tile-edge), 0 0 0 3px var(--accent-deep); }
.draw-seat small { opacity: 0; animation: fade-in 0.4s 2s forwards; }
@keyframes draw-back { to { transform: rotateY(-180deg); } }
@keyframes draw-face { to { transform: rotateY(0); } }
@keyframes fade-in { to { opacity: 1; } }

/* Word challenges */
.challenge-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; margin: 4px 0 6px; border-radius: 14px; background: var(--accent-soft); border: 1px solid var(--accent); font-size: 0.875rem; animation: sheet-up 0.3s var(--ease-out); }
.challenge-bar.is-yours { background: var(--surface); border-color: var(--line-strong); color: var(--muted); }
.challenge-bar .cb-text { flex: 1 1 200px; min-width: 0; }
.challenge-bar .cb-acts { display: flex; gap: 6px; }
#check-chips { flex-wrap: wrap; }
