:root {
  /* Paper and ink */
  --paper: #f6f1e7;
  --paper-2: #efe7d8;
  --card: #fffcf6;
  --ink: #1f1b16;
  --ink-2: #5f564c;
  --ink-3: #8f8577;
  --line: #e4dacb;
  --line-2: #d6c9b3;

  /* The wrestlers */
  --k: #d9622b;
  --k-deep: #a9461a;
  --k-soft: #fbe8dc;
  --j: #1e6f6a;
  --j-deep: #134d49;
  --j-soft: #dcedea;
  --gold: #e3a62f;
  --skin: #e9b98a;

  /* The board */
  --board: #e2d6c0;
  --square: #f6f0e3;
  --tw: #c2463a;
  --dw: #efc6b4;
  --tl: #2e5f82;
  --dl: #c5dbe6;
  --tile-top: #fffbf2;
  --tile: #f6ead3;
  --tile-edge: #dcc7a0;

  --good: #2f7d4f;
  --bad: #c2463a;

  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --soft: "SOFT" 100, "WONK" 0;
  --shadow-sm: 0 1px 2px rgba(60, 40, 10, .08);
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 10px 30px -14px rgba(60, 40, 10, .28);
}

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

html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---------- Logo ---------- */
.kj-logo .logo { display: block; width: 100%; height: auto; }
.logo text { font-family: var(--display); font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144; }
.logo-letter { font-size: 300px; font-weight: 900; text-anchor: middle; }
.logo-k { fill: var(--k); }
.logo-j { fill: var(--j); }
.logo-games { font-size: 172px; font-weight: 800; fill: var(--ink); }
.logo-table .t1 { fill: var(--gold); }
.logo-table .t2 { fill: var(--k); }
.logo-table .t3 { fill: var(--j); }
.arm-K { --c: var(--k); }
.arm-J { --c: var(--j); }
.arm-outline > * { fill: var(--ink); stroke: var(--ink); stroke-width: 11; stroke-linejoin: round; }
.arm-skin > * { fill: var(--skin); }
.arm-sleeve { fill: var(--c); stroke: var(--ink); stroke-width: 11; stroke-linejoin: round; paint-order: stroke fill; }
.arm-trim, .arm-stripe { fill: var(--paper); }
.arm-band { fill: var(--c); stroke: var(--ink); stroke-width: 5; stroke-linejoin: round; }
.arm-shine { fill: none; stroke: #fff; stroke-opacity: .6; stroke-width: 6; stroke-linecap: round; }
.arm-detail path { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; }
.strain path { fill: none; stroke: var(--gold); stroke-width: 7; stroke-linecap: round; }

/* ---------- Welcome ---------- */
.welcome {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 16px 48px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 38%, rgba(246, 241, 231, 1) 0 22%, rgba(246, 241, 231, 0) 70%),
    repeating-conic-gradient(from -3deg at 50% 38%, #f6f1e7 0 6deg, #f0e7d6 6deg 12deg);
}
.welcome-inner { width: min(100%, 600px); text-align: center; }
.welcome-logo { width: min(100%, 560px); margin: 0 auto; }
.gate-portrait { display: block; width: min(80vw, 38dvh, 340px); height: auto; margin: 0 auto; }
.password-form { width: min(100%, 400px); margin: 26px auto 0; text-align: left; }
.password-form label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.password-controls { display: flex; gap: 10px; }
.password-controls input { min-width: 0; flex: 1; width: 100%; padding: 13px 15px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--card); color: var(--ink); font: 18px var(--body); }
.password-controls input[aria-invalid="true"] { border-color: var(--bad); }
.password-controls .btn { flex: none; padding: 12px 18px; }
.password-error { min-height: 1.5em; margin-top: 10px; font-size: 14px; line-height: 1.5; color: var(--bad); }

.welcome-q {
  font-family: var(--display);
  font-variation-settings: var(--soft);
  font-weight: 600;
  font-size: clamp(26px, 5.6vw, 38px);
  letter-spacing: -.01em;
  line-height: 1.15;
  margin-top: 34px;
  text-wrap: balance;
}
.ink-k { color: var(--k); font-weight: 800; }
.ink-j { color: var(--j); font-weight: 800; }

