/* Shared styling for the tool pages. Extends the site theme in ../style.css. */

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

:root {
  --background:   #0d0d1a;
  --card:         #1a1a2e;
  --card-hover:   #22223b;
  --accent:       #f59e0b;
  --accent-light: #fbbf24;
  --text-primary: #f0f0f0;
  --text-muted:   #8888aa;
  --border:       #2a2a4a;
  --danger:       #f87171;
  --ok:           #4ade80;
  font-size: 100%;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

code, textarea, .gen-seed, .seed-input {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
}

/* ── Header ─────────────────────────────────── */
.tool-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.tool-header .home-link {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.tool-header .home-link .accent { color: var(--accent); }

.tool-header h1 {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-muted);
}

.tool-header .tool-nav {
  margin-left: auto;
  font-size: 0.875rem;
  display: flex;
  gap: 1rem;
}

.tool-header .tool-nav a {
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.tool-header .tool-nav a:hover { color: var(--accent); }

/* ── Layout ─────────────────────────────────── */
.tool-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  min-height: calc(100vh - 61px);
  align-items: start;
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem 2rem;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}

.main-panel {
  padding: 1.5rem;
  max-width: 860px;
  min-width: 0;
}

/* ── Sidebar groups ─────────────────────────── */
.side-group { margin-bottom: 1.25rem; }

.side-group h2 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.side-group ul { list-style: none; }

.side-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }

.side-item {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 0.5rem;
  text-align: left;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}

.side-item:hover { background: var(--card); }

.side-item.selected {
  background: var(--card);
  color: var(--accent-light);
  font-weight: 500;
}

.side-item .item-flag {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--danger);
}

.pack-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pack-badge.custom { background: var(--accent); color: var(--background); }

