/* Chess.
   Theme lives on <html data-theme>, set before first paint. */

@font-face {
  font-family: "Geist";
  src: url("../fonts/Geist-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  src: url("../fonts/Geist-SemiBold.ttf") format("truetype");
  font-weight: 600 700;
  font-display: swap;
}

:root,
:root[data-theme="light"] {
  --bg: #ededeb;
  --ink: #141414;
  --muted: #636361;
  --rule: #c4c4c0;
  --map: #e2e2df;
  --faint: #dededb;
  --echo-1: #6e6e6c;
  --echo-2: #959593;
  --echo-3: #b4b4b1;
  --shadow: rgba(0, 0, 0, 0.25);
  --pop-shadow: 0 14px 28px -12px var(--shadow), 0 2px 6px -2px var(--shadow);
  --go: #1f9d55;
  --pin: #e5484d;
  --sq-l: #e4e4e1;
  --sq-d: #aeaeab;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1c1c1c;
  --ink: #ededed;
  --muted: #9a9a9a;
  --rule: #3a3a3a;
  --map: #232323;
  --faint: #262626;
  --echo-1: #9a9a9a;
  --echo-2: #6e6e6e;
  --echo-3: #4e4e4e;
  --shadow: rgba(0, 0, 0, 0.45);
  --go: #2fd27a;
  --sq-l: #8f8f8d;
  --sq-d: #626260;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1c1c1c;
    --ink: #ededed;
    --muted: #9a9a9a;
    --rule: #3a3a3a;
    --map: #232323;
    --faint: #262626;
    --go: #2fd27a;
    --sq-l: #8f8f8d;
    --sq-d: #626260;
    color-scheme: dark;
  }
}

:root {
  --font-sans: "Neue Haas Grotesk Text", "Neue Haas Grotesk Display", "Helvetica Neue", Helvetica,
    "Geist", Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 150ms;
  --dur: 250ms;
  --dur-slow: 400ms;
  --gutter: 16px;
  --col-gap: 16px;
}

