/* ================= Earthy palette =================
   Sand / cream surfaces, espresso ink, terracotta accent,
   moss green, ochre, brick red, slate teal and dusty plum. */
:root {
  --sand: #f4ede1; --cream: #fffcf7; --ink: #3b2f25; --ink-2: #4a3b2e; --ink-3: #5c4a3b;
  --bark: #6b5a4a; --muted: #857261; --dim: #a8988a; --line-2: #d9ccbc; --line: #e8dccd;
  --soft: #f3ebdf; --soft-2: #faf6ef;
  --terra: #c0663a; --terra-d: #a8532c; --terra-dd: #8f4524; --terra-l: #f8e9df; --terra-ll: #ecc9b4;
  --moss: #6b8e4e; --moss-d: #557a3a; --moss-l: #eaf0df;
  --ochre: #d4a033; --ochre-d: #a0661d; --ochre-l: #fbf3e0;
  --brick: #b4432f; --brick-l: #f8e4dd;
  --plum: #8b5e6b; --plum-d: #6e4652; --plum-l: #f6eef0; --plum-ll: #e6d3d8;
  --surface: var(--cream);
}
html.dark { --surface: #241d17; color-scheme: dark; }

/* Theme toggle icon swap */
.theme-sun { display: none; }
html.dark .theme-sun { display: block; }
html.dark .theme-moon { display: none; }
html, body { -webkit-tap-highlight-color: transparent; }
body { background: var(--sand); }
.bg-green-50 { background-color: var(--sand) !important; }
.bg-white { background-color: var(--cream) !important; }
/* Map leftover accent utility classes onto the earthy palette */
.text-indigo-500, .text-indigo-600 { color: var(--terra) !important; }
.text-purple-500 { color: var(--plum) !important; }
.text-emerald-600 { color: var(--moss-d) !important; }
.text-rose-600 { color: var(--brick) !important; }
.text-amber-600 { color: var(--ochre-d) !important; }
.text-zinc-900 { color: var(--ink) !important; }
.text-zinc-800 { color: var(--ink-2) !important; }
.text-zinc-700 { color: var(--ink-3) !important; }
.text-zinc-600 { color: var(--bark) !important; }
.text-zinc-500 { color: var(--muted) !important; }
.text-zinc-400 { color: var(--dim) !important; }
.hover\:text-zinc-900:hover, .hover\:text-zinc-800:hover { color: var(--ink) !important; }
.border-zinc-200 { border-color: var(--line) !important; }
.bg-zinc-50 { background-color: var(--soft-2) !important; }
.bg-zinc-100 { background-color: var(--soft) !important; }
#confirmOk { background: var(--brick) !important; }
#confirmOk:hover { background: #9a3826 !important; }
[data-lucide], svg.lucide { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { scrollbar-width: none; }

/* Buttons */
.icon-btn { display: inline-flex; align-items: center; gap: .45rem; height: 36px; padding: 0 .75rem; border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--ink-3); transition: background .15s; }
.icon-btn:hover { background: var(--soft); }
.btn-primary { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; height: 48px; padding: 0 1.25rem; border-radius: 12px; background: var(--ink); color: #fffaf2; font-weight: 600; font-size: 15px; transition: background .15s, opacity .15s, transform .1s; }
.btn-primary:hover:not(:disabled) { background: var(--ink-2); }
.btn-primary:active:not(:disabled) { transform: scale(.98); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-secondary { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; height: 44px; padding: 0 1rem; border-radius: 12px; background: var(--cream); border: 1px solid var(--line); color: var(--ink-2); font-weight: 500; font-size: 14px; transition: background .15s, border-color .15s, opacity .15s; }
.btn-secondary:hover:not(:disabled) { background: var(--soft-2); border-color: var(--line-2); }
.btn-secondary:disabled { opacity: .4; cursor: not-allowed; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,250,242,.35); border-top-color: #fffaf2; border-radius: 50%; animation: spin .8s linear infinite; }
.btn-primary:not(:disabled) .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Setup */
.section-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .6rem; }
.opt-card { text-align: left; display: flex; flex-direction: column; gap: .25rem; padding: 1rem; border-radius: 14px; background: var(--cream); border: 1.5px solid var(--line); transition: border-color .15s, background .15s; }
.opt-card:hover { border-color: var(--line-2); }
.opt-card.active { border-color: var(--ink); background: var(--cream); }
.opt-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--soft); color: var(--bark); margin-bottom: .4rem; transition: background .15s, color .15s; }
.opt-card.active .opt-icon { background: var(--ink); color: #fffaf2; }
.opt-title { font-weight: 600; font-size: 15px; }
.opt-desc { font-size: 13px; color: var(--muted); line-height: 1.35; }
.opt-tag { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 6px; background: var(--terra-l); color: var(--terra-d); }

.seg { display: flex; padding: 4px; background: var(--soft); border-radius: 12px; gap: 4px; }
.seg button { flex: 1; height: 38px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--bark); display: inline-flex; align-items: center; justify-content: center; gap: .4rem; transition: background .15s, color .15s; white-space: nowrap; padding: 0 .5rem; }
.seg button [data-lucide], .seg button svg { width: 16px; height: 16px; }
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--cream); color: var(--ink); outline: 1px solid var(--line); }

.field { display: flex; align-items: center; gap: .6rem; height: 48px; padding: 0 .9rem; border-radius: 12px; background: var(--cream); border: 1.5px solid var(--line); transition: border-color .15s; }
.field:focus-within { border-color: var(--pc); }
.field-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--pc); flex-shrink: 0; }
.field input { flex: 1; min-width: 0; outline: none; background: transparent; font-size: 15px; font-weight: 500; }
.field.locked { background: var(--soft-2); }

.rule-summary { font-size: 14px; color: var(--ink-3); background: var(--cream); border: 1px dashed var(--line-2); border-radius: 12px; padding: .85rem 1rem; line-height: 1.5; }
.rule-summary b { color: var(--ink); }

@media (max-width: 480px) { .opt-card { padding: .8rem; } .opt-desc { font-size: 12px; } .opt-title { font-size: 14px; } }

/* Online */
.auth-box { display: flex; align-items: center; gap: .75rem; padding: .8rem .9rem; border-radius: 12px; background: var(--cream); border: 1px solid var(--line); font-size: 14px; }
.lobby-icon { width: 60px; height: 60px; border-radius: 18px; display: grid; place-items: center; background: var(--terra); color: #fffaf2; }
.lobby-icon svg { width: 26px; height: 26px; }
.code-box { display: flex; align-items: center; justify-content: space-between; gap: 1rem; height: 76px; padding: 0 1.1rem 0 1.4rem; border-radius: 16px; background: var(--cream); border: 1.5px dashed var(--line-2); transition: border-color .15s; }
.code-box:hover { border-color: var(--terra); }
.code-box #inviteCode { font-size: 28px; font-weight: 700; letter-spacing: .08em; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-copy { display: inline-flex; align-items: center; gap: .4rem; height: 36px; padding: 0 .8rem; border-radius: 10px; background: var(--soft); font-size: 13px; font-weight: 600; color: var(--ink-3); flex-shrink: 0; }
.code-copy svg { width: 15px; height: 15px; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--moss); position: relative; }
.pulse-dot::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--moss); opacity: 0; animation: ping 1.6s ease-out infinite; }
@keyframes ping { 0% { transform: scale(.5); opacity: .8; } 100% { transform: scale(1.6); opacity: 0; } }

