/* Hivelab: the design system every page shares. Page-specific rules live in the
   page's own stylesheet (game.css for the board pages, and so on). */

/* ================================================================ tokens */

:root {
  color-scheme: dark;
  --bg: #14171b;
  --bg-2: #181b20;          /* sunken areas, table stripes */
  --panel: #1d2127;
  --panel-2: #242931;       /* panel headers, raised controls */
  --panel-3: #2c323b;       /* hover on raised controls */
  --line: #2f363f;
  --line-2: #3d4550;
  --text: #d3d9e0;
  --text-strong: #eef1f4;
  --dim: #8d98a5;
  --faint: #66717d;
  --accent: #f0b429;        /* honey */
  --accent-2: #ffc94d;
  --accent-ink: #1d1602;
  --accent-soft: #f0b42924;
  --link: #6eb0f5;
  --select: #2f6fb8;        /* the current move, selected rows */
  --good: #5fb85a;
  --bad: #e5534b;
  --bad-soft: #e5534b26;
  --hover: #ffffff0d;
  --shadow: 0 6px 24px #0008, 0 1px 3px #0006;
  --board: #343e49;
  --board-grid: #ffffff0f;
  --tile-white: #efe8d8;
  --tile-white-edge: #b9b09b;
  --tile-black: #1f1d1b;
  --tile-black-edge: #3b3733;
  --gauge-black: #0f1113;
  --gauge-white: #e6e0d2;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 6px;
  --radius-lg: 10px;
  --topbar: 52px;
  --page-max: 1500px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eceae6;
  --bg-2: #f4f3f0;
  --panel: #ffffff;
  --panel-2: #f3f2ef;
  --panel-3: #e8e6e2;
  --line: #dcd9d3;
  --line-2: #c6c2bb;
  --text: #2c2f33;
  --text-strong: #111315;
  --dim: #6b7178;
  --faint: #959aa0;
  --accent: #d99a0b;
  --accent-2: #eaa914;
  --accent-ink: #1d1602;
  --accent-soft: #e9a71533;
  --link: #1f6fc5;
  --select: #3d82d1;
  --good: #3f9a3a;
  --bad: #c9362e;
  --bad-soft: #c9362e1f;
  --hover: #0000000a;
  --shadow: 0 6px 24px #0002, 0 1px 3px #0002;
  --board: #b9c2ca;
  --board-grid: #0000000d;
  --tile-black-edge: #3b3733;
  --gauge-black: #34383d;
  --gauge-white: #fbf8f1;
}

/* ================================================================ base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--text-strong); line-height: 1.25; font-weight: 600; }
h1 { font-size: 26px; margin: 0 0 16px; }
h2 { font-size: 19px; margin: 28px 0 10px; }
h3 { font-size: 16px; margin: 20px 0 8px; }
p { margin: 0 0 12px; }
code, kbd, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
kbd { background: var(--panel-2); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: #f0b42955; }
.muted { color: var(--dim); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ================================================================ buttons */

button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 34px; padding: 6px 14px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-weight: 500; line-height: 1.2; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover:not(:disabled) { background: var(--panel-3); border-color: var(--line-2); text-decoration: none; }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--hover); border-color: transparent; }
.btn.small { min-height: 28px; padding: 3px 10px; font-size: 12.5px; }
.btn.large { min-height: 44px; padding: 10px 22px; font-size: 15.5px; }
.btn.block { display: flex; width: 100%; }
.btn svg, .icon-button svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button {
  display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0;
  background: none; border: 1px solid transparent; border-radius: var(--radius); color: var(--dim);
}
.icon-button:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-button:disabled { opacity: .4; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* A row of mutually exclusive choices: <div class="choice"><button aria-pressed="true">… */
.choice { display: flex; }
.choice > button {
  flex: 1; min-height: 34px; padding: 5px 8px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 0; margin-left: -1px; color: var(--text); white-space: nowrap;
}
.choice > button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.choice > button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.choice > button:hover { background: var(--panel-3); }
.choice > button[aria-pressed="true"], .choice > button.on {
  background: var(--accent-soft); border-color: var(--accent); color: var(--text-strong);
  position: relative; z-index: 1; font-weight: 600;
}

/* On/off switch: <label class="switch"><input type="checkbox"><span></span></label> */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; width: 100%; height: 100%; }
.switch span { position: absolute; inset: 0; border-radius: 11px; background: var(--line-2); transition: background .15s; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px #0005;
}
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ================================================================ forms */

