/* Theme: light is the default. <html data-theme> is "light", "dark" or "system" (follow the device). */
:root {
  --bg: #f6f3ee; --surface: #ffffff; --text: #1f2a28; --muted: #5a6663; --border: #e2dcd1;
  --accent: #2f5d57; --accent-text: #ffffff; --accent-soft: #e5eeeb; --clay: #b0694a;
  --bar: #2f5d57; --bar-text: #f6f3ee; --bar-active-bg: #f6f3ee; --bar-active-text: #234a45;
  --danger: #b3261e; --focus: #1b5fd1;
  --shadow: 0 1px 2px rgba(31, 42, 40, 0.06), 0 6px 18px rgba(31, 42, 40, 0.06);
  --bar-h: 56px; --gutter: 16px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121817; --surface: #1c2423; --text: #e8ecea; --muted: #a2adaa; --border: #34403e;
  --accent: #6fb7b0; --accent-text: #0e1514; --accent-soft: #24332f; --clay: #d49a7c;
  --bar: #1a2927; --bar-text: #e8ecea; --bar-active-bg: #6fb7b0; --bar-active-text: #0e1514;
  --danger: #f2837b; --focus: #8ab4ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #121817; --surface: #1c2423; --text: #e8ecea; --muted: #a2adaa; --border: #34403e;
    --accent: #6fb7b0; --accent-text: #0e1514; --accent-soft: #24332f; --clay: #d49a7c;
    --bar: #1a2927; --bar-text: #e8ecea; --bar-active-bg: #6fb7b0; --bar-active-text: #0e1514;
    --danger: #f2837b; --focus: #8ab4ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden; min-height: 100vh;
}
h1 { font-size: 1.5rem; margin: 0 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 6px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  height: var(--bar-h); padding: 0 var(--gutter); background: var(--bar); color: var(--bar-text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
}
.topbar :focus-visible { outline-color: #fff; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--bar-text); text-decoration: none; flex: 1; letter-spacing: 0.01em; }
.brand::before {
  content: ""; width: 28px; height: 28px; flex: none;
  background: url("../icons/icon.svg") center / contain no-repeat;
}
.settings-btn, .menu-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  border-radius: 50%; color: var(--bar-text); background: none; border: 0; padding: 0; cursor: pointer;
}
.settings-btn:hover, .menu-btn:hover { background: rgba(255, 255, 255, 0.14); }
.settings-btn[aria-current="page"], .menu-btn[aria-expanded="true"] { background: var(--bar-active-bg); color: var(--bar-active-text); }
.nav-top { display: none; }
.nav a { text-decoration: none; }

/* Narrow screens: the four screens are in a ☰ menu dropping down from the top bar. */
.nav-menu {
  position: absolute; top: calc(var(--bar-h) - 4px); right: var(--gutter); z-index: 20; min-width: 200px;
  display: grid; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow), 0 10px 28px rgba(0, 0, 0, 0.22);
}
.nav-menu[hidden] { display: none; }
.nav-menu a { display: flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 8px; color: var(--text); }
.nav-menu a:hover { background: var(--accent-soft); }
.nav-menu a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.main { padding: 16px var(--gutter) 32px; max-width: 1100px; margin: 0 auto; }
.main:focus { outline: none; }
.notice { margin: 0; padding: 8px var(--gutter); background: var(--accent); color: var(--accent-text); }
.notice p { margin: 0; }

.empty { border: 2px dashed var(--border); border-radius: 12px; padding: 24px 16px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 12px; box-shadow: var(--shadow); }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.confirm { border-left: 4px solid var(--danger); padding-left: 12px; margin-bottom: 12px; }
.confirm[hidden] { display: none; }
.status { min-height: 1.5em; margin: 0; }
.status.bad { color: var(--danger); }

