/* TALOS — browser and Android edition.
   The chess boards use square-bound vector art; the land boards keep a stable
   camera and render at device pixel ratio in js/anarchess.js. */

:root {
  --window: #0e1015;
  --surface: #161922;
  --raised: #1d212c;
  --border: #2a3040;
  --text: #e8ebf2;
  --dim: #98a1b5;
  --accent: #f0b429;
  --accent2: #4cc2ff;
  --good: #4ade80;
  --bad: #f87171;
  --light: #f2ede1;
  --dark: #8d6a48;
  --board-light: #eee3cc;
  --board-dark: #8d6a48;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-width: 0;
  background: var(--window);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: hidden;
}

button, select, input { font: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--accent2);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.mark { width: 34px; height: 34px; flex: none; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { letter-spacing: 3px; font-size: 16px; }
.brand-text span { color: var(--dim); font-size: 11.5px; }

.tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 2px;
}
.tab {
  flex: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--raised); }
.tab.active {
  color: var(--window);
  background: var(--accent);
  font-weight: 700;
  border-color: var(--accent);
}

/* ------------------------------------------------------------------ main */
main { flex: 1; width: 100%; padding: 16px; }

.view { display: none; gap: 18px; align-items: flex-start; }
.view.active { display: flex; flex-wrap: wrap; justify-content: center; }

/* ----------------------------------------------------------------- board */
/* The wrapper's outer footprint includes its coordinate gutter. The board
   itself remains an exact square, and its vectors fit that measured square. */
.boardwrap {
  --board-square: 48px;
  --coordinate-size: 11px;
  --coordinate-gutter: 18px;
  position: relative;
  flex: 0 1 auto;
  /* vh first: every browser understands it. dvh is used only where it is
     understood, below - a browser that has never heard of dvh throws away
     the whole declaration, and a board with no height cap simply grows to
     the full width of the page and runs off the bottom of the window. */
  width: clamp(300px, min(760px, 100%, calc(100vw - 470px),
                          calc(100vh - 190px)), 760px);
  min-width: 0;
  padding: 0 0 var(--coordinate-gutter) var(--coordinate-gutter);
}
@supports (height: 100dvh) {
  /* The dynamic viewport is the honest one on a phone, where the address
     bar comes and goes - but only where it exists. */
  .boardwrap {
    width: clamp(300px, min(760px, 100%, calc(100vw - 470px),
                            calc(100dvh - 190px)), 760px);
  }
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  touch-action: manipulation;
}

.sq {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  user-select: none;
  cursor: pointer;
}
.sq.light { background: var(--board-light); }
.sq.dark  { background: var(--board-dark); }
.sq .piece {
  position: relative;
  z-index: 1;
  display: block;
  width: 86%;
  height: 86%;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .34));
}