.pack-version {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

/* ── Import a pack ──────────────────────────── */
.import-drop {
  margin: 1.25rem 0;
  padding: 2rem 1.25rem;
  border: 2px dashed var(--border);
  border-radius: 10px;
  text-align: center;
}

.import-drop.dragging { border-color: var(--accent); background: var(--card); }

.import-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.import-card h3 { font-size: 1.05rem; margin-bottom: 0.35rem; }
.import-card p { margin-bottom: 0.5rem; }
.import-ok { border-left-color: var(--ok); }
.import-failed { border-left-color: var(--danger); }

.import-gens { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }

.import-card summary { cursor: pointer; color: var(--text-muted); font-size: 0.85rem; }

.import-detail {
  margin-top: 0.5rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Storage meter ──────────────────────────── */
.storage-meter { font-size: 0.75rem; }

.storage-label { color: var(--text-muted); margin-bottom: 0.35rem; font-variant-numeric: tabular-nums; }

.storage-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.storage-fill {
  height: 100%;
  background: var(--ok);
  transition: width 0.25s ease;
}

.storage-meter[data-level='warn'] .storage-fill { background: var(--accent); }
.storage-meter[data-level='critical'] .storage-fill { background: var(--danger); }

.storage-warn {
  margin-top: 0.4rem;
  line-height: 1.4;
  color: var(--accent);
}
.storage-meter[data-level='critical'] .storage-warn { color: var(--danger); }

/* ── Buttons & inputs ───────────────────────── */
.btn {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn:hover { border-color: var(--accent); background: var(--card-hover); }

.btn:disabled { opacity: 0.5; cursor: default; }
.btn:disabled:hover { border-color: var(--border); background: var(--card); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--background);
  font-weight: 700;
}

.btn-primary:hover { background: var(--accent-light); border-color: var(--accent-light); }

.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

.btn-small { font-size: 0.75rem; padding: 0.2rem 0.6rem; }

input[type='text'], input[type='number'], input[type='search'], textarea, select {
  font: inherit;
  font-size: 0.875rem;
  color: var(--text-primary);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
}

input[type='text']:focus, input[type='number']:focus, input[type='search']:focus,
textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

select { background: var(--card); }

input[type='number'] { font-variant-numeric: tabular-nums; }

/* ── Run controls ───────────────────────────── */
.run-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin: 0.75rem 0 1.25rem;
}

.seed-input { width: 11rem; }

.count-field {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem; /* matches .run-bar, so × sits midway between button and input */
  color: var(--text-muted);
  font-size: 0.9rem;
}

.count-input { width: 3.5rem; text-align: center; }

.gen-title { font-size: 1.5rem; font-weight: 700; }

.gen-subtitle { color: var(--text-muted); font-size: 0.875rem; }

.gen-seed {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ── Results ────────────────────────────────── */
.result-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  overflow-x: auto;
}

.result-panel .placeholder { color: var(--text-muted); }

.gen-text { font-size: 1.15rem; }

.gen-card { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 1.25rem; }

.gen-card dt {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-top: 0.2rem;
}

.gen-card dd { min-width: 0; }

.gen-card .gen-card {
  font-size: 0.95em;
  border-left: 2px solid var(--border);
  padding-left: 0.9rem;
  margin: 0.2rem 0;
}

.gen-list { list-style: none; }

.gen-list li { padding: 0.1rem 0; }

.gen-list li::before { content: '• '; color: var(--accent); }

/* ── Per-part reroll button ─────────────────── */
.reroll-part {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85em;
  line-height: 1;
  padding: 0 0.3rem;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
}

.gen-card dt:hover .reroll-part,
.gen-list li:hover > .reroll-part,
.reroll-part:focus-visible {
  opacity: 1;
}

.reroll-part:hover { color: var(--accent); }

/* ── Batch (generate N at once) ─────────────── */
.gen-batch { display: flex; flex-direction: column; }

.gen-batch-item {
  display: flex;
  gap: 0.9rem;
  padding: 0.9rem 0;
  border-top: 1px solid var(--border);
}

.gen-batch-item:first-child { padding-top: 0; border-top: none; }
.gen-batch-item:last-child { padding-bottom: 0; }

.gen-batch-index {
  flex: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  padding-top: 0.15rem;
  min-width: 1.25rem;
  text-align: right;
}

.gen-batch-body { min-width: 0; flex: 1; }

.error-card {
  border: 1px solid var(--danger);
  border-radius: 12px;
  background: rgba(248, 113, 113, 0.08);
  color: var(--danger);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.result-actions { display: flex; gap: 0.6rem; margin-bottom: 2rem; }

/* ── Sections ───────────────────────────────── */
.tool-section { margin-top: 2.5rem; }

.tool-section > h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.4rem; }

.hint code {
  background: var(--card);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
}

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

.sidebar > .hint { margin-bottom: 1.25rem; }

/* ── View template ──────────────────────────── */
.vt-def { min-height: 12rem; }

.vt-def[readonly] { opacity: 0.85; }

.side-item .item-flag.modified { color: var(--accent); }

/* ── Create template view ───────────────────── */
.tpl-input {
  width: 100%;
  resize: vertical;
  line-height: 1.5;
}

.save-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.tpl-name { width: 16rem; min-width: 0; }

.editor-status.warn { color: var(--accent); }

/* ── Syntax reference ───────────────────────── */
.reference-panel { max-width: 760px; }

.ref-section > h2 { border-bottom: none; padding-bottom: 0; margin-bottom: 0.35rem; }

.ref-summary { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }

.ref-example {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
}

.ref-template {
  display: inline-block;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-size: 0.9rem;
  color: var(--accent-light);
}

.ref-run {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.55rem 0 0.4rem;
}

.ref-sample { flex: 1; min-width: 0; }

.ref-sample-text { font-size: 1.05rem; }

.ref-sample-error {
  display: inline-block;
  margin: 0;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.ref-reroll { flex: none; line-height: 1; }

.ref-note { color: var(--text-muted); font-size: 0.82rem; }

/* ── Table catalog ──────────────────────────── */
.catalog-search { max-width: 22rem; flex: 1; }

.catalog-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  padding: 0.75rem 1rem;
  margin-bottom: 0.7rem;
}

.catalog-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.catalog-name {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 0.9rem;
  color: var(--accent-light);
  cursor: pointer;
}

.catalog-name:hover { border-color: var(--accent); }

.catalog-meta { color: var(--text-muted); font-size: 0.78rem; margin-left: auto; font-variant-numeric: tabular-nums; }

.catalog-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.5rem 0 0.1rem;
}

.catalog-tag {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.05rem 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Dice roller ────────────────────────────── */
.dice-panel { max-width: 720px; }

.dice-input { flex: 1; min-width: 8rem; max-width: 20rem; }

.dice-quick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.dice-quick-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 0.1rem 0.35rem;
}

