/* Shared design system: light/dark modes, surface palettes, accents and controls. */
:root {
  --ui-scale: 1;
  --font: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --surface-3: #eceef2;
  --border: #e3e6ec;
  --border-strong: #cfd4dc;
  --text: #1b1e24;
  --text-2: #4a5160;
  --muted: #626b7a;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow: 0 2px 6px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.1);
  --shadow-lg: 0 12px 48px rgba(16, 24, 40, 0.2);
  --danger: #e03131;
  --danger-fg: #ffffff;
  --danger-bg: #fff0f0;
  --ok: #2f9e44;
  --warn: #f08c00;
  --tip-bg: #1b1e24;
  --tip-fg: #ffffff;
  --accent: #4f46e5;
  --accent-2: #4338ca;
  --accent-soft: #eef0ff;
  --accent-fg: #ffffff;
}
[data-accent='blue'] { --accent: #1864ab; --accent-2: #14558f; --accent-soft: #e7f2fd; }
[data-accent='teal'] { --accent: #0b7285; --accent-2: #095c6b; --accent-soft: #e3f7f9; }
[data-accent='green'] { --accent: #237032; --accent-2: #1c5a28; --accent-soft: #e8f6ea; }
[data-accent='orange'] { --accent: #ba4306; --accent-2: #9c3805; --accent-soft: #fff1e6; }
[data-accent='rose'] { --accent: #b8265a; --accent-2: #9c204c; --accent-soft: #fdebf1; }
[data-accent='violet'] { --accent: #7048e8; --accent-2: #5f3dc4; --accent-soft: #f1edfe; }

[data-theme='dark'] {
  --bg: #121418;
  --surface: #1c1f25;
  --surface-2: #23272e;
  --surface-3: #2c313a;
  --border: #2f343d;
  --border-strong: #3d434e;
  --text: #e9ecf1;
  --text-2: #bcc3ce;
  --muted: #a0a9b8;
  --danger: #ff8787;
  --danger-fg: #121418;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 56px rgba(0, 0, 0, 0.55);
  --danger-bg: #3a1d1f;
  --tip-bg: #e9ecf1;
  --tip-fg: #121418;
  --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
}
[data-theme='dark'][data-accent] { --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent); }

[data-theme='dark'][data-accent='indigo'] { --accent: #aaa5ff; --accent-2: #c3bfff; }
[data-theme='dark'][data-accent='blue'] { --accent: #74c0fc; --accent-2: #a5d8ff; }
[data-theme='dark'][data-accent='teal'] { --accent: #66d9e8; --accent-2: #99e9f2; }
[data-theme='dark'][data-accent='green'] { --accent: #8ce99a; --accent-2: #b2f2bb; }
[data-theme='dark'][data-accent='orange'] { --accent: #ffc078; --accent-2: #ffd8a8; }
[data-theme='dark'][data-accent='rose'] { --accent: #faa2c1; --accent-2: #fcc2d7; }
[data-theme='dark'][data-accent='violet'] { --accent: #c0aaff; --accent-2: #d0bfff; }
[data-theme='dark'][data-accent] { --accent-fg: #121418; }

/* Palettes tint the interface, not shared board paper, ink or graph curves. */
[data-palette='ocean'] {
  --bg: #e6f0f7; --surface: #f7fbff; --surface-2: #edf5fc; --surface-3: #dceaf5;
  --border: #c9dce9; --border-strong: #a9c2d5;
  --text: #152d40; --text-2: #354f64; --muted: #536b80;
}
[data-palette='forest'] {
  --bg: #e7efe8; --surface: #f8fcf8; --surface-2: #eff5ef; --surface-3: #dfeade;
  --border: #cddccc; --border-strong: #afc5af;
  --text: #203326; --text-2: #405c47; --muted: #596e5e;
}
[data-palette='sandstone'] {
  --bg: #f1e9dd; --surface: #fffbf5; --surface-2: #f8f1e7; --surface-3: #ece0d0;
  --border: #e1d1bc; --border-strong: #c9b596;
  --text: #382b20; --text-2: #63503c; --muted: #78634b;
}
[data-theme='dark'][data-palette='ocean'] {
  --bg: #0c1c2b; --surface: #142a3c; --surface-2: #1b354a; --surface-3: #254258;
  --border: #2b4a60; --border-strong: #45677e;
  --text: #edf6ff; --text-2: #caddea; --muted: #a5bdcf;
}
[data-theme='dark'][data-palette='forest'] {
  --bg: #111f18; --surface: #1b2e23; --surface-2: #243b2c; --surface-3: #304b38;
  --border: #36513e; --border-strong: #516e59;
  --text: #eff9ef; --text-2: #cedfce; --muted: #afc5b1;
}
[data-theme='dark'][data-palette='sandstone'] {
  --bg: #241c16; --surface: #32271f; --surface-2: #403226; --surface-3: #51402f;
  --border: #584534; --border-strong: #7d654b;
  --text: #fff4e5; --text-2: #e6d4bb; --muted: #cdb695;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }
svg { flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 500 14px var(--font);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, transform 0.06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-fg); }
.btn-danger:hover { filter: brightness(0.93); background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.active, .icon-btn[aria-pressed='true'] { background: var(--accent-soft); color: var(--accent); }
.icon-btn:disabled { opacity: 0.4; cursor: default; background: transparent; }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- forms ---------- */
.input, select.input, textarea.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 14px var(--font);
  transition: border-color 0.12s, box-shadow 0.12s;
}
textarea.input { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.field .interface-scale-help { font-size: 12px; color: var(--muted); font-weight: 400; }
.row { display: flex; gap: 12px; align-items: center; }
.row > .field { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--text-2); font: 500 13px var(--font);
  height: 30px; padding: 0 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.seg button svg { width: 16px; height: 16px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.theme-controls .seg { flex-wrap: wrap; }
.interface-scale-row { display: flex; align-items: center; gap: 8px; }
.interface-scale-row.scale-pinned {
  position: fixed; inset: auto; margin: 0; padding: 0; border: 0;
  left: var(--scale-anchor-x); top: var(--scale-anchor-y); width: var(--scale-anchor-width);
  zoom: calc(var(--scale-anchor-zoom) / var(--ui-scale));
  background: var(--surface); color: var(--text); overflow: visible; z-index: 1200;
}
.interface-scale-row .btn { width: 36px; height: 36px; padding: 0; flex: none; }
.interface-scale-value { min-width: 3.5em; text-align: center; font-variant-numeric: tabular-nums; }
.error-box { background: var(--danger-bg); color: var(--danger); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }

/* ---------- modal ---------- */
dialog.modal {
  zoom: var(--ui-scale);
  border: 0;
  padding: 0;
  border-radius: 16px;
  width: min(460px, calc(100vw / var(--ui-scale) - 24px));
  max-height: calc(100dvh / var(--ui-scale) - 24px);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
dialog.modal:not([open]) { display: none; }
dialog.modal-wide { width: min(820px, calc(100vw / var(--ui-scale) - 24px)); }
dialog.modal::backdrop { background: rgba(15, 18, 25, 0.42); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: pop 0.16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 16px 16px 8px 20px; }
.modal-title { flex: 1; font-size: 17px; font-weight: 650; }
.modal-body { padding: 8px 20px 16px; overflow: auto; min-height: 0; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 1000; pointer-events: none; }
.toast {
  background: var(--tip-bg); color: var(--tip-fg); padding: 10px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; max-width: 90vw;
}
.toast.in { opacity: 1; transform: none; }
.toast-error { background: var(--danger); color: var(--danger-fg); }
.toast-ok { background: var(--ok); color: #fff; }

/* ---------- tooltips (data-tip, optional data-key) ---------- */
.tip {
  position: fixed; z-index: 1100; pointer-events: none; background: var(--tip-bg); color: var(--tip-fg);
  font: 500 12.5px var(--font); padding: 6px 9px; border-radius: 8px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; white-space: nowrap; opacity: 0; transition: opacity 0.1s;
}
.tip.in { opacity: 1; }
.tip kbd {
  font: 600 11px var(--font); padding: 2px 6px; border-radius: 5px;
  background: color-mix(in srgb, var(--tip-fg) 18%, transparent); color: var(--tip-fg);
}

/* ---------- grades ---------- */
.grade {
  display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 24px; padding: 0 7px;
  border-radius: 7px; font-weight: 700; font-size: 13px; color: #fff; background: #adb5bd;
}
.grade-1 { background: #e03131; }
.grade-2 { background: #f76707; }
.grade-3 { background: #f59f00; }
.grade-4 { background: #74b816; }
.grade-5 { background: #2f9e44; }
.grade-6 { background: #0c8599; }
.grade-none { background: var(--surface-3); color: var(--muted); }

/* ---------- misc ---------- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: 12px; color: #fff; flex: none; border: 2px solid var(--surface);
}
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-3); color: var(--text-2); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-live { background: #e6f7ea; color: #2b8a3e; }
[data-theme='dark'] .badge-live { background: #1d3a26; color: #69db7c; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong); cursor: pointer; padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px var(--accent); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