@media (min-width: 800px) {
  .menu-btn, .nav-menu { display: none !important; }
  .nav-top { display: flex; gap: 4px; flex: 1; }
  .nav-top a {
    display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px; color: var(--bar-text); opacity: 0.88;
  }
  .nav-top a:hover { background: rgba(255, 255, 255, 0.14); opacity: 1; }
  .nav-top a[aria-current="page"] { background: var(--bar-active-bg); color: var(--bar-active-text); font-weight: 700; opacity: 1; }
  .brand { flex: 0 0 auto; margin-right: 16px; }

}
@media print { .topbar, .nav-menu { display: none; } body { background: #fff; color: #000; } }

/* ---- shared form and list pieces ---- */
.small { font-size: 0.85rem; }
.self-center { align-self: center; }
.row.tight { gap: 6px; margin-bottom: 0; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn[hidden] { display: none; }
.field-label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0 0 4px; }
.input, .select {
  min-height: 44px; padding: 0 12px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; max-width: 100%;
}
.input[aria-invalid="true"] { border-color: var(--danger); }
.select { padding-right: 8px; }

/* temperature scale */
.tscale { margin-bottom: 12px; }
.tscale-bar { position: relative; display: flex; height: 14px; border-radius: 7px; overflow: visible; }
.tscale-seg { flex: 1; opacity: 0.8; }
.tscale-seg.on { opacity: 1; }
.tscale-seg.t0 { background: #3f78b5; border-radius: 7px 0 0 7px; }
.tscale-seg.t1 { background: #7fa4c4; }
.tscale-seg.t2 { background: #b9b6ae; }
.tscale-seg.t3 { background: #d9a77a; }
.tscale-seg.t4 { background: #d1623a; border-radius: 0 7px 7px 0; }
.tscale-marker {
  position: absolute; top: -5px; width: 6px; height: 24px; margin-left: -3px; border-radius: 3px;
  background: var(--text); border: 2px solid var(--surface); box-sizing: content-box;
}
:root[data-theme="dark"] .tscale-seg.t0 { background: #5b9be0; } :root[data-theme="dark"] .tscale-seg.t1 { background: #86b3dc; }
:root[data-theme="dark"] .tscale-seg.t2 { background: #b9b6ae; } :root[data-theme="dark"] .tscale-seg.t3 { background: #e8a766; }
:root[data-theme="dark"] .tscale-seg.t4 { background: #f2683a; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .tscale-seg.t0 { background: #5b9be0; } :root[data-theme="system"] .tscale-seg.t1 { background: #86b3dc; }
  :root[data-theme="system"] .tscale-seg.t3 { background: #e8a766; } :root[data-theme="system"] .tscale-seg.t4 { background: #f2683a; }
}
.tscale-labels { display: flex; margin-top: 10px; }
.tscale-labels span { flex: 1; text-align: center; font-size: 0.7rem; line-height: 1.2; color: var(--muted); padding: 0 1px; }
.tscale-labels span.on { color: var(--text); font-weight: 700; }

.controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end; margin-bottom: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.saved-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.icon-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; flex: none;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted); cursor: pointer;
}
.icon-btn.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.room-svg { display: block; width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.ratio { display: flex; height: 44px; margin-top: 12px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.ratio-part { display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; }
.ratio-key { margin: 6px 0 4px; }
.saved { border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.saved.open { border-color: var(--accent); background: var(--accent-soft); }
.saved-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.saved-name { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.strip { display: flex; flex: none; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.strip span { width: 22px; height: 36px; }

/* dialogs */
.dlg {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: hidden;
}
.dlg[open] { display: flex; }
.dlg::backdrop { background: rgba(0, 0, 0, 0.5); }
.dlg-inner { display: flex; flex-direction: column; width: 100%; min-height: 0; padding: 16px; gap: 12px; }
.dlg-title { margin: 0; font-size: 1.15rem; }
.dlg-body { overflow-y: auto; min-height: 0; position: relative; }
.dlg-body.more { box-shadow: inset 0 -22px 14px -14px rgba(0, 0, 0, 0.35); }
.dlg-body.more::after {
  content: "Scroll for more"; position: sticky; display: block; bottom: 0; text-align: center; font-size: 0.75rem;
  color: var(--muted); padding: 10px 0 2px; background: linear-gradient(to bottom, transparent, var(--surface) 70%);
}
.field-error { color: var(--danger); font-size: 0.9rem; margin: 6px 0 0; font-weight: 600; }
.field-error::before { content: "! "; font-weight: 700; }
.field-error[hidden] { display: none; }
.dlg-mono {
  margin: 0 0 12px; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  font: 0.78rem/1.5 ui-monospace, Consolas, "Courier New", monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}
.dlg-note { font-size: 0.85rem; }
.dlg-footer { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.dlg .input { width: 100%; }

/* ---- polish ---- */
.skip-link {
  position: absolute; left: 8px; top: -100px; z-index: 100; padding: 10px 16px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.skip-link:focus { top: 8px; }
.empty-action { margin: 16px 0 0; }
.empty { margin-bottom: 12px; }
.first-run { border-color: var(--accent); }
.steps { margin: 0 0 12px; padding-left: 1.4em; display: grid; gap: 6px; }
.item-grid.defaults { margin-bottom: 12px; }
.item-grid.defaults { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-screen .card h2 { margin-bottom: 8px; }
.settings-screen .status { margin-bottom: 12px; }

/* contrast card */
.contrast-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.contrast-head h2 { margin: 0; }
.contrast-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.contrast-row { display: flex; align-items: center; gap: 8px; overflow-wrap: anywhere; }
.contrast-pair { border-top: 1px solid var(--border); padding-top: 8px; }
.contrast-pair p { margin: 0 0 4px; }
.contrast-flag { border-left: 4px solid var(--danger); background: var(--bg); padding: 6px 10px; border-radius: 0 8px 8px 0; font-size: 0.9rem; }
.flag-icon { font-weight: 700; color: var(--danger); }
.sheet-contrast .plain { margin: 0 0 4pt; padding-left: 1.2em; }

/* a warning is never colour alone: icon plus text */
.warn > p:first-child::before { content: "\26A0\FE0E  "; font-weight: 700; color: var(--danger); }
.field-err:not(:empty)::before, .status.bad::before { content: "! "; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* updates */
.update-banner, .toast {
  position: sticky; top: var(--bar-h); z-index: 9; margin: 0; padding: 10px var(--gutter);
  background: var(--accent); color: var(--accent-text); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
}
.update-banner[hidden], .toast[hidden] { display: none; }
.update-banner p, .toast p { margin: 0; flex: 1 1 14em; }
.toast a { color: inherit; font-weight: 600; }
.update-banner .row { margin: 0; }
.update-banner .btn.primary { background: var(--accent-text); color: var(--accent); border-color: var(--accent-text); }
.update-banner .btn, .toast .btn { color: var(--text); }

/* ---- swatch picker (js/ui/swatchSelect.js) ---- */
.swatch-select { position: relative; }
.ss-btn { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; text-align: left; cursor: pointer; padding: 4px 10px; }
.ss-slot { display: inline-flex; flex: none; }
.ss-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-meta { color: var(--muted); }
.ss-caret { flex: none; color: var(--muted); }
.ss-thumb { display: inline-block; flex: none; width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); }
.ss-thumb.big { width: 100%; height: 52px; border-radius: 8px; }
.ss-thumb.none { background: repeating-linear-gradient(45deg, transparent 0 4px, var(--border) 4px 6px); }
.ss-pop {
  position: absolute; z-index: 40; left: 0; top: calc(100% + 4px); width: min(460px, calc(100vw - 32px)); max-height: 340px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow), 0 10px 30px rgba(0, 0, 0, 0.22); padding: 10px;
}
.ss-pop[hidden], .ss-backdrop[hidden] { display: none; }
.ss-sheet-title { display: none; margin: 0 0 8px; font-weight: 700; }
.ss-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); outline: none; }
.ss-opt { display: flex; flex-direction: column; gap: 3px; padding: 6px; border: 2px solid var(--border); border-radius: 10px; cursor: pointer; min-width: 0; background: var(--surface); }
.ss-opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.ss-opt.active { outline: 3px solid var(--focus); outline-offset: 1px; }
.ss-label { font-size: 0.9rem; font-weight: 600; overflow-wrap: anywhere; line-height: 1.2; }
.ss-sub { font-size: 0.75rem; color: var(--muted); }
.ss-list.ss-hints { grid-template-columns: minmax(0, 1fr); }
.ss-hinted { flex-direction: row; align-items: center; gap: 10px; }
.ss-hinted .ss-thumb.big { width: 36px; height: 36px; flex: none; }
.ss-text-col { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ss-hint { font-size: 0.8rem; color: var(--muted); line-height: 1.25; }
.ss-code { font: 0.72rem/1.2 ui-monospace, Consolas, monospace; color: var(--muted); }
@media (max-width: 599px) {
  .ss-backdrop { position: fixed; inset: 0; z-index: 39; background: rgba(0, 0, 0, 0.45); }
  .ss-pop {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-height: 72dvh; border-radius: 16px 16px 0 0; z-index: 41;
    padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  }
  .ss-sheet-title { display: block; }
  .ss-list { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

/* The real <select> behind a swatch picker: fixed (so it takes no space and is skipped by layout), invisible, not focusable. */
.ss-native { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