/* Reconnect / away / meaning */
.resume-box { border-color: var(--terra-ll); background: var(--terra-l); }
.net-banner { display: flex; align-items: center; gap: .7rem; padding: .7rem .9rem; margin-bottom: .75rem; border-radius: 12px; background: var(--ochre-l); border: 1px solid #ecd49a; color: #7a4a14; font-size: 13px; }
.net-banner.hidden, .away-bar.hidden { display: none; }
.spinner.dark { border-color: rgba(122,74,20,.25); border-top-color: var(--ochre-d); flex-shrink: 0; }
.away-bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: .6rem; padding: .6rem .8rem; border-radius: 12px; background: var(--soft); color: var(--bark); font-size: 13px; line-height: 1.4; }
.away-bar svg { width: 16px; height: 16px; }
.away-btn { display: inline-flex; align-items: center; gap: .35rem; height: 30px; padding: 0 .7rem; border-radius: 8px; background: var(--cream); border: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.away-btn:hover { border-color: var(--dim); }
.away-btn svg { width: 14px; height: 14px; }
.p-avatar.away { background: var(--dim) !important; }
.meaning { border: 1px solid var(--line); border-radius: 12px; padding: .8rem .9rem; background: var(--soft-2); }
.meaning.hidden { display: none; }
.meaning-head { display: flex; align-items: center; gap: .45rem; font-size: 12px; font-weight: 500; color: var(--bark); margin-bottom: .45rem; }
.meaning-head svg { width: 15px; height: 15px; color: var(--terra); }
.meaning-head b { color: var(--ink); letter-spacing: .03em; }
.meaning-body { font-size: 13.5px; color: var(--ink-3); line-height: 1.5; }
.meaning-list { list-style: decimal; padding-left: 1.1rem; display: flex; flex-direction: column; gap: .3rem; }
.meaning-list .pos { font-style: italic; color: var(--terra); font-size: 12px; margin-right: .35rem; }
.skeleton { height: 10px; border-radius: 5px; background: var(--line); margin: .35rem 0; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.modal-panel { max-height: calc(100dvh - 2rem); overflow-y: auto; }

/* Public lobby browser */
.lobby-row { display: flex; align-items: center; gap: .7rem; min-height: 62px; padding: .55rem .55rem .55rem .7rem; border-radius: 14px; background: var(--cream); border: 1.5px solid var(--line); transition: border-color .15s; }
.lobby-row:hover { border-color: var(--line-2); }
.lobby-count { display: inline-flex; align-items: center; gap: .3rem; font-size: 12px; font-weight: 600; color: var(--bark); background: var(--soft); padding: 4px 8px; border-radius: 8px; flex-shrink: 0; }
.lobby-count svg { width: 13px; height: 13px; }
.lobby-join { height: 36px; padding: 0 .95rem; border-radius: 10px; background: var(--ink); color: #fffaf2; font-size: 13px; font-weight: 600; flex-shrink: 0; transition: background .15s; }
.lobby-join:hover { background: var(--ink-2); }
.lobby-empty { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1rem; border-radius: 14px; border: 1.5px dashed var(--line-2); color: var(--bark); font-size: 14px; }
.lobby-empty svg { width: 20px; height: 20px; color: var(--dim); }
@media (max-width: 420px) { .lobby-count { display: none; } }

/* Setup player rows */
.prow { display: flex; align-items: center; gap: .6rem; height: 56px; padding: 0 .5rem 0 .6rem; border-radius: 14px; background: var(--cream); border: 1.5px solid var(--line); transition: border-color .15s; }
.prow:focus-within { border-color: var(--pc); }
.prow input { flex: 1; min-width: 0; outline: none; background: transparent; font-size: 15px; font-weight: 500; }
.prow .tag { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--soft); padding: 3px 7px; border-radius: 6px; flex-shrink: 0; }
.p-avatar.sm { width: 34px; height: 34px; border-radius: 10px; font-size: 14px; }
.p-avatar.sm svg { width: 17px; height: 17px; }
.mini-seg { display: flex; padding: 3px; background: var(--soft); border-radius: 10px; gap: 2px; flex-shrink: 0; }
.mini-seg button { width: 34px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); transition: background .15s, color .15s; }
.mini-seg button svg { width: 16px; height: 16px; }
.mini-seg button.active { background: var(--cream); color: var(--ink); outline: 1px solid var(--line); }
.rm-btn { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: var(--dim); flex-shrink: 0; transition: background .15s, color .15s; }
.rm-btn:hover:not(:disabled) { background: var(--brick-l); color: var(--brick); }
.rm-btn:disabled { opacity: .3; cursor: not-allowed; }
.rm-btn svg { width: 16px; height: 16px; }
.add-row { width: 100%; height: 48px; border-radius: 14px; border: 1.5px dashed var(--line-2); color: var(--bark); font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: .45rem; transition: border-color .15s, color .15s, background .15s; }
.add-row:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); background: var(--cream); }
.add-row:disabled { opacity: .45; cursor: not-allowed; }