.input, .select, .textarea,
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea {
  width: 100%; min-height: 36px; padding: 7px 10px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
.textarea, .form textarea { resize: vertical; min-height: 64px; }
.input:focus, .select:focus, .textarea:focus,
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.mono, .textarea.mono { font-family: var(--mono); font-size: 12.5px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .field-label { color: var(--dim); font-size: 12.5px; font-weight: 600; }
.field .hint { color: var(--faint); font-size: 12px; }
.field.error input, .field.error select, .field.error textarea { border-color: var(--bad); }
.form-error { color: var(--bad); font-size: 13px; min-height: 1.2em; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.select, .form select {
  appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* ================================================================ panels and cards */

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.card-body { padding: 16px 18px; }
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  font-weight: 600; color: var(--text-strong);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 14px; }
.card > :last-child { border-bottom-left-radius: inherit; border-bottom-right-radius: inherit; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--dim); line-height: 1.5;
}
.badge.accent { background: var(--accent-soft); border-color: #f0b42966; color: var(--accent-2); }
:root[data-theme="light"] .badge.accent { color: #8a5d00; }
.notice { padding: 10px 14px; border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--line); }
.notice.error { background: var(--bad-soft); border-color: var(--bad); color: var(--text-strong); }
.empty { color: var(--dim); text-align: center; padding: 28px 16px; }
.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite;
  vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================ tables */

.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th {
  text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--dim); padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2);
}
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:nth-child(even) { background: var(--bg-2); }
.data-table tbody tr:hover { background: var(--hover); }
.data-table .num, .data-table th.num { text-align: right; }
.table-scroll { overflow-x: auto; }

/* ================================================================ tabs */

/* <div class="tabs" role="tablist"><button role="tab" aria-selected="true">… */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs > [role=tab], .tabs > a {
  background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 9px 14px; color: var(--dim); font-weight: 600; white-space: nowrap; text-decoration: none;
}
.tabs > [role=tab]:hover, .tabs > a:hover { color: var(--text); }
.tabs > [aria-selected="true"], .tabs > a[aria-current] { color: var(--text-strong); border-bottom-color: var(--accent); }

/* ================================================================ dialogs and toasts */

dialog, .dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2);
  border-radius: var(--radius-lg); padding: 20px 22px; width: min(400px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 14px; font-size: 17px; }
