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

:root {
  --bg: #e5ebe7;
  --surface: #f5f8f6;
  --paper: #ffffff;
  --forest: #03390f;
  --forest-80: rgba(3, 57, 15, 0.8);
  --muted: rgba(3, 57, 15, 0.64);
  --line: rgba(3, 57, 15, 0.14);
  --lime: #cfff71;
  --lime-soft: #ecfbc9;
  --sage: #b9cdbf;
  --danger: #b3261e;

  --p0: #00baaf; --p0-soft: #ccf2ef;
  --p1: #3f46da; --p1-soft: #d9daf8;
  --p2: #ff7300; --p2-soft: #ffe3cc;
  --p3: #ff0084; --p3-soft: #ffcce6;

  --display: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
  --text: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--forest);
  font: 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 2rem; font-weight: 750; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 0.75rem; }
a { color: var(--forest); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--p1); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* ---------- Blinkies (placeholder art: neon green circles) ---------- */
.blinkie {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: inset 0 -3px 0 rgba(3, 57, 15, 0.12);
  position: relative;
  flex: none;
}
.blinkie::before, .blinkie::after {
  content: "";
  position: absolute;
  top: 38%;
  width: 14%;
  height: 18%;
  border-radius: 50%;
  background: var(--forest);
}
.blinkie::before { left: 30%; }
.blinkie::after { right: 30%; }
.blinkie-sm { width: 0.75rem; height: 0.75rem; }
.blinkie-sm::before, .blinkie-sm::after { display: none; }
.blinkie-lg { width: 4.5rem; height: 4.5rem; }
.blinkie-xl { width: 7rem; height: 7rem; }
@media (prefers-reduced-motion: no-preference) {
  .blinkie-lg::before, .blinkie-lg::after, .blinkie-xl::before, .blinkie-xl::after { animation: blink 5s infinite; }
}
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.1); } }

/* ---------- Buttons and inputs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1.1rem;
  border: 1.5px solid var(--forest);
  border-radius: 999px;
  background: transparent;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--forest); color: var(--paper); }
.btn-lime { background: var(--lime); border-color: var(--lime); color: var(--forest); }
.btn-quiet { border-color: transparent; }
.btn-quiet:hover:not(:disabled) { background: rgba(3, 57, 15, 0.06); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-sm { min-height: 36px; padding: 0 0.85rem; font-size: 0.875rem; }

input[type="search"], input[type="text"] {
  width: 100%;
  min-height: 46px;
  padding: 0 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper);
  color: var(--forest);
  font: inherit;
}
input:focus { outline: none; border-color: var(--forest); }

.switch { display: flex; align-items: center; gap: 0.75rem; cursor: pointer; }
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--sage); position: relative; margin: 0; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--paper); transition: transform 0.15s; }
.switch input:checked { background: var(--forest); }
.switch input:checked::after { transform: translateX(18px); background: var(--lime); }

.segmented { display: inline-flex; background: var(--surface); border-radius: 999px; padding: 4px; gap: 4px; }
.segmented button { border: 0; background: transparent; min-width: 52px; min-height: 40px; border-radius: 999px; font-weight: 650; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--forest); color: var(--paper); }

/* ---------- App shell ---------- */
.shell { max-width: 960px; margin: 0 auto; padding: 0 16px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 16px 0; }
.wordmark { display: inline-flex; align-items: center; gap: 0.5rem; font-family: var(--display); font-weight: 800; font-size: 1.6rem; letter-spacing: -0.03em; text-decoration: none; }
.wordmark .blinkie { width: 1.1rem; height: 1.1rem; }
.nav { display: flex; gap: 0.25rem; }
.nav a { padding: 0.45rem 0.8rem; border-radius: 999px; text-decoration: none; font-weight: 600; font-size: 0.95rem; color: var(--muted); }
.nav a[aria-current="page"] { background: var(--paper); color: var(--forest); }
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .nav { width: 100%; justify-content: space-between; }
  .nav a { padding: 0.4rem 0.6rem; }
}

.panel { background: var(--paper); border-radius: var(--r-lg); padding: 20px; }
.stack > * + * { margin-top: 1rem; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--forest); color: var(--paper); padding: 0.75rem 1.1rem; border-radius: var(--r-md);
  max-width: min(92vw, 420px); box-shadow: 0 8px 24px rgba(3, 57, 15, 0.25);
}
.toast.error { background: var(--danger); }

/* ---------- Lobby ---------- */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: end; padding: 12px 0 24px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); }
.hero p { margin: 0.4rem 0 0; color: var(--muted); }
.hero-blinkies { display: flex; align-items: flex-end; gap: 6px; }
.hero-blinkies .blinkie:nth-child(2) { width: 2.4rem; height: 2.4rem; }
.hero-blinkies .blinkie:nth-child(3) { width: 1.4rem; height: 1.4rem; }
@media (max-width: 560px) { .hero { grid-template-columns: 1fr; } .hero-blinkies { display: none; } }

