/* Trilha: trail-marker yellow on lichen paper. Everything you can press has a lip and sinks when pressed. */
:root {
  --paper: #eef2ec;
  --ink: #17261e;
  --muted: #5b6b61;
  --tile: #ffffff;
  --lip: #c3cec0;
  --pressed: #e3e9e1;
  --blaze: #f5c518;
  --danger: #b93a26;
  --focus: #2f6db5;
  --font: 'Bricolage Grotesque', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body[data-mode="solo"] .versus-only,
body[data-mode="versus"] .solo-only { display: none !important; }

html { -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.app { width: min(460px, 100% - 32px); margin: 0 auto; padding: 20px 0 32px; }
.center { text-align: center; }
.muted { color: var(--muted); margin: 0; }
.stack { display: grid; gap: 16px; }
.stack-tight { display: grid; gap: 10px; }

/* Header */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.topbar-actions { display: flex; gap: 10px; }
.logo {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 800;
  font-stretch: 80%;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--tile);
  box-shadow: 0 4px 0 var(--ink);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.07s, box-shadow 0.07s;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn-blaze { background: var(--blaze); }
.btn-big { width: 100%; min-height: 56px; font-size: 1.15rem; }
.btn-icon { width: 44px; padding: 0; font-size: 1.3rem; }

.error { margin: 0 0 12px; color: var(--danger); font-weight: 700; }
.error:empty { display: none; }

/* Board */
.game { display: grid; gap: 14px; }
.info { margin: 0; color: var(--muted); font-weight: 600; }
.board {
  --max-height: 56vh;
  display: block;
  width: min(100%, var(--max-height) * var(--cols, 1) / var(--rows, 1));
  aspect-ratio: var(--cols, 1) / var(--rows, 1);
  margin: 0 auto;
  overflow: visible;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.board.mini { --max-height: 190px; }
.board.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.lip { fill: var(--lip); }
.tile { fill: var(--tile); }
.tile.pressed { fill: var(--pressed); }
polyline { fill: none; stroke-width: 0.6; stroke-linecap: round; stroke-linejoin: round; }
polyline.trail { stroke: var(--ink); }
polyline.fresh { stroke-dasharray: 1; animation: draw 0.45s ease-out both; }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
polyline.arrow { stroke: #fff; stroke-width: 0.045; stroke-opacity: 0.9; }
.hint { fill: none; stroke: var(--ink); stroke-width: 0.05; stroke-dasharray: 0.1 0.07; }
.board text {
  fill: var(--ink);
  font-family: var(--font);
  font-size: 0.5px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
.board text.on { fill: #fff; }

/* What you're tracing, as little tiles under the board */
.trail { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px; min-height: 38px; }
.trail .letter {
  display: grid;
  place-items: center;
  width: 30px;
  height: 36px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}
.trail .letter.new { animation: pop 0.14s ease-out; }
@keyframes pop { from { transform: scale(0.5); } }
.trail-hint { color: var(--muted); }

/* Hidden words stacked, shortest on top: one row of tiles per word */
.slots { display: grid; justify-content: start; gap: 5px; }
.slot { display: flex; gap: 3px; }
.slot span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 26px;
  border-radius: 6px;
  background: var(--tile);
  box-shadow: inset 0 -3px 0 var(--lip);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}
.slot.found span { box-shadow: none; }

.message { min-height: 1.6em; margin: 0; text-align: center; font-size: 1.3rem; font-weight: 800; }
.actions { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: 10px; }
.level { margin: 0; color: var(--muted); font-size: 0.85rem; text-align: center; }

/* Versus: panels */
.panel {
  display: grid;
  gap: 18px;
  margin-bottom: 16px;
  padding: 20px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--tile);
}
.panel h2 { margin: 0; font-size: 1.3rem; font-weight: 800; font-stretch: 85%; }

.code-tiles { display: flex; justify-content: center; gap: 10px; }
.code-tiles span {
  display: grid;
  place-items: center;
  width: 64px;
  height: 78px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--blaze);
  box-shadow: 0 5px 0 var(--ink);
  font-size: 2.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.roster { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.roster li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 5px;
  border-radius: 999px;
  background: var(--paper);
  font-weight: 600;
}
.roster li.offline { opacity: 0.45; }
.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color);
  color: #fff;
  font-weight: 800;
}
.tag { color: var(--muted); font-size: 0.85rem; font-weight: 500; }

/* Versus: the race. One lane per player, one segment per board. */
.race {
  display: grid;
  gap: 12px;
  margin-bottom: 4px;
  padding: 14px 16px 16px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--tile);
}
.clock { font-size: 2rem; font-weight: 800; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.lanes { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.lane {
  display: grid;
  grid-template-columns: minmax(0, 6.5em) 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  font-weight: 600;
}
.lane.offline { opacity: 0.45; }
.lane-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lane-track {
  position: relative;
  height: 12px;
  border-radius: 6px;
  background: repeating-linear-gradient(
    90deg,
    var(--paper) 0 calc(100% / var(--boards) - 3px),
    transparent calc(100% / var(--boards) - 3px) calc(100% / var(--boards))
  );
}
.lane-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--progress, 0) * 100%);
  border-radius: 6px;
  background: var(--color);
  transition: width 0.4s ease-out;
}
.lane-fill::after {
  content: '';
  position: absolute;
  top: 50%;
  right: -8px;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 3px solid var(--tile);
  border-radius: 50%;
  background: var(--color);
}
.lane-count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Versus: results */
.results-time { margin: -8px 0 0; font-size: 3rem; font-weight: 800; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.result-boards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.result-card { display: grid; align-content: start; gap: 10px; padding: 12px; border-radius: 14px; background: var(--paper); }
.result-card.winner { background: var(--blaze); }
.result-card .board { --max-height: 220px; }
.result-head { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 700; }
.result-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-detail { margin: 0; color: var(--muted); font-size: 0.85rem; line-height: 1.3; }
.result-card.winner .result-detail { color: var(--ink); }

/* Bottom sheet to create or join a room */
.sheet {
  width: min(480px, 100%);
  max-width: 100%;
  margin: auto auto 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--tile);
  color: var(--ink);
}
.sheet[open] { display: grid; gap: 16px; animation: rise 0.22s ease-out; }
.sheet::backdrop { background: rgb(23 38 30 / 0.45); }
@keyframes rise { from { transform: translateY(48px); opacity: 0; } }
@media (min-width: 600px) {
  .sheet { margin: auto; border: 2px solid var(--ink); border-radius: 22px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 1.4rem; font-weight: 800; font-stretch: 85%; }
.sheet-head form { margin: 0; }

.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--paper); }
.tabs button {
  padding: 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.tabs button[aria-selected="true"],
.tabs button[aria-checked="true"] { background: var(--tile); color: var(--ink); box-shadow: 0 2px 0 var(--lip); }

.field, .field-label { display: grid; gap: 6px; font-weight: 700; }
.field input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--tile);
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 600;
}
.field input.code-input { font-size: 2rem; font-weight: 800; letter-spacing: 0.5em; text-align: center; font-variant-numeric: tabular-nums; }

.stepper { display: flex; align-items: center; justify-content: space-between; }
.stepper-control { display: flex; align-items: center; gap: 14px; }
.stepper output { min-width: 1.4em; font-size: 2rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }

/* Tutorial: one step at a time, like pages of a manual */
.tutorial[open] { gap: 18px; }
.tutorial-step { display: grid; gap: 12px; justify-items: center; text-align: center; }
.tutorial-step h3 { margin: 4px 0 0; font-size: 1.25rem; font-weight: 800; font-stretch: 85%; }
.tutorial-step p { max-width: 34ch; margin: 0; }
.tutorial-step .slots { justify-content: center; }
.tutorial-nav { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.dots { display: flex; gap: 6px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--lip); }
.dots span.on { background: var(--ink); }

/* Credits */
.credits { display: grid; gap: 4px; margin-top: 36px; color: var(--muted); font-size: 0.8rem; text-align: center; }
.credits > p { margin: 0; font-size: 0.9rem; }
.credits summary { cursor: pointer; }
.credits a { color: inherit; }

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