/* Chess. Chrome follows the joeycloud house style; the board is its own thing. */

/* The `hidden` attribute must win: the UA sheet's `[hidden] { display: none }`
   loses to any author rule that sets `display`, so a hidden element would still
   be laid out. */
[hidden] { display: none !important; }

:root {
  --bg: #0b0e13;
  --panel: #131922;
  --panel-2: #0f141b;
  --line: #232c39;
  --ink: #e6edf3;
  --muted: #8b98a5;
  --accent: #4da3ff;
  --good: #46d39a;
  --warn: #ffcf7a;
  --bad: #ff8a8a;
  /* Board squares are coloured on the wood rules themselves, not from here. */
  --radius: 10px;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

/* ------------------------------------------------------------- top bar --- */
.topbar {
  display: flex; align-items: center; gap: .9rem;
  padding: .6rem 1rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.home-btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .32rem .62rem; border: 1px solid var(--line); border-radius: 7px;
  background: #161d27; color: var(--ink);
  font-size: .84rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.home-btn:hover { border-color: #39415a; text-decoration: none; }
.brand { display: flex; align-items: center; gap: .55rem; }
.brand-mark {
  display: grid; place-items: center; width: 26px; height: 26px;
  border-radius: 7px; background: linear-gradient(160deg, #3a4a63, #1d2532);
  font-size: 1rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; font-weight: 650; }
.brand-text small { color: var(--muted); font-weight: 400; font-size: .72rem; }
.who { margin-left: auto; font-size: .82rem; color: var(--muted); }
.who strong { color: var(--ink); }

/* --------------------------------------------------------------- layout --- */
main { max-width: 1180px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.layout { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(340px, 1fr); gap: 1.4rem; align-items: start; }
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

h2 { font-size: 1.05rem; margin: 0 0 .35rem; }
h3 { font-size: .78rem; margin: 1.1rem 0 .4rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hint { color: var(--muted); font-size: .8rem; margin: .3rem 0 .6rem; }

/* ---------------------------------------------------------------- board --- */
.board-column { position: sticky; top: 4.2rem; }
@media (max-width: 880px) { .board-column { position: static; } }

.player-strip {
  display: flex; align-items: center; justify-content: space-between;
  padding: .45rem .7rem; margin: .35rem 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.player-strip.active { border-color: var(--accent); }
.strip-name { font-weight: 600; font-size: .9rem; }
.strip-clock {
  font-variant-numeric: tabular-nums; font-size: 1.05rem; font-weight: 650;
  padding: .05rem .5rem; border-radius: 6px; background: #0d1219; border: 1px solid var(--line);
}
.strip-clock.low { color: var(--bad); border-color: #5a2b2b; }

.board-wrap { position: relative; }

/* A wooden board: light maple against dark walnut, both grained, sitting in a
   dark frame the way the reference set does. */
.board {
  --grain:
    repeating-linear-gradient(
      87deg,
      rgba(96, 58, 22, .11) 0px, rgba(96, 58, 22, .11) 1px,
      rgba(255, 238, 205, .07) 1px, rgba(255, 238, 205, .07) 3px,
      rgba(120, 74, 30, .09) 3px, rgba(120, 74, 30, .09) 4px,
      rgba(255, 244, 220, .04) 4px, rgba(255, 244, 220, .04) 7px,
      rgba(80, 48, 18, .07) 7px, rgba(80, 48, 18, .07) 9px
    );
  --sheen: linear-gradient(150deg, rgba(255, 255, 255, .20) 0%, rgba(255, 255, 255, 0) 42%,
                          rgba(0, 0, 0, .04) 68%, rgba(0, 0, 0, .16) 100%);

  display: grid;
  /* Both axes are declared: implicit rows would size to the piece inside them and
     the squares would stop being square. */
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  user-select: none;
  border-radius: 6px;
  overflow: hidden;
  border: 10px solid #3a2a1c;
  border-image: linear-gradient(150deg, #5c4229 0%, #33251a 55%, #241a12 100%) 1;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .45), 0 0 0 1px rgba(0, 0, 0, .6);
}

.sq {
  position: relative;
  /* min-height/min-width 0 stops a tall piece from stretching its row. */
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  cursor: default;
  overflow: hidden;
}
.sq.light {
  background-color: #e6c69a;
  background-image: var(--grain), var(--sheen);
  background-blend-mode: multiply, normal;
}
.sq.dark {
  background-color: #9c6535;
  background-image: var(--grain), var(--sheen);
  background-blend-mode: multiply, normal;
}

/* Pieces are vector, so they scale with the square instead of being a font size. */
.piece-svg {
  width: 97%; height: 97%; display: block;
  filter: drop-shadow(0 2px 2.5px rgba(20, 12, 4, .5));
}
.sq.pickable { cursor: pointer; }
.sq.pickable .piece-svg { transition: transform .07s ease-out; }
.sq.pickable:hover .piece-svg { transform: translateY(-2px); }

.sq.selected::after {
  content: ""; position: absolute; inset: 0;
  box-shadow: inset 0 0 0 3px rgba(255, 214, 92, .92), inset 0 0 12px rgba(255, 214, 92, .45);
}
.sq.target::before {
  content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(46, 92, 44, .5);
  box-shadow: 0 0 8px rgba(46, 92, 44, .5);
}
.sq.target.occupied::before {
  width: 88%; height: 88%; border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 4px rgba(46, 92, 44, .62), 0 0 8px rgba(46, 92, 44, .4);
}
.sq.check::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(232, 54, 54, .82) 0%, rgba(232, 54, 54, .32) 52%,
                              rgba(232, 54, 54, 0) 78%);
}

/* Coordinates sit on the wood, so they are tinted to stay readable on both tones. */
.sq .coord {
  position: absolute; bottom: 1px; right: 3px; font-size: .58rem;
  font-weight: 700; opacity: .62;
}
.sq.light .coord { color: #6b4420; }
.sq.dark .coord { color: #f0dcbe; }
.sq .coord.rank { bottom: auto; top: 2px; left: 4px; right: auto; }

.board-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(8, 11, 16, .82); border-radius: 8px; z-index: 5;
}
.board-overlay[hidden] { display: none; }
.overlay-inner { text-align: center; padding: 1.2rem; max-width: 22rem; }
.overlay-inner h2 { font-size: 1.35rem; margin-bottom: .35rem; }
.overlay-inner p { color: var(--muted); margin: 0 0 1rem; font-size: .9rem; }

.status-line { min-height: 1.3rem; font-size: .84rem; color: var(--muted); margin: .5rem 0 0; }
.status-line.thinking { color: var(--warn); }
.board-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }

/* ---------------------------------------------------------------- tabs --- */
.tabs { display: flex; gap: .3rem; margin-bottom: .7rem; flex-wrap: wrap; }
.tab {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: .38rem .7rem; font: inherit; font-size: .84rem;
  font-weight: 600; cursor: pointer;
}
.tab:hover { border-color: #39415a; color: var(--ink); }
.tab.is-active { background: #1b2735; border-color: #2f4560; color: var(--ink); }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem;
}
.panel[hidden] { display: none; }

/* ------------------------------------------------------------- controls --- */
.btn {
  background: #161d27; border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink); padding: .45rem .8rem; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: #39415a; }
.btn.primary { background: #1b3a5c; border-color: #2c5c8a; color: #eaf4ff; }
.btn.primary:hover { border-color: var(--accent); }
.btn.wide { width: 100%; margin-top: .8rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { background: #4a1d22; border-color: #7d2f38; color: #ffdede; }
.btn.danger:hover { border-color: var(--bad); }

/* ------------------------------------------------------------------ modal ---
   The new-game setup and the leave warning. Both are the same shell: a backdrop
   that also closes on click, and a card that scrolls if it is taller than the
   screen (which the engine picker is, on a phone). */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(6, 9, 14, .72);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  width: min(30rem, 100%);
  max-height: min(88vh, 46rem);
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.modal-head {
  flex: none; display: flex; align-items: center; gap: .6rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.02rem; }
.modal-x {
  margin-left: auto; flex: none;
  width: 28px; height: 28px;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 7px;
  font-size: .85rem; line-height: 1; cursor: pointer;
}
.modal-x:hover { color: var(--ink); border-color: var(--accent); }
.modal-body { padding: 1rem; overflow: auto; }
.modal-body h3 { margin: 1rem 0 .4rem; font-size: .84rem; color: var(--muted);
                 text-transform: uppercase; letter-spacing: .06em; }
.modal-body h3:first-child { margin-top: 0; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

/* The Game panel's summary: a compact line or two about what is on the board. */
.game-summary { font-size: .85rem; color: var(--muted); line-height: 1.6; }
.game-summary b { color: var(--ink); font-weight: 600; }

.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid var(--line); border-radius: 999px;
  padding: .3rem .7rem; font-size: .84rem; cursor: pointer; background: var(--panel-2);
}
.chip:has(input:checked) { border-color: var(--accent); background: #16263a; }
.chip input { margin: 0; }
.mode-row { display: flex; gap: .45rem; flex-wrap: wrap; }

.engine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.engine-card {
  text-align: left; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: .6rem .7rem; cursor: pointer; font: inherit; color: var(--ink);
}
.engine-card:hover { border-color: #39415a; }
.engine-card.is-picked { border-color: var(--accent); background: #16263a; }
.engine-card .en-head { display: flex; align-items: baseline; justify-content: space-between; gap: .4rem; }
.engine-card .en-name { font-weight: 650; }
.engine-card .en-elo {
  font-size: .72rem; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 0 .45rem;
}
.engine-card .en-about { font-size: .75rem; color: var(--muted); margin-top: .3rem; }

/* ---------------------------------------------------------------- lists --- */
.list { display: flex; flex-direction: column; gap: .4rem; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: .5rem .7rem; font-size: .87rem;
}
.list-row .lr-main { min-width: 0; }
.list-row .lr-sub { color: var(--muted); font-size: .76rem; }
.empty-note { color: var(--muted); font-size: .84rem; padding: .4rem 0; }

/* ---------------------------------------------------------------- table --- */
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.board-table { border-collapse: collapse; width: 100%; font-size: .8rem; }
.board-table th, .board-table td {
  padding: .38rem .55rem; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.board-table th:first-child, .board-table td:first-child { text-align: left; }
.board-table thead th {
  background: var(--panel-2); color: var(--muted); font-weight: 600;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
}
.board-table tbody tr:last-child td { border-bottom: 0; }
.board-table tr.is-me { background: #16263a; }
.board-table .eng-head { border-left: 1px solid var(--line); }
.board-table .sub { color: var(--muted); font-size: .7rem; }
.board-table .hidden-rate { color: var(--muted); font-style: italic; }
.board-table .form { display: inline-flex; gap: 2px; }
.form-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.form-dot.win { background: var(--good); }
.form-dot.loss { background: var(--bad); }
.form-dot.draw { background: var(--muted); }

/* ----------------------------------------------------------------- you --- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; font-size: .86rem; margin: 0 0 .8rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.switch-row {
  display: flex; align-items: flex-start; gap: .55rem;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: .7rem; font-size: .86rem;
}
.switch-row input { margin-top: .22rem; }
.switch-row .sr-body { flex: 1; }
.switch-row .sr-note { color: var(--muted); font-size: .78rem; margin-top: .15rem; }

.foot { margin-top: 1.6rem; }
.notfound { max-width: 520px; margin: 4rem auto; padding: 0 1rem; }
