/* Theme colours come from the ui-kit tokens (--pk-*), which switch with <html data-theme>.
   This file only maps them onto the app's variables; shared component geometry stays here. */
@import url('../ui-kit/tokens.css');

/* One mapping for every theme: the tokens change, the mapping does not. */
:root {
  color-scheme: light;
  --paper: var(--pk-bg); --sheet: var(--pk-panel-top); --ink: var(--pk-ink); --ink-2: var(--pk-muted);
  --rule: var(--pk-line); --wash: var(--pk-selected); --pen: var(--pk-accent); --red-line: var(--pk-line);
  --red: var(--pk-red); --green: var(--pk-green);
  --good-bg: var(--pk-green-bg); --help-bg: var(--pk-amber-bg); --bad-bg: var(--pk-red-bg);
  --rail-surface: var(--pk-sidebar); --rail-ink: var(--pk-sidebar-ink); --rail-muted: var(--pk-sidebar-muted);
  --rail-active: var(--pk-selected); --rail-active-ink: var(--pk-ink);
  --action: var(--pk-accent); --action-ink: var(--pk-on-accent); --action-hover: var(--pk-accent-hover);
  /* No token of their own; derived so that every theme follows its tokens.
     rule-strong: control borders, between the kit's line-strong and muted text (>= 3:1 on the sheet).
     grid: squared-page lines, a light rule. amber: pk-amber with a little ink, so ± text keeps
     4.5:1 on the amber background. amber-line: the help bar and warn borders, a softer amber. */
  --rule-strong: color-mix(in srgb, var(--pk-line-strong) 50%, var(--pk-muted));
  --grid: color-mix(in srgb, var(--pk-line) 55%, var(--pk-panel-top));
  --amber: color-mix(in srgb, var(--pk-amber) 85%, var(--pk-ink));
  --amber-line: color-mix(in srgb, var(--pk-amber) 80%, var(--pk-panel-top));
  /* Shadows are geometry as much as colour; the kit's --pk-shadow has another shape, so they stay per theme. */
  --elevation: 0 8px 24px -16px #25385865; --surface-radius: 12px; --r: 8px;
}
:root[data-theme="archive"] {
  /* The archive rail is dark and the kit's selected colour is light: keep the accent tab with light text. */
  --rail-active: var(--pk-accent); --rail-active-ink: var(--pk-on-accent);
  --font-ui: "Literata", Georgia, serif; --font-task: "Literata", Georgia, serif;
  --elevation: 0 9px 22px -14px #51433670;
}
:root[data-theme="night"] {
  color-scheme: dark;
  /* Links, focus and accent-color follow the kit's coral accent (6.8:1 on the background, 5.8:1 on cards). */
  /* The kit's on-accent is white, 2.2:1 on the coral button; the night background reads 6.8:1. */
  --action-ink: var(--pk-bg);
  --elevation: 0 10px 26px -16px #000c;
  --font-task: "Golos Text", "Segoe UI", sans-serif;
}
html { accent-color: var(--pen); }
::selection { background: var(--wash); color: var(--ink); }
::placeholder { color: var(--ink-2); }
.view { max-width: 90rem; width: 100%; }
.rail { background: var(--rail-surface); border-color: var(--red-line); }
.rail .brand, .rail-nav a { color: var(--rail-ink); }
.rail .rail-note { color: var(--rail-muted); }
.rail-nav a[aria-current] { background: var(--rail-active); color: var(--rail-active-ink); border-color: transparent; border-radius: var(--r); }
.rail-nav a:hover { background: var(--rail-active); color: var(--rail-active-ink); }
/* Keyboard focus in the rail: the general --pen ring lies on the rail and is 1.6:1 there in the archive
   (and 1:1 on its accent tab). The ring takes the rail's text colour instead, readable on the rail and on
   the active/hovered tab in every theme: porcelain 13.4:1 / 13.0:1, archive 12.0:1 / 7.7:1, night 14.7:1 / 9.9:1. */
.rail .brand:focus-visible, .rail-nav a:focus-visible { outline-color: var(--rail-ink); }
/* The bottom navigation (narrow screen) is pinned to the window's bottom edge and its tabs fill it edge to edge:
   a ring outside a tab would cross the rail's top onto the page (1:1 on the archive's light cards) and be cut
   by the window; a ring inside would run through "Оформление" and its backup dot, which fill the whole tab
   from edge to edge on a phone. So the focus mark there is two lines across the tab, 4px inside its top and
   bottom: they stay on the tab's own fill (contrast as above), clear of the label and the dot, which sit
   centred with 13px or more above and below. Borders survive forced-colours mode, so the mark does too. */
