:root {
  --cream: #FFF4E0;
  --paper: #FFFDF7;
  --ink: #1B1B2F;
  --ink-soft: #55556B;
  --tomato: #FF5A36;
  --sun: #FFC530;
  --mint: #2EC4B6;
  --lilac: #9B8AFB;
  --pink: #FF8FB1;
  --line: 3px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --shadow-lg: 6px 6px 0 var(--ink);
  --radius: 16px;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'DM Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--body);
  font-size: 16px;
  color: var(--ink);
  background-color: var(--cream);
  background-image: radial-gradient(rgba(27, 27, 47, .09) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}

h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.05; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; margin-bottom: 14px; }
h3 { font-size: 1.15rem; margin: 22px 0 4px; }
.center { text-align: center; }
.eyebrow { font-family: var(--display); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); }
.hint { color: var(--ink-soft); font-size: .9rem; margin: 6px 0 0; }
.count { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 8px; border-radius: 99px; background: var(--ink); color: var(--cream); font-size: .85rem; vertical-align: middle; margin-left: 6px; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; max-width: 1100px; margin: 0 auto; }
.brand { display: inline-flex; align-items: center; gap: 2px; text-decoration: none; color: var(--ink); font-family: var(--display); font-weight: 800; font-size: 1.6rem; letter-spacing: -0.03em; }
.brand-tile { display: inline-grid; place-items: center; width: 38px; height: 38px; background: var(--sun); border: var(--line); border-radius: 10px; box-shadow: 3px 3px 0 var(--ink); transform: rotate(-6deg); margin-right: 4px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.me-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; background: var(--paper); border: var(--line); border-radius: 99px; font-weight: 700; font-size: .9rem; }
.code-chip { font-family: var(--display); font-weight: 800; letter-spacing: .12em; padding: 6px 12px; background: var(--ink); color: var(--sun); border-radius: 99px; font-size: .9rem; }

main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 120px; }
.screen { animation: pop .35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Cards & fields ---------- */
.card { background: var(--paper); border: var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: .9rem; }
input, select {
  font: inherit; font-size: 1.05rem; color: var(--ink);
  background: #fff; border: var(--line); border-radius: 12px; padding: 12px 14px; width: 100%;
  outline: none; transition: box-shadow .15s, transform .15s;
}
input:focus, select:focus { box-shadow: var(--shadow); transform: translate(-2px, -2px); }
input::placeholder { color: #A4A3B5; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
select:disabled, input:disabled { opacity: .7; cursor: not-allowed; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: .95rem; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--tomato); padding: 0; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--display); font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em;
  border: var(--line); border-radius: 14px; padding: 12px 20px; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .1s, box-shadow .1s, background .15s;
  color: var(--ink); background: var(--paper); white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--tomato); color: #fff; }
