/* Dots and Boxes — stylesheet (Playnesta original, MIT).
 *
 * The board is one square SVG that scales with the viewport; everything else is
 * a compact top bar, two rows of chips and a status line, so the whole shell
 * fits a 348x261 phone stage without scrolling. Colours follow the Playnesta
 * dark table: slate lines, blue for the player, amber for the computer.
 */

:root {
  --bg: #0f1522;
  --panel: #151d2d;
  --panel-2: #1b2436;
  --line: #2b3750;
  --line-lit: #4b5d80;
  --ink: #e8edf7;
  --ink-dim: #93a2bd;
  --you: #4f8cff;
  --cpu: #f5a524;
  --good: #35d07f;
  --bad: #ef5f6b;
  --radius: 10px;
  --pad: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100dvh;
  padding: var(--pad);
}

/* --- top bar --------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
}

.title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title small {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-dim);
  margin-left: 6px;
}

.spacer {
  flex: 1;
}

.score {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-dim);
  white-space: nowrap;
}

.score b {
  color: var(--ink);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.score .side {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.score i {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}

.score .you i {
  background: var(--you);
}

.score .cpu i {
  background: var(--cpu);
}

.score .vs {
  opacity: 0.5;
}

.score.thinking .cpu b {
  color: var(--cpu);
}

/* --- board ----------------------------------------------------------------- */

#board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

#board {
  display: block;
  width: 320px;
  height: 320px;
  max-width: 100%;
  max-height: 100%;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: crosshair;
}

.edge {
  stroke: var(--line);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke 120ms ease;
}

.edge.preview {
  stroke: var(--line-lit);
}

.edge.you {
  stroke: var(--you);
}

.edge.cpu {
  stroke: var(--cpu);
}

.edge.fresh {
  animation: pop 260ms ease-out;
}

@keyframes pop {
  0% {
    stroke-width: 12;
    opacity: 0.4;
  }
  55% {
    stroke-width: 18;
  }
  100% {
    stroke-width: 12;
    opacity: 1;
  }
}

.hit {
  stroke: transparent;
  stroke-width: 58;
  stroke-linecap: round;
  fill: none;
  pointer-events: stroke;
  cursor: pointer;
}

.dot {
  fill: #6b7c9e;
  pointer-events: none;
}

.box {
  fill: transparent;
  transition: fill 160ms ease;
  pointer-events: none;
}

.box.you {
  fill: rgba(79, 140, 255, 0.2);
}

.box.cpu {
  fill: rgba(245, 165, 36, 0.18);
}

.box.fresh {
  animation: fill-in 320ms ease-out;
}

@keyframes fill-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

.box-pip {
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
}

.box-pip.you {
  fill: var(--you);
  opacity: 0.9;
}

.box-pip.cpu {
  fill: var(--cpu);
  opacity: 0.9;
}

.hint-mark {
  stroke: var(--good);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 2 26;
  opacity: 0.9;
  pointer-events: none;
  animation: hint-pulse 900ms ease-in-out infinite;
}

@keyframes hint-pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

/* --- overlay --------------------------------------------------------------- */

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(9, 13, 21, 0.72);
  backdrop-filter: blur(2px);
  z-index: 4;
}

#overlay.hidden {
  display: none;
}

#overlay .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  max-width: 92%;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
}

.card-title.win {
  color: var(--good);
}

.card-title.lose {
  color: var(--bad);
}

.card-score {
  font-size: 26px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 2px;
}

.card-line {
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 10px;
  line-height: 1.35;
}

/* --- controls -------------------------------------------------------------- */

#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.group {
  display: inline-flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
}

.group.actions {
  background: transparent;
  border: 0;
  padding: 0;
  gap: 5px;
}

.chip,
.btn {
  font: inherit;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 5px 9px;
  min-height: 24px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.chip {
  font-size: 12px;
  min-width: 40px;
}

.btn {
  font-size: 12px;
  background: var(--panel);
  border-color: var(--line);
  min-height: 26px;
}

.chip:hover,
.btn:hover {
  color: var(--ink);
  background: var(--panel-2);
}

.chip[aria-pressed="true"] {
  color: #0c1220;
  background: var(--ink);
  font-weight: 650;
}

.btn.primary {
  background: var(--you);
  border-color: var(--you);
  color: #08111f;
  font-weight: 700;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.chip:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--you);
  outline-offset: 1px;
}

/* --- status ---------------------------------------------------------------- */

#statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--ink-dim);
  min-height: 15px;
}

#status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#record {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* --- modal + toast --------------------------------------------------------- */

#modal-root .modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 15, 0.7);
  display: grid;
  place-items: center;
  padding: 12px;
  z-index: 10;
}

#modal-root .sheet {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  max-width: 430px;
  width: 100%;
  max-height: 86dvh;
  overflow: auto;
  font-size: 13px;
  line-height: 1.5;
}

#modal-root h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

#modal-root ul {
  margin: 8px 0 12px;
  padding-left: 18px;
}

#modal-root li {
  margin-bottom: 5px;
}

#modal-root .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%) translateY(12px);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 12;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hidden {
  display: none !important;
}

/* --- small screens --------------------------------------------------------- */

@media (max-width: 520px) {
  .title small {
    display: none;
  }

  .chip,
  .btn {
    padding: 4px 7px;
    min-height: 26px;
    font-size: 11.5px;
  }

  #controls {
    gap: 5px;
  }

  .group {
    padding: 2px;
  }
}

@media (max-height: 340px) {
  #app {
    gap: 3px;
    padding: 5px;
  }

  .topbar {
    min-height: 20px;
  }

  .title {
    font-size: 12.5px;
  }

  .score {
    font-size: 11px;
    gap: 4px;
  }

  .score b {
    font-size: 13px;
  }

  .chip,
  .btn {
    min-height: 22px;
    padding: 2px 6px;
    font-size: 10.5px;
  }

  .chip {
    min-width: 34px;
  }

  .group {
    padding: 1px;
    gap: 3px;
  }

  .group.actions {
    gap: 4px;
  }

  #statusbar {
    font-size: 10px;
    min-height: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .edge.fresh,
  .box.fresh,
  .hint-mark {
    animation: none;
  }
}