dialog p { color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toasts {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  background: #0b0d10ee; color: #eef1f4; border: 1px solid #ffffff1a; border-radius: var(--radius);
  padding: 9px 16px; box-shadow: var(--shadow); font-weight: 500; max-width: calc(100vw - 32px);
  animation: toast-in .18s ease-out; transition: opacity .25s, transform .25s;
}
.toast.success { border-left: 3px solid var(--good); }
.toast.error { border-left: 3px solid var(--bad); }
.toast.leaving { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ================================================================ the top bar */

.site-header {
  position: sticky; top: 0; z-index: 50; flex: none;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar {
  display: flex; align-items: center; height: var(--topbar);
  max-width: var(--page-max); margin: 0 auto; padding: 0 16px; gap: 6px;
}
.brand {
  display: flex; align-items: center; gap: 9px; margin-right: 18px;
  color: var(--text-strong); font-size: 20px; font-weight: 700; letter-spacing: -.01em; text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--text-strong); }
.logo { width: 26px; height: 26px; }
.logo polygon { stroke-linejoin: round; stroke-width: 1.6; }
.logo-a { fill: var(--accent); stroke: var(--accent); }
.logo-b { fill: none; stroke: var(--accent); stroke-width: 2.6 !important; }
.logo-c { fill: var(--accent); stroke: var(--accent); opacity: .55; }

.site-nav { display: flex; align-items: stretch; height: 100%; }
.nav-section { position: relative; display: flex; align-items: stretch; }
.nav-top {
  display: flex; align-items: center; gap: 2px; padding: 0 13px;
  background: none; border: 0; color: var(--dim);
  font-size: 13.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; text-decoration: none;
}
.nav-top:hover, .nav-section.open > .nav-top { color: var(--text-strong); text-decoration: none; }
.nav-section.active > .nav-top { color: var(--text-strong); box-shadow: inset 0 -2px 0 var(--accent); }
.caret { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: .6; }
.nav-menu {
  display: none; position: absolute; top: calc(100% - 4px); left: 0; min-width: 200px; z-index: 60;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 6px;
}
.nav-menu.right { left: auto; right: 0; }
.nav-section.open > .nav-menu { display: block; }
.nav-menu [role=menuitem] {
  display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; border-radius: 5px;
  background: none; color: var(--text); font-size: 14px; text-decoration: none; white-space: nowrap;
}
.nav-menu [role=menuitem]:hover, .nav-menu [role=menuitem]:focus-visible {
  background: var(--accent); color: var(--accent-ink); outline: none; text-decoration: none;
}
.nav-menu [aria-current=page] { font-weight: 650; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; height: 100%; }
.account-area { display: flex; align-items: center; height: 100%; gap: 4px; }
.signin, .register {
  font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  padding: 7px 12px; border-radius: var(--radius); text-decoration: none; white-space: nowrap;
}
.signin { color: var(--text); }
.signin:hover { color: var(--text-strong); background: var(--hover); text-decoration: none; }
.register { color: var(--accent); border: 1px solid #f0b42980; }
.register:hover { background: var(--accent); color: var(--accent-ink); text-decoration: none; }
.user-button { gap: 7px; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); }
.user-button svg:first-child { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.user-button span { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.nav-toggle { display: none; }

/* ================================================================ page layout */

.site-main { flex: 1; width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 18px 16px 40px; }
.site-main.narrow { max-width: 860px; }
.site-main.medium { max-width: 1120px; }
.page-head { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .lead { color: var(--dim); margin: 0; }
.site-footer {
  flex: none; border-top: 1px solid var(--line); color: var(--faint); font-size: 12.5px;
  padding: 14px 16px; text-align: center;
}
.site-footer a { color: var(--dim); }
.site-footer p { margin: 6px 0 0; }
span.piece-icon { display: inline-block; vertical-align: middle; }

/* Long-form text: rules, FAQ, resources. */
.prose { font-size: 15px; line-height: 1.65; }
.prose p, .prose ul, .prose ol { margin: 0 0 14px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin-bottom: 5px; }
[id] { scroll-margin-top: calc(var(--topbar) + 14px); }
.prose h2 { padding-top: 6px; border-top: 1px solid var(--line); margin-top: 32px; display: flex; align-items: center; gap: 10px; }
.prose h2 .piece-icon, .prose h2 svg.piece-icon { width: 34px; height: 34px; }
.prose h2:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.prose strong { color: var(--text-strong); }
.prose dl { margin: 0 0 14px; }
.prose dt { font-weight: 650; color: var(--text-strong); }
.prose dd { margin: 0 0 10px 0; color: var(--text); }

/* A table of contents beside long pages. */
.with-toc { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px; align-items: start; }
.toc { position: sticky; top: calc(var(--topbar) + 18px); font-size: 13.5px; }
.toc h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--dim); margin: 0 0 8px; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc a { display: block; padding: 4px 0 4px 12px; color: var(--dim); margin-left: -1px; border-left: 2px solid transparent; }
.toc a:hover { color: var(--text); text-decoration: none; border-left-color: var(--line-2); }

/* ================================================================ pieces (any page) */

.tile.white { --tile: var(--tile-white); }
.tile.black { --tile: var(--tile-black); }
.tile .face { fill: var(--tile); stroke: var(--tile); stroke-width: 7; stroke-linejoin: round; }
.tile.white .face { filter: drop-shadow(0 2px 0 var(--tile-white-edge)); }
.tile.black .face { stroke: var(--tile-black-edge); filter: drop-shadow(0 2px 0 #0b0a09); }
svg.piece-icon { display: block; width: 44px; height: 44px; }

/* Small board diagrams (diagram.js). */
.diagram {
  margin: 4px 0 18px; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.diagram svg { display: block; width: 100%; max-width: 330px; height: auto; background: var(--board); border-radius: var(--radius-lg); }
.diagram figcaption { color: var(--dim); font-size: 13px; text-align: center; max-width: 420px; line-height: 1.45; }
.diagram .cell { fill: var(--board-grid); stroke: none; }
.diagram .ok circle { fill: #63b95cd0; }
.diagram .ok.climb circle { fill: none; stroke: #63b95ce0; stroke-width: 7; }
.diagram .no path { stroke: #ef6a62; stroke-width: 8; stroke-linecap: round; }
.diagram .path { fill: none; stroke: #4aa3ffd0; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 12; }
.diagram .path-end { fill: #4aa3ff; }
.diagram .label { fill: #f4f6f8; font: 600 22px var(--font); text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke: #0009; stroke-width: 5px; }
.diagram .hl { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linejoin: round; }
.diagram-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 18px; margin: 6px 0 18px; }
.diagram-row .diagram { margin: 0; }

/* ================================================================ phones and narrow windows */

@media (max-width: 1000px) {
  .with-toc { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 800px) {
  .topbar { padding: 0 8px 0 6px; gap: 2px; }
  .nav-toggle { display: inline-grid; }
  .brand { margin-right: 6px; font-size: 18px; }
  .logo { width: 24px; height: 24px; }
  .site-nav {
    display: none; position: absolute; top: var(--topbar); left: 0; right: 0; height: auto;
    flex-direction: column; background: var(--panel); border-bottom: 1px solid var(--line-2);
    box-shadow: var(--shadow); padding: 6px 0 10px; max-height: calc(100dvh - var(--topbar)); overflow-y: auto;
  }
  .nav-open .site-nav { display: flex; }
  .nav-section { flex-direction: column; }
  .nav-section.active > .nav-top { box-shadow: inset 3px 0 0 var(--accent); }
  .nav-top { padding: 10px 18px 4px; pointer-events: none; font-size: 12px; color: var(--faint); }
  .nav-top .caret { display: none; }
  .site-nav .nav-section:not(.has-menu) > .nav-top { pointer-events: auto; color: var(--text); }
  .site-nav .nav-section:not(.has-menu).active > .nav-top { color: var(--accent); }
  .site-nav .nav-menu { display: block; position: static; border: 0; box-shadow: none; background: none; padding: 0 6px 0 18px; min-width: 0; }
  .site-nav .nav-menu [role=menuitem] { font-size: 15px; padding: 8px 12px; }
  .site-nav .nav-menu [aria-current=page] { color: var(--accent); }
  .account .nav-top { pointer-events: auto; padding: 0 8px; font-size: 14px; color: var(--text); }
  .account .nav-top .caret { display: inline; }
  .user-button span { max-width: 90px; }
  .signin, .register { padding: 6px 8px; font-size: 12px; letter-spacing: .03em; }
  .site-main { padding: 12px 12px 32px; }
  h1 { font-size: 22px; }
  .prose { font-size: 15px; }
}

@media (max-width: 380px) {
  .brand span { display: none; }
}
