:root {
  --crust: #2a2633;      /* geode outer rock */
  --cavity: #353042;     /* panels */
  --cavity-2: #403a50;
  --quartz: #f3eee6;     /* text */
  --haze: #b9b1c8;       /* secondary text */
  --amethyst: #9b7fd1;   /* accent */
  --amethyst-deep: #6f54a8;
  --citrine: #f0c35a;    /* move highlights */
  --sandstone: #e9d8b4;  /* light squares */
  --slate: #7d8a96;      /* dark squares */
  --garnet: #e06c75;     /* check, errors */
  --display: Rockwell, "Rockwell Nova", "Roboto Slab", "DejaVu Serif", Georgia, serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pieces: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols2", "Arial Unicode MS", serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--crust); }
body {
  margin: 0; color: var(--quartz); font-family: var(--body); font-size: 16px; line-height: 1.55;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(155, 127, 209, 0.22), transparent 55%),
    var(--crust);
  min-height: 100vh;
}
a { color: var(--citrine); }
a:hover { color: #ffd987; }
:focus-visible { outline: 3px solid var(--citrine); outline-offset: 2px; }

/* ---------- header ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  max-width: 1120px; margin: 0 auto; padding: 18px 20px;
}
.wordmark {
  font-family: var(--display); font-weight: 700; font-size: 1.9rem; letter-spacing: -0.5px;
  color: var(--quartz); text-decoration: none; line-height: 1;
}
.wordmark .dot { color: var(--amethyst); }
.wordmark:hover { color: var(--quartz); }
.site-nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.site-nav a { color: var(--haze); text-decoration: none; }
.site-nav a:hover { color: var(--quartz); }
.inline-form { display: inline; margin: 0; }
.linkbtn {
  background: none; border: 0; padding: 0; color: var(--haze); font: inherit; cursor: pointer;
}
.linkbtn:hover { color: var(--quartz); }

main { max-width: 1120px; margin: 0 auto; padding: 8px 20px 60px; }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0 0 12px; }
h1 { font-size: 2.6rem; letter-spacing: -1px; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
p { max-width: 68ch; }
.muted { color: var(--haze); }
.small { font-size: 0.875rem; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 1rem var(--body); padding: 11px 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; background: var(--amethyst); color: #fff; text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: var(--amethyst-deep); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--cavity-2); color: var(--quartz); }
.btn.ghost:hover { background: var(--cavity-2); }
.btn.danger { background: transparent; border-color: rgba(224, 108, 117, 0.5); color: var(--garnet); }
.btn.danger:hover { background: rgba(224, 108, 117, 0.12); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small { padding: 7px 12px; font-size: 0.9rem; }
input[type=text], input[type=password], select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--cavity-2);
  background: var(--crust); color: var(--quartz); font: inherit; margin: 4px 0 14px;
}
label { font-weight: 600; font-size: 0.95rem; }
.check-label { font-weight: 400; display: flex; gap: 8px; align-items: center; }
.honeypot { display: none !important; }
.error { color: var(--garnet); }
.success { color: #8fd19e; }
.panel { background: var(--cavity); border-radius: 14px; padding: 20px; }
.form-narrow { max-width: 420px; }

/* ---------- home ---------- */
.home { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; }
.hero h1 { font-size: clamp(2.4rem, 6vw, 4rem); }
.tc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 18px 0 10px; max-width: 460px; }
.tc-btn {
  display: flex; flex-direction: column; align-items: flex-start; padding: 16px 18px; border-radius: 14px;
  background: var(--cavity); border: 1px solid var(--cavity-2); color: var(--quartz); cursor: pointer; font: inherit; text-align: left;
}
.tc-btn:hover { border-color: var(--amethyst); }
.tc-btn strong { font-family: var(--display); font-size: 1.6rem; line-height: 1.1; }
.tc-btn span { color: var(--haze); font-size: 0.9rem; }
.lobby-list { list-style: none; padding: 0; margin: 0; }
.lobby-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--cavity-2);
}
.lobby-list li:last-child { border-bottom: 0; }
.tag { font-size: 0.8rem; padding: 2px 8px; border-radius: 99px; background: var(--cavity-2); color: var(--haze); }
.tag.turn { background: var(--citrine); color: var(--crust); font-weight: 700; }