@media (width < 60rem) {
  .rail-nav a { position: relative; }
  .rail-nav a:focus-visible { outline: none; }
  .rail-nav a:focus-visible::before {
    content: "";
    position: absolute;
    inset: 4px;
    border-block: 2px solid var(--rail-ink);
    pointer-events: none;
  }
}
/* Backup reminder dot: the tab's own text colour, visible on the rail, on hover and on the active tab. */
.rail-nav a[data-due]::after { background: currentColor; }
.btn { box-shadow: 0 2px 4px -3px #18223870; }
.btn--primary, .seg-opt input:checked + span { background: var(--action); color: var(--action-ink); border-color: var(--action); }
/* Focus on the chosen option: the inset ring sits on the --action fill, where the --pen ring (= --action) vanishes.
   The ring takes the option's text colour instead, so it reads like its label: 5.4:1 porcelain, 7.6:1 archive,
   6.8:1 night, with --action on both sides of it. Unchosen options keep the --pen ring on the sheet. */
.seg-opt input:checked:focus-visible + span { outline-color: var(--action-ink); }
.btn--primary:hover { background: var(--action-hover); }
.btn--danger:hover { background: var(--bad-bg); }
.notice { background: var(--help-bg); }
.mark--help { color: var(--amber); }
.slot--paid, .mark-btn[aria-pressed="true"][data-mark="self"] { background: var(--good-bg); }
.slot--due, .mark-btn[aria-pressed="true"][data-mark="error"] { background: var(--bad-bg); }
.mark-btn[aria-pressed="true"][data-mark="help"] { background: var(--help-bg); }
.dropzone:hover, .dropzone--over { background: var(--wash); }
.toast { background: var(--action); color: var(--action-ink); }
.rows { background: var(--sheet); padding: 0 1rem; border: 0; border-radius: var(--surface-radius); box-shadow: var(--elevation); }
.row:last-child { border-bottom: 0; }
.rows .row--link:hover, .rows .row--picked { box-shadow: none; }
.page { box-shadow: var(--elevation); border-radius: var(--surface-radius); }
.appearance-settings { padding: 1.25rem; background: var(--sheet); border-radius: var(--surface-radius); box-shadow: var(--elevation); }
.appearance-settings > p { margin-top: .5rem; }
.theme-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin: 1.25rem 0; }
.theme-card { display: flex; flex-direction: column; min-width: 0; padding: .65rem; background: var(--paper); border: 2px solid transparent; border-radius: var(--surface-radius); cursor: pointer; }
.theme-card:has(input:checked) { border-color: var(--pen); }
.theme-card:has(input:focus-visible) { outline: 2px solid var(--pen); outline-offset: 3px; }
.theme-preview { display: block; width: 100%; height: auto; aspect-ratio: 8 / 5; object-fit: contain; border-radius: 6px; background: var(--paper); }
.theme-choice-line { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; min-height: 44px; padding: .5rem .25rem; }
.theme-choice-line input { width: 1.125rem; height: 1.125rem; flex: 0 0 auto; }
.theme-choice-status { margin-left: auto; font: 500 .8125rem/1.4 "Golos Text", sans-serif; color: var(--ink-2); }
.theme-description { display: block; color: var(--ink-2); font-size: .875rem; padding: 0 .25rem .5rem; }
@media (max-width: 46rem) { .theme-options { grid-template-columns: 1fr; } .theme-preview { max-height: 13rem; } .rail-nav a { font-size: .75rem; } }
@media (min-width: 60rem) { .rail { box-shadow: 4px 0 22px -20px #18223880; } .view { padding: 2rem 2.25rem; } }
/* Import cropping sits on a white scanned page: the night's coral pen is 2.2:1 there,
   so the frame, number and delete button use the dark blue of the night tokens (7.5:1, white text 7.5:1). */
:root[data-theme="night"] .crop-rect { border-color: var(--pk-blue-bg); }
:root[data-theme="night"] .crop-num, :root[data-theme="night"] .crop-del { background: var(--pk-blue-bg); color: var(--pk-on-accent); }
/* Student-facing paper stays legible in a dark editor. The night tokens have no light colours,
   so this sheet (and print below) keeps its own fixed light palette, control borders included:
   --rule-strong is set here (3.6:1 on white) instead of being derived from the night tokens (2.3:1). */
:root[data-theme="night"] .page {
  --sheet: #fff; --ink: #1b2a4a; --ink-2: #52617b; --rule: #d1dbe9; --rule-strong: #79879f;
  --grid: #e6edf6; --wash: #e1e9fc; --pen: #3f57c6; --red-line: #ccd6e9;
  --red: #af2e40; --green: #256346; --amber: #805415; --amber-line: #b5802b;
  --good-bg: #e4f3ea; --help-bg: #fbf0d9; --bad-bg: #fbe6e8;
  color: var(--ink); color-scheme: light;
}
@media print {
  :root[data-theme] { color-scheme: light; --paper: #fff; --sheet: #fff; --ink: #000; --ink-2: #333; --rule: #ccc; --grid: #eee; --pen: #000;
    --red: #af2e40; --green: #256346; --amber: #805415; --wash: #e1e9fc;
    --good-bg: #e4f3ea; --help-bg: #fbf0d9; --bad-bg: #fbe6e8; }
  .appearance-settings { display: none !important; }
  .page { border-radius: 0; box-shadow: none; color: #000; }
  .sheet-sub, .sheet-title, .task-text, .answers { color: #000; }
}