.btn-dark { background: var(--ink); color: var(--cream); }
.btn-light { background: var(--sun); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; font-weight: 700; font-size: .95rem; }
.btn-ghost:hover:not(:disabled) { box-shadow: none; transform: none; }
.btn-big { font-size: 1.3rem; padding: 16px 28px; width: 100%; }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 24px 0 28px; }
.tiles { display: flex; justify-content: center; gap: 8px; margin-bottom: 26px; flex-wrap: wrap; }
.tile {
  display: inline-grid; place-items: center; width: clamp(48px, 12vw, 76px); aspect-ratio: 1;
  font-family: var(--display); font-weight: 800; font-size: clamp(1.8rem, 6vw, 3rem);
  border: var(--line); border-radius: 14px; box-shadow: var(--shadow);
  animation: bob 3s ease-in-out infinite;
}
.t1 { background: var(--sun); --r: -8deg; animation-delay: 0s; }
.t2 { background: var(--tomato); color: #fff; --r: 5deg; animation-delay: .15s; }
.t3 { background: var(--mint); --r: -3deg; animation-delay: .3s; }
.t4 { background: var(--lilac); color: #fff; --r: 7deg; animation-delay: .45s; }
.t5 { background: var(--pink); --r: -6deg; animation-delay: .6s; }
.t6 { background: var(--paper); --r: 4deg; animation-delay: .75s; }
@keyframes bob { 0%, 100% { transform: rotate(var(--r)) translateY(0); } 50% { transform: rotate(var(--r)) translateY(-6px); } }
.hero h1 { font-size: clamp(2rem, 5.5vw, 3.6rem); font-weight: 800; }
.hero h1 em { font-style: normal; background: linear-gradient(transparent 60%, var(--sun) 60%); padding: 0 4px; }
.lead { max-width: 560px; margin: 16px auto 0; font-size: 1.1rem; color: var(--ink-soft); line-height: 1.5; }

.home-card { max-width: 460px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); font-size: .85rem; font-weight: 700; }
.or::before, .or::after { content: ''; flex: 1; border-top: 2px dashed rgba(27, 27, 47, .25); }
.join-row { display: flex; gap: 10px; }
.join-row input { font-family: var(--display); font-weight: 800; letter-spacing: .3em; text-transform: uppercase; text-align: center; font-size: 1.3rem; }
.home-card .hint { text-align: center; }

.rules { list-style: none; padding: 0; margin: 36px auto 0; max-width: 820px; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.rules li { background: var(--paper); border: 2px solid var(--ink); border-radius: 14px; padding: 14px; font-size: .95rem; line-height: 1.4; }
.rules b:first-child { font-family: var(--display); color: var(--tomato); }

/* ---------- Avatars & players ---------- */
.avatar { display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%; border: var(--line); font-size: 1.45rem; line-height: 1; background: var(--c, var(--sun)); }
.avatar.sm { width: 32px; height: 32px; font-size: 1.05rem; border-width: 2px; }
.avatar.xl { width: 84px; height: 84px; font-size: 2.8rem; }
.players { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.players li { display: flex; align-items: center; gap: 12px; padding: 8px 12px 8px 8px; border: 2px solid var(--ink); border-radius: 14px; background: #fff; font-weight: 700; animation: pop .3s; }
.players li.off { opacity: .45; }
.players .tag { margin-left: auto; font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--sun); border: 2px solid var(--ink); }
.players .you { font-weight: 500; color: var(--ink-soft); font-size: .85rem; }

/* ---------- Lobby ---------- */
.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; background: var(--sun); }
.room-code { font-family: var(--display); font-weight: 800; font-size: clamp(2.6rem, 9vw, 4rem); letter-spacing: .18em; line-height: 1; }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: 20px; align-items: start; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.settings .check { grid-column: 1 / -1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  font: inherit; font-weight: 700; font-size: .95rem; cursor: pointer;
  padding: 8px 14px; border-radius: 99px; border: 2px solid var(--ink); background: #fff; color: var(--ink-soft);
  transition: transform .1s, background .15s;
}
.chip:hover:not(:disabled) { transform: translateY(-2px); }
.chip.on { background: var(--mint); color: var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.chip.custom.on { background: var(--lilac); color: #fff; }
.chip .x { margin-left: 6px; opacity: .8; }
.chip:disabled { cursor: default; }
.chips.readonly .chip:not(.on) { display: none; }
.add-cat { display: flex; gap: 10px; margin-top: 16px; }
.lobby-foot { max-width: 460px; margin: 28px auto 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.waiting { text-align: center; font-weight: 700; color: var(--ink-soft); margin: 0; }
.waiting::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; background: var(--tomato); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- Letter tile ---------- */
.letter-tile {
  display: inline-grid; place-items: center; flex: none;
  width: 96px; height: 96px; background: var(--sun); border: var(--line); border-radius: 18px; box-shadow: var(--shadow-lg);
  font-family: var(--display); font-weight: 800; font-size: 3.6rem; transform: rotate(-4deg); position: relative;
}
.letter-tile::after { content: attr(data-pts); position: absolute; right: 9px; bottom: 5px; font-size: .9rem; }
.letter-tile.small { width: 64px; height: 64px; font-size: 2.3rem; border-radius: 14px; box-shadow: var(--shadow); }
.letter-tile.huge { width: 190px; height: 190px; font-size: 8rem; border-radius: 30px; box-shadow: 10px 10px 0 var(--ink); }

/* ---------- Game ---------- */
.game-head { display: flex; align-items: center; gap: 20px; margin: 4px 0 22px; flex-wrap: wrap; }
.game-meta { display: flex; flex-direction: column; gap: 4px; }
.timer { font-family: var(--display); font-weight: 800; font-size: 2.6rem; font-variant-numeric: tabular-nums; line-height: 1; }
.timer.urgent { color: var(--tomato); animation: shake .5s infinite; }
@keyframes shake { 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
.mini-players { list-style: none; margin: 0 0 0 auto; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; max-width: 520px; }
.mini-players li { display: flex; align-items: center; gap: 6px; background: var(--paper); border: 2px solid var(--ink); border-radius: 99px; padding: 3px 10px 3px 3px; font-size: .85rem; font-weight: 700; }
.mini-players .bar { width: 44px; height: 8px; border-radius: 99px; background: rgba(27, 27, 47, .12); overflow: hidden; }
.mini-players .bar i { display: block; height: 100%; background: var(--mint); transition: width .3s; }

.answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 18px; }
.answers .field span { display: flex; justify-content: space-between; }
.answers input { font-size: 1.15rem; font-weight: 500; }
.answers input.filled { background: #EFFFFC; }
.answers input.wrong { background: #FFF0EB; }
.btn-stop {
  display: block; margin: 26px auto 0; font-size: 2.4rem; padding: 18px 56px; border-radius: 22px;
  background: var(--tomato); color: #fff; box-shadow: var(--shadow-lg); letter-spacing: .02em;
  position: sticky; bottom: 16px; z-index: 5;
}
.btn-stop:disabled { opacity: 1; background: #E4E2EC; color: var(--ink-soft); }
.btn-stop:not(:disabled) { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.05) rotate(-1deg); } }
#stop-hint { text-align: center; }

/* ---------- Review ---------- */
.review-head { display: flex; align-items: center; gap: 18px; margin-bottom: 14px; }
.review-head h2 { margin-bottom: 0; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.badge { display: inline-flex; align-items: center; font-weight: 700; font-size: .8rem; padding: 4px 10px; border-radius: 99px; border: 2px solid var(--ink); white-space: nowrap; }
.badge.ok { background: var(--mint); }
.badge.dup { background: var(--sun); }
.badge.bad { background: #E4E2EC; color: var(--ink-soft); text-decoration: line-through; }
.review { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.review .card { padding: 16px; }
.review h3 { margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.review h3 .num { display: inline-grid; place-items: center; width: 28px; height: 28px; font-size: .85rem; background: var(--ink); color: var(--cream); border-radius: 8px; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 6px; border-radius: 12px; background: #fff; border: 2px solid rgba(27, 27, 47, .12); }
.row .ans { flex: 1; min-width: 0; font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.row .ans small { display: block; font-weight: 500; font-size: .75rem; color: var(--ink-soft); }
.row.st-empty .ans, .row.st-letter .ans, .row.st-rejected .ans { color: var(--ink-soft); text-decoration: line-through; }
.row.st-empty .ans { text-decoration: none; font-style: italic; font-weight: 500; }
.seg { display: inline-flex; flex: none; border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { font: inherit; font-family: var(--display); font-weight: 800; font-size: .9rem; min-width: 36px; padding: 6px 8px; border: 0; border-left: 2px solid var(--ink); background: transparent; color: var(--ink-soft); cursor: pointer; }
.seg button:first-child { border-left: 0; }
.seg button:hover:not(.on) { background: var(--cream); }
.seg button.on { color: var(--ink); }
.seg button.on.ok { background: var(--mint); }
.seg button.on.dup { background: var(--sun); }
.seg button.on.bad { background: var(--tomato); color: #fff; }
.vote { font: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; border: 2px solid var(--ink); border-radius: 10px; background: #fff; padding: 5px 9px; flex: none; transition: transform .1s; }
.vote:hover { transform: scale(1.06); }
.vote.on { background: var(--tomato); color: #fff; }
.vote-count { font-size: .8rem; font-weight: 700; color: var(--tomato); flex: none; }
.sticky-foot { position: sticky; bottom: 0; margin: 24px -16px 0; padding: 16px; background: linear-gradient(transparent, var(--cream) 30%); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.sticky-foot .btn-big { max-width: 460px; }

/* ---------- Results ---------- */
#results-title { font-size: clamp(1.8rem, 5vw, 2.6rem); margin: 10px 0 20px; }
.leaderboard { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.leaderboard li { display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px; border: 2px solid var(--ink); border-radius: 14px; background: #fff; animation: pop .4s backwards; }
.leaderboard .rank { font-family: var(--display); font-weight: 800; width: 28px; text-align: center; font-size: 1.2rem; }
.leaderboard .who { flex: 1; min-width: 0; font-weight: 700; }
.leaderboard .who small { display: block; font-weight: 500; color: var(--ink-soft); font-size: .8rem; overflow-wrap: anywhere; }
.leaderboard .gain { font-family: var(--display); font-weight: 800; color: #0F8C80; }
.leaderboard .total { font-family: var(--display); font-weight: 800; font-size: 1.4rem; min-width: 64px; text-align: right; }
.leaderboard li:first-child { background: #FFF6D6; }

/* ---------- End ---------- */
.big-title { font-size: clamp(2rem, 6vw, 3.2rem); margin: 10px 0 8px; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 14px; margin: 26px 0 30px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(30%, 170px); }
.step .name { font-weight: 700; text-align: center; overflow-wrap: anywhere; }
.step .block { width: 100%; border: var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow); display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 2rem; animation: rise .8s cubic-bezier(.2, .9, .3, 1.2) backwards; transform-origin: bottom; }
.step .pts { font-family: var(--display); font-weight: 800; }
.step.p1 .block { height: 150px; background: var(--sun); animation-delay: .6s; }
.step.p2 .block { height: 110px; background: var(--mint); animation-delay: .3s; }
.step.p3 .block { height: 80px; background: var(--pink); }
.step.p1 .avatar { animation: bob 2s infinite; --r: 0deg; }
@keyframes rise { from { transform: scaleY(0); } }

/* ---------- Overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(255, 244, 224, .92); backdrop-filter: blur(4px); animation: fade .2s; }
.overlay-inner { display: flex; flex-direction: column; align-items: center; gap: 22px; text-align: center; }
.overlay .eyebrow { font-size: 1.1rem; color: var(--ink); }
.overlay-sub { font-family: var(--display); font-weight: 700; font-size: 1.3rem; }
.overlay.stop .letter-tile { background: var(--tomato); color: #fff; font-size: 4.4rem; width: auto; padding: 0 36px; animation: slam .4s cubic-bezier(.2, .9, .3, 1.4); }
.overlay .letter-tile.spin { animation: wobble .12s infinite; }
.overlay .letter-tile.land { animation: land .5s cubic-bezier(.2, .9, .3, 1.5); }
@keyframes fade { from { opacity: 0; } }
@keyframes wobble { 50% { transform: rotate(4deg) scale(.96); } }
@keyframes land { from { transform: scale(1.5) rotate(10deg); } to { transform: rotate(-4deg); } }
@keyframes slam { from { transform: scale(2.4) rotate(-12deg); opacity: 0; } to { transform: rotate(-4deg); } }

/* ---------- Toast & confetti ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translate(-50%, 120px); background: var(--ink); color: var(--cream); padding: 12px 20px; border-radius: 14px; font-weight: 700; box-shadow: 4px 4px 0 var(--tomato); transition: transform .3s cubic-bezier(.2, .9, .3, 1.3); max-width: calc(100% - 32px); text-align: center; }
.toast.show { transform: translate(-50%, 0); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 16px; border: 2px solid var(--ink); border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .mini-players { margin-left: 0; justify-content: flex-start; max-width: none; width: 100%; }
  .review { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .card { padding: 16px; }
  .settings { grid-template-columns: 1fr; }
  .lobby-head .btn { width: 100%; }
  .letter-tile { width: 76px; height: 76px; font-size: 2.8rem; }
  .letter-tile.huge { width: 150px; height: 150px; font-size: 6rem; }
  .timer { font-size: 2rem; }
  .btn-stop { width: 100%; font-size: 2rem; padding: 16px; }
  .add-cat { flex-direction: column; }
  .brand { font-size: 1.35rem; }
  .me-chip .nm { display: none; }
  .me-chip { padding: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