/* ---------- game layout ---------- */
.game { display: grid; grid-template-columns: auto minmax(260px, 340px); gap: 24px; align-items: start; justify-content: center; }
.side { display: flex; flex-direction: column; gap: 14px; }
.player-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--cavity); border-radius: 12px; padding: 10px 14px;
}
.player-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-name .rating { color: var(--haze); font-weight: 400; margin-left: 6px; }
.clock {
  font-family: var(--display); font-size: 1.7rem; font-variant-numeric: tabular-nums;
  background: var(--crust); padding: 2px 12px; border-radius: 8px; min-width: 104px; text-align: center;
}
.clock.running { background: var(--quartz); color: var(--crust); }
.clock.low { background: var(--garnet); color: #fff; }
.status-line { min-height: 1.6em; font-weight: 600; }
.moves {
  background: var(--cavity); border-radius: 12px; padding: 10px 12px; max-height: 260px; overflow-y: auto;
  display: grid; grid-template-columns: 2.6em 1fr 1fr; gap: 2px 8px; font-variant-numeric: tabular-nums;
}
.moves .no { color: var(--haze); }
.moves .ply.current { color: var(--citrine); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.offer {
  background: rgba(240, 195, 90, 0.12); border: 1px solid rgba(240, 195, 90, 0.4);
  padding: 12px; border-radius: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}

/* ---------- board ---------- */
.board-wrap { position: relative; width: min(92vw, calc(100vh - 220px), 600px); min-width: 280px; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1; width: 100%;
  border-radius: 8px; overflow: hidden; container-type: inline-size;
  box-shadow: 0 0 0 7px #4a4458, 0 0 0 9px #5b5470, 0 18px 50px rgba(0, 0, 0, 0.5);
}
.sq {
  position: relative; border: 0; margin: 0; padding: 0; cursor: default;
  min-width: 0; min-height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center; font: inherit;
}
.sq.light { background: var(--sandstone); }
.sq.dark { background: var(--slate); }
.board.interactive .sq.movable, .board.interactive .sq.target { cursor: pointer; }
.sq::before { content: ""; position: absolute; inset: 0; pointer-events: none; }
.sq.last::before { background: rgba(240, 195, 90, 0.5); }
.sq.sel::before { background: rgba(155, 127, 209, 0.65); }
.sq.check::before { background: radial-gradient(circle, rgba(224, 108, 117, 0.95) 0%, rgba(224, 108, 117, 0.55) 45%, transparent 75%); }
.sq.target::after {
  content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(42, 38, 51, 0.38); pointer-events: none;
}
.sq.target.occupied::after { width: 100%; height: 100%; border-radius: 0; background: transparent; box-shadow: inset 0 0 0 5px rgba(42, 38, 51, 0.42); }
.sq:focus-visible { outline: 3px solid var(--citrine); outline-offset: -3px; z-index: 2; }
.piece {
  position: relative; z-index: 1; font-family: var(--pieces); line-height: 1; pointer-events: none; user-select: none;
  font-size: 9.6cqw; font-size: min(9.6cqw, 58px);
}
.piece.w {
  color: #fffaf0;
  text-shadow: 0 0 1px #2a2633, 1px 0 0 #2a2633, -1px 0 0 #2a2633, 0 1px 0 #2a2633, 0 -1px 0 #2a2633, 0 3px 4px rgba(0, 0, 0, 0.35);
}
.piece.b { color: #2b2433; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.28), 0 3px 4px rgba(0, 0, 0, 0.3); }
.coord { position: absolute; font-size: 0.7rem; font-weight: 700; pointer-events: none; z-index: 1; }
.coord.file { right: 4px; bottom: 2px; }
.coord.rank { left: 4px; top: 2px; }
.sq.light .coord { color: var(--slate); }
.sq.dark .coord { color: var(--sandstone); }
.promo {
  position: absolute; inset: 0; z-index: 5; background: rgba(42, 38, 51, 0.78);
  display: flex; align-items: center; justify-content: center; gap: 10px; border-radius: 8px;
}
.promo button {
  width: 21%; aspect-ratio: 1; border-radius: 12px; border: 2px solid var(--amethyst);
  background: var(--sandstone); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.promo button:hover { background: #fff; }

/* ---------- misc ---------- */
.qr { width: 200px; height: 200px; background: #fff; margin: 10px 0; padding: 0; }
.qr svg { width: 100%; height: 100%; display: block; }
.recovery-codes { columns: 2; letter-spacing: 1px; }
.notice { padding: 16px; border-radius: 12px; background: var(--cavity); border-left: 4px solid var(--citrine); margin-bottom: 18px; }
code { background: var(--crust); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.stats { display: flex; gap: 28px; flex-wrap: wrap; margin: 12px 0 24px; }
.stats div strong { display: block; font-family: var(--display); font-size: 2rem; }
table.list { width: 100%; border-collapse: collapse; }
table.list td, table.list th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--cavity-2); }
.site-footer { max-width: 1120px; margin: 0 auto; padding: 24px 20px 40px; color: var(--haze); font-size: 0.875rem; }

@media (max-width: 900px) {
  .home, .game { grid-template-columns: 1fr; }
  .board-wrap { width: min(94vw, 600px); margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