@media (min-width: 768px) {
  :root {
    --gutter: 40px;
    --col-gap: 24px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

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

/* ── Type ─────────────────────────────────────────────────────────────── */

.label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

/* Text buttons: plain type, a hairline that draws in. */
.text-btn {
  appearance: none;
  padding: 6px 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  min-height: 32px;
  transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
.text-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.ul {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 calc(100% - 5px);
  background-size: 0% 1px;
  transition: background-size 180ms var(--ease);
}
.ul:hover,
.ul[aria-current="page"],
.ul[aria-pressed="true"] {
  background-size: 100% 1px;
}
.text-btn[aria-pressed="true"] {
  font-weight: 700;
}
.text-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.seg {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.seg .sep {
  color: var(--muted);
}

.btn {
  appearance: none;
  height: 48px;
  padding: 0 20px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-radius: 0;
  transition: transform var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:active:not(:disabled) {
  transform: scale(0.97);
  opacity: 0.85;
}
.btn.ghost {
  background: transparent;
  color: var(--ink);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.btn.block {
  width: 100%;
}

/* ── Shell ────────────────────────────────────────────────────────────── */

#shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.sh {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(20px, env(safe-area-inset-top)) var(--gutter) 14px;
  border-bottom: 1px solid var(--ink);
  background: var(--bg);
  position: relative;
  z-index: 20;
}

.sh-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.mark {
  flex: none;
  display: block;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mark .mk {
  transition: transform 300ms var(--ease);
  transform-box: fill-box;
  transform-origin: center;
}
.sh-logo:hover .mk {
  transform: scale(0.8);
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.theme-switch .sep {
  color: var(--muted);
}
:root[data-theme="light"] .theme-switch [data-option="light"],
:root[data-theme="dark"] .theme-switch [data-option="dark"] {
  font-weight: 700;
}

#main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px var(--gutter) 32px;
}

.view {
  display: none;
  max-width: 560px;
  margin: 0 auto;
}
.view.on {
  display: block;
}

.tabs {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--ink);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
  position: relative;
  z-index: 20;
}
.tab {
  appearance: none;
  border: 0;
  background: none;
  padding: 14px 0 12px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: transform var(--dur-fast) var(--ease);
}
.tab:active {
  transform: scale(0.92);
}
.tab .label {
  transition: color var(--dur-fast) var(--ease), background-size 180ms var(--ease);
  display: inline-block;
  padding-bottom: 2px;
  background-position: 0 100%;
  color: var(--muted);
}
.tab[aria-current="page"] .label {
  color: var(--ink);
}
.tab .dot {
  position: absolute;
  top: 12px;
  left: calc(50% + 30px);
  width: 6px;
  height: 6px;
  background: var(--pin);
  border-radius: 50%;
}

/* Lights: the page dims while the theme changes. */
.lights {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}
:root[data-lights="off"] .lights {
  opacity: 1;
  transition-duration: 180ms;
}

/* ── Lists ────────────────────────────────────────────────────────────── */

.group-head {
  display: flex;
  justify-content: space-between;
  margin: 28px 0 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--ink);
  font-size: 15px;
  font-weight: 700;
}
.group-head:first-child {
  margin-top: 0;
}
.group-head .count {
  font-weight: 400;
  color: var(--muted);
}

.rows > * {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  width: 100%;
  padding: 14px 0;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: none;
  text-align: left;
  align-items: baseline;
  cursor: pointer;
  position: relative;
  transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), padding var(--dur) var(--ease);
}
.rows > *:active:not([disabled]) {
  transform: scale(0.985);
}
.rows > *[disabled] {
  cursor: default;
  color: var(--muted);
}
.rows .sub {
  grid-column: 1;
  color: var(--muted);
  font-size: 13px;
}
.rows .end {
  grid-column: 2;
  grid-row: 1;
  text-align: right;
}
.rows > *[aria-pressed="true"] .name {
  font-weight: 700;
}
.rows > *[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  border-bottom: 1px solid var(--ink);
}

.placard {
  border: 1px solid var(--ink);
  padding: 16px;
  display: grid;
  gap: 6px;
}
.placard .meta {
  color: var(--muted);
  font-size: 13px;
}
.placard .quote {
  margin-top: 6px;
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  margin-top: 8px;
}
.stack {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}
.row-between {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.reveal {
  animation: rise var(--dur-slow) var(--ease) both;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ── Board ────────────────────────────────────────────────────────────── */

.boardrow {
  display: grid;
  grid-template-columns: 1fr 8px;
  gap: 8px;
  margin: 12px 0 8px;
}
.gauge {
  display: flex;
  flex-direction: column-reverse;
  background: #141414;
  border: 1px solid var(--ink);
  overflow: hidden;
}
.gauge.top {
  flex-direction: column;
}
.gauge i {
  display: block;
  height: 50%;
  background: #f5f5f3;
  transition: height var(--dur) var(--ease);
}
.gauge.off {
  visibility: hidden;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border: 1px solid var(--ink);
}
.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}
.sq.l {
  background: var(--sq-l);
}
.sq.d {
  background: var(--sq-d);
}
.sq::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.sq.last::before {
  background: color-mix(in srgb, var(--ink) 16%, transparent);
}
.sq.sel::before {
  background: color-mix(in srgb, var(--ink) 28%, transparent);
}
.sq.good::before {
  background: color-mix(in srgb, var(--go) 55%, transparent);
}
.sq.bad::before {
  background: color-mix(in srgb, var(--pin) 55%, transparent);
}
.sq.chk::before {
  background: radial-gradient(circle, var(--pin) 0, transparent 72%);
}
.sq.tgt::after {
  content: "";
  position: absolute;
  z-index: 2;
  width: 32%;
  height: 32%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 70%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--bg, #fff) 60%, transparent);
  pointer-events: none;
}
.sq.tgt.cap::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 4px solid color-mix(in srgb, var(--ink) 70%, transparent);
}
.co {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  color: var(--ink);
  opacity: 0.55;
}
.co.r {
  top: 3px;
  left: 3px;
}
.co.f {
  bottom: 2px;
  right: 3px;
}

.pc {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  background-size: 96%;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
}
.pc.wK { background-image: url("../vendor/pieces/wK.svg"); }
.pc.wQ { background-image: url("../vendor/pieces/wQ.svg"); }
.pc.wR { background-image: url("../vendor/pieces/wR.svg"); }
.pc.wB { background-image: url("../vendor/pieces/wB.svg"); }
.pc.wN { background-image: url("../vendor/pieces/wN.svg"); }
.pc.wP { background-image: url("../vendor/pieces/wP.svg"); }
.pc.bK { background-image: url("../vendor/pieces/bK.svg"); }
.pc.bQ { background-image: url("../vendor/pieces/bQ.svg"); }
.pc.bR { background-image: url("../vendor/pieces/bR.svg"); }
.pc.bB { background-image: url("../vendor/pieces/bB.svg"); }
.pc.bN { background-image: url("../vendor/pieces/bN.svg"); }
.pc.bP { background-image: url("../vendor/pieces/bP.svg"); }
.pc.lift {
  opacity: 0.25;
}
.drag-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  transform: translate(-50%, -58%) scale(1.18);
}

.arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}
.arrows .go {
  stroke: var(--go);
  fill: var(--go);
}
.arrows .bad {
  stroke: var(--pin);
  fill: var(--pin);
}
.arrows .neutral {
  stroke: var(--ink);
  fill: var(--ink);
  opacity: 0.6;
}

.status {
  min-height: 20px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.opp {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.strip {
  margin-top: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
  scrollbar-width: none;
}
.strip::-webkit-scrollbar {
  display: none;
}
.strip b {
  color: var(--ink);
}

/* ── Review ───────────────────────────────────────────────────────────── */

.caption {
  min-height: 44px;
  margin-top: 4px;
}
.caption .tag-blunder { color: var(--pin); font-weight: 700; }
.caption .tag-mistake { color: #d9822b; font-weight: 700; }
.caption .tag-inaccuracy { color: #a6882a; font-weight: 700; }
.caption .best { color: var(--go); font-weight: 700; }

svg.graph {
  display: block;
  width: 100%;
  height: 72px;
  margin-top: 8px;
  background: var(--map);
  cursor: pointer;
  touch-action: none;
}

.twocol {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--col-gap);
}
.big {
  font-size: 28px;
  letter-spacing: -0.02em;
  line-height: 1;
}

.movelist {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  margin-top: 4px;
}
.movelist .n {
  color: var(--muted);
  padding: 6px 0;
}
.movelist button {
  appearance: none;
  border: 0;
  background: none;
  text-align: left;
  padding: 6px 4px;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.movelist button:active {
  transform: scale(0.92);
}
.movelist button.on {
  background: var(--faint);
  font-weight: 700;
}
.movelist .blunder { color: var(--pin); }
.movelist .mistake { color: #d9822b; }
.movelist .inaccuracy { color: #a6882a; }

.progress {
  height: 1px;
  background: var(--rule);
  margin: 12px 0;
  position: relative;
}
.progress i {
  position: absolute;
  left: 0;
  top: -1px;
  height: 3px;
  background: var(--ink);
  width: 0;
  transition: width var(--dur) var(--ease);
}

/* ── Sheets ───────────────────────────────────────────────────────────── */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade var(--dur) var(--ease) both;
}
@keyframes fade {
  from { opacity: 0; }
}
.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--bg);
  box-shadow: var(--pop-shadow);
  padding: 20px var(--gutter) max(24px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--ink);
  animation: sheetup var(--dur) var(--ease) both;
}
@keyframes sheetup {
  from { transform: translateY(24px); opacity: 0; }
}
.sheet h2 {
  margin-bottom: 14px;
}
.promo {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.promo button {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--sq-l);
  aspect-ratio: 1;
  cursor: pointer;
  padding: 0;
}
.startbar {
  position: sticky;
  bottom: 0;
  margin: 20px calc(-1 * var(--gutter)) -32px;
  padding: 12px var(--gutter) 14px;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  z-index: 5;
}
textarea {
  width: 100%;
  height: 160px;
  padding: 10px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font: inherit;
  border-radius: 0;
  resize: none;
}
textarea:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  animation: rise var(--dur) var(--ease) both;
}

.empty {
  padding: 40px 0;
}
.offline-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.offline-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--go);
}
.offline-pill.wait::before {
  background: var(--echo-2);
}

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

/* Hover feedback only where a real pointer exists, so touch never gets stuck states. */
@media (hover: hover) {
  .btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--ink) 55%, transparent);
  }
  .btn.ghost:hover:not(:disabled) {
    background: var(--faint);
  }
  .tab:hover .label {
    color: var(--ink);
  }
  .rows > *:hover:not([disabled]) {
    background-color: var(--faint);
    padding-left: 8px;
    padding-right: 8px;
  }
  .movelist button:hover {
    background: var(--faint);
  }
  .theme-switch .text-btn:hover,
  .seg .text-btn:hover {
    transform: translateY(-1px);
  }
}

/* Board colours (Settings -> Board). */
:root[data-pieces="a"] { --sq-l: #e8dec8; --sq-d: #b4956c; }
:root[data-pieces="b"] { --sq-l: #e2e6e9; --sq-d: #8d9eab; }
