/* Swipe Fight — mobile-first, no framework, light theme.
   Layout goal: one column on phones (status → board → controls → players),
   board + everything else in a side column on wide screens. */

:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #23211d;
  --muted: #6f6a61;
  --line: #e6e1d5;
  --accent: #1f83be;
  --chip-bg: #f0ece2;
  --danger: #b3261e;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1,
h2 {
  line-height: 1.2;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- screens & cards ---------- */

.screen {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 2.75rem);
  letter-spacing: -0.02em;
}

.hero .muted {
  margin: 4px 0 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 4%);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.lead {
  margin: 0;
  font-size: 15px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.actions .btn {
  flex: 1 1 auto;
}

.error {
  margin: 0;
  min-height: 1.2em;
  color: var(--danger);
  font-size: 14px;
}

/* ---------- forms ---------- */

.form {
  display: grid;
  gap: 14px;
}

.form-title {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.field-label {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

input[type='text'],
input[type='number'] {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-size: 16px; /* >=16px stops iOS zooming on focus */
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.big {
  padding: 13px 16px;
}

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

/* ---------- app shell ---------- */

.app {
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px 14px 40px;
  display: grid;
  gap: 12px;
}

.apphead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.apptitle {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 12px;
}

/* ---------- player list ---------- */

.players-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.players-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
}

.countdown.urgent {
  color: var(--danger);
}

.playerlist {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.player {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 9px;
  font-size: 15px;
}

.player[data-me='true'] {
  background: var(--chip-bg);
  font-weight: 600;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 25%);
}

.pname {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prank,
.pfields {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 600;
}

.pcheck {
  color: #177245;
  font-weight: 700;
}

.phost {
  margin-left: 4px;
  font-size: 13px;
}

.pvote {
  min-width: 1em;
  color: #177245;
  font-weight: 700;
  text-align: center;
}

/* ---------- replay / rematch ---------- */

.replay-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.replay .actions {
  margin-top: 10px;
}

.replay .hint {
  margin: 8px 0 0;
}

/* ---------- playing screen ---------- */

.play {
  grid-template-areas:
    'head'
    'status'
    'board'
    'controls'
    'feedback'
    'players';
}

.play > .apphead {
  grid-area: head;
}

.play > .statusline {
  grid-area: status;
}

.play > [data-list-host] {
  grid-area: players;
}

.play > .board-wrap {
  grid-area: board;
}

.play > .controls {
  grid-area: controls;
}

.play > .feedback {
  grid-area: feedback;
}

.statusline {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-size: 14px;
}

.statusline[data-status='your-turn'] {
  border-left-color: var(--accent);
}

.statusline[data-status='drawing'] {
  border-left-color: #268f17;
}

.statusline[data-status='waiting'] {
  border-left-color: #977819;
}

.statusline[data-status='revealing'] {
  border-left-color: #7969e7;
}

.board-wrap {
  padding: 10px;
}

canvas.board {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none; /* drag draws a line instead of scrolling */
  border-radius: 8px;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.feedback {
  margin: 0;
  min-height: 1.2em;
  color: var(--danger);
  font-size: 14px;
}

.lobby-note .lead {
  font-size: 16px;
  font-weight: 600;
}

.result h2 {
  margin: 0 0 6px;
}

/* ---------- finished screen: static final board ---------- */

/* Same footprint as the playing board, but read-only: no crosshair, no drag,
   no tap highlight — it is a picture, not an input. */
.finished .board-wrap {
  width: min(560px, 100%);
  justify-self: center;
  padding: 10px;
}

.finished canvas.board {
  cursor: default;
  touch-action: auto;
}

/* ---------- desktop: board left, side column right ---------- */

@media (min-width: 880px) {
  .play {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    grid-template-areas:
      'head head'
      'board status'
      'board players'
      'board controls'
      'board feedback';
    align-items: start;
  }

  .play > .board-wrap {
    width: min(560px, 100%);
    justify-self: center;
  }

  .screen {
    padding-top: 44px;
  }
}

/* ---------- utilities ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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