.dice-total {
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--accent-light);
}

.dice-expr {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0.15rem 0 0.9rem;
}

.dice-breakdown { display: flex; flex-direction: column; gap: 0.5rem; }

.dice-term {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.dice-term-sign { color: var(--text-muted); width: 0.9rem; text-align: center; }

.dice-term-label {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 0.82rem;
  color: var(--text-muted);
  min-width: 4.5rem;
}

.dice-dice { display: flex; flex-wrap: wrap; gap: 0.3rem; flex: 1; }

.die {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.35rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--background);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.die.kept { border-color: var(--accent); color: var(--text-primary); }

.die.dropped { color: var(--text-muted); text-decoration: line-through; opacity: 0.6; }

.dice-term-subtotal { color: var(--text-muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }

.dice-history-actions { margin-bottom: 0.75rem; }

/* ── Library ────────────────────────────────── */
.library-list { list-style: none; }

.library-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--border);
}

.library-item .lib-name {
  background: none;
  border: none;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  text-align: left;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-item .lib-name:hover { color: var(--accent-light); }

.library-item .lib-meta { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ── Workshop editor ────────────────────────── */
.editor-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.editor-head .pack-name { font-size: 1.25rem; font-weight: 700; margin-right: auto; }

.editor-textarea {
  width: 100%;
  min-height: 22rem;
  resize: vertical;
  line-height: 1.5;
  font-size: 0.85rem;
  tab-size: 2;
  white-space: pre;
}

.editor-status {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
  font-size: 0.85rem;
  min-height: 1.5rem;
}

.editor-status.ok { color: var(--ok); }
.editor-status.bad { color: var(--danger); }
.editor-status .dirty-flag { color: var(--accent); }

.preview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

/* ── Toast ──────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translate(-50%, 1rem);
  background: var(--card-hover);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.5rem 1.25rem;
  font-size: 0.875rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}

.toast.toast-visible { opacity: 1; transform: translate(-50%, 0); }

/* ── Notice bar ─────────────────────────────── */
/* z-index sits one above .toast so a save toast cannot cover the notice that
   the same save triggered. */
.notice-bar {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(42rem, calc(100vw - 2rem));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--card-hover);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: var(--text-primary);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.35);
  z-index: 11;
}

.notice-bar p { margin: 0; flex: 1 1 18rem; line-height: 1.5; }

/* ── Initiative Tracker ─────────────────────── */
.init-panel { max-width: 720px; }

.init-roundbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0 1.25rem;
}

.init-round {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.init-round-label { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.init-round-num { font-size: 1.75rem; font-weight: 700; color: var(--accent); min-width: 1.5ch; font-variant-numeric: tabular-nums; }

.init-turn-controls { display: flex; gap: 0.4rem; }

/* Export / import / reset, pushed to the trailing edge of the round bar.
   Wraps to its own line on a phone rather than squeezing the turn controls. */
.init-datatools { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-left: auto; }

.init-name { flex: 1; min-width: 8rem; max-width: 18rem; }
.init-init { width: 5rem; }

.init-list { list-style: none; }

.init-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid transparent;
}

.init-row.current {
  border-left-color: var(--accent);
  background: var(--card-hover);
}

.init-row-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.init-badge {
  flex: none;
  min-width: 2rem;
  text-align: center;
  font-weight: 700;
  color: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.init-cname { font-weight: 600; margin-right: auto; }

.init-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.init-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.init-chip-x {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
}
.init-chip-x:hover { color: var(--danger); }

.init-controls { display: flex; gap: 0.3rem; flex: none; }

.init-cond-form {
  display: none;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}
.init-cond-form.open { display: flex; flex-wrap: wrap; align-items: center; }
.init-cond-name { flex: 1; min-width: 7rem; max-width: 14rem; }
.init-cond-rounds { width: 4rem; }

.init-empty { padding: 1rem 0.25rem; }

/* ── Game Timer ─────────────────────────────── */
.timer-panel { max-width: 620px; }

.timer-clock {
  position: relative;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  padding: 1.5rem 1rem 1.25rem;
  margin: 1rem 0 1.25rem;
  transition: border-color 0.2s, background 0.2s;
}

.timer-round {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}
.timer-round-label { color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; }
.timer-round-num { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }

.timer-active-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  min-height: 1.4rem;
}

.timer-readout {
  font-size: 3.75rem;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--accent-light);
}
.timer-readout-label { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }

