/*
 * Sandtable's shared stylesheet. Every page in every module uses it, so the
 * whole suite looks and behaves the same.
 *
 * The theme is the list of variables in :root below. Pages and modules use
 * these variables (var(--space-3), var(--color-accent)...) instead of writing
 * their own colours and sizes, so a change here changes the whole suite.
 *
 * Contents:
 *   Theme       - colours, spacing, type, corners, in light and dark
 *   Page        - the page layout: header, main area, footer
 *   Text        - headings, links, muted text, tags
 *   Buttons
 *   Forms       - a form's fields, its buttons row
 *   Tables      - plain tables, and sortable, filterable ones (static/ui/table.js)
 *   Messages    - the notes shown after an action ("Unit moved.")
 *   Empty       - what a list shows when it has nothing in it
 *   Log         - the game log: one entry per action, with its notes
 *   Units       - unit icons and token badges (static/icons/units.js draws them)
 */

/* ---- Theme ------------------------------------------------------------- */

:root {
  /* Colours */
  --color-bg: #f6f7f9;          /* behind everything */
  --color-surface: #ffffff;     /* cards, tables, the header */
  --color-text: #1d2330;
  --color-muted: #5d6677;       /* secondary text; still readable on both backgrounds */
  --color-border: #d9dde4;
  --color-accent: #2f5d8a;      /* links, main buttons */
  --color-accent-hover: #244a6f;
  --color-on-accent: #ffffff;   /* text on an accent background */
  --color-success-bg: #e6f4ea;
  --color-success-border: #9fd0ae;
  --color-error-bg: #fbe9e9;
  --color-error-border: #e3a5a5;
  --color-error-text: #9b1c1c;
  --color-focus: #f0a43a;       /* the outline around whatever has keyboard focus */
  --color-card-red: #b3261e;    /* hearts and diamonds on playing cards */

  /* Spacing: every gap and padding is one of these steps (base 4px). */
  --space-1: 0.25rem;  /* 4px */
  --space-2: 0.5rem;   /* 8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.5rem;   /* 24px */
  --space-6: 2rem;     /* 32px */

  /* Type */
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;

  /* Shapes */
  --radius: 6px;
  --page-width: 72rem;  /* widest the main area grows; map pages can opt out */

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #12161d;
    --color-surface: #1b212b;
    --color-text: #e6e9ef;
    --color-muted: #a3acbb;
    --color-border: #313a48;
    --color-accent: #7fb0e0;
    --color-accent-hover: #a3c7ea;
    --color-on-accent: #0d1a27;
    --color-success-bg: #173322;
    --color-success-border: #2f6b45;
    --color-error-bg: #3a1b1b;
    --color-error-border: #7a3333;
    --color-error-text: #f3b3b3;
    --color-card-red: #ff8a80;
  }
}

/* ---- Page -------------------------------------------------------------- */

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
}

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.site-header__inner,
.site-main,
.site-footer__inner {
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 3.5rem;
}

.site-name {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.site-nav form { margin: 0; }

.site-main {
  flex: 1;
  padding-top: var(--space-5);
  padding-bottom: var(--space-6);
}

/* Pages such as the map that use the whole window. */
body.wide .site-main { max-width: none; }

.site-footer {
  border-top: 1px solid var(--color-border);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.site-footer__inner { padding-top: var(--space-3); padding-bottom: var(--space-3); }

/* ---- Text -------------------------------------------------------------- */

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--space-4); }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-base); }
p { margin: 0 0 var(--space-4); }

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

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

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

/* A page's title with its main action beside it, e.g. "People" and "Add an account". */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.page-header h1 { margin: 0; }

/* Read by screen readers, not shown, e.g. the heading of a column of links. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* A side's colour: <span class="swatch" style="--swatch: #b22222">. Always shown
   next to the side's name, never on its own. */
.swatch {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 1px solid var(--color-border);
  border-radius: 2px;
  background: var(--swatch, transparent);
  vertical-align: -0.125em;
}