/* Game player grid */
.player-grid { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.player-grid.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.player-grid.n4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.player-grid.n5, .player-grid.n6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (min-width: 640px) { .player-grid.n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.player-card.compact { padding: .6rem .65rem; gap: .55rem; }
.player-card.compact .p-avatar { width: 32px; height: 32px; font-size: 14px; border-radius: 9px; }
.player-card.compact .p-avatar svg { width: 17px; height: 17px; }
.player-card.compact .p-score { font-size: 20px; }
.player-card.out { opacity: .42; }
.player-card.sitting { opacity: .6; }
.player-card.out .p-name { text-decoration: line-through; }
.hearts { display: flex; gap: 2px; margin-top: 3px; flex-wrap: wrap; }
.hearts svg { width: 12px; height: 12px; }
.p-status { font-size: 11px; color: var(--muted); margin-top: 2px; }
.player-grid.dense .p-sub { display: none; }
@media (max-width: 480px) { .player-grid.dense .player-card .p-avatar { display: none; } .player-grid.dense .p-turn { display: none !important; } }

/* Result board */
.res-board { border: 1px solid var(--soft); border-radius: 12px; overflow: hidden; }
.res-row { display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem; font-size: 14px; }
.res-row + .res-row { border-top: 1px solid var(--soft); }
.res-row .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--pc); flex-shrink: 0; }
.res-row .nm { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-row.out .nm { color: var(--dim); text-decoration: line-through; }
.res-row .val { font-weight: 700; font-family: 'Space Grotesk', sans-serif; display: flex; align-items: center; gap: 2px; }
.res-row .val svg { width: 13px; height: 13px; }
.res-row .delta { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.res-row .delta.neg { background: var(--brick-l); color: var(--brick); }
.res-row .delta.pos { background: var(--moss-l); color: var(--moss-d); }

/* Player cards */
.player-card { display: flex; align-items: center; gap: .75rem; padding: .75rem .85rem; background: var(--cream); border: 1.5px solid var(--line); border-radius: 14px; transition: border-color .2s, background .2s; min-width: 0; }
.player-card.active { border-color: var(--pc); }
.p-avatar { width: 38px; height: 38px; border-radius: 11px; background: var(--pc); color: #fffaf2; display: grid; place-items: center; font-weight: 700; font-family: 'Space Grotesk', sans-serif; font-size: 16px; flex-shrink: 0; }
.p-avatar svg { width: 20px; height: 20px; }
.p-name { font-weight: 600; font-size: 14px; }
.p-sub { font-size: 12px; color: var(--muted); }
.p-turn { display: none; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 6px; color: var(--pc); background: color-mix(in srgb, var(--pc) 12%, var(--cream)); }
.player-card.active .p-turn { display: inline-block; }
.p-score { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 26px; line-height: 1; padding-left: .25rem; }
.pips { display: flex; gap: 3px; margin-top: 5px; }
.pip { width: 14px; height: 4px; border-radius: 2px; background: var(--line); }
.pip.on { background: var(--pc); }
@media (max-width: 480px) { .p-avatar { width: 32px; height: 32px; font-size: 14px; border-radius: 9px; } .p-score { font-size: 22px; } .p-sub { display: none; } }

.hist-dot { flex-shrink: 0; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; color: #fffaf2; background: var(--pc); text-transform: uppercase; letter-spacing: .03em; }

/* Tiles */
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 100%; padding: 0 .5rem; }
.tile { width: 56px; height: 64px; border-radius: 12px; background: var(--cream); border: 2px solid var(--pc); border-bottom-width: 5px; display: grid; place-items: center; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 30px; text-transform: uppercase; color: var(--ink); position: relative; }
.tile.new { animation: pop .28s cubic-bezier(.2,1.4,.4,1); }
.tile.ghost { border: 2px dashed var(--line-2); border-bottom-width: 2px; color: var(--dim); background: transparent; }
.tile.ghost.pending { border-style: solid; border-color: var(--pc); border-bottom-width: 5px; background: color-mix(in srgb, var(--pc) 8%, var(--cream)); color: var(--pc); animation: breathe 1.4s ease-in-out infinite; }
.tile.ghost.thinking::after { content: ''; width: 22px; height: 6px; background: radial-gradient(circle, var(--dim) 2.5px, transparent 3px) 0 0/8px 6px repeat-x; animation: dots 1s steps(3) infinite; }
.tile.word { background: color-mix(in srgb, var(--pc) 10%, var(--cream)); }
.tiles.sm .tile { width: 38px; height: 44px; font-size: 20px; border-radius: 9px; border-bottom-width: 4px; }
.tiles.long .tile { width: 44px; height: 52px; font-size: 24px; }
@media (max-width: 480px) { .tile { width: 44px; height: 52px; font-size: 24px; } .tiles.long .tile { width: 36px; height: 44px; font-size: 20px; } }
@keyframes pop { 0% { transform: scale(.4) translateY(12px); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes breathe { 50% { transform: translateY(-3px); } }
@keyframes dots { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.tiles.shake { animation: shake .4s; }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

.toast { position: absolute; bottom: 0; left: 50%; transform: translate(-50%, 8px); display: inline-flex; align-items: center; gap: .5rem; background: var(--ink); color: #fffaf2; font-size: 13px; font-weight: 500; padding: .55rem .9rem; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap; max-width: 92vw; }
.toast [data-lucide], .toast svg { width: 16px; height: 16px; color: #e08a72; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Turn timer */
.turn-timer { display: flex; align-items: center; gap: .55rem; width: 220px; max-width: 80vw; margin-top: .9rem; color: var(--pc); }
.turn-timer.hidden { display: none; }
.turn-timer svg { width: 16px; height: 16px; }
.tt-track { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.tt-fill { height: 100%; width: 100%; border-radius: 3px; background: var(--pc); transition: width .15s linear; }
.tt-num { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 14px; min-width: 2.2em; text-align: right; font-variant-numeric: tabular-nums; }
.turn-timer.low { color: var(--brick); animation: tick 1s ease-in-out infinite; }
.turn-timer.low .tt-fill { background: var(--brick); }
@keyframes tick { 50% { opacity: .55; } }

/* Keyboard */
.kbd { display: flex; flex-direction: column; gap: 6px; user-select: none; }
.kbd-row { display: flex; justify-content: center; gap: 6px; }
.key { flex: 1; max-width: 52px; height: 52px; border-radius: 10px; background: var(--cream); border: 1px solid var(--line); border-bottom-width: 3px; font-weight: 600; font-size: 17px; text-transform: uppercase; color: var(--ink-2); transition: background .12s, color .12s, border-color .12s, transform .08s; }
.key:hover:not(:disabled) { background: var(--soft-2); }
.key:active:not(:disabled) { transform: translateY(1px); }
.key.sel { background: var(--pc); border-color: var(--pc); color: #fffaf2; }
.key:disabled { opacity: .35; cursor: not-allowed; }
.kbd.locked .key { pointer-events: none; opacity: .5; }
@media (max-width: 480px) { .kbd-row { gap: 4px; } .kbd { gap: 5px; } .key { height: 48px; font-size: 15px; border-radius: 8px; } }

/* Modals */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; padding: 1rem; }
@media (min-width: 640px) { .modal { align-items: center; } }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(59,47,37,.45); animation: fade .2s; }
.modal-panel { position: relative; width: 100%; max-width: 440px; background: var(--cream); border-radius: 20px; padding: 1.4rem; animation: rise .25s cubic-bezier(.2,1,.4,1); border: 1px solid var(--line); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
.res-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: color-mix(in srgb, var(--pc) 14%, var(--cream)); color: var(--pc); }
.res-icon svg { width: 22px; height: 22px; }
.word-chip { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 4px 8px; border-radius: 7px; background: var(--soft); color: var(--ink-3); }
.word-chip.obscure { background: var(--plum-l); color: var(--plum-d); font-style: italic; }
.score-line { display: flex; align-items: center; justify-content: center; gap: .9rem; padding: .8rem; background: var(--soft-2); border-radius: 12px; font-weight: 600; font-size: 14px; }
.score-line b { font-family: 'Space Grotesk', sans-serif; font-size: 20px; margin-left: .35rem; }
.ch-input { width: 100%; height: 50px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--cream); padding: 0 1rem; font-size: 18px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; outline: none; font-family: 'Space Grotesk', sans-serif; }
.ch-input:focus { border-color: var(--ink); }
.rules-list { list-style: none; counter-reset: r; display: flex; flex-direction: column; gap: .75rem; }
.rules-list li { counter-increment: r; position: relative; padding-left: 2.1rem; }
.rules-list li::before { content: counter(r); position: absolute; left: 0; top: 0; width: 1.5rem; height: 1.5rem; border-radius: 7px; background: var(--terra); color: #fffaf2; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.rules-list b { color: var(--ink); }

/* ================= Stats ================= */
#btnStats { position: relative; }
#btnStats.has-pending::after { content: ''; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--terra); }
.stats-who { display: flex; align-items: center; gap: .45rem; font-size: 12px; color: var(--muted); margin-bottom: .75rem; }
.stats-who svg { width: 15px; height: 15px; color: var(--moss); }
.stats-who b { color: var(--ink-3); }
.stat-grid { display: grid; gap: 8px; }
.stat-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 420px) { .stat-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat-tile { border: 1px solid var(--line); border-radius: 12px; padding: .65rem .75rem; min-width: 0; }
.stat-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 24px; line-height: 1.15; margin-top: 2px; color: var(--ink); }
.stat-of { font-size: 14px; color: var(--dim); font-weight: 600; }
.stat-sub { font-size: 11px; color: var(--dim); margin-top: 1px; }
.stats-section { margin-top: 1.25rem; }
.lw-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.lw-row { display: flex; align-items: center; gap: .65rem; padding: .5rem .75rem; }
.lw-row + .lw-row { border-top: 1px solid var(--soft); }
.lw-rank { width: 20px; font-size: 12px; font-weight: 700; color: var(--dim); font-family: 'Space Grotesk', sans-serif; }
.lw-row:first-child .lw-rank { color: var(--ochre); }
.lw-word { font-family: 'Space Grotesk', sans-serif; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; font-size: 15px; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lw-meta { flex: 1; font-size: 11px; color: var(--dim); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lw-len { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--terra-l); color: var(--terra-d); flex-shrink: 0; }
.round-bar { height: 8px; border-radius: 4px; background: var(--brick-l); overflow: hidden; }
.round-bar span { display: block; height: 100%; background: var(--moss); border-radius: 4px; }
.rg-list { display: flex; flex-direction: column; gap: 6px; }
.rg-row { display: flex; align-items: center; gap: .65rem; padding: .55rem .7rem; border-radius: 12px; border: 1px solid var(--line); }
.rg-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.rg-icon svg { width: 15px; height: 15px; }
.rg-icon.won { background: var(--moss-l); color: var(--moss-d); }
.rg-icon.lost { background: var(--brick-l); color: var(--brick); }
.stats-mini-empty { font-size: 13px; color: var(--dim); padding: .9rem; border: 1.5px dashed var(--line); border-radius: 12px; text-align: center; }
.stats-empty { display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 2.5rem 0; color: var(--muted); font-size: 14px; }
.stats-signin { text-align: center; padding: .75rem 0 .25rem; }
.stats-signin-icon { width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; display: grid; place-items: center; background: var(--terra-l); color: var(--terra); }
.stats-signin-icon svg { width: 26px; height: 26px; }
.stats-pending { display: flex; align-items: center; gap: .5rem; justify-content: center; margin: .9rem auto 0; padding: .55rem .8rem; border-radius: 10px; background: var(--terra-l); color: var(--terra-dd); font-size: 12.5px; max-width: 360px; text-align: left; }
.stats-pending svg { width: 15px; height: 15px; }

/* Stats / leaderboard view switch */
.view-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.view-tabs button { display: inline-flex; align-items: center; gap: .4rem; height: 38px; padding: 0 .8rem; font-size: 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s; }
.view-tabs button svg { width: 16px; height: 16px; }
.view-tabs button:hover { color: var(--ink); }
.view-tabs button.active { color: var(--ink); border-bottom-color: var(--terra); font-weight: 600; }

/* Leaderboard */
.lb-tabs button { height: 34px; font-size: 13px; }
.lb-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.lb-row { display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem; min-height: 46px; }
.lb-row + .lb-row { border-top: 1px solid var(--soft); }
.lb-row.me { background: var(--terra-l); }
.lb-rank { width: 24px; display: grid; place-items: center; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 13px; color: var(--dim); flex-shrink: 0; }
.lb-rank svg { width: 17px; height: 17px; }
.lb-rank.m1 { color: #c99a2e; }
.lb-rank.m2 { color: #9a8f84; }
.lb-rank.m3 { color: #a8532c; }
.lb-avatar { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--soft); color: var(--bark); font-weight: 700; font-size: 13px; font-family: 'Space Grotesk', sans-serif; flex-shrink: 0; }
.lb-row.me .lb-avatar { background: var(--terra); color: #fffaf2; }
.lb-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-you { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 5px; background: var(--terra); color: #fffaf2; margin-left: 4px; vertical-align: 1px; }
.lb-val { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 17px; }
.lb-sub { font-size: 11px; color: var(--dim); width: 68px; text-align: right; flex-shrink: 0; }
.lb-word { font-family: 'Space Grotesk', sans-serif; font-weight: 700; letter-spacing: .05em; font-size: 14px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-len { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--terra-l); color: var(--terra-d); flex-shrink: 0; }
.lb-gap { display: flex; justify-content: center; padding: .35rem 0; }
.lb-gap span { width: 4px; height: 4px; border-radius: 50%; background: var(--line-2); box-shadow: 0 -8px 0 var(--line-2), 0 8px 0 var(--line-2); margin: 8px 0; }
.lb-foot { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--dim); margin-top: .6rem; }
.lb-foot svg { width: 13px; height: 13px; }
.lb-toggle { display: flex; align-items: center; gap: .75rem; padding: .7rem .85rem; border-radius: 12px; border: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.lb-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.lb-switch { width: 38px; height: 22px; border-radius: 11px; background: var(--line-2); position: relative; flex-shrink: 0; transition: background .15s; }
.lb-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fffaf2; transition: transform .15s; }
.lb-toggle input:checked + .lb-switch { background: var(--moss); }
.lb-toggle input:checked + .lb-switch::after { transform: translateX(16px); }
.lb-toggle input:focus-visible + .lb-switch { outline: 2px solid var(--terra); outline-offset: 2px; }

/* End-of-game stats summary */
.game-summary { border: 1px solid var(--line); border-radius: 14px; padding: .8rem .85rem; animation: rise .35s cubic-bezier(.2,1,.4,1) .15s both; }
.game-summary.hidden { display: none; }
.gs-head { display: flex; align-items: center; gap: .45rem; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.gs-head svg { width: 15px; height: 15px; color: var(--terra); }
.gs-tag { margin-left: auto; font-size: 11px; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--dim); }
.gs-list { display: flex; flex-direction: column; gap: 6px; margin-top: .65rem; }
.gs-item { display: flex; align-items: center; gap: .6rem; font-size: 13.5px; color: var(--ink-3); line-height: 1.35; }
.gs-item b { color: var(--ink); }
.gs-ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.gs-ic svg { width: 15px; height: 15px; }
.gs-item.warm .gs-ic { background: var(--terra-l); color: var(--terra-d); }
.gs-item.gold .gs-ic { background: var(--ochre-l); color: var(--ochre-d); }
.gs-item.cool .gs-ic { background: var(--soft); color: var(--muted); }
.gs-item.indigo .gs-ic { background: #e6eeee; color: #4f7f80; }
.gs-word { font-family: 'Space Grotesk', sans-serif; letter-spacing: .05em; }
.gs-dim { color: var(--dim); font-size: 12px; }
.gs-badge { flex-shrink: 0; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 6px; background: var(--ink); color: #fffaf2; }
.gs-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--soft); }
.gs-k { font-size: 11px; color: var(--dim); font-weight: 500; }
.gs-v { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 18px; color: var(--ink); display: flex; align-items: baseline; gap: 5px; }
.gs-of { font-size: 12px; color: var(--dim); font-weight: 600; }
.gs-delta { font-family: 'Inter', sans-serif; font-size: 11px; font-weight: 700; color: var(--dim); }
.gs-delta.up { color: var(--moss-d); }
.gs-delta.down { color: var(--brick); }
.gs-save { display: flex; align-items: center; gap: .6rem; margin-top: .7rem; padding: .55rem .65rem; border-radius: 10px; background: var(--terra-l); font-size: 12.5px; color: var(--terra-dd); }
.gs-save > span { flex: 1; min-width: 0; }
.gs-save-btn { height: 30px; padding: 0 .75rem; border-radius: 8px; background: var(--terra-d); color: #fffaf2; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.gs-save-btn:hover { background: var(--terra-dd); }
.gs-saved { display: inline-flex; align-items: center; gap: .4rem; }
.gs-saved svg { width: 15px; height: 15px; }

/* ================= Chat ================= */
#btnChat.on { background: var(--soft); }
.chat-badge { position: absolute; top: 2px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--brick); color: #fffaf2; font-size: 10px; font-weight: 700; display: grid; place-items: center; line-height: 1; }
.chat-badge.hidden { display: none; }
.chat-panel { position: fixed; z-index: 40; right: 12px; top: 64px; bottom: 12px; width: 340px; max-width: calc(100vw - 24px); display: flex; flex-direction: column; background: var(--cream); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; transform: translateX(calc(100% + 24px)); opacity: 0; pointer-events: none; transition: transform .25s cubic-bezier(.2,1,.4,1), opacity .2s; }
.chat-panel.open { transform: none; opacity: 1; pointer-events: auto; }
@media (max-width: 640px) {
  .chat-panel { left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-width: none; height: min(70dvh, 520px); border-radius: 18px 18px 0 0; border-bottom: 0; transform: translateY(100%); }
}
.chat-head { display: flex; align-items: center; gap: .5rem; height: 52px; padding: 0 .5rem 0 1rem; border-bottom: 1px solid var(--soft); flex-shrink: 0; }
.chat-head > svg { width: 18px; height: 18px; color: var(--terra); }
.chat-list { flex: 1; overflow-y: auto; padding: .9rem; display: flex; flex-direction: column; gap: 4px; }
.chat-empty { margin: auto; text-align: center; color: var(--dim); font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: .5rem; max-width: 200px; }
.chat-empty svg { width: 28px; height: 28px; }
.chat-msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 85%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-name { font-size: 11px; font-weight: 600; color: var(--pc); margin: 6px 4px 2px; }
.chat-bubble { padding: .45rem .75rem; border-radius: 14px; font-size: 14px; line-height: 1.35; background: var(--soft); color: var(--ink); word-break: break-word; border-top-left-radius: 6px; }
.chat-msg.mine .chat-bubble { background: var(--pc); color: #fffaf2; border-top-left-radius: 14px; border-top-right-radius: 6px; }
.chat-react-line { align-self: center; display: inline-flex; align-items: center; gap: .35rem; font-size: 12px; color: var(--muted); margin: 4px 0; }
.chat-react-line .dot { width: 7px; height: 7px; border-radius: 50%; }
.chat-react-line b { color: var(--ink-3); font-weight: 600; }
.chat-react-line .emo { font-size: 18px; line-height: 1; }
.chat-tools { border-top: 1px solid var(--soft); padding: .6rem .6rem calc(.6rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: .5rem; flex-shrink: 0; }
.chat-reacts { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.react-btn { height: 38px; border-radius: 10px; font-size: 21px; line-height: 1; transition: background .12s, transform .1s; }
.react-btn:hover { background: var(--soft); }
.react-btn:active { transform: scale(.88); }
.chat-phrases { display: flex; gap: 6px; overflow-x: auto; }
.phrase-btn { flex-shrink: 0; height: 30px; padding: 0 .7rem; border-radius: 15px; border: 1px solid var(--line); font-size: 12.5px; font-weight: 500; color: var(--ink-3); white-space: nowrap; transition: background .12s, border-color .12s; }
.phrase-btn:hover { background: var(--soft-2); border-color: var(--line-2); }
.chat-form { display: flex; gap: 6px; }
.chat-form input { flex: 1; min-width: 0; height: 42px; padding: 0 .9rem; border-radius: 12px; border: 1.5px solid var(--line); background: var(--cream); font-size: 14px; outline: none; transition: border-color .15s; }
.chat-form input:focus { border-color: var(--ink); }
.chat-send { width: 42px; height: 42px; border-radius: 12px; background: var(--ink); color: #fffaf2; display: grid; place-items: center; flex-shrink: 0; }
.chat-send:hover { background: var(--ink-2); }
.chat-peek { position: fixed; z-index: 39; top: 64px; right: 12px; max-width: min(320px, calc(100vw - 24px)); display: flex; align-items: center; gap: .45rem; padding: .55rem .8rem; border-radius: 12px; background: var(--ink); color: #fffaf2; font-size: 13px; cursor: pointer; opacity: 0; transform: translateY(-8px); pointer-events: none; transition: opacity .2s, transform .2s; }
.chat-peek.show { opacity: 1; transform: none; pointer-events: auto; }
.chat-peek .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); flex-shrink: 0; }
.chat-peek b { flex-shrink: 0; }
.react-layer { position: fixed; inset: 0; pointer-events: none; z-index: 45; overflow: hidden; }
.react-float { position: absolute; bottom: 18%; display: flex; flex-direction: column; align-items: center; gap: 2px; animation: floatUp 2.6s ease-out forwards; }
.react-float .emo { font-size: 44px; line-height: 1; }
.react-float .who { font-size: 11px; font-weight: 700; color: #fffaf2; background: var(--pc); padding: 1px 7px; border-radius: 8px; }
@keyframes floatUp { 0% { transform: translateY(20px) scale(.5); opacity: 0; } 15% { transform: translateY(0) scale(1.1); opacity: 1; } 70% { opacity: 1; } 100% { transform: translateY(-220px) scale(1); opacity: 0; } }

/* ================= Menu flow ================= */
.home-logo { width: 96px; height: 96px; border-radius: 24px; }
.home-play { width: 100%; max-width: 280px; height: 58px; font-size: 18px; border-radius: 16px; background: var(--terra); }
.home-play:hover:not(:disabled) { background: var(--terra-d); }
.home-play svg { width: 20px; height: 20px; }
.choice-card { display: flex; align-items: center; gap: 1rem; width: 100%; text-align: left; padding: 1.1rem 1.1rem; border-radius: 18px; background: var(--cream); border: 1.5px solid var(--line); transition: border-color .15s, transform .1s; }
.choice-card:hover { border-color: var(--pc); }
.choice-card:active { transform: scale(.99); }
.choice-ic { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; flex-shrink: 0; background: color-mix(in srgb, var(--pc) 13%, var(--cream)); color: var(--pc); }
.choice-ic svg { width: 24px; height: 24px; }
.choice-title { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-weight: 600; font-size: 17px; color: var(--ink); }
.choice-desc { display: block; font-size: 13.5px; color: var(--muted); line-height: 1.4; margin-top: 2px; }
.rule-summary-btn { display: flex; align-items: flex-start; gap: .75rem; transition: border-color .15s; }
.rule-summary-btn:hover { border-color: var(--dim); }
.rule-edit { display: inline-flex; align-items: center; gap: .3rem; flex-shrink: 0; font-size: 12px; font-weight: 600; color: var(--bark); padding: 3px 8px; border-radius: 8px; background: var(--soft); }
.rule-edit svg { width: 14px; height: 14px; }
#btnSettings svg { transition: transform .3s; }
#btnSettings:hover svg { transform: rotate(45deg); }

/* Training coach */
.train-intro { border-color: var(--plum-ll); background: var(--plum-l); }
.coach { margin-bottom: .75rem; padding: .65rem .75rem; border-radius: 14px; border: 1px solid var(--plum-ll); background: var(--plum-l); }
.coach.hidden { display: none; }
.coach-head { display: flex; align-items: center; gap: .5rem; }
.coach-tag { display: inline-flex; align-items: center; gap: .35rem; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--plum); }
.coach-tag svg { width: 15px; height: 15px; }
.coach-btn { display: inline-flex; align-items: center; gap: .3rem; height: 30px; padding: 0 .65rem; border-radius: 9px; background: var(--cream); border: 1px solid var(--plum-ll); font-size: 12.5px; font-weight: 600; color: var(--plum-d); transition: border-color .15s, opacity .15s; }
.coach-btn:hover:not(:disabled) { border-color: var(--plum); }
.coach-btn:disabled { opacity: .4; cursor: not-allowed; }
.coach-btn svg { width: 14px; height: 14px; }
.coach-text { font-size: 13px; color: var(--ink-3); line-height: 1.45; margin-top: .45rem; min-height: 19px; }
.coach-words { display: flex; flex-wrap: wrap; gap: 5px; margin-top: .5rem; }
.coach-words.hidden { display: none; }
.risk { display: inline-block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 6px; margin-right: .45rem; vertical-align: 1px; color: #fffaf2; }
.risk.good { background: var(--moss); }
.risk.mid { background: var(--ochre); }
.risk.bad { background: var(--brick); }

/* Next-round vote */
.res-vote { border: 1px solid var(--line); border-radius: 14px; padding: .75rem .85rem; background: var(--soft-2); }
.res-vote.hidden { display: none; }
.vote-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-size: 13.5px; color: var(--ink-2); }
.vote-head b { color: var(--terra); font-family: 'Space Grotesk', sans-serif; font-size: 15px; }
.vote-count { font-size: 12px; color: var(--muted); white-space: nowrap; }
.vote-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: .55rem; }
.vote-bar span { display: block; height: 100%; border-radius: 3px; background: var(--moss); transition: width .25s; }
.vote-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: .6rem; }
.vote-chip { display: inline-flex; align-items: center; gap: .35rem; height: 26px; padding: 0 .6rem; border-radius: 13px; border: 1px solid var(--line); background: var(--cream); font-size: 12px; font-weight: 600; color: var(--muted); }
.vote-chip svg { width: 12px; height: 12px; }
.vote-chip .vote-dot { width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--dim); }
.vote-chip.on { border-color: var(--pc); color: var(--pc); background: color-mix(in srgb, var(--pc) 10%, var(--cream)); }

/* Result actions */
.res-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.res-actions:has(#resChange:not([style*="none"])) #resChange { grid-column: 1 / -1; order: -1; }
.res-actions button { width: 100%; }
.res-actions #resUndo:not([style*="none"]) { grid-column: 1 / -1; order: -2; }

/* Word list settings */
.seg-wrap { flex-wrap: wrap; }
.seg-wrap button { flex: 1 1 auto; min-width: calc(50% - 4px); }
@media (min-width: 480px) { .seg-wrap button { min-width: 0; } }
.custom-words { width: 100%; border-radius: 12px; border: 1.5px solid var(--line); background: var(--cream); padding: .7rem .85rem; font-size: 14px; line-height: 1.5; outline: none; resize: vertical; text-transform: lowercase; }
.custom-words:focus { border-color: var(--ink); }

/* Game action bar: Play letter always stays on screen */
html, body { overflow-x: hidden; }
#app { min-width: 0; max-width: 100vw; }
.act-bar { display: flex; align-items: center; gap: 8px; width: 100%; min-width: 0; }
.act-bar > button { flex: 0 0 auto; min-width: 0; }
.act-bar #btnPlay { margin-left: auto; flex: 1 1 auto; max-width: 220px; white-space: nowrap; }
.act-bar .btn-secondary { padding: 0 .8rem; white-space: nowrap; }
@media (max-width: 640px) {
  /* Phones: every button keeps its label. Secondary actions share one row,
     and Play letter gets its own full-width row underneath. */
  .act-bar { flex-wrap: wrap; gap: 6px; }
  .act-bar > button.btn-secondary { flex: 1 1 0; padding: 0 .5rem; gap: .35rem; height: 42px; font-size: 13.5px; }
  .act-bar > button[style*="none"] { display: none !important; }
  .act-bar #btnPlay { flex: 1 1 100%; max-width: none; margin-left: 0; height: 48px; order: 10; }
}
@media (max-width: 360px) {
  .act-bar > button.btn-secondary { font-size: 12.5px; padding: 0 .35rem; }
  .act-bar > button.btn-secondary svg { width: 15px; height: 15px; }
}

/* ===== Full-screen game layout (phones, tablets, desktops) =====
   The game screen fills the visible viewport: players + word at the top, the
   keyboard pinned to the bottom, and the word area flexing to take what's left. */
#app { min-height: 100vh; min-height: 100dvh; }
body.in-game #app { min-height: 100vh; min-height: 100dvh; }
body.in-game main { display: flex; flex-direction: column; }
#gameScreen { padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
#gameScreen .word-stage { flex: 1 1 auto; min-height: 180px; }
#keyboard .kbd-row { width: 100%; }
@media (max-width: 640px) {
  #gameScreen { padding-left: max(.6rem, env(safe-area-inset-left)); padding-right: max(.6rem, env(safe-area-inset-right)); padding-top: .75rem; }
  .key { max-width: none; height: 50px; }
  .kbd { gap: 6px; }
  .kbd-row { gap: 5px; }
}
/* Short screens (landscape phones, small laptops): tighten vertical spacing */
@media (max-height: 720px) {
  #gameScreen .word-stage { min-height: 140px; padding-top: 1rem; padding-bottom: 1rem; }
  .tile { width: 46px; height: 54px; font-size: 25px; }
  .key { height: 44px; }
  .kbd { gap: 5px; }
}
@media (max-height: 560px) {
  #gameScreen .word-stage { min-height: 110px; padding-top: .5rem; padding-bottom: .5rem; }
  .tile { width: 38px; height: 44px; font-size: 21px; border-bottom-width: 4px; }
  .key { height: 38px; font-size: 14px; }
  .turn-timer { margin-top: .4rem; }
}
/* Large screens: let the game use more width */
@media (min-width: 1024px) {
  #gameScreen { max-width: 52rem; }
  .key { max-width: 60px; height: 56px; }
}
.player-grid.n1 { grid-template-columns: 1fr; max-width: 420px; width: 100%; margin-left: auto; margin-right: auto; }
/* Header never pushes the page wider than the screen */
.app-header { min-width: 0; }
.header-actions { overflow-x: auto; scrollbar-width: none; }
.header-actions::-webkit-scrollbar { display: none; }
.header-actions .icon-btn { flex-shrink: 0; }
@media (max-width: 420px) {
  .brand-name { display: none; }
  .header-actions .icon-btn { padding: 0 .55rem !important; }
}
.player-grid { min-width: 0; }
.player-card { overflow: hidden; }

/* Continue button */
.cont-btn { gap: .4rem; }
.cont-count { min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--soft); color: var(--bark); font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; font-family: 'Space Grotesk', sans-serif; }
.cont-btn.ready { border-color: var(--terra); color: var(--terra-dd); background: var(--terra-l); animation: breathe 1.4s ease-in-out infinite; }
.cont-btn.ready .cont-count { background: var(--terra); color: #fffaf2; }

/* Strikes & continues on player cards */
.pmarks { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.mk { display: inline-flex; gap: 3px; }
.mk-x { width: 10px; height: 10px; border-radius: 3px; border: 1.5px solid var(--line-2); position: relative; }
.mk-x.on { background: var(--brick); border-color: var(--brick); }
.mk-x.on::before, .mk-x.on::after { content: ''; position: absolute; left: 50%; top: 50%; width: 7px; height: 1.5px; background: #fffaf2; transform: translate(-50%, -50%) rotate(45deg); }
.mk-x.on::after { transform: translate(-50%, -50%) rotate(-45deg); }
.mk-c { display: inline-flex; align-items: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--pc); font-family: 'Space Grotesk', sans-serif; }
.mk-c svg { width: 11px; height: 11px; }
.mk-c.none { color: var(--dim); }

/* ================= Daily challenge ================= */
.daily-letters { display: flex; gap: 4px; flex-shrink: 0; }
.daily-letters span { width: 28px; height: 32px; border-radius: 7px; background: var(--cream); border: 1.5px solid var(--ochre); border-bottom-width: 3px; display: grid; place-items: center; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 15px; color: var(--ink); text-transform: uppercase; }
.daily-letters span.daily-done, html.dark .daily-letters span.daily-done { width: auto; height: auto; border: 0; font-family: 'Inter', sans-serif; background: var(--moss); color: #fffaf2; }
.daily-done { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 6px; background: var(--moss); color: #fffaf2; flex-shrink: 0; }
@media (max-width: 420px) { .daily-letters { display: none; } }
/* Daily bonus quest */
.d-quest { display: flex; align-items: center; gap: .8rem; padding: .85rem .9rem; border-radius: 14px; border: 1.5px dashed var(--ochre); background: var(--ochre-l); }
.d-quest.done { border-style: solid; border-color: var(--moss); background: var(--moss-l); }
.d-quest.missed { border-color: var(--line-2); background: var(--soft-2); opacity: .85; }
.d-quest-ic { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; background: var(--ochre); color: #fffaf2; }
.d-quest.done .d-quest-ic { background: var(--moss); }
.d-quest.missed .d-quest-ic { background: var(--dim); }
.d-quest-ic svg { width: 20px; height: 20px; }
.d-quest-k { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ochre-d); }
.d-quest.done .d-quest-k { color: var(--moss-d); }
.d-quest.missed .d-quest-k { color: var(--muted); }
.d-quest-t { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 16px; color: var(--ink); line-height: 1.25; margin-top: 1px; }
.d-quest-d { font-size: 13px; color: var(--bark); line-height: 1.4; margin-top: 2px; }
.d-quest-d b { color: var(--ink); }
.d-quest-b { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 17px; color: var(--ochre-d); flex-shrink: 0; }
.d-quest.done .d-quest-b { color: var(--moss-d); }
.d-quest.missed .d-quest-b { color: var(--dim); text-decoration: line-through; }
@media (max-width: 480px) {
  .d-quest { flex-wrap: wrap; align-items: flex-start; }
  .d-quest > div:nth-child(2) { flex: 1 1 calc(100% - 56px); }
  .d-quest-b { margin-left: 52px; font-size: 15px; }
}
.d-total { font-size: 14px; color: var(--muted); font-weight: 600; }
.d-total span { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 40px; color: var(--terra); line-height: 1; margin-right: .2rem; }
.d-break { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.d-break span { font-size: 12.5px; padding: 4px 10px; border-radius: 8px; background: var(--soft); color: var(--muted); }
.d-break span.on { background: var(--moss-l); color: var(--moss-d); }
.d-break b { margin-left: .2rem; }
.d-stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 320px; }
.d-tags { display: inline-flex; gap: 4px; flex-shrink: 0; }
.d-tag { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.d-tag.win { background: var(--moss-l); color: var(--moss-d); text-transform: uppercase; letter-spacing: .04em; }
.d-tag.quest { background: var(--ochre-l); color: var(--ochre-d); }
/* Live quest strip in a daily game */
.dq-bar { display: flex; align-items: flex-start; gap: .6rem; margin-top: .6rem; padding: .6rem .75rem; border-radius: 12px; border: 1px dashed var(--ochre); background: var(--ochre-l); font-size: 13px; color: var(--ink-3); min-width: 0; }
.dq-bar.hidden { display: none; }
.dq-bar > svg { width: 18px; height: 18px; color: var(--ochre-d); flex-shrink: 0; margin-top: 2px; }
.dq-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: .1rem .45rem; }
.dq-k { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ochre-d); }
.dq-head b { color: var(--ink); font-size: 13.5px; }
.dq-text { font-size: 12.5px; line-height: 1.4; color: var(--bark); margin-top: 1px; }
.dq-text b { color: var(--ink); }
.dq-prog { flex-shrink: 0; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 7px; background: var(--cream); color: var(--ochre-d); white-space: nowrap; }
.dq-bar.done { border-style: solid; border-color: var(--moss); background: var(--moss-l); }
.dq-bar.done > svg, .dq-bar.done .dq-prog, .dq-bar.done .dq-k { color: var(--moss-d); }
.dq-bar.missed { border-style: solid; border-color: var(--line-2); background: var(--soft-2); opacity: .8; }
.dq-bar.missed > svg, .dq-bar.missed .dq-prog, .dq-bar.missed .dq-k { color: var(--muted); }
/* Phones: keep the full description, and drop the progress chip onto its own line so nothing is squeezed out. */
@media (max-width: 480px) {
  .dq-bar { flex-wrap: wrap; padding: .55rem .65rem; gap: .5rem; }
  .dq-bar > div { flex: 1 1 calc(100% - 30px); }
  .dq-prog { margin-left: 26px; }
}

.app-footer { text-align: center; font-size: 11.5px; color: var(--dim); padding: .9rem 1rem calc(.9rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); letter-spacing: .01em; }
body.in-game .app-footer { display: none; }
.forms-desc { display: grid; gap: 6px; font-size: 12.5px; line-height: 1.4; color: var(--bark); }
.forms-desc > div { padding: .5rem .65rem; border-radius: 10px; background: var(--soft-2); border: 1px solid var(--line); }
.forms-desc b { color: var(--ink); margin-right: .3rem; }
.rules-sub { font-size: 12px; font-weight: 600; color: var(--terra); margin-top: 1px; }
.rule-summary { text-transform: none; }
#ruleSummary::first-letter, #lobbyRules::first-letter { text-transform: uppercase; }

/* Selection breadcrumb under the header */
.crumb-bar { border-bottom: 1px solid var(--line); background: var(--soft-2); }
.crumb-bar.hidden { display: none; }
.crumb-inner { max-width: 42rem; margin: 0 auto; padding: .45rem 1rem; display: flex; align-items: center; gap: .4rem; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.crumb-inner::-webkit-scrollbar { display: none; }
.crumb { display: inline-flex; align-items: center; gap: .35rem; height: 28px; padding: 0 .65rem; border-radius: 14px; font-size: 12.5px; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
button.crumb { color: var(--pc); background: color-mix(in srgb, var(--pc) 12%, var(--cream)); border: 1px solid color-mix(in srgb, var(--pc) 30%, transparent); transition: background .15s; }
button.crumb:hover:not(:disabled) { background: color-mix(in srgb, var(--pc) 20%, var(--cream)); }
button.crumb:disabled { cursor: default; }
.crumb svg { width: 14px; height: 14px; }
.crumb.muted { color: var(--ink-3); background: var(--cream); border: 1px solid var(--line); }
.crumb-sep { color: var(--dim); display: inline-flex; flex-shrink: 0; }
.crumb-sep svg { width: 14px; height: 14px; }
.d-badge { width: 64px; height: 64px; margin: 0 auto; border-radius: 18px; display: grid; place-items: center; background: var(--ochre-l); color: var(--ochre-d); }
.d-badge svg { width: 30px; height: 30px; }
.d-badge.muted { background: var(--soft); color: var(--muted); }
.d-rules { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.d-rules span { display: inline-flex; align-items: center; gap: .35rem; height: 30px; padding: 0 .7rem; border-radius: 15px; background: var(--soft); color: var(--ink-3); font-size: 12.5px; font-weight: 600; }
.d-rules svg { width: 14px; height: 14px; color: var(--ochre-d); }
.d-opp { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; }
.d-bot { display: inline-flex; align-items: center; gap: .3rem; font-size: 12.5px; font-weight: 600; color: var(--ink-2); padding: 3px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--cream); }
.d-bot svg { width: 13px; height: 13px; color: var(--muted); }
.d-hero { text-align: center; padding: 1.5rem 1rem; border-radius: 18px; background: var(--cream); border: 1px solid var(--line); }
.d-points { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; font-size: 12.5px; color: var(--bark); }
.d-points span { padding: 4px 9px; border-radius: 8px; background: var(--soft); }
.d-points b { color: var(--ink); }
.d-timer { width: 100%; max-width: none; margin-top: 0; }
.d-preview { min-height: 64px; }
.d-preview .d-typed { border-color: var(--line-2); animation: pop .2s cubic-bezier(.2,1.4,.4,1); }
.d-form { display: flex; align-items: center; gap: .5rem; height: 56px; padding: 0 .4rem 0 1rem; border-radius: 14px; background: var(--cream); border: 1.5px solid var(--line); transition: border-color .15s; }
.d-form:focus-within { border-color: var(--terra); }
.d-fixed { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 20px; letter-spacing: .08em; color: var(--terra); }
.d-form input { flex: 1; min-width: 0; outline: none; background: transparent; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 20px; letter-spacing: .08em; text-transform: uppercase; }
.d-form input::placeholder { text-transform: none; letter-spacing: 0; font-family: 'Inter', sans-serif; font-weight: 400; font-size: 15px; color: var(--dim); }
.d-go { width: 44px; height: 44px; border-radius: 11px; background: var(--ink); color: #fffaf2; display: grid; place-items: center; flex-shrink: 0; }
.d-go:hover { background: var(--ink-2); }
.d-msg { height: 22px; margin-top: .5rem; text-align: center; font-size: 13px; font-weight: 600; opacity: 0; transition: opacity .2s; }
.d-msg.show { opacity: 1; }
.d-msg.good { color: var(--moss-d); }
.d-msg.bad { color: var(--brick); }
.d-chip { display: inline-flex; align-items: center; gap: .35rem; }
.d-chip b { font-size: 10px; color: var(--terra); }
.d-chip.fresh { animation: pop .3s cubic-bezier(.2,1.4,.4,1); background: var(--terra-l); }
.d-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 420px; margin-left: auto; margin-right: auto; }
.d-stats > div { border: 1px solid var(--line); border-radius: 12px; padding: .6rem .3rem; }
.d-big { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 26px; line-height: 1.1; color: var(--ink); }
.d-lbl { font-size: 11px; color: var(--muted); font-weight: 500; }
.d-board { margin-top: 1.75rem; }
.d-row { display: flex; align-items: center; gap: .7rem; min-height: 46px; padding: .4rem .8rem; border-radius: 12px; background: var(--cream); border: 1px solid var(--line); font-size: 14px; }
.d-row.me { border-color: var(--terra); background: var(--terra-l); }
.d-rank { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--soft); font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.d-rank.top { background: var(--ink); color: #fffaf2; }
.d-pts { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 17px; min-width: 2ch; text-align: right; }
.d-gap { height: 6px; }

/* ================= Dark mode (warm soil & bark) ================= */
html.dark {
  --sand: #1a1511; --cream: #241d17; --soft: #33291f; --soft-2: #2a221b; --line: #3a2f25; --line-2: #4a3d31;
  --ink: #f5ede1; --ink-2: #e3d7c6; --ink-3: #d3c4b1; --bark: #b9a893; --muted: #ab9a87; --dim: #857361;
  --terra: #d98a62; --terra-d: #e5a988; --terra-dd: #f0c4a8; --terra-l: rgba(192,102,58,.16); --terra-ll: rgba(192,102,58,.38);
  --moss: #8fae6f; --moss-d: #a8c58a; --moss-l: rgba(107,142,78,.2);
  --ochre: #e2bd6a; --ochre-d: #e9c97e; --ochre-l: rgba(212,160,51,.14);
  --brick: #e08a72; --brick-l: rgba(180,67,47,.2);
  --plum: #c4909d; --plum-d: #d8b0ba; --plum-l: rgba(139,94,107,.16); --plum-ll: rgba(139,94,107,.38);
}
html.dark body { background: var(--sand); color: var(--ink); }
html.dark .bg-zinc-50 { background-color: var(--soft-2); }
html.dark .bg-zinc-100 { background-color: var(--soft); }
html.dark .border-zinc-200 { border-color: var(--line); }
html.dark .text-zinc-900 { color: #f5ede1; }
html.dark .text-zinc-800 { color: #efe6d8; }
html.dark .text-zinc-700 { color: #e3d7c6; }
html.dark .text-zinc-600 { color: #b9a893; }
html.dark .text-zinc-500 { color: #ab9a87; }
html.dark .text-zinc-400 { color: #857361; }
html.dark .hover\:text-zinc-900:hover, html.dark .hover\:text-zinc-800:hover { color: #f5ede1; }
html.dark .text-rose-600 { color: #e08a72; }
html.dark .text-amber-600 { color: #e2bd6a; }
html.dark .text-emerald-600 { color: #a8c58a; }
html.dark .text-indigo-500, html.dark .text-indigo-600 { color: #d98a62; }
html.dark .text-purple-500 { color: #c4909d; }
html.dark header img { border-radius: 8px; outline: 1px solid var(--line-2); }

html.dark .btn-primary { background: var(--ink); color: #241d17; }
html.dark .btn-primary:hover:not(:disabled) { background: var(--ink-2); }
html.dark .btn-primary .spinner { border-color: rgba(36,29,23,.25); border-top-color: #241d17; }
html.dark .home-play { background: #c0663a; color: #fffaf2; }
html.dark .home-play:hover:not(:disabled) { background: #a8532c; }
html.dark .opt-card.active .opt-icon, html.dark .lobby-join, html.dark .chat-send, html.dark .d-go, html.dark .d-rank.top, html.dark .gs-badge { color: #241d17; }
html.dark .lobby-icon { background: #c0663a; color: #fffaf2; }
html.dark .seg { background: #2a221b; }
html.dark .seg button.active { background: var(--line-2); color: var(--ink); outline-color: #5e4f41; }
html.dark .mini-seg button.active { background: var(--line-2); color: var(--ink); outline-color: #5e4f41; }
html.dark .p-avatar, html.dark .hist-dot, html.dark .key.sel, html.dark .chat-msg.mine .chat-bubble, html.dark .react-float .who { color: #fffaf2; }
html.dark .net-banner { color: #e9c97e; border-color: rgba(212,160,51,.35); }
html.dark .spinner.dark { border-color: rgba(226,189,106,.25); border-top-color: #e2bd6a; }
html.dark .toast, html.dark .chat-peek { background: var(--ink); color: #241d17; }
html.dark .modal-backdrop { background: rgba(10,7,5,.65); }
html.dark .chat-form input, html.dark .custom-words { background: #1a1511; }
html.dark .rules-list li::before { background: #c0663a; color: #fffaf2; }
html.dark .gs-item.indigo .gs-ic { background: rgba(79,127,128,.22); color: #8fb8b8; }
html.dark .lb-rank.m1 { color: #e2bd6a; }
html.dark .lb-rank.m3 { color: #d98a62; }
html.dark .lb-row.me .lb-avatar, html.dark .lb-you, html.dark .cont-btn.ready .cont-count { color: #241d17; }