.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.count { font-family: var(--text); font-weight: 600; color: var(--muted); font-size: 0.9rem; }

.game-list { list-style: none; margin: 0; padding: 0; background: var(--paper); border-radius: var(--r-lg); overflow: hidden; }
.game-row { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 14px 16px; border-top: 1px solid var(--line); }
.game-row:first-child { border-top: 0; }
.game-row.is-turn { background: linear-gradient(90deg, var(--lime-soft), var(--paper) 70%); }
.game-row .who { font-weight: 650; }
.game-row .what { font-size: 0.9rem; color: var(--muted); }
.game-row a.cover { text-decoration: none; }
.dots { display: flex; }
.dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 0.78rem; font-weight: 750; border: 2px solid var(--paper); margin-left: -6px; }
.dot:first-child { margin-left: 0; }
.dot.empty { background: var(--surface); color: var(--muted); border-style: dashed; border-color: var(--sage); }
.seat-0 { --c: var(--p0); --c-soft: var(--p0-soft); }
.seat-1 { --c: var(--p1); --c-soft: var(--p1-soft); }
.seat-2 { --c: var(--p2); --c-soft: var(--p2-soft); }
.seat-3 { --c: var(--p3); --c-soft: var(--p3-soft); }
.dot[class*="seat-"] { background: var(--c-soft); color: var(--c); }
.row-actions { display: flex; gap: 0.5rem; }

.empty { text-align: center; padding: 40px 16px; }
.empty .blinkie { margin-bottom: 12px; }
.empty p { color: var(--muted); }