.sq.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.sq.last::after,
.sq.from::after {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  background: rgba(240, 180, 41, .28);
  pointer-events: none;
}
.sq.target::before {
  content: "";
  position: absolute;
  z-index: 2;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: rgba(0, 0, 0, .23);
  pointer-events: none;
}
.sq.capture::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 6%;
  border-radius: 50%;
  border: var(--capture-ring, 3px) solid rgba(0, 0, 0, .28);
  pointer-events: none;
}
.sq.check::after {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  background: radial-gradient(circle, rgba(248, 113, 113, .88), transparent 70%);
  pointer-events: none;
}
.sq.hint { box-shadow: inset 0 0 0 3px var(--accent2); }
.sq .badge {
  position: absolute;
  z-index: 3;
  right: 4%;
  bottom: 4%;
  font-size: 22%;
  background: var(--accent);
  color: #1a1305;
  border-radius: 50%;
  width: 30%;
  height: 30%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.ranks, .files {
  position: absolute;
  display: flex;
  pointer-events: none;
  color: var(--dim);
  font-size: var(--coordinate-size);
  font-weight: 700;
  line-height: 1;
}
.ranks {
  left: 0;
  top: 0;
  bottom: var(--coordinate-gutter);
  width: var(--coordinate-gutter);
  flex-direction: column;
}
.ranks span { flex: 1; display: flex; align-items: center; justify-content: center; }
.files {
  bottom: 0;
  left: var(--coordinate-gutter);
  right: 0;
  height: var(--coordinate-gutter);
  align-items: center;
  justify-content: space-around;
}

/* -------------------------------------------------------------- land games */
.land-view.active {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  width: min(1180px, 100%);
  margin: 0 auto;
  align-items: start;
}
.land-stage {
  position: relative;
  min-width: 0;
  height: clamp(430px, calc(100dvh - 176px), 720px);
  border-radius: var(--radius);
  overflow: hidden;
  background: #12151c;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.land-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  outline: none;
}
.land-canvas:active { cursor: grabbing; }
.land-toolbar {
  position: absolute;
  z-index: 3;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 5px;
  padding: 4px;
  border: 1px solid rgba(69, 78, 99, .85);
  border-radius: 10px;
  background: rgba(14, 16, 21, .88);
  backdrop-filter: blur(8px);
}
.land-toolbar button {
  min-width: 32px;
  min-height: 30px;
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 12px;
}
.an-hint {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  max-width: calc(100% - 190px);
  background: rgba(14, 16, 21, .87);
  border: 1px solid rgba(69, 78, 99, .85);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--accent);
  pointer-events: none;
}
.land-side { width: 100%; max-width: 380px; }
.game-card { border-top: 3px solid var(--accent); }
.solo-card { border-top-color: var(--accent2); }
.checkers-card { border-top-color: #e05a4f; }
.game-card h2 {
  margin: 2px 0 8px;
  font-size: 19px;
  letter-spacing: .7px;
  color: var(--text);
}
.game-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1.15px;
}
.solo-card .game-kicker { color: var(--accent2); }
.checkers-card .game-kicker { color: #ff8e83; }
.land-side .row > label {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  color: var(--dim);
  font-size: 13px;
}
.land-side .row > label > select { flex: 1; min-width: 0; }
.field-note { min-height: 19px; margin: -3px 0 8px; padding-left: 0; }
.score-target {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin: 10px 0 12px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(76, 194, 255, .09);
  color: var(--dim);
  font-size: 12px;
}
.score-target b { color: var(--accent2); font-size: 22px; line-height: 1; }
.game-rules ol { margin: 0; padding-left: 18px; }
.game-rules li + li { margin-top: 5px; }

/* ------------------------------------------------------------------ side */
.side { flex: 1 1 300px; max-width: 380px; display: grid; gap: 12px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.card h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--dim);
}

