:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2330; --muted: #6b7385;
  --line: #dde1e8; --accent: #0b6bcb; --accent-text: #ffffff;
  --btn: #eef1f5; --btn-hover: #e2e7ee; --canvas: #2a2e36;
  --done: #1f8a4c; --skip: #b5541c;
  --warn-bg: #b42318; --warn-text: #ffffff; --warn-line: #912018;
  --flash: #8a5a00;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c; --panel: #1c2027; --text: #e6e9ef; --muted: #8f97a8;
    --line: #2d333d; --accent: #4ea1ff; --accent-text: #0b1220;
    --btn: #262b34; --btn-hover: #2f3540; --canvas: #0e1014;
    --done: #45c27a; --skip: #e08a52;
    --warn-bg: #f2786d; --warn-text: #1b0d0c; --warn-line: #ff9e95;
    --flash: #e0a030;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c; --panel: #1c2027; --text: #e6e9ef; --muted: #8f97a8;
  --line: #2d333d; --accent: #4ea1ff; --accent-text: #0b1220;
  --btn: #262b34; --btn-hover: #2f3540; --canvas: #0e1014;
  --done: #45c27a; --skip: #e08a52;
  --warn-bg: #f2786d; --warn-text: #1b0d0c; --warn-line: #ff9e95;
  --flash: #e0a030;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; margin: 0; }
.brand span { font-weight: 400; color: var(--muted); }
.brand-group { display: flex; align-items: baseline; gap: 6px; margin-right: auto; white-space: nowrap; }
.version { font-size: 11px; color: var(--muted); text-decoration: none; font-variant-numeric: tabular-nums; }
.version:hover { color: var(--accent); text-decoration: underline; }
.tb-group { display: flex; gap: 6px; flex-wrap: nowrap; flex: none; }
.tb-util { align-items: center; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--btn); color: var(--text); padding: 6px 10px; border-radius: 6px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { background: var(--btn-hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { background: #c53030; border-color: #c53030; color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.seg { display: inline-flex; }
.seg-btn { border-radius: 0; }
.seg-btn:first-child { border-radius: 6px 0 0 6px; }
.seg-btn:last-child { border-radius: 0 6px 6px 0; }
.seg-btn + .seg-btn { border-left: none; }
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 270px; flex: none; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; overflow: hidden; }
.panel { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; border-bottom: none; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.panel h2 small { text-transform: none; letter-spacing: 0; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.field input[type=text], .field input[type=number] { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; }
.check { display: flex; gap: 6px; align-items: center; font-size: 12px; margin-bottom: 6px; }
.muted { color: var(--muted); }
.imglist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.imglist li { border-radius: 5px; font-size: 12px; }
.imglist .imgbtn { all: unset; box-sizing: border-box; width: 100%; padding: 5px 6px; border-radius: 5px; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.imglist li:hover { background: var(--btn); }
.imglist li.current { background: var(--btn-hover); font-weight: 600; }
.imglist .dot { width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--muted); flex: none; }
.imglist .dot.done { background: var(--done); border-color: var(--done); }
.imglist .dot.skip { background: var(--skip); border-color: var(--skip); }
.imglist .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.toolbar { display: flex; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.zoom-group .seg-btn { display: inline-grid; place-items: center; padding: 5px 8px; }
.nav-pos { min-width: 72px; font-variant-numeric: tabular-nums; font-weight: 600; }
.zoom-pct { min-width: 62px; font-variant-numeric: tabular-nums; font-size: 13px; }
.chip { flex: 1 1 60px; min-width: 0; max-width: 420px; padding: 4px 10px; border-radius: 999px; background: var(--btn); border: 1px solid var(--line); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:empty { display: none; }
.canvas-wrap { flex: 1; position: relative; background: var(--canvas); min-height: 0; overflow: hidden; }
.canvas-wrap.dragover { outline: 3px dashed var(--accent); outline-offset: -8px; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #c9cfda; text-align: center; padding: 16px; pointer-events: none; }
.empty .muted { color: #8f97a8; }
/* two fixed one-line rows (figures, then hint) so changing hints never resize the canvas; the file name
   is the part that shortens when space runs out */
.statusbar { display: flex; flex-wrap: wrap; column-gap: 18px; padding: 5px 12px; border-top: 1px solid var(--line); background: var(--panel); font-size: 12px; line-height: 1.45; font-variant-numeric: tabular-nums; }
.statusbar > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusbar #stFile { flex: 1 1 0; min-width: 0; }
.statusbar #stArea, .statusbar #stCursor { flex: none; }
.statusbar #stHint { flex: 0 0 100%; min-height: 1.45em; }
@media (max-width: 760px) { .statusbar #stCursor { display: none; } } /* keeps phones at two rows too */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); max-width: 760px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.help-grid h3 { font-size: 13px; margin: 10px 0 4px; }
.help-grid ul { margin: 0; padding-left: 18px; }
kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--bg); }
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 38vh; border-right: none; border-bottom: 1px solid var(--line); }
  .help-grid { grid-template-columns: 1fr; }
  .topbar { padding: 8px 16px; }
}

/* colour-theme switch: light / auto / dark, with a sliding thumb */
.theme-switch { position: relative; display: inline-grid; grid-template-columns: repeat(3, 30px); height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--btn); }
.theme-switch button { position: relative; z-index: 1; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); border-radius: 999px; cursor: pointer; padding: 0; transition: color .2s ease; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-checked="true"] { color: var(--accent-text); }
.theme-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.theme-thumb { position: absolute; top: 2px; left: 2px; width: 30px; height: 24px; border-radius: 999px; background: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .25s cubic-bezier(.4,.0,.2,1); }
.theme-switch[data-value="auto"] .theme-thumb { transform: translateX(30px); }
.theme-switch[data-value="dark"] .theme-thumb { transform: translateX(60px); }
@media (prefers-reduced-motion: reduce) { .theme-thumb, .theme-switch button { transition: none; } }

/* toolbar layout: clusters never split; they wrap to the next row as a whole */
.toolbar { gap: 8px 12px; }
.tb-cluster { display: inline-flex; align-items: center; gap: 6px; flex: none; flex-wrap: nowrap; }
.tb-end { margin-left: auto; }
.seg { flex-wrap: nowrap; }
.panel-toggle { display: none; padding: 5px 9px; }
.sidebar.collapsed { display: none; }
@media (max-width: 1000px) {
  .topbar .btn, .toolbar .btn { padding: 5px 8px; font-size: 13px; }
}
@media (max-width: 760px) {
  .panel-toggle { display: inline-block; }
  .canvas-wrap { min-height: 55vh; }
  .stage { min-height: 0; }
  .layout { overflow-y: auto; }
}
@media (max-width: 520px) {
  .chip { display: none; }
  .brand-group { width: 100%; }
}

/* autosave failure banner: floats above the canvas so it never shifts the layout */
.save-warn { position: fixed; left: 16px; right: 16px; bottom: 44px; margin: 0 auto; width: fit-content; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  max-width: 720px; padding: 10px 12px 10px 16px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text);
  border: 1px solid var(--warn-line); box-shadow: 0 6px 20px rgba(0, 0, 0, .25); font-size: 13px; line-height: 1.35; }
.save-warn[hidden] { display: none; }
.save-warn span { flex: 1 1 240px; }
.save-warn .btn { flex: none; margin-left: auto; background: var(--warn-text); color: var(--warn-bg); border-color: var(--warn-text); font-weight: 600; }

/* accessibility */
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.imglist .imgbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; } /* inside: the list clips overflow */
.statusbar #stHint.flash { color: var(--flash); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