.tag {
  display: inline-block;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--color-muted);
}

/* ---- Buttons ----------------------------------------------------------- */

/* A <button>, or a link that should look like one: <a class="button">. */
button,
.button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  color: var(--color-on-accent);
}

/* Less important actions sit beside the main one: class="secondary". */
button.secondary,
.button.secondary {
  background: transparent;
  color: var(--color-accent);
}

button.secondary:hover,
.button.secondary:hover {
  background: var(--color-bg);
  color: var(--color-accent-hover);
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Forms ------------------------------------------------------------- */

label { display: block; font-weight: 600; margin-bottom: var(--space-1); }

input, select, textarea {
  width: 100%;
  max-width: 32rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
}

input[type="checkbox"], input[type="radio"] { width: auto; }

/* A colour picker shows as a swatch, with the colour's name beside it. */
.color-field {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

input[type="color"] {
  width: 3.5rem;
  height: 2.5rem;
  padding: var(--space-1);
  cursor: pointer;
}

.form { margin-bottom: var(--space-5); }

.field { margin-bottom: var(--space-4); }
/* A checkbox field: the box in front of its label, the help text underneath. */
.field--check label { display: flex; align-items: center; gap: var(--space-2); }
.field--check .helptext { padding-left: calc(1rem + var(--space-2)); }

/* The row of buttons and links under a form. */
.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.helptext { display: block; color: var(--color-muted); font-size: var(--text-sm); }

.errorlist {
  list-style: none;
  margin: var(--space-1) 0;
  padding: 0;
  color: var(--color-error-text);
  font-size: var(--text-sm);
}

/* ---- Tables ------------------------------------------------------------ */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: var(--space-5);
}

th, td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

td form { margin: 0; }

th { font-size: var(--text-sm); color: var(--color-muted); font-weight: 600; }

tbody th { color: var(--color-text); width: 1%; white-space: nowrap; }

/* Wide tables scroll sideways on narrow screens instead of squashing. */
.table-scroll { overflow-x: auto; margin-bottom: var(--space-5); }
.table-scroll table { margin-bottom: 0; }

/* The search box and filters above a sortable table. */
.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.table-tools .field { margin-bottom: 0; }
.table-tools input, .table-tools select { width: auto; min-width: 10rem; }
.table-count { margin: 0 0 var(--space-2); font-size: var(--text-sm); }

/* A sortable column heading: a button that looks like the heading. */
.sort-button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.sort-button:hover { background: none; color: var(--color-accent); }
th[aria-sort="ascending"] .sort-button::after { content: " ▲"; }
th[aria-sort="descending"] .sort-button::after { content: " ▼"; }

/* Indents a unit under the unit it is part of: <span class="indent" style="--depth: 2">,
   or in a table, <td class="indented-cell" style="--depth: 2">. */
.indent { display: inline-block; width: calc(var(--depth, 0) * var(--space-5)); }
.indented-cell { padding-left: calc(var(--space-3) + var(--depth, 0) * var(--space-4)); }
.is-sorted .indented-cell { padding-left: var(--space-3); }
/* Rows a module lists under a unit, e.g. BattleForce elements: smaller, and always set in under their unit. */
.sub-row td { font-size: 0.9em; color: var(--color-muted); }
.is-sorted .sub-row .indented-cell { padding-left: calc(var(--space-3) + var(--space-4)); }
.sub-row-details { white-space: normal; }

.tree { list-style: none; padding: 0; margin: 0 0 var(--space-5); }
.tree li { padding: var(--space-1) 0; }

/* ---- Messages ---------------------------------------------------------- */

.messages { list-style: none; margin: 0 0 var(--space-4); padding: 0; }

.messages li {
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  border: 1px solid var(--color-success-border);
  border-radius: var(--radius);
  background: var(--color-success-bg);
}

.messages li.error {
  border-color: var(--color-error-border);
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

/* ---- Log ---------------------------------------------------------------- */

.log { list-style: none; margin: 0 0 var(--space-5); padding: 0; }

.log-entry {
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.log-entry__meta { font-size: var(--text-sm); }
.log-entry__summary { margin: var(--space-1) 0; }

/* An undone action stays in the log, struck through. */
.log-entry--undone .log-entry__summary { text-decoration: line-through; color: var(--color-muted); }

.log-entry__notes {
  margin: var(--space-2) 0;
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-border);
  list-style: none;
}

.log-entry .form-actions { align-items: flex-start; }
.log-entry details { flex: 1; }
.log-entry summary { cursor: pointer; color: var(--color-accent); }
.log-entry details .form { margin: var(--space-2) 0 0; }

/* ---- Empty ------------------------------------------------------------- */

.empty {
  padding: var(--space-5);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  color: var(--color-muted);
  text-align: center;
}

/* ---- Units -------------------------------------------------------------- */

/* A spot static/icons/units.js fills with a unit's icon: <span class="unit-icon" data-unit-icon="...">. */
.unit-icon { display: inline-block; vertical-align: middle; line-height: 0; }
.unit-icon:empty { width: 2.5rem; height: 2.5rem; }
.icon-preview { margin-top: var(--space-2); }
.icon-cell { width: 1%; padding-top: 0; padding-bottom: 0; }

.unit-counter .counter { stroke: #222; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.unit-counter .code,
.token-badge text { text-anchor: middle; dominant-baseline: central; font-family: var(--font-body); font-weight: 700; pointer-events: none; }
.unit-counter + .cross,
.unit-counter .cross { stroke: #111; stroke-width: 3; vector-effect: non-scaling-stroke; }
.token-badge circle { stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }

/* A token on a unit's page: its colour, its name, and a button to take it off. */
.token-list { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0 0 var(--space-4); padding: 0; }
.token-list li {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}
.token-list form { margin: 0; }
.token-list button { padding: 0 var(--space-2); font-size: var(--text-sm); white-space: nowrap; }

/* A token's badge in a list: <span class="token-badge-sample" style="--badge: #e8a317; --badge-ink: #111">S</span>. */
.token-badge-sample {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0 var(--space-1);
  border: 2px solid var(--color-surface);
  border-radius: 999px;
  background: var(--badge, var(--color-muted));
  box-shadow: 0 0 0 1px var(--color-border);
  color: var(--badge-ink, #fff);
  font-size: var(--text-sm);
  font-weight: 700;
}

/* A form tucked away until asked for: <details class="form"><summary>Put a token on</summary>...</details>. */
details.form > summary { cursor: pointer; color: var(--color-accent); margin-bottom: var(--space-2); }

/* ---- Fog of war ---------------------------------------------------------
 * The "Viewing as" switch for game masters (visibility/includes/view_as.html).
 */
.view-as { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; }
.view-as label { font-weight: 600; margin: 0; }
.view-as select { width: auto; max-width: 14rem; }
.view-banner {
  padding: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-3);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

/* A playing card: <span class="playing-card is-red">7<span>♥</span></span>. Used on the cards page and the map. */
.playing-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  height: 3.5rem;
  padding: 0 var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 700;
  font-size: var(--text-lg);
  line-height: 1;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.15);
}
.playing-card.is-red { color: var(--color-card-red); }
.playing-card.is-latest { border: 2px solid var(--color-accent); }
.playing-card.is-small { min-width: 2rem; height: 2.75rem; font-size: var(--text-base); }
.card-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: var(--space-2) 0; }

/* The cards page: one section per deck. */
.deck { border-top: 1px solid var(--color-border); padding-top: var(--space-4); margin-top: var(--space-5); }
.deck h2 { margin: 0; }
.deck .hand { list-style: none; padding: 0; }
.deck .hand li { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); }
.deck .hand form { margin: 0; }
.deck .hand button { padding: 0 var(--space-2); font-size: var(--text-sm); }
.deck-draw { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 var(--space-4); }
.deck-draw .field input[type=number] { width: 5rem; }
.deck-draw .form-actions { margin: 0 0 var(--space-4); }