.pick { display: flex; align-items: center; justify-content: center; gap: clamp(18px, 6vw, 40px); margin-top: 28px; }
.who-btn {
  width: clamp(124px, 34vw, 168px);
  aspect-ratio: 1;
  border: 0;
  border-radius: 32px;
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
  font-weight: 900;
  font-size: clamp(76px, 21vw, 108px);
  line-height: 1;
  color: var(--paper);
  padding-bottom: 6px;
  transition: transform .14s ease, box-shadow .14s ease;
}
.who-k { background: var(--k); box-shadow: 0 8px 0 var(--k-deep), 0 22px 30px -14px rgba(169, 70, 26, .6); }
.who-j { background: var(--j); box-shadow: 0 8px 0 var(--j-deep), 0 22px 30px -14px rgba(19, 77, 73, .6); }
.who-btn:hover { transform: translateY(-3px); }
.who-k:hover { box-shadow: 0 11px 0 var(--k-deep), 0 26px 34px -14px rgba(169, 70, 26, .6); }
.who-j:hover { box-shadow: 0 11px 0 var(--j-deep), 0 26px 34px -14px rgba(19, 77, 73, .6); }
.who-btn:active { transform: translateY(6px); }
.who-k:active { box-shadow: 0 2px 0 var(--k-deep), 0 6px 12px -6px rgba(169, 70, 26, .6); }
.who-j:active { box-shadow: 0 2px 0 var(--j-deep), 0 6px 12px -6px rgba(19, 77, 73, .6); }

/* ---------- Game shell ---------- */
.game { min-height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1160px;
  margin: 0 auto;
  padding: 10px clamp(12px, 3vw, 28px);
}
.topbar-logo { width: 124px; flex: none; }
.topbar-title { display: flex; flex-direction: column; min-width: 0; margin-right: auto; padding-left: 16px; border-left: 1px solid var(--line-2); }
.game-name {
  font-family: var(--display);
  font-variation-settings: var(--soft);
  font-weight: 700;
  font-size: clamp(19px, 3.4vw, 24px);
  letter-spacing: -.01em;
  line-height: 1.1;
  white-space: nowrap;
}
.tagline { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; flex: none; }
.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-2);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.chip-btn:hover { border-color: var(--ink-3); }
.me-chip { padding: 4px 5px 4px 14px; }
.me-chip b {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: var(--paper);
  font-family: var(--display);
  font-variation-settings: var(--soft);
  font-weight: 800;
  font-size: 15px;
}
.me-chip.is-K b { background: var(--k); }
.me-chip.is-J b { background: var(--j); }