.timer-clock.over {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, var(--card));
}
.timer-clock.over .timer-readout { color: var(--danger); }

.timer-transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.timer-pass { font-size: 1.05rem; padding: 0.6rem 1.4rem; }
/* Export / import / new game, pushed to the trailing edge of the transport row.
   Wraps to its own line on a phone rather than squeezing the turn controls. */
.timer-datatools { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-left: auto; }

.timer-settings { align-items: center; margin-bottom: 0.75rem; }
.timer-field { display: flex; align-items: center; gap: 0.5rem; color: var(--text-muted); font-size: 0.85rem; }
.timer-secs { width: 5rem; }
.timer-sound { display: flex; align-items: center; gap: 0.35rem; color: var(--text-muted); font-size: 0.85rem; cursor: pointer; }

.timer-name { flex: 1; min-width: 8rem; max-width: 18rem; }

.timer-list { list-style: none; }

.timer-prow {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid transparent;
}
.timer-prow.active {
  border-left-color: var(--accent);
  background: var(--card-hover);
}

.timer-pname {
  flex: 1;
  min-width: 6rem;
  font-weight: 600;
  background: transparent;
  border-color: transparent;
}
.timer-pname:hover { border-color: var(--border); }
.timer-pname:focus { background: var(--background); border-color: var(--accent); }

.timer-ptotal {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.timer-pcontrols { display: flex; gap: 0.3rem; flex: none; }

.timer-empty { padding: 1rem 0.25rem; }

/* ── Score Tracker ──────────────────────────── */
.score-panel { max-width: 860px; }

.score-bar { align-items: center; }
.score-field { display: flex; align-items: center; gap: 0.5rem; }
.score-field-label { color: var(--text-muted); font-size: 0.85rem; }
.score-sheet-name { flex: 1; min-width: 8rem; max-width: 16rem; font-weight: 600; }
.score-delete { margin-left: auto; }

.score-grid-wrap { overflow-x: auto; margin-bottom: 1.25rem; }
.score-empty { color: var(--text-muted); padding: 1.25rem 0.25rem; }

.score-table {
  border-collapse: collapse;
  width: 100%;
}
.score-table th, .score-table td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.5rem;
  text-align: center;
  vertical-align: middle;
}
.score-corner {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.score-total-head {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.score-chead { min-width: 6.5rem; background: var(--card); }
.score-cname {
  width: 100%;
  min-width: 4.5rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.85rem;
  background: transparent;
  border-color: transparent;
}
.score-cname:hover { border-color: var(--border); }
.score-cname:focus { background: var(--background); border-color: var(--accent); }
.score-chead-ctrls { display: flex; justify-content: center; gap: 0.2rem; margin-top: 0.3rem; }

.score-pname-cell { text-align: left; background: var(--card); min-width: 9rem; }
.score-pname {
  min-width: 6rem;
  font-weight: 600;
  background: transparent;
  border-color: transparent;
}
.score-pname:hover { border-color: var(--border); }
.score-pname:focus { background: var(--background); border-color: var(--accent); }
.score-pctrls { display: flex; gap: 0.2rem; margin-top: 0.3rem; }

.score-cell {
  width: 3.75rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0.3rem 0.35rem;
}
.score-cell-td { padding: 0.2rem; }

.score-total {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-light);
  min-width: 3.5rem;
}

.score-prow.leader .score-pname-cell { border-left: 3px solid var(--accent); }
.score-prow.leader .score-total { color: var(--accent); }

.score-controls { align-items: center; }
.score-add { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.score-add-name { min-width: 8rem; }

/* ── Site pages (Your data, Privacy) ────────── */
.page-panel { max-width: 760px; margin: 0 auto; }

.page-text, .prose p { margin-bottom: 1rem; }

.page-list, .prose ul { padding-left: 1.25rem; margin-bottom: 1rem; }
.page-list li, .prose li { margin-bottom: 0.5rem; }

.prose h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 2rem 0 0.5rem;
}

.prose a, .page-panel p a, .page-list a { color: var(--accent); }

.prose code {
  background: var(--card);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
}

.data-table-wrap { overflow-x: auto; margin-bottom: 1rem; }

.data-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }

.data-table th, .data-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.data-table a { color: var(--accent); text-decoration: none; }
.data-table a:hover { text-decoration: underline; }

.data-detail { color: var(--text-muted); }
.data-size { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }

.page-panel .placeholder { color: var(--text-muted); margin-bottom: 1rem; }

.data-meter { max-width: 320px; }

.data-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; }

.restore-plan {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

.restore-plan h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.restore-plan .data-actions { margin: 0.75rem 0 0; }

/* ── Site footer (every page) ───────────────── */
.site-footer {
  text-align: center;
  padding: 2rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.site-footer nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin-bottom: 0.5rem;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.25rem 0;
}

.site-footer a:hover,
.site-footer a:focus-visible { color: var(--accent); }

.tool-layout + .site-footer { border-top: 1px solid var(--border); }

/* ── Dialog (confirmDialog / promptDialog in ui.js) ── */
.dialog {
  margin: auto;
  width: min(26rem, calc(100% - 2rem));
  padding: 1.25rem;
  color: var(--text-primary);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.dialog-message { margin-bottom: 1rem; line-height: 1.5; }

.dialog-input { width: 100%; margin-bottom: 1rem; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

.dialog .btn-danger { border-color: var(--danger); color: var(--danger); }

/* ── Autocomplete (autocomplete.js) ─────────── */
.ac-wrap { position: relative; }

.ac-list {
  position: absolute;
  z-index: 20;
  min-width: 220px;
  max-width: 320px;
  max-height: 16rem;
  overflow-y: auto;
  list-style: none;
  padding: 0.25rem;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.ac-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
}

.ac-item[aria-selected='true'] { background: var(--card-hover); color: var(--accent); }

.ac-value { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; }

.ac-detail { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; }

@media (pointer: coarse) {
  .ac-item { padding: 0.6rem; }
}

/* ── Focus ──────────────────────────────────── */
/* One visible ring for keyboard users everywhere; text inputs keep their
   accent border instead (see the input rules above). */
button:focus-visible,
a:focus-visible,
summary:focus-visible,
input[type='checkbox']:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Sidebar toggle (phones only; see wireSidebarToggle in ui.js) ── */
.sidebar-toggle { display: none; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 820px) {
  .tool-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  /* The nav takes its own row and scrolls, rather than the whole page. */
  .tool-header { flex-wrap: wrap; row-gap: 0.35rem; padding: 0.75rem 1rem; }
  .tool-header .tool-nav {
    margin-left: 0;
    width: 100%;
    overflow-x: auto;
    gap: 1.25rem;
  }

  .main-panel { padding: 1.25rem 1rem; }

  .sidebar-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: calc(100% - 2rem);
    margin: 0.75rem 1rem 0;
  }
  .sidebar-toggle::after { content: '▾'; }
  .sidebar-toggle[aria-expanded='true']::after { content: '▴'; }
  .sidebar.collapsible.collapsed { display: none; }
}

/* Phones: a label column would take a third of the width, so each label
   sits above its value instead. */
@media (max-width: 480px) {
  .gen-card { grid-template-columns: 1fr; gap: 0; }
  .gen-card dd { margin-bottom: 0.6rem; }
  .gen-card dt { padding-top: 0; }
  .result-panel { padding: 1rem; }
}

/* ── Touch ──────────────────────────────────── */
/* Bigger hit areas only where the pointer is a finger; mouse layouts are
   unchanged. 44px is the common platform minimum. */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn-small { min-height: 36px; }
  input[type='text'], input[type='number'], input[type='search'], select { min-height: 44px; }
  input[type='checkbox'] { width: 1.25rem; height: 1.25rem; }
  .side-item { padding: 0.6rem 0.6rem; }
  .tool-header .tool-nav a,
  .tool-header .home-link { padding: 0.5rem 0; }
  .site-footer a { padding: 0.6rem 0.25rem; }
  .reroll-part { min-width: 32px; min-height: 32px; }
  .ref-reroll { min-width: 40px; min-height: 40px; }
}

/* No hover on touch screens, so hover-revealed controls must just show. */
@media (hover: none) {
  .reroll-part { opacity: 0.6; }
}
