/* Stationairy games - calm, warm, no external fonts. */

:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f1ebe0;
  --ink: #2d2a26;
  --muted: #6f675d;
  --line: #e4dacb;
  --accent: #3d7a6e;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe6;
  --warn: #b4553a;
  --warn-soft: #f6e1d9;
  --sq-light: #f1ead9;
  --sq-dark: #a9ba90;
  --coord-on-light: #7d8f66;
  --coord-on-dark: #f6f1e4;
  --last: rgba(236, 196, 84, 0.5);
  --sel: rgba(61, 122, 110, 0.55);
  --hint: rgba(45, 42, 38, 0.24);
  --online: #4c9a6a;
  --away: #d4a33c;
  --offline: #b9b0a3;
  --shadow: 0 1px 2px rgba(60, 45, 20, 0.06), 0 6px 24px rgba(60, 45, 20, 0.07);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1c1a;
    --surface: #282622;
    --surface-2: #312e29;
    --ink: #eee8dd;
    --muted: #b1a797;
    --line: #3b3731;
    --accent: #72b6a6;
    --accent-ink: #13221f;
    --accent-soft: #24403a;
    --warn: #e08a6f;
    --warn-soft: #43281f;
    --sq-light: #dcd3bf;
    --sq-dark: #879a72;
    --coord-on-light: #6b7d57;
    --coord-on-dark: #eee8dd;
    --hint: rgba(20, 20, 20, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
[hidden] { display: none !important; }
.small { font-size: 0.875rem; }
.muted { color: var(--muted); }

/* ---- header / footer ---- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 650;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.brand img { display: block; border-radius: 8px; }
.badge {
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.site-footer {
  max-width: 1120px;
  margin: 32px auto 0;
  padding: 16px 16px 32px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---- buttons, inputs ---- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--warn); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, .sq:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

input[type="text"], textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { resize: none; }

/* ---- home ---- */

.home { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.hero { padding: 28px 0 8px; }
.hero h1 {
  font-size: clamp(1.7rem, 4.5vw, 2.5rem);
  line-height: 1.2;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
  font-weight: 700;
}
.lede { font-size: 1.15rem; color: var(--muted); margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin: 24px 0;
}
.card h2 { margin: 0 0 16px; font-size: 1.25rem; }

.field { display: block; margin-bottom: 18px; }
.field > span, fieldset > legend { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
fieldset { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg legend { width: 100%; }
.seg label { position: relative; }
.seg input, .choice input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  background: var(--surface);
}
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.seg input:focus-visible + span, .choice input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--muted); display: inline-block; }
.swatch.white { background: #fff; }
.swatch.black { background: #2d2a26; }
.swatch.random { background: linear-gradient(90deg, #fff 50%, #2d2a26 50%); }

.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice legend { grid-column: 1 / -1; }
.choice label { position: relative; display: block; }
.choice span {
  display: block;
  height: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  background: var(--surface);
}
.choice strong { display: block; }
.choice small { display: block; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.choice input:checked + span { border-color: var(--accent); background: var(--accent-soft); }

.form-error, .error-text { color: var(--warn); margin: 10px 0 0; }

.copy-row { display: flex; gap: 8px; align-items: stretch; margin: 8px 0 12px; }
.copy-row input, .copy-row textarea { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; }
.copy-row .btn { flex: none; }

.steps { padding-left: 1.2em; margin: 0 0 10px; }
.steps li { margin-bottom: 6px; }

@media (max-width: 560px) {
  .choice { grid-template-columns: 1fr; }
  .copy-row { flex-direction: column; }
  .card { padding: 18px; }
}

/* ---- game layout ---- */

.game {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}
.board-col { min-width: 0; max-width: min(640px, calc(100vh - 210px)); width: 100%; justify-self: center; }
.side-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

@media (max-width: 880px) {
  .game { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .board-col { max-width: 560px; }
  .side-col { max-width: 560px; width: 100%; justify-self: center; }
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  min-height: 44px;
}
/* On a narrow phone the meta text gives way first (ellipsis); the name keeps
   at least ~4.5em so it never collapses to one letter. */
.player-bar .pname { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; min-width: 4.5em; max-width: 45%; }
.player-bar .meta { color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.player-bar .kind-tag, .player-bar .turn-tag, .player-bar .icon-btn, .player-bar .dot { flex-shrink: 0; }
@media (max-width: 480px) { .player-bar { gap: 8px; } }
.player-bar .spacer { flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--offline); flex: none; }
.dot.online { background: var(--online); box-shadow: 0 0 0 3px color-mix(in srgb, var(--online) 25%, transparent); }
.dot.away { background: var(--away); }
.kind-tag {
  font-size: 0.75rem;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.turn-tag { font-size: 0.8rem; font-weight: 600; color: var(--accent); white-space: nowrap; }
.icon-btn {
  white-space: nowrap;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 6px;
  border-radius: 6px;
  min-height: 32px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.name-form { display: flex; gap: 6px; flex: 1; min-width: 0; }
.name-form input { min-height: 36px; padding: 4px 10px; }

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

.board-wrap { position: relative; width: 100%; aspect-ratio: 1 / 1; }
.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; cursor: default; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before, .sq.sel::before { content: ""; position: absolute; inset: 0; pointer-events: none; }
.sq.last::before { background: var(--last); }
.sq.sel::before { background: var(--sel); }
.sq.check { background-image: radial-gradient(circle, rgba(214, 69, 65, 0.95) 0%, rgba(214, 69, 65, 0.55) 40%, rgba(214, 69, 65, 0) 72%); }
.sq.movable { cursor: grab; }
.sq.target { cursor: pointer; }
.sq.hint::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: var(--hint);
  pointer-events: none;
}
.sq.hint.capture::after {
  width: 92%;
  height: 92%;
  background: transparent;
  border: 6px solid var(--hint);
  box-sizing: border-box;
}
.sq.drop-over { box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.75); }
.pc { width: 92%; height: 92%; pointer-events: none; position: relative; z-index: 1; }
.pc.dragging { opacity: 0.25; }
.ghost { position: fixed; pointer-events: none; z-index: 50; transform: translate(-50%, -50%); filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.25)); }
.coord { position: absolute; font-size: clamp(9px, 1.6vw, 12px); font-weight: 650; pointer-events: none; z-index: 2; line-height: 1; }
.coord.file { right: 4px; bottom: 3px; }
.coord.rank { left: 4px; top: 4px; }
.sq.light .coord { color: var(--coord-on-light); }
.sq.dark .coord { color: var(--coord-on-dark); }

.promo {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(30, 28, 24, 0.35);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.promo-box {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
  text-align: center;
}
.promo-box p { margin: 0 0 10px; font-weight: 600; }
.promo-choices { display: flex; gap: 8px; }
.promo-choices button {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--sq-light);
  cursor: pointer;
  padding: 4px;
}
.promo-choices button:hover { border-color: var(--accent); }
.promo-choices img { width: 100%; height: 100%; }

/* ---- status, controls ---- */

.status {
  margin: 12px 0 8px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 550;
}
.status.yours { border-color: var(--accent); background: var(--accent-soft); }
.status.over { background: var(--surface-2); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  margin: 8px 0;
  background: var(--accent-soft);
}
.notice.warn { background: var(--warn-soft); }
.notice .grow { flex: 1 1 200px; }

/* ---- side panels ---- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.panel h2 { font-size: 0.95rem; margin: 0 0 10px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }
.moves {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 2.6em 1fr 1fr;
  column-gap: 6px;
  font-variant-numeric: tabular-nums;
}
.moves li { display: contents; }
.moves .no { color: var(--muted); }
.moves .mv { padding: 2px 6px; border-radius: 6px; }
.moves .mv.latest { background: var(--last); }
.moves-empty { color: var(--muted); margin: 0; }

.chat-log {
  height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  margin-bottom: 10px;
}
.msg { line-height: 1.4; overflow-wrap: anywhere; }
.msg .who { font-weight: 650; margin-right: 6px; }
.msg .who::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; border: 1px solid var(--muted); vertical-align: 1px; }
.msg.white .who::before { background: #fff; }
.msg.black .who::before { background: #2d2a26; }
.msg .text { white-space: pre-wrap; }
.msg.mine .who { color: var(--accent); }
.chat-empty { color: var(--muted); margin: auto 0; text-align: center; font-size: 0.9rem; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: calc(100vw - 32px);
  font-size: 0.95rem;
}

.center-msg { max-width: 560px; margin: 60px auto; padding: 0 16px; text-align: center; }