.turn {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--raised);
  font-size: 12.5px;
  font-weight: 600;
}
.status-text { margin-top: 8px; font-size: 14px; min-height: 42px; }
.material { display: flex; gap: 14px; margin-top: 8px; font-size: 13px; }
.material span { display: flex; align-items: center; gap: 6px; }
.material i { width: 11px; height: 11px; border-radius: 3px; display: block; }
.material i.w { background: #fdfbf5; border: 1px solid #9a9488; }
.material i.b { background: #23262f; border: 1px solid #5d6473; }

.row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.row > label { flex: none; width: 74px; font-size: 13px; color: var(--dim); }

select, input[type="search"] {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  background: var(--raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 13.5px;
}
select[size] { height: auto; max-height: 190px; }

.buttons { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
button {
  background: var(--raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 36px;
  padding: 7px 12px;
  font-size: 13.5px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { cursor: not-allowed; opacity: .48; }
button.primary, .presets button:first-child {
  background: var(--accent);
  color: #1a1305;
  border-color: var(--accent);
  font-weight: 700;
}
button.primary:hover { filter: brightness(1.08); color: #1a1305; }

.movelist {
  margin: 0;
  padding-left: 0;
  list-style: none;
  max-height: 210px;
  overflow-y: auto;
  font-size: 13.5px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 10px;
}
.movelist li { display: flex; gap: 6px; padding: 2px 4px; border-radius: 4px; }
.movelist li:nth-child(odd) { background: rgba(255, 255, 255, .02); }
.movelist .n { color: var(--dim); min-width: 22px; text-align: right; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin-top: 6px; }
.dim { color: var(--dim); font-size: 13px; }
.small { font-size: 12.5px; }
.feedback { margin: 10px 0 0; min-height: 40px; font-size: 14px; }
.feedback.ok { color: var(--good); }
.feedback.no { color: var(--bad); }
.score-row { display: flex; gap: 14px; font-size: 13px; color: var(--dim); flex-wrap: wrap; }
.score-row b { color: var(--text); }

/* ----------------------------------------------------------------- rules */
.prose { max-width: 760px; margin: 0 auto; }
.prose h2 { font-size: 20px; margin: 26px 0 8px; color: var(--accent); }
.prose .lead { color: var(--dim); }
.presets { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

.rules { display: grid; gap: 8px; }
.rule {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.rule input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--accent); }
.rule b { display: block; font-size: 14px; }
.rule span { color: var(--dim); font-size: 12.8px; }

/* --------------------------------------------------------------- players */
.tribe {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.tribe:last-child { border-bottom: none; }
.tribe.turn { font-weight: 700; }
.tribe .dot { width: 13px; height: 13px; border-radius: 50%; flex: none; }
.tribe .who { flex: 1; }
.tribe .pts { color: var(--accent); font-weight: 700; }
.tribe .res { color: var(--dim); font-size: 12px; }

/* ---------------------------------------------------------------- loader */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(14, 16, 21, .96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity .3s;
}
.loader.hidden { opacity: 0; pointer-events: none; }
.loader-inner { text-align: center; max-width: 320px; }
.spinner {
  width: 46px;
  height: 46px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- footer */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--dim);
  font-size: 12px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 1000px) {
  .topbar { align-items: flex-start; }
  .tabs { margin-left: 0; }
  .land-view.active { grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); }
}

@media (max-width: 860px) {
  main { padding: 12px; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .tabs { width: 100%; order: 3; margin-left: 0; }
  .view.active { flex-direction: column; align-items: stretch; }
  .boardwrap, .side { max-width: none; width: 100%; }
  /* Same rule as above, for the narrow layout: vh as the baseline, dvh
     layered on only where the browser supports it. */
  .boardwrap {
    width: min(100%, 760px, calc(100vh - 144px));
    max-width: none;
    align-self: center;
  }
  @supports (height: 100dvh) {
    .boardwrap {
      width: min(100%, 760px, calc(100dvh - 144px));
    }
  }
  .land-view.active { display: flex; width: 100%; }
  .land-stage { width: 100%; height: clamp(360px, 58dvh, 560px); }
  .land-side { max-width: none; }
}

@media (max-width: 460px) {
  .brand-text span { display: none; }
  .brand-text strong { font-size: 15px; }
  .topbar { padding-inline: 10px; }
  .tab { padding-inline: 10px; font-size: 13px; }
  main { padding: 9px; }
  .boardwrap { max-width: 100%; }
  .land-stage { height: clamp(330px, 56dvh, 460px); }
  .an-hint { top: auto; bottom: 10px; max-width: calc(100% - 22px); }
  .land-toolbar { top: 8px; right: 8px; }
  .land-toolbar button { min-width: 29px; padding-inline: 5px; }
  .movelist { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

@media (prefers-color-scheme: light) {
  :root {
    --window: #f4f1ea;
    --surface: #fffdf8;
    --raised: #efe9dc;
    --border: #d9d0bd;
    --text: #23262f;
    --dim: #6b6558;
  }
  .land-stage { background: #e9e4d9; }
}

/* The Anarchess die: a wooden cube with three light sides and three dark. */
.an-die-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 4px;
}
.an-die {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
}
.an-die-note {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.35;
}