.stripes { display: grid; grid-template-rows: repeat(3, 3px); gap: 2px; }
.stripes i:nth-child(1) { background: var(--gold); }
.stripes i:nth-child(2) { background: var(--k); }
.stripes i:nth-child(3) { background: var(--j); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 28px;
  max-width: 1160px;
  margin: 0 auto;
  padding: 18px clamp(10px, 3vw, 28px) 28px;
  align-items: start;
}
.play { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

/* ---------- Board ---------- */
.board-wrap {
  width: min(100%, max(320px, calc(100dvh - 306px)));
  background: var(--board);
  border-radius: 18px;
  padding: clamp(6px, 1.3vw, 11px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 1px 2px rgba(60, 40, 10, .1), 0 24px 44px -26px rgba(60, 40, 10, .45);
  container-type: inline-size;
}
.board {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  gap: .42cqw;
}
.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: .75cqw;
  background: var(--square);
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-user-select: none;
}
.cell.bonus-tw { background: var(--tw); color: #fff6ec; }
.cell.bonus-dw, .cell.bonus-st { background: var(--dw); color: #8a3a26; }
.cell.bonus-tl { background: var(--tl); color: #eef4f8; }
.cell.bonus-dl { background: var(--dl); color: #2b5677; }
.cell.drop-hover { box-shadow: inset 0 0 0 .5cqw var(--gold); }
.cell.is-open { cursor: pointer; }
.cell.is-open:not(:has(.tile)):hover { filter: brightness(.97); }

.bonus { display: grid; justify-items: center; line-height: 1; pointer-events: none; }
.bonus b { font-size: 2.2cqw; font-weight: 700; letter-spacing: -.02em; }
.bonus i { font-style: normal; font-size: 1.08cqw; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; opacity: .8; margin-top: .3cqw; }
.bonus.star b { font-size: 3.4cqw; color: var(--tw); }
@container (max-width: 520px) { .bonus i { display: none; } .bonus b { font-size: 2.6cqw; } }

.cursor {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 .5cqw var(--ink);
  background: rgba(31, 27, 22, .08);
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: 3cqw;
  font-weight: 700;
  pointer-events: none;
  animation: blink 1.1s ease-in-out infinite;
}
@keyframes blink { 50% { background: rgba(31, 27, 22, .2); } }

/* ---------- Tiles ---------- */
.tile {
  position: relative;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--tile-top) 0%, var(--tile) 100%);
  color: var(--ink);
  border-radius: 16%;
  box-shadow: inset 0 -3px 0 var(--tile-edge), 0 1px 2px rgba(60, 40, 10, .3);
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}
.tile .tl {
  font-family: var(--display);
  font-variation-settings: "SOFT" 50, "opsz" 72;
  font-weight: 600;
  transform: translateY(-3%);
}
.tile .tv { position: absolute; right: 10%; bottom: 10%; font-family: var(--body); font-weight: 700; color: var(--ink-2); }
.tile.is-blank .tl { color: var(--ink-3); font-style: italic; }
.tile[data-tile] { cursor: grab; touch-action: none; }

.cell .tile { position: absolute; inset: 0; font-size: 3.9cqw; box-shadow: inset 0 -.42cqw 0 var(--tile-edge), 0 .12cqw .3cqw rgba(60, 40, 10, .3); }
.cell .tile .tv { font-size: 1.45cqw; }
.cell .tile.by-K { box-shadow: inset 0 -.42cqw 0 #eaa98a, 0 .12cqw .3cqw rgba(60, 40, 10, .3); }
.cell .tile.by-J { box-shadow: inset 0 -.42cqw 0 #8fc2bc, 0 .12cqw .3cqw rgba(60, 40, 10, .3); }
.cell .tile.last-K { outline: .45cqw solid var(--k); outline-offset: -.05cqw; z-index: 1; }
.cell .tile.last-J { outline: .45cqw solid var(--j); outline-offset: -.05cqw; z-index: 1; }
.cell .tile.pending {
  background: linear-gradient(180deg, #fffdf7 0%, #fbeec9 100%);
  box-shadow: inset 0 -.42cqw 0 #e2bf6e, 0 .5cqw 1.1cqw rgba(60, 40, 10, .35);
  outline: .4cqw solid var(--gold);
  z-index: 2;
}
.cell .tile.fresh { animation: plop .16s ease-out; }
@keyframes plop { from { transform: scale(1.15); } to { transform: scale(1); } }
.tile.lifting { opacity: .25; }
.tile.ghost {
  position: fixed;
  inset: auto;
  z-index: 1000;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-4deg) scale(1.1);
  box-shadow: inset 0 -3px 0 var(--tile-edge), 0 14px 26px rgba(60, 40, 10, .4);
}

.score-bubble {
  position: absolute;
  top: 0; right: 0;
  transform: translate(42%, -50%);
  z-index: 5;
  min-width: 4.6cqw;
  padding: .55cqw 1.2cqw;
  border-radius: 999px;
  background: var(--ink-2);
  color: #fff;
  font-size: 2.4cqw;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 0 0 .35cqw var(--card), 0 .4cqw 1cqw rgba(0, 0, 0, .25);
}
.score-bubble.good { background: var(--good); }
.score-bubble.bad { background: var(--bad); }
@container (max-width: 520px) { .score-bubble { font-size: 3.4cqw; padding: .7cqw 1.6cqw; } }

/* ---------- Rack + controls ---------- */
.controls { width: min(100%, max(320px, calc(100dvh - 306px))); display: grid; gap: 9px; }
.preview {
  min-height: 30px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-3);
  text-align: center;
}
.preview .oops { color: var(--bad); font-weight: 600; }
.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px 4px 11px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line-2);
  color: var(--ink);
  font-weight: 700;
  letter-spacing: .05em;
}
.word-chip em { font-style: normal; font-weight: 700; letter-spacing: 0; color: var(--ink-2); background: var(--paper-2); border-radius: 999px; padding: 1px 7px; }
.word-chip.good { border-color: var(--good); }
.word-chip.good em { background: #e1efe5; color: var(--good); }
.word-chip.bad { border-color: var(--bad); color: var(--bad); }
.word-chip.bad em { background: #f7e1dd; color: var(--bad); }
.word-chip.bonus-chip { background: #fbefcf; border-color: var(--gold); }
.power-tag { font-size: 11.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; color: #fff; letter-spacing: .02em; }
.power-tag.K { background: var(--k); }
.power-tag.J { background: var(--j); }

.rack {
  --rt: clamp(38px, 11.2vw, 56px);
  display: flex;
  justify-content: center;
  gap: clamp(4px, 1.2vw, 8px);
  min-height: calc(var(--rt) + 24px);
  padding: 10px 10px 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, #4a3727 0%, #3a2a1e 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), inset 0 -4px 0 rgba(0, 0, 0, .18), 0 10px 22px -12px rgba(40, 24, 10, .6);
  position: relative;
}
.rack::after {
  content: "";
  position: absolute;
  left: 18px; right: 18px; bottom: 5px;
  height: 3px;
  border-radius: 3px;
  background: var(--accent, transparent);
  opacity: .9;
}
.rack.mine-K { --accent: var(--k); }
.rack.mine-J { --accent: #3aa59d; }
.rack .tile { width: var(--rt); height: var(--rt); font-size: calc(var(--rt) * .56); flex: none; transition: transform .12s ease; }
.rack .tile .tv { font-size: calc(var(--rt) * .22); }
.rack .tile:hover { transform: translateY(-3px); }
.rack .tile.selected { transform: translateY(-9px); box-shadow: inset 0 -3px 0 var(--tile-edge), 0 0 0 3px var(--gold), 0 8px 14px rgba(0, 0, 0, .35); }
.rack.shake { animation: shake .3s linear; }
.rack-empty { align-self: center; color: rgba(246, 241, 231, .6); font-size: 14px; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }

.buttons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.6fr); gap: 8px; }
.btn {
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--card);
  padding: 11px 6px;
  font-weight: 600;
  font-size: 15px;
  box-shadow: var(--shadow-sm);
  transition: background .12s ease, border-color .12s ease, transform .08s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #fff; border-color: var(--ink-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; box-shadow: none; }
.btn-play { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 700; }
.btn-play:hover:not(:disabled) { background: #000; border-color: #000; }
.btn-play.is-K:not(:disabled) { background: var(--k); border-color: var(--k); box-shadow: 0 3px 0 var(--k-deep); }
.btn-play.is-K:hover:not(:disabled) { background: #cf5a24; }
.btn-play.is-J:not(:disabled) { background: var(--j); border-color: var(--j); box-shadow: 0 3px 0 var(--j-deep); }
.btn-play.is-J:hover:not(:disabled) { background: #1a6560; }
.btn-play:disabled { background: var(--paper-2); border-color: var(--line); color: var(--ink-3); opacity: 1; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a93a2f; border-color: #a93a2f; }
.btn-quiet { box-shadow: none; border-color: transparent; background: transparent; }
.btn-quiet:hover:not(:disabled) { background: var(--paper-2); border-color: transparent; }

/* ---------- Side column ---------- */
.scores { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.score-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px 14px 12px;
  box-shadow: var(--shadow);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.score-card.K { --c: var(--k); --c-soft: var(--k-soft); }
.score-card.J { --c: var(--j); --c-soft: var(--j-soft); }
.score-card.active { border-color: var(--c); box-shadow: 0 0 0 3px var(--c-soft), var(--shadow); }
.score-top { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.score-letter {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c);
  color: var(--paper);
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "WONK" 1;
  font-weight: 800;
  font-size: 17px;
}
.score-who { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-right: auto; }
.score-num {
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "opsz" 144;
  font-weight: 600;
  font-size: 46px;
  line-height: 1;
  letter-spacing: -.02em;
  margin-top: 10px;
  font-variant-numeric: tabular-nums lining-nums;
}
.turn-flag {
  background: var(--c);
  color: #fff;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.turn-flag.win { background: var(--gold); color: var(--ink); }
.turn-flag.tie { background: var(--paper-2); color: var(--ink-2); }

.status h2 { font-family: var(--display); font-variation-settings: var(--soft); font-weight: 700; font-size: 22px; letter-spacing: -.01em; line-height: 1.2; }
.status p { margin-top: 6px; font-size: 14.5px; line-height: 1.5; color: var(--ink-2); }
.status p strong { color: var(--ink); }
.status .ago { color: var(--ink-3); white-space: nowrap; }
.status .facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.fact { font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--paper-2); color: var(--ink-2); }
.status.my-turn-K { background: linear-gradient(180deg, var(--k-soft), var(--card) 85%); border-color: #f0c7b0; }
.status.my-turn-J { background: linear-gradient(180deg, var(--j-soft), var(--card) 85%); border-color: #b7d8d4; }
.status.over { background: linear-gradient(180deg, #fbefcf, var(--card) 85%); border-color: #ecd59a; }
.status .btn { margin-top: 14px; width: 100%; }

.log-card { padding-bottom: 8px; }
.log-card h2 { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); margin-bottom: 4px; }
.log { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
.log li { display: grid; grid-template-columns: 24px 1fr auto; align-items: start; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.log li:first-child { border-top: 0; }
.log .who {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--paper);
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "WONK" 1;
  font-weight: 800;
  font-size: 13px;
}
.log .who.K { background: var(--k); }
.log .who.J { background: var(--j); }
.log .what { min-width: 0; padding-top: 3px; }
.log .what b { font-weight: 700; letter-spacing: .04em; }
.log .what small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.log .pts { font-weight: 700; font-variant-numeric: tabular-nums; line-height: 24px; }
.log .muted { color: var(--ink-2); font-style: italic; }
.log-empty { color: var(--ink-3); font-size: 14px; }

.side-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; font-size: 13px; color: var(--ink-3); padding: 0 6px; }
.sync { margin-right: auto; }
.sync.offline { color: var(--bad); font-weight: 600; }
.link-btn { border: 0; background: none; padding: 4px 0; font-weight: 600; font-size: 13px; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
.link-btn:hover { color: var(--ink); text-decoration-color: currentColor; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 500;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(31, 27, 22, .45);
  backdrop-filter: blur(3px);
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal-box {
  width: min(100%, 440px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--card);
  border-radius: 22px;
  box-shadow: 0 30px 60px -20px rgba(31, 27, 22, .5);
  padding: 24px;
  animation: rise .2s cubic-bezier(.2, 1.2, .4, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal-box h2 { font-family: var(--display); font-variation-settings: var(--soft); font-weight: 700; font-size: 24px; letter-spacing: -.01em; line-height: 1.2; }
.modal-box p { margin-top: 8px; line-height: 1.5; color: var(--ink-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions .btn { padding: 10px 18px; }
.letter-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 16px; }
.letter-grid button {
  aspect-ratio: 1;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(180deg, var(--tile-top), var(--tile));
  box-shadow: inset 0 -2px 0 var(--tile-edge);
  font-family: var(--display);
  font-weight: 600;
  font-size: 19px;
}
.letter-grid button:hover { background: #fbeec9; }
.swap-rack { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding: 12px; border-radius: 14px; background: linear-gradient(180deg, #4a3727, #3a2a1e); }
.swap-rack .tile { width: 46px; height: 46px; font-size: 26px; cursor: pointer; border: 0; transition: transform .12s ease; }
.swap-rack .tile .tv { font-size: 10.5px; }
.swap-rack .tile.chosen { transform: translateY(-7px); box-shadow: inset 0 -3px 0 var(--tile-edge), 0 0 0 3px var(--gold); }
.rules { margin: 14px 0 0; padding: 0; list-style: none; display: grid; gap: 11px; font-size: 14.5px; line-height: 1.45; color: var(--ink-2); }
.rules b { color: var(--ink); }
.rules li { display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start; }
.swatch { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; }
.swatch.tw { background: var(--tw); }
.swatch.dw { background: var(--dw); color: #8a3a26; }
.swatch.tl { background: var(--tl); }
.swatch.dl { background: var(--dl); color: #2b5677; }
.swatch.kj { background: linear-gradient(135deg, var(--k) 50%, var(--j) 50%); font-family: var(--display); font-weight: 800; }
.swatch.plain { background: var(--paper-2); color: var(--ink-2); }

/* ---------- Toasts + confetti ---------- */
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 900; display: grid; gap: 8px; justify-items: center; width: min(92vw, 460px); pointer-events: none; }
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  padding: 10px 18px 10px 14px;
  font-weight: 600;
  font-size: 14.5px;
  box-shadow: 0 14px 30px -10px rgba(31, 27, 22, .5);
  animation: toast-in .25s cubic-bezier(.2, 1.3, .4, 1);
}
.toast::before { content: ""; flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.toast.K::before { background: var(--k); }
.toast.J::before { background: #3aa59d; }
.toast.bad::before { background: #e66b5d; }
.toast.out { opacity: 0; transform: translateY(-10px); transition: all .3s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(.96); } }

.confetti { position: fixed; top: -20px; width: 9px; height: 14px; border-radius: 2px; z-index: 950; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .layout { display: flex; flex-direction: column; align-items: stretch; gap: 12px; padding-top: 12px; }
  .play, .side { display: contents; }
  .scores { order: 1; }
  .status { order: 2; }
  .board-wrap { order: 3; align-self: center; width: min(100%, 640px); }
  .controls { order: 4; align-self: center; width: min(100%, 640px); }
  .log-card { order: 5; }
  .side-foot { order: 6; }
  .score-num { font-size: 36px; margin-top: 6px; }
  .tagline { display: none; }
  .topbar-logo { width: 100px; }
}
@media (max-width: 480px) {
  .topbar { gap: 10px; }
  .topbar-title { padding-left: 10px; }
  .chip-btn { padding: 6px 11px; font-size: 13px; }
  .me-chip { padding: 3px; }
  .chip-long { display: none; }
  .topbar-logo { width: 82px; }
  .btn { font-size: 13.5px; padding: 10px 2px; }
  .buttons { gap: 6px; }
  .card { padding: 14px 15px; }
  .status h2 { font-size: 20px; }
}

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