/* ---------- New game ---------- */
.form-row { display: grid; gap: 0.5rem; }
.form-row + .form-row { margin-top: 1.5rem; }
.label { font-weight: 650; }
.hint { font-size: 0.875rem; color: var(--muted); }
.results { list-style: none; margin: 6px 0 0; padding: 0; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line); }
.results:empty { display: none; }
.results button { width: 100%; text-align: left; border: 0; background: var(--paper); padding: 0.65rem 0.9rem; cursor: pointer; display: flex; justify-content: space-between; gap: 1rem; }
.results button:hover, .results button:focus-visible { background: var(--lime-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip { display: inline-flex; align-items: center; gap: 0.4rem; background: var(--lime-soft); border-radius: 999px; padding: 0.3rem 0.4rem 0.3rem 0.85rem; font-weight: 600; font-size: 0.9rem; }
.chip button { border: 0; background: transparent; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; }
.chip button:hover { background: rgba(3, 57, 15, 0.1); }

/* ---------- Game ---------- */
.game {
  --board: min(calc(100vw - 16px), calc(100dvh - 300px), 640px);
  display: grid;
  gap: 12px;
  justify-content: center;
  padding: 8px 8px 16px;
}
.only-wide { display: none; }
@media (min-width: 820px) {
  .only-wide { display: block; }
  .only-narrow { display: none; }
  .game {
    --board: min(calc(100dvh - 32px), calc(100vw - 400px), 760px);
    grid-template-columns: var(--board) minmax(300px, 340px);
    grid-template-areas: "board side";
    align-items: start;
    padding: 16px;
  }
  .game .board-wrap { grid-area: board; }
  .game .side { grid-area: side; }
}
.game-top { display: flex; align-items: center; gap: 8px; }
.game-top .btn { padding: 0 0.6rem; }
.players { display: grid; grid-template-columns: repeat(var(--n, 2), 1fr); gap: 6px; flex: 1; }
.player {
  border-radius: var(--r-md);
  background: var(--c-soft);
  padding: 6px 10px;
  border: 2px solid transparent;
  min-width: 0;
}
.player.is-turn { border-color: var(--c); background: var(--paper); }
.player.is-out { opacity: 0.5; }
.player .name { font-weight: 650; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .score { font-family: var(--display); font-weight: 800; font-size: 1.35rem; line-height: 1.1; color: var(--c); }
.player .meta { font-size: 0.75rem; color: var(--muted); }

.board-wrap { width: var(--board); display: grid; gap: 12px; }
.board {
  width: var(--board);
  height: var(--board);
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: calc(var(--board) * 0.004);
  padding: calc(var(--board) * 0.012);
  background: var(--paper);
  border-radius: var(--r-lg);
  touch-action: manipulation;
  user-select: none;
}
.sq {
  position: relative;
  border-radius: calc(var(--board) * 0.008);
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: calc(var(--board) * 0.021);
  font-weight: 750;
  color: var(--muted);
  border: 0;
  padding: 0;
  cursor: pointer;
}
.sq[data-p="DL"] { background: var(--lime-soft); color: var(--forest); }
.sq[data-p="TL"] { background: var(--lime); color: var(--forest); }
.sq[data-p="DW"] { background: var(--sage); color: var(--forest); }
.sq[data-p="TW"] { background: var(--forest); color: var(--lime); }
.sq.center .blinkie { width: 70%; height: 70%; }
.sq.drop-target { outline: 3px solid var(--forest); outline-offset: -2px; }
.sq.selectable:hover { filter: brightness(0.96); }

.tile {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--board) * 0.008);
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 750;
  font-size: calc(var(--board) * 0.036);
  line-height: 1;
  color: var(--forest);
  background: var(--c-soft, var(--paper));
  box-shadow: inset 0 calc(var(--board) * -0.004) 0 var(--c, var(--sage));
}
.tile .v { position: absolute; top: 8%; right: 10%; font-family: var(--text); font-size: 0.38em; font-weight: 700; }
.tile.blank .l { color: var(--muted); }
.tile.recent { outline: 2px solid var(--c); outline-offset: -2px; }
.tile.pending { background: var(--lime); box-shadow: inset 0 0 0 2px var(--forest); touch-action: none; cursor: grab; }
.tile.pending.invalid { background: #ffd7d3; }

.rack-area { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.rack {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  max-width: 460px;
  width: 100%;
  margin: 0 auto;
  min-height: 52px;
  touch-action: none;
}
.rack .tile {
  aspect-ratio: 1;
  height: auto;
  font-size: clamp(1.25rem, 6vw, 1.75rem);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: inset 0 -4px 0 var(--c, var(--sage));
  border: 0;
  padding: 0;
  cursor: grab;
}
.rack .tile.selected { transform: translateY(-6px); box-shadow: inset 0 -4px 0 var(--c, var(--sage)), 0 0 0 3px var(--forest); }
.rack .tile.marked { background: var(--p3-soft); }
.rack .slot { aspect-ratio: 1; border-radius: 10px; border: 1.5px dashed var(--sage); }
.drag-ghost { position: fixed; z-index: 100; pointer-events: none; width: 48px; height: 48px; font-size: 1.6rem; border-radius: 10px; background: var(--lime); box-shadow: 0 10px 24px rgba(3, 57, 15, 0.3); display: grid; place-items: center; font-family: var(--display); font-weight: 750; transform: translate(-50%, -70%); }

.preview { min-height: 1.5rem; text-align: center; font-size: 0.95rem; font-weight: 600; }
.preview.bad { color: var(--danger); }
.actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.actions .play { min-width: 140px; }

.side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; min-width: 0; }
.bag { font-size: 0.9rem; color: var(--muted); text-align: center; }
.log { background: var(--paper); border-radius: var(--r-lg); padding: 12px 14px; max-height: 260px; overflow: auto; }
.log ol { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--line); font-size: 0.9rem; }
.log li:first-child { border-top: 0; }
.log .swatch { width: 10px; height: 10px; border-radius: 50%; background: var(--c); align-self: center; }
.log .pts { font-weight: 700; }
.banner { border-radius: var(--r-lg); padding: 16px; background: var(--forest); color: var(--paper); display: flex; align-items: center; gap: 14px; }
.banner h2 { color: var(--lime); }
.banner p { margin: 0.2rem 0 0; }

@media (max-width: 819px) {
  .game .side .log { max-height: 200px; }
}

/* ---------- Dialog ---------- */
dialog { border: 0; border-radius: var(--r-lg); padding: 20px; max-width: min(92vw, 420px); color: var(--forest); }
dialog::backdrop { background: rgba(3, 57, 15, 0.35); }
.letter-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 1rem 0; }
.letter-grid button { aspect-ratio: 1; border: 0; border-radius: 8px; background: var(--surface); font-family: var(--display); font-weight: 750; font-size: 1.2rem; cursor: pointer; }
.letter-grid button:hover { background: var(--lime); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

/* ---------- Waiting room ---------- */
.seats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.seat { border-radius: var(--r-md); padding: 14px; background: var(--c-soft, var(--surface)); display: flex; align-items: center; gap: 10px; min-height: 64px; }
.seat.invited { background: var(--surface); border: 1.5px dashed var(--sage); }
.seat.open { background: transparent; border: 1.5px dashed var(--sage); color: var(--muted); }

/* ---------- Leaderboard and profile ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.7rem 0.5rem; border-top: 1px solid var(--line); }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; border-top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { background: var(--lime-soft); }
.rank { font-family: var(--display); font-weight: 800; width: 3rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border-radius: var(--r-md); padding: 12px; }
.stat b { display: block; font-family: var(--display); font-size: 1.6rem; font-weight: 800; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.badge { border-radius: var(--r-md); padding: 14px; background: var(--surface); display: grid; gap: 4px; }
.badge .medal { width: 40px; height: 40px; border-radius: 50%; border: 2px dashed var(--sage); margin-bottom: 4px; }
.blinkie-badge { width: 40px; height: 40px; margin-bottom: 4px; }
.badge.earned { background: var(--paper); box-shadow: inset 0 0 0 2px var(--lime); }
.badge:not(.earned) { color: var(--muted); }

/* ---------- Notice pages ---------- */
body.plain { display: grid; min-height: 100vh; place-items: center; }
.notice { text-align: center; max-width: 420px; padding: 24px 16px; }
.notice h1 { font-size: 1.6rem; margin: 16px 0 8px; }
.notice p { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
