:root {
  --bg1: #5b4bf5; --bg2: #8b3ff0; --bg3: #2a1c8f;
  --card: #ffffff; --card2: #f4f2ff; --line: #e6e2fb;
  --text: #1f1a3d; --muted: #6f6a8f;
  --primary: #5b4bf5; --primary-2: #4636e0; --on-primary: #fff;
  --accent: #ffd23f; --good: #22c55e; --good-bg: #dcfce7; --warn: #ef4444; --close: #f59e0b;
  --sys: #3b82f6; --guessed-bg: #ecfdf3; --drawer-bg: #fff7d6;
  --shadow: 0 10px 30px -10px rgba(25, 10, 90, .45), 0 2px 6px rgba(25, 10, 90, .12);
  --radius: 18px;
  --font-display: "Fredoka", "Nunito", system-ui, sans-serif;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg1: #241a6b; --bg2: #3b1a6e; --bg3: #0f0b2b;
    --card: #1d1838; --card2: #26204a; --line: #352d63;
    --text: #f1eeff; --muted: #a7a1cc;
    --primary: #7c6cff; --primary-2: #6a59ff;
    --good-bg: #123b26; --guessed-bg: #10301f; --drawer-bg: #3a3112;
    --shadow: 0 10px 30px -10px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg1: #241a6b; --bg2: #3b1a6e; --bg3: #0f0b2b;
  --card: #1d1838; --card2: #26204a; --line: #352d63;
  --text: #f1eeff; --muted: #a7a1cc;
  --primary: #7c6cff; --primary-2: #6a59ff;
  --good-bg: #123b26; --guessed-bg: #10301f; --drawer-bg: #3a3112;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--text);
  background: radial-gradient(1200px 800px at 15% -10%, var(--bg2), transparent 60%),
              radial-gradient(1000px 700px at 110% 110%, var(--bg3), transparent 60%),
              linear-gradient(135deg, var(--bg1), var(--bg3));
  background-color: var(--bg1);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.bg-doodles {
  position: fixed; inset: 0; z-index: -1; opacity: .13; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'%3E%3Cg fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 40c12-18 24-18 30 0s20 18 30 0'/%3E%3Ccircle cx='160' cy='40' r='16'/%3E%3Cpath d='M40 150l14-28 14 28z'/%3E%3Cpath d='M140 130l8 16 18 3-13 12 3 18-16-9-16 9 3-18-13-12 18-3z'/%3E%3Cpath d='M100 200c-10-10 10-20 0-30'/%3E%3Cpath d='M190 190l-20-20M170 190l20-20'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 220px;
  animation: drift 60s linear infinite;
}
@keyframes drift { to { background-position: 220px 440px; } }
@media (prefers-reduced-motion: reduce) { .bg-doodles { animation: none; } }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }

.btn {
  border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 800; letter-spacing: .2px;
  transition: transform .08s ease, box-shadow .15s ease, background .15s; white-space: nowrap;
}
.btn:active { transform: translateY(2px); }
.btn.primary { background: linear-gradient(180deg, #6f61ff, var(--primary-2)); color: var(--on-primary); box-shadow: 0 4px 0 #3122b8, 0 8px 20px -6px rgba(70, 54, 224, .7); }
.btn.primary:active { box-shadow: 0 2px 0 #3122b8; }
.btn.primary:disabled { filter: grayscale(.6) opacity(.6); cursor: not-allowed; transform: none; }
.btn.secondary { background: var(--card2); color: var(--primary); box-shadow: inset 0 0 0 2px var(--line); }
.btn.secondary:hover { box-shadow: inset 0 0 0 2px var(--primary); }
.btn.big { width: 100%; white-space: normal; line-height: 1.2; padding: 15px 20px; font-size: 1.08rem; font-family: var(--font-display); font-weight: 600; letter-spacing: .4px; }
.link-btn { background: none; border: 0; color: var(--primary); font-weight: 800; padding: 6px 10px; border-radius: 10px; }
.link-btn:hover { background: var(--card2); }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--card2); font-size: 1.1rem; display: grid; place-items: center; transition: transform .1s; }
.icon-btn:hover { transform: scale(1.06); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------------- HOME ---------------- */
#home { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; padding: max(28px, env(safe-area-inset-top)) 16px 24px; gap: 14px; }
.logo { font-family: var(--font-display); font-weight: 700; font-size: clamp(3rem, 12vw, 5.2rem); margin: 4px 0 0; letter-spacing: 1px; line-height: 1; display: flex; }
.logo span { color: var(--c); text-shadow: 0 4px 0 rgba(0, 0, 0, .25), 0 10px 22px rgba(0, 0, 0, .25); display: inline-block; animation: bob 2.6s ease-in-out infinite; }
.logo span:nth-child(odd) { animation-delay: -.6s; }
.logo span:nth-child(3n) { animation-delay: -1.3s; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-6px) rotate(3deg); } }
@media (prefers-reduced-motion: reduce) { .logo span { animation: none; } }
.tagline { color: #fff; opacity: .9; margin: 0 0 6px; font-weight: 700; text-align: center; }
.home-card { width: min(420px, 100%); padding: 22px 22px 18px; display: flex; flex-direction: column; gap: 12px; }

.avatar-editor { display: grid; grid-template-columns: 34px 1fr 34px; grid-template-rows: repeat(3, 1fr); align-items: center; justify-items: center; height: 156px; }
.avatar-editor .arrow { grid-column: 1; width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--card2); color: var(--primary); font-size: 1.4rem; line-height: 1; font-weight: 800; }
.avatar-editor .arrow.r { grid-column: 3; }
.avatar-editor .arrow[data-part="h"] { grid-row: 1; }
.avatar-editor .arrow[data-part="e"] { grid-row: 2; }
.avatar-editor .arrow[data-part="m"] { grid-row: 3; }
.avatar-editor .arrow:hover { background: var(--primary); color: #fff; }
.avatar-big { grid-column: 2; grid-row: 1 / 4; width: 150px; height: 150px; filter: drop-shadow(0 8px 12px rgba(40, 20, 120, .25)); }
.avatar-big svg { width: 100%; height: 100%; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 3px solid transparent; padding: 0; background: var(--c); box-shadow: 0 0 0 1px rgba(0, 0, 0, .12); }
.swatches button.sel { border-color: var(--card); box-shadow: 0 0 0 2px var(--primary); }
#randomAvatar { align-self: center; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; font-size: .9rem; }
.field input, .code-row input, .settings select, .settings textarea, .invite input {
  border: 2px solid var(--line); background: var(--card2); border-radius: 12px; padding: 12px 14px; outline: none; width: 100%; min-width: 0;
  transition: border-color .15s;
}
.field input:focus, .code-row input:focus, .settings select:focus, .settings textarea:focus { border-color: var(--primary); }
.join-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: linear-gradient(90deg, #fff4c2, #ffe8f0); color: #3d2a00; border-radius: 12px; padding: 10px 14px; font-weight: 700; }
.join-banner strong { font-family: var(--font-display); letter-spacing: 3px; font-size: 1.2rem; color: #5b4bf5; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.divider::before, .divider::after { content: ""; flex: 1; height: 2px; background: var(--line); border-radius: 2px; }
.code-row { display: flex; gap: 8px; }
.code-row input { text-transform: uppercase; letter-spacing: 4px; font-weight: 800; text-align: center; font-family: var(--font-display); }
.status { min-height: 1.2em; margin: 0; text-align: center; font-weight: 700; color: var(--muted); font-size: .92rem; }
.status.err { color: var(--warn); }
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(640px, 100%); }
.how div { background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .2); color: #fff; padding: 12px; border-radius: 14px; display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: .9rem; backdrop-filter: blur(6px); }
.how b { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #3d2a00; display: grid; place-items: center; font-family: var(--font-display); }
.foot { color: rgba(255, 255, 255, .7); font-size: .82rem; font-weight: 700; }
@media (max-width: 560px) { .how { grid-template-columns: 1fr; } }

/* ---------------- GAME ---------------- */
#game {
  height: 100dvh; max-width: 1440px; margin: 0 auto; display: grid; grid-template-rows: auto minmax(0, 1fr);
  gap: 10px; padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 10px; gap: 10px; min-height: 60px; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 8px; }
.tb-right { justify-content: flex-end; }
.clock { position: relative; width: 46px; height: 46px; flex: none; }
.clock svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.clock circle { fill: none; stroke-width: 4; }
.clock-bg { stroke: var(--line); fill: var(--card2) !important; }
.clock-fg { stroke: var(--primary); stroke-linecap: round; stroke-dasharray: 97.4; stroke-dashoffset: 0; transition: stroke-dashoffset .25s linear, stroke .3s; }
.clock.low .clock-fg { stroke: var(--warn); }
.clock.low { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.clock span { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.round { font-weight: 800; color: var(--muted); font-size: .92rem; white-space: nowrap; }
.tb-word { text-align: center; min-width: 0; overflow: hidden; }
.tb-word .hint { max-width: 100%; }
.tb-word .label { font-size: .72rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
.hint { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.1rem, 2.6vw, 1.7rem); letter-spacing: .32em; white-space: nowrap; display: inline-flex; align-items: baseline; gap: .1em; }
.hint .gap { width: .6em; }
.hint .len { font-family: var(--font); font-size: .75rem; letter-spacing: 0; color: var(--muted); margin-left: .3em; }
.hint.word { color: var(--good); letter-spacing: .1em; }
.hint.pop span { animation: pop .4s ease; }

.main { display: grid; grid-template-columns: 230px minmax(0, 1fr) 300px; gap: 10px; min-height: 0; }
.center { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; align-items: center; }

/* players */
.players { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.player { display: grid; grid-template-columns: 26px 44px minmax(0, 1fr) auto; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 14px; background: var(--card2); position: relative; }
.player.new { animation: slideIn .3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } }
.player.guessed { background: var(--guessed-bg); box-shadow: inset 0 0 0 2px var(--good); }
.player.drawing { background: var(--drawer-bg); box-shadow: inset 0 0 0 2px var(--accent); }
.player .rank { font-family: var(--font-display); font-weight: 700; color: var(--muted); text-align: center; font-size: .9rem; }
.player .av { width: 44px; height: 44px; }
.player .av svg { width: 100%; height: 100%; }
.player .info { min-width: 0; }
.player .nm { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .95rem; }
.player .nm .you { color: var(--primary); font-weight: 800; }
.player .pts { font-size: .8rem; color: var(--muted); font-weight: 700; }
.player .badges { display: flex; gap: 2px; align-items: center; font-size: 1.05rem; }
.player .kick { border: 0; background: none; font-size: .9rem; opacity: .0; padding: 2px; transition: opacity .15s; }
.player:hover .kick, .player .kick:focus-visible { opacity: .7; }
@media (hover: none) { .player .kick { opacity: .55; } }
.player .gain { color: var(--good); font-weight: 800; margin-left: 4px; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }

/* spectators */
.spec-head { margin: 8px 4px 2px; font-size: .75rem; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.spec-row { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 12px; font-size: .88rem; font-weight: 700; color: var(--muted); }
.spec-row .av { width: 28px; height: 28px; flex: none; opacity: .85; }
.spec-row .av svg { width: 100%; height: 100%; }
.spec-row .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spec-row .nm .you { color: var(--primary); }
.spec-row .kick { border: 0; background: none; font-size: .85rem; opacity: .55; padding: 2px; }
.msg.spec { color: #7c3aed; font-style: italic; }
:root[data-theme="dark"] .msg.spec { color: #c4b5fd; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .msg.spec { color: #c4b5fd; } }
.play-btn { background: var(--good-bg); }
body.spectating .board { box-shadow: var(--shadow), 0 0 0 3px rgba(124, 108, 255, .35); }
.join-actions { display: flex; flex-direction: column; gap: 8px; }
.join-actions:has(#joinBtn[hidden]) { display: none; }
.lobby-actions { display: flex; gap: 8px; align-items: stretch; }
.lobby-actions .btn.secondary { flex: none; }
.lobby-actions #startBtn { flex: 1; }
.lobby-actions #startBtn[hidden] + *, .lobby-actions:has(#startBtn[hidden]) #modeBtn { flex: 1; }

/* lobby */
.lobby { width: 100%; padding: 0; overflow: hidden; display: flex; flex-direction: column; min-height: 0; max-height: 100%; }
.lobby-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 18px 18px 8px; display: flex; flex-direction: column; gap: 16px; overscroll-behavior: contain; }
.lobby-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; justify-content: space-between; }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: 2px; font-weight: 800; color: var(--muted); }
.room-code { font-family: var(--font-display); font-weight: 700; font-size: 2.2rem; letter-spacing: 6px; color: var(--primary); line-height: 1.1; }
.invite { display: flex; gap: 8px; flex: 1 1 320px; max-width: 520px; }
.invite input { font-size: .85rem; padding: 10px 12px; color: var(--muted); }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-weight: 800; font-size: .85rem; }
.settings label.wide { grid-column: 1 / -1; }
.settings small { font-weight: 600; color: var(--muted); }
.settings select { padding: 10px 12px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%; background-size: 6px 6px; background-repeat: no-repeat; }
.settings textarea { resize: vertical; min-height: 70px; }
.settings label.check { flex-direction: row; align-items: center; gap: 10px; grid-column: 1 / -1; }
.settings label.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.settings :disabled { opacity: .7; cursor: not-allowed; }
.lobby-foot { display: flex; flex-direction: column; gap: 8px; align-items: stretch; padding: 10px 18px 16px; border-top: 2px solid var(--line); background: var(--card); flex: none; }
.lobby-foot p { margin: 0; text-align: center; font-weight: 700; }

/* board */
.board-wrap { width: 100%; flex: 1 1 auto; min-height: 0; display: flex; align-items: flex-start; justify-content: center; container-type: size; }
.board { position: relative; width: min(100cqw, 100cqh * 4 / 3); aspect-ratio: 4 / 3; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
@supports not (container-type: size) { .board { width: 100%; } }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#canvas.no-draw { cursor: default; }
.board { container-type: inline-size; }
.feed { position: absolute; left: 8px; bottom: 8px; z-index: 2; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: min(70%, 340px); pointer-events: none; }
.feed .fl { max-width: 100%; padding: 3px 9px; border-radius: 10px; font-size: 12.5px; font-weight: 600; line-height: 1.35; color: #fff; background: rgba(31, 26, 61, .72); backdrop-filter: blur(2px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: feedIn .2s ease, feedOut .5s ease 3.6s forwards; }
.feed .fl b { font-weight: 800; opacity: .85; }
.feed .fl.good { background: rgba(22, 163, 74, .9); }
.feed .fl.close { background: rgba(217, 119, 6, .92); }
.feed .fl.guessed, .feed .fl.spec { background: rgba(109, 40, 217, .78); }
@keyframes feedIn { from { opacity: 0; transform: translateY(6px); } }
@keyframes feedOut { to { opacity: 0; transform: translateY(-4px); } }
@container (max-width: 440px) { .feed { left: 5px; bottom: 5px; gap: 3px; } .feed .fl { font-size: 11px; padding: 2px 7px; } }
@media (prefers-reduced-motion: reduce) { .feed .fl { animation: feedOut .3s ease 3.6s forwards; } }
@container (max-width: 440px) {
  .overlay { gap: 8px; padding: 10px; }
  .overlay h2 { font-size: 1.05rem; }
  .overlay .sub { display: none; }
  .choices { gap: 6px; }
  .choices button { font-size: .95rem; padding: 7px 12px; box-shadow: 0 3px 0 #c9c2ff; }
  .ov-avatar { width: 56px; height: 56px; }
  .results { min-width: 90%; font-size: .85rem; }
  .podium .step { font-size: 1.1rem; }
  .podium .p1 .step { height: 56px; } .podium .p2 .step { height: 40px; } .podium .p3 .step { height: 28px; }
}
.overlay { position: absolute; inset: 0; background: rgba(24, 16, 64, .72); backdrop-filter: blur(3px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: #fff; text-align: center; padding: 16px; animation: fade .25s ease; overflow-y: auto; }
@keyframes fade { from { opacity: 0; } }
.overlay h2 { font-family: var(--font-display); font-weight: 600; margin: 0; font-size: clamp(1.2rem, 3.2vw, 2rem); }
.overlay h2 b { color: var(--accent); }
.overlay .sub { margin: 0; opacity: .85; font-weight: 700; }
.choices { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.choices button { border: 0; background: #fff; color: #2a1c8f; font-family: var(--font-display); font-weight: 600; font-size: clamp(1rem, 2.4vw, 1.35rem); padding: 12px 20px; border-radius: 14px; box-shadow: 0 4px 0 #c9c2ff; transition: transform .1s; }
.choices button:hover { transform: translateY(-3px) rotate(-1deg); background: var(--accent); }
.choices button:disabled { opacity: .45; cursor: default; transform: none; }
.choices button.picked { opacity: 1; background: var(--accent); transform: scale(1.06); }
.ov-avatar { width: 84px; height: 84px; animation: bob 1.6s ease-in-out infinite; }
.results { display: flex; flex-direction: column; gap: 4px; min-width: min(320px, 90%); max-height: 50%; overflow-y: auto; }
.results div { display: flex; justify-content: space-between; gap: 18px; font-weight: 800; padding: 4px 12px; border-radius: 8px; background: rgba(255, 255, 255, .08); }
.results .plus { color: #4ade80; }
.results .zero { color: #fca5a5; }
.podium { display: flex; align-items: flex-end; gap: 10px; justify-content: center; }
.podium .pl { display: flex; flex-direction: column; align-items: center; gap: 4px; width: clamp(80px, 18vw, 130px); }
.podium .pl .av { width: clamp(48px, 9vw, 76px); height: clamp(48px, 9vw, 76px); }
.podium .pl .nm { font-weight: 800; font-size: .9rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .step { width: 100%; border-radius: 12px 12px 0 0; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; color: #2a1c8f; }
.podium .p1 .step { height: 90px; background: linear-gradient(#ffe066, #f6b500); }
.podium .p2 .step { height: 66px; background: linear-gradient(#f1f5f9, #b6c2d1); }
.podium .p3 .step { height: 48px; background: linear-gradient(#fcd3a6, #d98a4a); }
.podium .pts { font-size: .8rem; opacity: .85; font-weight: 700; }

/* toolbar */
.toolbar { width: 100%; padding: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.tool-cur { width: 42px; height: 42px; border-radius: 12px; position: relative; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .12); overflow: hidden; flex: none; }
.tool-cur input { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); opacity: 0; cursor: pointer; }
.palette { display: grid; grid-template-columns: repeat(13, 21px); grid-auto-rows: 21px; gap: 2px; border-radius: 10px; overflow: hidden; }
.palette button { border: 0; padding: 0; background: var(--c); border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); transition: transform .08s; }
.palette button:hover { transform: scale(1.15); z-index: 1; }
.palette button.sel { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--primary); z-index: 2; }
.sizes, .tools { display: flex; gap: 4px; }
.sizes button, .tool { width: 42px; height: 42px; border-radius: 12px; border: 0; background: var(--card2); display: grid; place-items: center; font-size: 1.15rem; color: var(--text); transition: background .1s, transform .1s; }
.sizes button i { display: block; border-radius: 50%; background: var(--text); }
.sizes button.sel, .tool.active { background: var(--primary); color: #fff; }
.sizes button.sel i { background: #fff; }
.tool:active, .sizes button:active { transform: scale(.92); }

/* chat */
.chat { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 6px; display: flex; flex-direction: column; gap: 1px; font-size: .92rem; overscroll-behavior: contain; }
.msg { padding: 5px 10px; border-radius: 10px; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.35; animation: fade .2s; }
.msg:nth-child(odd) { background: color-mix(in srgb, var(--card2) 60%, transparent); }
.msg b { font-weight: 800; }
.msg.system { color: var(--sys); font-weight: 800; }
.msg.good { color: var(--good); font-weight: 800; background: var(--good-bg); }
.msg.warn { color: var(--warn); font-weight: 800; }
.msg.close { color: var(--close); font-weight: 800; }
.msg.guessed { color: #15803d; background: var(--guessed-bg); }
:root[data-theme="dark"] .msg.guessed { color: #86efac; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .msg.guessed { color: #86efac; } }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 2px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; border: 2px solid var(--line); background: var(--card2); border-radius: 12px; padding: 10px 12px; outline: none; font-size: 16px; }
.chat-form input:focus { border-color: var(--primary); }
.chat-form input:disabled { opacity: .6; }
.send { width: 44px; border: 0; border-radius: 12px; background: var(--primary); color: #fff; font-size: 1.05rem; flex: none; }

/* toast + modal */
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 140%); opacity: 0; visibility: hidden; background: #1f1a3d; color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 800; box-shadow: var(--shadow); transition: transform .3s cubic-bezier(.2, 1.4, .4, 1); z-index: 50; max-width: calc(100% - 32px); text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition: transform .3s cubic-bezier(.2, 1.4, .4, 1), opacity .2s; }
.modal { position: fixed; inset: 0; background: rgba(10, 6, 30, .6); display: grid; place-items: center; z-index: 40; padding: 16px; backdrop-filter: blur(4px); animation: fade .2s; }
.modal-card { padding: 22px; width: min(380px, 100%); text-align: center; animation: pop .3s ease; }
.modal-card h2 { font-family: var(--font-display); margin: 0 0 6px; font-weight: 600; }
.modal-card p { color: var(--muted); font-weight: 700; margin: 0 0 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; }

/* ---------------- RESPONSIVE ---------------- */
@media (max-width: 1100px) {
  .main { grid-template-columns: 190px minmax(0, 1fr) 250px; }
  .player { grid-template-columns: 20px 36px minmax(0, 1fr) auto; }
  .player .av { width: 36px; height: 36px; }
  .palette { grid-template-columns: repeat(13, 19px); grid-auto-rows: 19px; }
}
@media (max-width: 860px) {
  #game { gap: 6px; padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom)); }
  .topbar { grid-template-columns: auto 1fr auto; padding: 6px 8px; min-height: 52px; border-radius: 14px; gap: 6px; }
  .clock { width: 40px; height: 40px; }
  .round { font-size: .78rem; }
  .icon-btn { width: 34px; height: 34px; font-size: .95rem; border-radius: 10px; }
  .tb-right { gap: 4px; }
  .hint { font-size: 1.05rem; letter-spacing: .22em; }
  .main {
    grid-template-columns: minmax(0, 40%) minmax(0, 1fr);
    grid-template-rows: auto minmax(150px, 1fr);
    grid-template-areas: "center center" "players chat";
    gap: 6px;
  }
  .center { grid-area: center; gap: 6px; }
  .players { grid-area: players; padding: 4px; gap: 4px; border-radius: 14px; }
  .chat { grid-area: chat; border-radius: 14px; }
  .board-wrap { flex: none; container-type: normal; }
  .board { width: min(100%, calc((100dvh - 330px) * 4 / 3)); border-radius: 14px; }
  .lobby { max-height: 56dvh; border-radius: 14px; }
  .lobby-scroll { padding: 14px 14px 8px; gap: 12px; }
  .lobby-foot { padding: 8px 14px 12px; }
  .lobby-foot .btn.big { padding: 12px 16px; }
  .room-code { font-size: 1.7rem; }
  .player { grid-template-columns: 30px minmax(0, 1fr) auto; padding: 4px 6px; gap: 6px; border-radius: 10px; }
  .player .rank { display: none; }
  .player .av { width: 30px; height: 30px; }
  .player .nm { font-size: .82rem; }
  .player .pts { font-size: .72rem; }
  .player .badges { font-size: .85rem; }
  .toolbar { padding: 6px; gap: 6px; border-radius: 14px; }
  .palette { grid-template-columns: repeat(13, minmax(0, 1fr)); grid-auto-rows: 24px; gap: 3px; flex: 1 1 100%; order: 3; }
  .tool-cur { width: 36px; height: 36px; }
  .sizes button, .tool { width: 36px; height: 36px; font-size: 1rem; border-radius: 10px; }
  .chat-log { font-size: .84rem; padding: 4px; }
  .msg { padding: 3px 7px; }
  .chat-form { padding: 6px; }
  .chat-form input { padding: 8px 10px; }
  .send { width: 38px; }
}
@media (max-width: 400px) {
  .round { display: none; }
  .tb-word .label { font-size: .62rem; letter-spacing: 1px; }
  .topbar { gap: 4px; padding: 6px; }
  .icon-btn { width: 32px; height: 32px; font-size: .9rem; }
  .tb-right { gap: 3px; }
  .hint { letter-spacing: .14em; }
}
@media (max-width: 340px) {
  .clock { width: 34px; height: 34px; }
  .clock span { font-size: .85rem; }
  .icon-btn { width: 30px; height: 30px; font-size: .82rem; }
  .code-row { flex-wrap: wrap; }
  .code-row input { flex: 1 1 100%; }
  .code-row .btn { flex: 1; }
  .home-card { padding: 18px 14px 14px; }
  .main { grid-template-columns: minmax(0, 42%) minmax(0, 1fr); }
  .player { grid-template-columns: 24px minmax(0, 1fr) auto; gap: 4px; }
  .player .av { width: 24px; height: 24px; }
}
/* Landscape phones: side-by-side columns */
@media (max-height: 500px) and (orientation: landscape) and (max-width: 1000px) {
  #game { grid-template-rows: auto minmax(0, 1fr); }
  .main { grid-template-columns: 150px minmax(0, 1fr) 200px; grid-template-rows: minmax(0, 1fr); grid-template-areas: "players center chat"; }
  .board-wrap { flex: 1 1 auto; container-type: size; }
  .board { width: min(100cqw, 100cqh * 4 / 3); }
  .toolbar { flex-wrap: wrap; justify-content: center; padding: 4px; gap: 4px; }
  .palette { order: 0; flex: none; grid-template-columns: repeat(13, 18px); grid-auto-rows: 18px; }
  .tool-cur, .sizes button, .tool { width: 30px; height: 30px; font-size: .85rem; border-radius: 8px; }
  .lobby { max-height: 100%; }
}

/* =========================================================
   Game-style components (all sizes)
   ========================================================= */
/* word as letter tiles */
.hint.tiles { letter-spacing: 0; gap: .12em; align-items: flex-end; }
.hint.tiles .t { display: inline-block; min-width: .78em; text-align: center; line-height: 1.05; padding-bottom: .04em; border-bottom: .14em solid currentColor; }
.hint.tiles .t.blank { border-bottom-color: color-mix(in srgb, var(--text) 55%, transparent); }
.hint.tiles .p { padding: 0 .04em; }
.hint.tiles .gap { width: .5em; }
.hint.word.tiles .t { border-bottom-color: color-mix(in srgb, var(--good) 60%, transparent); }

/* overflow menu (phones) */
.topbar { position: relative; }
.menu-btn { display: none; font-size: 1.3rem; font-weight: 800; line-height: 1; }
.menu { position: absolute; right: 8px; top: calc(100% + 6px); z-index: 30; display: flex; flex-direction: column; padding: 6px; min-width: 190px; animation: pop .18s ease; }
.menu button { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 12px 12px; border-radius: 12px; font-weight: 800; text-align: left; min-height: 44px; }
.menu button:hover, .menu button:focus-visible { background: var(--card2); }
.menu .danger { color: var(--warn); }

/* lobby invite + collapsible settings */
.invite-big { display: none; }
.settings-box { border: 2px solid var(--line); border-radius: 16px; background: var(--card2); }
.settings-box > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; font-weight: 800; }
.settings-box > summary::-webkit-details-marker { display: none; }
.settings-box > summary::after { content: "▾"; color: var(--muted); transition: transform .2s; }
.settings-box[open] > summary::after { transform: rotate(180deg); }
.settings-box > summary small { flex: 1; text-align: right; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-box .settings { padding: 0 14px 14px; }
.settings-box select, .settings-box textarea { background: var(--card); }

.r-short { display: none; }
.pal-custom { display: none; }

/* =========================================================
   Phone layout: HUD · player strip · board · dock · chat
   ========================================================= */
@media (max-width: 860px) and (orientation: portrait), (max-width: 600px) {
  #game { grid-template-rows: auto minmax(0, 1fr); gap: 6px; }

  /* HUD */
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; min-height: 56px; padding: 6px 8px; border-radius: 18px; }
  .tb-extra { display: none; }
  .menu-btn { display: grid; }
  .round { display: block !important; font-size: .7rem; font-weight: 800; color: var(--muted); }
  .round .r-long { display: none; }
  .round .r-short { display: inline; background: var(--card2); padding: 2px 7px; border-radius: 999px; }
  .tb-left { gap: 6px; }
  .tb-word .label { font-size: .62rem; letter-spacing: 1.2px; }
  .hint { font-size: 1.35rem; }
  .icon-btn { width: 40px; height: 40px; border-radius: 12px; }

  /* stack: strip, stage, chat */
  .main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(132px, 1fr);
    grid-template-areas: "players" "center" "chat";
    gap: 6px;
  }

  /* player strip */
  .players { grid-area: players; flex-direction: row; overflow-x: auto; overflow-y: hidden; gap: 6px; padding: 6px; border-radius: 18px; scrollbar-width: none; scroll-snap-type: x proximity; }
  .players::-webkit-scrollbar { display: none; }
  .player { flex: none; width: 66px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 3px 4px; border-radius: 14px; scroll-snap-align: start; }
  .player .rank { display: block; position: absolute; top: 2px; left: 3px; font-size: .62rem; background: var(--card); border-radius: 999px; padding: 0 4px; line-height: 1.5; }
  .player .rank:empty { display: none; }
  .player .av { width: 38px; height: 38px; }
  .player .info { width: 100%; text-align: center; }
  .player .nm { font-size: .72rem; }
  .player .nm .you { display: none; }
  .player .pts { font-size: .66rem; }
  .player .gain { display: block; margin: 0; font-size: .62rem; }
  .player .badges { position: absolute; top: 1px; right: 2px; font-size: .72rem; gap: 0; }
  .player .kick { opacity: .6; font-size: .7rem; padding: 0 2px; }
  .player.me { box-shadow: inset 0 0 0 2px var(--primary); }
  .player.guessed { box-shadow: inset 0 0 0 2px var(--good); }
  .player.drawing { box-shadow: inset 0 0 0 2px var(--accent); }
  .spec-head { flex: none; align-self: center; margin: 0 4px; padding: 6px 10px; border-radius: 999px; background: var(--card2); text-transform: none; letter-spacing: 0; font-size: .75rem; white-space: nowrap; }
  .spec-row { display: none; }

  /* stage */
  .center { grid-area: center; gap: 6px; }
  .board-wrap { flex: none; container-type: normal; }
  .board { width: min(100%, calc((100dvh - 360px) * 4 / 3)); border-radius: 18px; }
  .lobby { max-height: 58dvh; border-radius: 18px; }

  /* drawing dock: one row, palette pops up */
  .toolbar { position: relative; display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; padding: 5px; border-radius: 16px; }
  .toolbar .sizes, .toolbar .tools { display: contents; }
  .tool-cur, .sizes button, .tool { width: auto; height: 42px; border-radius: 12px; }
  .tool-cur { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .7), 0 0 0 2px var(--line); cursor: pointer; }
  .tool-cur input { pointer-events: none; }
  .tool-cur::after { content: "▴"; position: absolute; right: 3px; bottom: 0; font-size: .7rem; color: #fff; text-shadow: 0 0 2px rgba(0, 0, 0, .6); }
  .toolbar.open .tool-cur::after { content: "▾"; }
  .palette { display: none; position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 20; grid-template-columns: repeat(9, minmax(0, 1fr)); grid-auto-rows: 36px; gap: 6px; padding: 10px; background: var(--card); border-radius: 18px; box-shadow: var(--shadow), 0 0 0 2px var(--line); order: 0; }
  .toolbar.open .palette { display: grid; animation: pop .16s ease; }
  .palette button { border-radius: 10px; }
  .pal-custom { display: block; background: conic-gradient(#ff5d73, #ffd23f, #4ade80, #38bdf8, #a78bfa, #ff5d73) !important; font-size: 1rem; }

  /* chat: full width, messenger style */
  .chat { grid-area: chat; border-radius: 18px; }
  .chat-log { font-size: .86rem; padding: 6px; }
  .chat-form { padding: 6px; gap: 6px; }
  .chat-form input { border-radius: 999px; padding: 10px 14px; }
  .send { width: 44px; border-radius: 999px; }

  /* lobby */
  .lobby-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .lobby-head > div:first-child { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
  .invite { display: none; }
  .invite-big { display: block; width: 100%; padding: 13px; font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
  .settings { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}
@media (max-width: 360px) and (orientation: portrait) {
  .player { width: 58px; }
  .player .av { width: 32px; height: 32px; }
  .hint { font-size: 1.15rem; }
  .icon-btn { width: 36px; height: 36px; }
  .tool-cur, .sizes button, .tool { height: 38px; font-size: .9rem; }
  .toolbar { gap: 3px; padding: 4px; }
  .settings { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 340px) and (orientation: portrait) {
  .toolbar { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .board { width: min(100%, calc((100dvh - 400px) * 4 / 3)); }
}


/* =========================================================
   Easier colours + keyboard-safe phone shell
   ========================================================= */
.palette button { border-radius: 50%; }
.palette button.sel { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--text); }
.sizes button i { background: var(--cur, var(--text)) !important; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); }
.sizes button.sel { background: var(--card2); box-shadow: inset 0 0 0 2px var(--primary); }
.tool.confirm { background: var(--warn) !important; color: #fff; font-size: .78rem !important; font-weight: 800; }

@media (max-width: 860px) and (orientation: portrait), (max-width: 600px) {
  /* app shell follows the visible viewport, so the keyboard shrinks the layout instead of covering it */
  #game:not(.hidden) { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); }
  .board { width: min(100%, calc((var(--app-h, 100dvh) - 360px) * 4 / 3)); }
  body.typing .players { display: none; }
  body.typing .main { grid-template-rows: auto minmax(104px, 1fr); grid-template-areas: "center" "chat"; }
  body.typing .board { width: min(100%, calc((var(--app-h, 100dvh) - 196px) * 4 / 3)); }
  body.typing .toolbar { display: none; }

  /* big, round, thumb-friendly swatches */
  .palette { grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: auto; gap: 8px; padding: 12px; }
  .palette button { aspect-ratio: 1; height: auto; max-height: 48px; justify-self: center; width: 100%; max-width: 48px; }
  .palette button.sel { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--text); transform: scale(1.04); }
}
@media (max-width: 340px) and (orientation: portrait) {
  .board { width: min(100%, calc((var(--app-h, 100dvh) - 400px) * 4 / 3)); }
}
@media (max-width: 340px) and (orientation: portrait) {
  .palette { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; padding: 10px; }
}
