/* Dots & Boxes styles. The theme and the shared controls are in ../shared/base.css. */

/* ---------- Setup ---------- */
.names { display: flex; flex-direction: column; gap: 8px; }
.swatch { width: 22px; height: 22px; border-radius: 50%; flex: none; transition: background-color 0.3s; }

.check { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 16px; font-weight: 600; margin-top: 4px; }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }

.preview { display: grid; place-items: center; padding: 4px 0; }
.board.mini { width: 100%; max-width: 220px; height: 150px; }

/* ---------- The board (SVG, in units of one side) ---------- */
.board { display: block; width: 100%; height: 100%; overflow: visible; }
.board .card { fill: var(--bg); stroke: none; filter: drop-shadow(0 0.12px 0 rgba(0, 0, 0, 0.18)); }
.board .ghosts line { stroke: rgba(255, 255, 255, 0.09); stroke-width: 0.07; stroke-linecap: round; }
.board .lines line {
  stroke: #e9ebff;
  stroke-width: 0.11;
  stroke-linecap: round;
  stroke-dasharray: 1 1;
  stroke-dashoffset: 0;
  transition: stroke 0.4s;
}
.board .lines line.draw { animation: draw ease-out both; }
.board .preview-line line { stroke-width: 0.17; stroke-linecap: round; opacity: 0.95; }
.board .preview-line line.hover { stroke-width: 0.11; opacity: 0.45; }
.board .preview-line line.over { stroke: #fff; stroke-width: 0.2; opacity: 0.35; }
.board .dots circle { fill: #f3f4ff; transition: r 0.15s; }
.board .dots circle.picked { r: 0.2px; fill: #fff; }
.board .cell { stroke-width: 0.12; stroke-linejoin: round; transform-box: fill-box; transform-origin: center; }
.board .cell.pop { animation: pop 0.38s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
.board.mini .dots circle { r: 0.12px; }

@keyframes draw {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}
@keyframes pop {
  from { transform: scale(0); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- Play: the whole screen is the colour of the player whose turn it is ---------- */
.play {
  --turn: var(--accent);
  --ink: #14162b;
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "bar" "scores" "board" "hint";
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
    calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  background: var(--turn);
  color: var(--ink);
  transition: background-color 0.5s ease;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}

.topbar { grid-area: bar; display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  border: 0;
  background: rgba(20, 22, 43, 0.14);
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  display: grid;
  place-items: center;
  transition: opacity 0.2s, transform 0.1s;
}
#undo { font-size: 26px; }
.icon-btn:active:not(:disabled) { transform: scale(0.92); }
.icon-btn:disabled { opacity: 0.25; cursor: default; }

.turn { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; line-height: 1.05; }
.turn-name {
  font-size: clamp(28px, 8vmin, 48px);
  font-weight: 900;
  letter-spacing: -1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.turn-sub { font-weight: 800; font-size: clamp(14px, 3.6vmin, 18px); opacity: 0.7; margin-top: 2px; }
.turn.bump { animation: bump 0.4s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes bump {
  from { transform: scale(0.82); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

.scores { grid-area: scores; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.score {
  --c: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 48%;
  background: var(--ink);
  color: #f3f4ff;
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
  font-weight: 700;
  font-size: 15px;
  transition: transform 0.3s, box-shadow 0.3s;
}
.score span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score b {
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--c);
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.score b.up { animation: bump 0.45s cubic-bezier(0.3, 1.6, 0.5, 1); }
.score.on { transform: scale(1.04); box-shadow: 0 0 0 3px #fff; }

/* The SVG fills the area and keeps its shape inside it (viewBox "meet"), so the whole
   area, also round the board, takes presses. */
.board-wrap { grid-area: board; position: relative; min-height: 0; min-width: 0; }
.board-wrap .board { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.play.busy .board { cursor: default; }

.hint { grid-area: hint; margin: 0; text-align: center; font-weight: 700; font-size: 14px; opacity: 0.65; min-height: 1.2em; }

/* Sideways phone, tablet, desktop: names and scores on the left, the board on the right. */
@media (orientation: landscape) {
  .play {
    grid-template-columns: minmax(200px, 300px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "bar board" "scores board" "hint board";
    column-gap: 16px;
  }
  .scores { flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; align-items: stretch; }
  .score { max-width: none; }
  .score.on { transform: translateX(6px); }
  .hint { text-align: left; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .play { gap: 6px; }
  .score { padding: 3px 12px 3px 3px; font-size: 14px; }
  .score b { min-width: 28px; height: 28px; font-size: 15px; }
  .turn-name { font-size: 26px; }
}

/* ---------- The result, over the finished board ---------- */
.result {
  --win: var(--accent);
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--win) 88%, transparent);
  overflow-y: auto;
  touch-action: pan-y;
  animation: fade 0.35s ease-out both;
}
.result-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg);
  color: var(--text);
  border-radius: 28px;
  padding: 24px 20px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.18);
  animation: rise 0.45s cubic-bezier(0.3, 1.4, 0.5, 1) both;
}
.result-icon { font-size: 64px; line-height: 1; animation: trophy 0.6s 0.2s cubic-bezier(0.3, 1.8, 0.5, 1) both; }
.result-title { font-size: clamp(28px, 8vw, 38px); font-weight: 900; letter-spacing: -1px; text-align: center; margin: 4px 0 0; overflow-wrap: anywhere; }
.result-sub { margin: 0; color: var(--muted); font-weight: 600; }
.result-list { list-style: none; padding: 0; margin: 8px 0 4px; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.result-row { display: grid; grid-template-columns: minmax(0, 7.5em) 1fr auto; align-items: center; gap: 10px; font-weight: 700; }
.result-name { color: var(--c); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-row b { font-size: 20px; font-variant-numeric: tabular-nums; min-width: 1.6em; text-align: right; }
.result-row.won b::before { content: "★ "; color: var(--c); font-size: 15px; }
.bar { height: 14px; border-radius: 999px; background: var(--panel); overflow: hidden; }
.bar-fill { display: block; height: 100%; width: var(--w); border-radius: 999px; background: var(--c); transform-origin: left; animation: grow 0.6s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
.result-actions { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.result-actions .link { align-self: center; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px) scale(0.92); opacity: 0; } }
@keyframes trophy { from { transform: scale(0) rotate(-25deg); } }
@keyframes grow { from { transform: scaleX(0); } }

/* The ✕ menu */
.stop-sheet .btn { width: 100%; }
.stop-sheet .stack { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

@media (prefers-reduced-motion: reduce) {
  .play, .board .lines line, .swatch { transition: none; }
  .board .lines line.draw, .board .cell.pop, .turn.bump, .score b.up,
  .result, .result-card, .result-icon, .bar-fill { animation: none; }
}
