@font-face {
  font-family: "Bricolage";
  src: url("fonts/bricolage.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --sun: #FFC93C;
  --sun-deep: #F2B01A;
  --ink: #171B3D;
  --indigo: #2A2F7F;
  --indigo-lit: #4650C4;
  --chalk: #F4F1E8;
  --chalk-dim: #E2DDCC;
  --ivory: #FFFDF6;
  --red: #E5412D;
  --red-deep: #B72A1A;
  --ok: #0E8F6B;
  --radius: 16px;
  --gutter: 16px;
  --bs: min(calc(100vw - 2 * var(--gutter)), calc(100dvh - 318px), 600px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--sun);
  color: var(--ink);
  font: 500 17px/1.4 "Bricolage", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }

#app { min-height: 100%; display: flex; justify-content: center; }
.screen {
  position: relative; width: 100%; max-width: 520px;
  padding: 12px var(--gutter) 28px;
  display: flex; flex-direction: column; gap: 16px;
  overflow: hidden;
}
h1, h2, h3 { margin: 0; line-height: 1; letter-spacing: -0.03em; font-weight: 800; }
h2 { font-size: 34px; }
p { margin: 0; }
.muted { opacity: .72; }
.small { font-size: 14px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 2.5px solid var(--ink); background: transparent; color: var(--ink);
  font-family: inherit; font-weight: 700; font-size: 17px; line-height: 1.1;
  padding: 14px 18px; border-radius: 14px; cursor: pointer; text-align: left;
  transition: transform .08s ease, background-color .12s ease, color .12s ease;
}
.btn:active { transform: translateY(2px) scale(.99); }
.btn:hover { background: rgba(23, 27, 61, .08); }
.btn.primary { background: var(--ink); color: var(--sun); }
.btn.primary:hover { background: #262c63; }
.btn.big { font-size: 21px; padding: 20px 20px; letter-spacing: -0.01em; }
.btn.small { padding: 10px 14px; font-size: 15px; border-width: 2px; }
.btn.ghost { border-color: transparent; text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; padding-left: 4px; padding-right: 4px; }
.btn:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 3px solid var(--indigo-lit); outline-offset: 3px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.back {
  align-self: flex-start; appearance: none; background: none; border: 0; padding: 8px 8px 8px 0; margin-left: -2px;
  font-family: inherit; font-weight: 700; font-size: 16px; color: var(--ink); cursor: pointer;
}
.icon-btn { appearance: none; background: none; border: 0; color: var(--ink); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; cursor: pointer; }
.icon-btn[aria-pressed="false"] .waves { display: none; }

/* ---------- menu ---------- */
#menu { padding-top: max(28px, 7vh); gap: 28px; min-height: 100dvh; }
.brand h1 { font-size: clamp(56px, 19vw, 92px); line-height: .9; letter-spacing: -0.045em; font-weight: 800; }
.tag { margin-top: 16px; font-size: 18px; max-width: 24ch; font-weight: 600; }
.hero-discs { display: flex; margin-top: 26px; }
.hero-discs i {
  width: 72px; height: 72px; border-radius: 50%; margin-right: -14px; position: relative; display: grid; place-items: center;
  box-shadow: 0 4px 0 rgba(23, 27, 61, .35), inset 0 0 0 3px var(--rim), inset 0 0 0 10px var(--face), inset 0 0 0 13px var(--rim);
  background: var(--face);
}
.hero-discs i.w { --face: var(--ivory); --rim: var(--chalk-dim); }
.hero-discs i.b { --face: var(--red); --rim: var(--red-deep); }
.hero-discs i.w.k { --crown: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 18h18l1.5-11-5 4L12 4 6.500 11l-5-4z' fill='%23171B3D'/%3E%3Crect x='3' y='19.500' width='18' height='2.500' rx='1' fill='%23171B3D'/%3E%3C/svg%3E"); }
.hero-discs i.k::after { content: ""; width: 44%; height: 44%; background: var(--crown) center / contain no-repeat; }
.brand, .stack { position: relative; z-index: 1; }
#menu .stack { margin-top: auto; }

/* ---------- forms ---------- */
.choice { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.choice legend { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; padding: 0; margin-bottom: 8px; }
.choice label { display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { display: block; padding: 14px 16px; border: 2.5px solid var(--ink); border-radius: 14px; font-weight: 500; }
.choice span b { display: block; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.choice input:checked + span { background: var(--ink); color: var(--sun); }
.choice input:focus-visible + span { outline: 3px solid var(--indigo-lit); outline-offset: 3px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.field input, .join input {
  font-family: inherit; font-weight: 700; font-size: 20px; color: var(--ink); background: var(--chalk);
  border: 2.5px solid var(--ink); border-radius: 14px; padding: 13px 14px; width: 100%;
}
#code-input { text-transform: uppercase; letter-spacing: .3em; text-align: center; }
.join { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.join .btn { height: 54px; }
.switch { display: flex; align-items: center; gap: 12px; font-weight: 700; cursor: pointer; }
.switch input { width: 26px; height: 26px; accent-color: var(--ink); }
.conn { min-height: 1.4em; font-weight: 700; }
.conn.bad { color: var(--red-deep); }
.conn.ok { color: var(--ok); }
.wait { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.big-msg { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.code { font-size: clamp(64px, 24vw, 104px); font-weight: 800; letter-spacing: .12em; line-height: 1; padding-left: .12em; }
.rules { padding-left: 1.1em; display: flex; flex-direction: column; gap: 12px; margin: 0; max-width: 60ch; }

/* ---------- game ---------- */
#game { padding-top: 6px; gap: 8px; align-items: center; }
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.mode { font-weight: 700; opacity: .75; }
.player { width: var(--bs); display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 2px; border-bottom: 4px solid transparent; transition: border-color .2s; }
.player.active { border-bottom-color: var(--ink); }
.pname { font-weight: 800; font-size: 19px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pstat { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pstat.warn { color: var(--red-deep); }
.disc { width: 22px; height: 22px; border-radius: 50%; display: inline-block; flex: none; }
.disc.w { background: var(--ivory); box-shadow: inset 0 0 0 3px var(--chalk-dim), 0 0 0 2px var(--ink); }
.disc.b { background: var(--red); box-shadow: inset 0 0 0 3px var(--red-deep), 0 0 0 2px var(--ink); }

.board-wrap { position: relative; width: var(--bs); height: var(--bs); border-radius: 12px; box-shadow: 0 0 0 5px var(--ink); }
.board { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: 12px; overflow: hidden; touch-action: manipulation; }
.sq { position: relative; background: var(--chalk); border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: default; }
.sq.dark { background: var(--indigo); }
.sq.last { background: var(--indigo-lit); }
.sq.sel { box-shadow: inset 0 0 0 4px var(--sun); }
.sq.path { box-shadow: inset 0 0 0 4px rgba(255, 201, 60, .55); }
.sq.target::after { content: ""; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; transform: translate(-50%, -50%); border-radius: 50%; background: var(--sun); }
.sq.target.cap::after { width: 36%; height: 36%; background: transparent; box-shadow: inset 0 0 0 4px var(--sun); }
.sq.canmove { cursor: pointer; }
.sq.target { cursor: pointer; }

.pieces { position: absolute; inset: 0; pointer-events: none; }
.piece {
  position: absolute; width: 12.5%; height: 12.5%; display: grid; place-items: center;
  transition: left .2s cubic-bezier(.3, .7, .3, 1), top .2s cubic-bezier(.3, .7, .3, 1), opacity .2s, transform .2s;
}
.piece::before {
  content: ""; width: 80%; height: 80%; border-radius: 50%;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35), inset 0 0 0 calc(var(--bs) * .011) var(--rim), inset 0 0 0 calc(var(--bs) * .028) var(--face), inset 0 0 0 calc(var(--bs) * .036) var(--rim);
  background: var(--face);
}
.piece.w { --face: var(--ivory); --rim: var(--chalk-dim); }
.piece.b { --face: var(--red); --rim: var(--red-deep); }
.piece.k::after {
  content: ""; position: absolute; width: 44%; height: 44%;
  background: var(--crown) center / contain no-repeat;
}
.piece.w.k { --crown: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 18h18l1.5-11-5 4L12 4 6.500 11l-5-4z' fill='%23171B3D'/%3E%3Crect x='3' y='19.500' width='18' height='2.500' rx='1' fill='%23171B3D'/%3E%3C/svg%3E"); }
.piece.b.k { --crown: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 18h18l1.5-11-5 4L12 4 6.500 11l-5-4z' fill='%23FFFDF6'/%3E%3Crect x='3' y='19.500' width='18' height='2.500' rx='1' fill='%23FFFDF6'/%3E%3C/svg%3E"); }
.piece.must::before { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 0 0 rgba(255, 201, 60, .95), inset 0 0 0 calc(var(--bs) * .011) var(--rim), inset 0 0 0 calc(var(--bs) * .028) var(--face), inset 0 0 0 calc(var(--bs) * .036) var(--rim); }
  50% { box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 0 calc(var(--bs) * .02) rgba(255, 201, 60, .9), inset 0 0 0 calc(var(--bs) * .011) var(--rim), inset 0 0 0 calc(var(--bs) * .028) var(--face), inset 0 0 0 calc(var(--bs) * .036) var(--rim); }
}
.piece.sel { transform: scale(1.08); z-index: 3; }
.piece.moving { z-index: 5; transition-duration: .22s; }
.piece.gone { opacity: 0; transform: scale(.6); }
.piece.crowned::before { animation: crown .5s ease-out; }
@keyframes crown { 0% { transform: scale(1); } 40% { transform: scale(1.3); } 100% { transform: scale(1); } }

.toast {
  position: absolute; left: 50%; bottom: 10px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; z-index: 10;
  background: var(--ink); color: var(--sun); padding: 9px 14px; border-radius: 12px; font-weight: 700; font-size: 15px; white-space: nowrap; max-width: 94%;
  overflow: hidden; text-overflow: ellipsis; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.turn { width: var(--bs); font-weight: 800; font-size: 20px; letter-spacing: -0.01em; min-height: 1.4em; }
.banner { width: var(--bs); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: var(--ink); color: var(--sun); padding: 10px 12px; border-radius: 14px; font-weight: 700; }
.banner span { flex: 1 1 100%; }
.banner .btn.primary { background: var(--sun); color: var(--ink); border-color: var(--sun); }
.banner .btn { border-color: var(--sun); color: var(--sun); }
.banner .btn.primary { color: var(--ink); }
.actions { width: var(--bs); display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- dialog ---------- */
dialog { border: 3px solid var(--ink); border-radius: 22px; padding: 22px; background: var(--sun); color: var(--ink); width: min(92vw, 380px); box-shadow: 8px 8px 0 var(--ink); }
dialog::backdrop { background: rgba(23, 27, 61, .55); }
dialog h3 { font-size: 34px; margin-bottom: 8px; }
dialog p { margin-bottom: 18px; font-weight: 600; }
dialog .row { flex-direction: column; align-items: stretch; }
dialog .btn { text-align: center; }
#dlg-x { margin: -6px 0 16px; display: flex; flex-direction: column; gap: 10px; }
.pts { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.pts small { font-size: 15px; font-weight: 700; opacity: .75; letter-spacing: 0; margin-left: 6px; }
dialog #dlg-x p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  .piece, .toast, .btn { transition: none; }
  .piece.must::before, .piece.crowned::before { animation: none; }
}
@media (min-width: 700px) {
  :root { --bs: min(calc(100dvh - 300px), 640px); }
  .screen { max-width: 680px; }
}
@media (max-height: 640px) {
  :root { --bs: min(calc(100vw - 2 * var(--gutter)), calc(100dvh - 250px), 600px); }
}

#wait-friend, #wait-quick { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }

/* ---------- ranks, leaderboard, join ---------- */
.chip {
  align-self: flex-start; appearance: none; font-family: inherit; font-weight: 800; font-size: 15px; color: var(--sun);
  background: var(--ink); border: 0; border-radius: 999px; padding: 8px 14px; cursor: pointer; letter-spacing: -0.005em;
  box-shadow: 3px 3px 0 rgba(23, 27, 61, .35);
}
.chip:active { transform: translateY(1px); }
.tabs { display: flex; border: 2.5px solid var(--ink); border-radius: 14px; overflow: hidden; align-self: flex-start; }
.tab { appearance: none; border: 0; background: transparent; color: var(--ink); font-family: inherit; font-weight: 800; font-size: 16px; padding: 10px 16px; cursor: pointer; }
.tab + .tab { border-left: 2.5px solid var(--ink); }
.tab.on { background: var(--ink); color: var(--sun); }
.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lb-list li {
  display: grid; grid-template-columns: 2.2em 1fr auto; align-items: center; gap: 10px;
  padding: 10px 14px; border: 2.5px solid var(--ink); border-radius: 14px; background: var(--chalk);
}
.lb-list li.you { background: var(--ink); color: var(--sun); box-shadow: 4px 4px 0 rgba(23, 27, 61, .35); }
.lb-list .pos { font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.lb-list li:nth-child(-n+3) .pos::before { content: ""; display: inline-block; width: .5em; height: .5em; border-radius: 50%; background: var(--sun-deep); margin-right: .25em; box-shadow: 0 0 0 2px var(--ink); }
.lb-list li.you:nth-child(-n+3) .pos::before { background: var(--sun); box-shadow: none; }
.lb-list .nm { font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .nm small { display: block; font-weight: 600; font-size: 13px; opacity: .72; }
.lb-list .sc { font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.lb-empty { padding: 18px; border: 2.5px dashed var(--ink); border-radius: 14px; font-weight: 700; }
.promo, .me-card { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; padding: 16px; border: 3px solid var(--ink); border-radius: 18px; background: var(--ivory); box-shadow: 6px 6px 0 var(--ink); }
.promo b { font-size: 21px; line-height: 1.15; letter-spacing: -0.02em; }
dialog .promo { box-shadow: 4px 4px 0 var(--ink); padding: 14px; }
.promo .row { gap: 6px; }
.me-card b { font-size: 22px; letter-spacing: -0.02em; }
.bar { width: 100%; height: 12px; border: 2.5px solid var(--ink); border-radius: 999px; background: var(--chalk); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ink); }
.linkbtn { appearance: none; background: none; border: 0; padding: 6px 2px; font-family: inherit; font-weight: 700; font-size: 15px; color: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.linkbtn.danger { color: var(--red-deep); }
.err { min-height: 1.4em; font-weight: 700; color: var(--red-deep); }
#lb-me { display: flex; flex-direction: column; gap: 12px; }

/* ---------- menu link row: one line on phones ---------- */
#menu .row { flex-wrap: nowrap; justify-content: space-between; gap: 6px; }
#menu .row .btn.ghost { font-size: 15px; white-space: nowrap; padding: 8px 2px; text-decoration-thickness: 2px; }
a.btn { display: inline-block; color: var(--ink); text-decoration: underline; }

/* ---------- inside a web page (iframe): the page decides the height, the game fits its content ---------- */
.embed, .embed body { height: auto; }
.embed #app { min-height: 0; }
.embed #menu { min-height: 0; gap: 18px; padding-top: 22px; padding-bottom: 20px; }
.embed { --bs: min(calc(100vw - 2 * var(--gutter)), 560px); }
.compact .brand { display: none; }
.compact #menu { padding-top: 16px; }
.compact #menu .stack { margin-top: 0; }

/* recovery code + full screen */
.rec-code { font: 800 34px/1.1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; text-align: center; background: var(--chalk); border: 2.5px solid var(--ink); border-radius: 14px; padding: 14px 8px; margin: 4px 0 10px; user-select: all; }
#g-full[hidden] { display: none; }
.fs .topbar { opacity: .9; }

/* ---------- full screen (two players, one phone): fill the whole screen like a native app ---------- */
.fs { --gutter: 8px; --bs: min(calc(100vw - 16px), calc(100dvh - 232px), 760px); }
.fs, .fs body { height: 100%; overflow: hidden; }
.fs #app { height: 100dvh; min-height: 0; }
.fs #game { height: 100dvh; max-width: none; padding: max(8px, env(safe-area-inset-top)) 8px max(14px, env(safe-area-inset-bottom)); gap: 8px; justify-content: flex-start; }
.fs #p-top { margin-top: auto; transform: rotate(180deg); } /* the player across the table reads their own side */
.fs #p-bot { margin-bottom: auto; }
.fs .turn { width: 100%; text-align: center; }
.fs .actions { width: 100%; max-width: 560px; flex-wrap: nowrap; }
.fs .actions .btn { flex: 1; min-height: 48px; font-size: 17px; }
.fs .banner { width: 100%; }
@media (orientation: landscape) and (max-height: 520px) {
  .fs { --bs: calc(100dvh - 150px); }
  .fs .turn { display: none; }
}

/* ---------- reactions (online games) ---------- */
.player { position: relative; }
.bubble { position: absolute; right: 0; top: 50%; transform: translateY(-50%); background: var(--ink); color: var(--sun); font-weight: 800; font-size: 16px; padding: 7px 12px; border-radius: 16px; white-space: nowrap; box-shadow: 0 3px 0 rgba(0,0,0,.25); pointer-events: none; animation: bubble-in .28s cubic-bezier(.2,1.4,.5,1) both; z-index: 3; }
.bubble.me { background: var(--ivory); color: var(--ink); box-shadow: 0 0 0 2.5px var(--ink); }
.bubble b { font-size: 22px; margin-right: 6px; vertical-align: -2px; }
.bubble[hidden] { display: none; }
.bubble.out { animation: bubble-out .35s ease-in both; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(-50%) scale(.6); } to { opacity: 1; transform: translateY(-50%) scale(1); } }
@keyframes bubble-out { to { opacity: 0; transform: translateY(-80%) scale(.9); } }
.tray { width: var(--bs); display: flex; flex-direction: column; gap: 10px; }
.tray[hidden] { display: none; }
.tray-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.react-btn { appearance: none; border: 2.5px solid var(--ink); background: var(--chalk); color: var(--ink); border-radius: 14px; padding: 8px 2px 6px; font: inherit; font-weight: 700; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; min-height: 58px; }
.react-btn i { font-style: normal; font-size: 26px; line-height: 1.1; }
.react-btn:active { transform: scale(.95); }
.react-btn:disabled { opacity: .45; cursor: default; }
.tray-mute { font-size: 14px; }
@media (prefers-reduced-motion: reduce) { .bubble, .bubble.out { animation: none; } }

/* ---------- computer setup: everything, including Start, fits on one phone screen ---------- */
#ai-setup { gap: 18px; }
.seg { border: 0; padding: 0; margin: 0; }
.seg legend { font-weight: 800; font-size: 18px; letter-spacing: -0.02em; padding: 0; margin-bottom: 8px; }
.seg-row { display: grid; gap: 6px; }
.seg4 { grid-template-columns: repeat(4, 1fr); }
.seg3 { grid-template-columns: repeat(3, 1fr); }
.seg-row label { display: block; cursor: pointer; min-width: 0; }
.seg-row input { position: absolute; opacity: 0; pointer-events: none; }
.seg-row span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 58px; padding: 8px 4px; border: 2.5px solid var(--ink); border-radius: 14px; font-weight: 800; font-size: 16px; letter-spacing: -0.01em; text-align: center; }
.seg-row input:checked + span { background: var(--ink); color: var(--sun); }
.seg-row input:focus-visible + span { outline: 3px solid var(--indigo-lit); outline-offset: 3px; }
.seg-desc { margin: 8px 2px 0; min-height: 1.4em; font-weight: 600; font-size: 16px; opacity: .85; }
.start-bar { position: sticky; bottom: 0; margin-top: 4px; padding: 8px 0 max(10px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--sun) 70%, rgba(255, 201, 60, 0)); z-index: 2; }
.start-bar .btn { width: 100%; justify-content: center; text-align: center; }
@media (max-width: 340px) { .seg-row span { font-size: 14px; } }
