/* The page's tokens and the styles every component shares. Adopted by the
   document and by each component's shadow root.

   Each colour is light-dark(light, dark): the page's color-scheme picks one.
   It follows the system, unless Appearance in the settings sets data-theme
   on the root (app/appearance.js). */

:root {
  color-scheme: light dark;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  --text: light-dark(#1d1d1f, #f5f5f7);
  --muted: light-dark(#6e6e73, #a1a1a6);
  --line: light-dark(#e3e3e8, #3a3a3e);
  --track: light-dark(#f0f0f3, #2a2a2d);
  --surface: light-dark(#ffffff, #1c1c1e);
  --page: light-dark(#fbfbfd, #111113);
  --accent: light-dark(#2f7fd6, #5ea3ec);
  --highlight: light-dark(#fff1a8, #6b5d12);
  --error: light-dark(#c62828, #ef6b6b);
  /* A note's pages are photos of paper: dimmed a little in the dark. */
  --paper: light-dark(#ffffff, #d9d9d6);
  --dim: light-dark(transparent, rgb(0 0 0 / 0.18));
  --serif: "New York", ui-serif, Georgia, "Times New Roman", serif;
  /* The window's bar (a row; the whole bar, measured by app-bar.js, is
     taller on a phone with the tools under it) and the sidebar beside the page. */
  --bar-row: 3.25rem;
  /* A favourite's star. */
  --star: light-dark(#e3a600, #f5c242);
  /* A media guide's notes, by kind (now-playing): idioms and expressions, words, dialect, misheard, culture. */
  --gloss-idiom: light-dark(#c77700, #f2b544);
  --gloss-word: light-dark(#2e7d32, #9ccc65);
  --gloss-dialect: light-dark(#2f7fd6, #7cc4ff);
  --gloss-heard: light-dark(#c62828, #ff8a7a);
  --gloss-culture: light-dark(#8e24aa, #ce93d8);
  /* Every element carrying a gloss's kind gets its colour as --gloss. */
  --gloss: var(--gloss-idiom);
  /* The syntax page's relations, by family (DeprelStyle.swift; syntax-glossary.js family). */
  --rel-core: light-dark(#1f6fd1, #5ea3ec);
  --rel-clause: light-dark(#8a3fc7, #c08af0);
  --rel-mod: light-dark(#2e8b3d, #6fcf7c);
  --rel-function: light-dark(#c26a00, #f0a94a);
  --rel-conj: light-dark(#13878a, #4fc7c9);
  --rel-punct: light-dark(#8e8e93, #8e8e93);
  --rel-other: var(--muted);
  --bar-height: var(--bar-row);
  --sidebar-width: 16.5rem;
  /* The sidebar slim: its places' icons alone. */
  --sidebar-slim: 3.6rem;
  /* What's under the pointer, pressed, or chosen (as SwiftUI's): a tint behind it, never
     an underline. Hover only where there's a pointer (@media (hover: hover)). */
  --hover-tint: color-mix(in srgb, var(--text) 5%, transparent);
  --press-tint: color-mix(in srgb, var(--text) 11%, transparent);
  --selected-tint: color-mix(in srgb, var(--accent) 10%, transparent);
  /* A link in text: the accent; under the pointer, a little darker. */
  --link-hover: color-mix(in srgb, var(--accent) 72%, var(--text));
  /* The page's side padding (app-shell's main), which a list's rows reach out over. */
  --page-pad: 1.5rem;
  /* Lists (list-view, list-row): a row's height and the pictures' sizes, one set for all. */
  --row-pad-y: 0.75rem;
  --row-gap: 0.85rem;
  --row-icon: 1.25rem;
  --row-picture-portrait: 3.4rem 4.5rem;
  --row-picture-wide: 6.4rem 3.6rem;
  --row-picture-square: 3.6rem 3.6rem;
}
@media (max-width: 760px) {
  :root { --page-pad: 1rem; }
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
}
/* Pages without the app shell, such as the 404 page. */
body > main { max-width: 40rem; margin: 0 auto; padding: 3rem 1rem; }

/* A rating's colour, as the app's: Again red, Hard orange, Good green, Easy blue.
   Set data-rating on the row; the text and rules in it use var(--rating). */
[data-rating="1"] { --rating: light-dark(#d70015, #ff6961); }
[data-rating="2"] { --rating: light-dark(#c75300, #ffa94d); }
[data-rating="3"] { --rating: light-dark(#248a3d, #4cd964); }
[data-rating="4"] { --rating: light-dark(#0062cc, #5ea3ec); }

/* Levels: the "green to violet" palette, neighbouring levels in neighbouring colours. */
[data-level="A1"] { --level: #7cb518; }
[data-level="A2"] { --level: #3fa34d; }
[data-level="B1"] { --level: #119e8a; }
[data-level="B2"] { --level: #2f7fd6; }
[data-level="C1"] { --level: #5a55d6; }
[data-level="C2"] { --level: #9a4fcf; }

:host { display: block; }
[hidden] { display: none !important; }

/* Links, as SwiftUI's: none underlined. One in text (the inline renderer's, or any with no
   class of its own) is the accent's tint, darker under the pointer, dimmed while pressed,
   the hand over it; a link that's a control (a row, a tool, a chip: it has a class) is
   the arrow, as the Mac's buttons are, and shows its state by a tint behind it. */
a { color: inherit; text-decoration: none; }
a[class] { cursor: default; }
a[href]:not([class]), a.link, button.link { color: var(--accent); }
@media (hover: hover) {
  a[href]:not([class]):hover, a.link:hover, button.link:hover { color: var(--link-hover); }
}
a[href]:not([class]):active, a.link:active, button.link:active { opacity: 0.55; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.6rem; }
ul { list-style: none; margin: 0; padding: 0; }

button, input {
  font: inherit;
  color: inherit;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
}
button { cursor: default; }
/* Pressed: a tint over whatever it is, held while the press lasts. */
button:not(:disabled):active { box-shadow: inset 0 0 0 100vmax var(--press-tint); }
button.primary { background: var(--text); color: var(--surface); border-color: var(--text); }
button.link { border: none; padding: 0; background: none; }
button.link:not(:disabled):active { box-shadow: none; }
button:disabled { opacity: 0.5; cursor: progress; }
input { min-width: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Only what's learnt is text to select (as an app's): a card's, an article's, an example's,
   a transcript's words. The app's own chrome isn't: its buttons, tools, chips, tabs,
   menus, labels and titles, the bar, the sidebar, a list's rows (list-row) and headings.
   What's typed in is, of course. A word that's a button in learning text (an analysed
   sentence's, a tree's) takes it back (.selectable). */
button, summary, label, select, option, th,
[role="button"], [role="tab"], [role="menuitem"],
.tool, .chip, .badge, .large-title, .group-heading, .pill, .tab {
  -webkit-user-select: none;
  user-select: none;
}
input, textarea, [contenteditable]:not([contenteditable="false"]), .selectable {
  -webkit-user-select: text;
  user-select: text;
}

/* A part may set --mark for its marks (the dictionary's cards: lighter). */
mark { background: var(--mark, var(--highlight)); color: inherit; border-radius: 2px; }

.muted { color: var(--muted); }
/* A page's own big title, on a phone, which the window's bar shows small once
   it has scrolled under it; beside the sidebar the bar shows the title. */
.large-title { font-size: 1.9rem; margin: 0.25rem 0 0.75rem; }
@media (min-width: 761px) {
  .large-title { display: none; }
}
/* The tools a page hands the window's bar: hidden until moved there. */
[data-ref="tools"] { display: none; }
.error { color: var(--error); }
.number { color: var(--muted); font-size: 0.85em; font-variant-numeric: tabular-nums; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

/* A level as a small tag in its colour; set data-level on it. */
.badge {
  display: inline-block;
  padding: 0 0.4rem;
  border-radius: 0.4rem;
  font-weight: 600;
  font-size: 0.85em;
  text-decoration: none;
  color: var(--level, var(--muted));
  background: color-mix(in srgb, var(--level, var(--muted)) 15%, transparent);
}

/* A small heading over a group, as list sections head theirs. */
.group-heading {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 1.5rem 0 0.25rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

/* A box around a component's content. */
.panel {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--surface);
}

/* One of the app's own messages (app-notices): its words, then what to do
   about it. */
.notice {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.6rem 0.6rem 0.6rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: var(--surface);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--text) 10%, transparent);
  font-size: 0.9rem;
}
.notice .text { flex: 1; margin: 0; line-height: 1.45; }
.notice .primary, .notice .button { padding: 0.3rem 0.9rem; border-radius: 999px; white-space: nowrap; }
.notice .button { text-decoration: none; background: var(--text); color: var(--surface); }

/* A level as coloured text, as the card list shows it; set data-level on it. */
.level-text { color: var(--level, var(--muted)); font-weight: 600; }

/* The card's own word in a sentence (term-marks.js). */
.term { text-decoration: underline; text-underline-offset: 0.15em; }

/* Rows in a group, as settings list them: what a row is on the left, its
   value or control on the right; a row that opens a page ends in a chevron. */
.list-group {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--surface);
  overflow: hidden;
}
.list-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.45rem 1rem;
  box-sizing: border-box;
  text-decoration: none;
}
.list-row + .list-row { border-top: 1px solid var(--line); }
.list-row > :first-child { flex: 1; }
.list-row .value { color: var(--muted); font-variant-numeric: tabular-nums; }
a.list-row::after {
  content: "";
  width: 1em;
  height: 1em;
  background: var(--muted);
  mask: url("/icons/chevron-right.svg") center / contain no-repeat;
}
a.list-row:hover { background: color-mix(in srgb, var(--text) 4%, transparent); }
.list-footer { margin: 0.4rem 1rem 0; font-size: 0.85em; color: var(--muted); }

/* An on/off switch. */
.switch {
  appearance: none;
  position: relative;
  width: 2.6rem;
  height: 1.55rem;
  padding: 0;
  border: none;
  border-radius: 1rem;
  background: var(--line);
  cursor: default;
  transition: background 0.15s;
}
.switch::before {
  content: "";
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  transition: transform 0.15s;
}
.switch:checked { background: #34c759; }
.switch:checked::before { transform: translateX(1.05rem); }

/* A menu button: an icon and a chevron. */
.menu-toggle {
  display: inline-flex;
  gap: 0.1rem;
  align-items: center;
  height: 2.1rem;
  padding: 0 0.5rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}
.menu-toggle:hover { background: var(--track); color: var(--text); }
.menu-toggle app-icon { font-size: 1.1rem; }
.menu-toggle .chevron { font-size: 0.75rem; }

/* A menu button's popover (card-sort, map-filter): under the button, held
   inside the window; its items checked as chosen. */
.menu-popover {
  position: fixed;
  inset: auto;
  margin: 0;
  min-width: 15rem;
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px color-mix(in srgb, var(--text) 18%, transparent);
}
.menu-heading { margin: 0.3rem 0.6rem 0.2rem 1.9rem; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.menu-popover hr { margin: 0.35rem 0.6rem; border: none; border-top: 1px solid var(--line); }
.menu-item {
  position: relative;
  display: block;
  width: 100%;
  padding: 0.35rem 0.6rem 0.35rem 1.9rem;
  border: none;
  border-radius: 0.45rem;
  background: transparent;
  text-align: left;
}
.menu-item:hover { background: var(--track); }
a.menu-item { color: inherit; text-decoration: none; }
.menu-icon { position: absolute; left: 0.55rem; top: 50%; transform: translateY(-50%); font-size: 0.9rem; }
.menu-check { position: absolute; left: 0.55rem; top: 50%; transform: translateY(-50%); font-size: 0.9rem; visibility: hidden; }
.menu-item[aria-checked="true"] .menu-check { visibility: visible; }

/* A chip: a tag on a card, a card on a map item. Rounded, on the track colour. */
.chip {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  padding: 0.2rem 0.7rem;
  border: none;
  /* Rounded, not a pill: a long card name wraps. */
  border-radius: 0.9rem;
  background: var(--track);
  color: var(--text);
  font-size: 0.9rem;
  text-decoration: none;
}
.chip:hover { background: color-mix(in srgb, var(--text) 12%, transparent); }
.chip app-icon { color: var(--muted); }

/* The word being said in a text read aloud (app/word-highlight.js). */
[data-said] { background-color: color-mix(in srgb, var(--accent, #3b82f6) 22%, transparent); border-radius: 3px; }

/* A popover opened by its button (popovertarget, one to a component: the
   filters, the sort and Show menus, the account menu), class by-button:
   under the button, its right edge on the button's and at least 16px from
   the window's; above the button when there's more room there (a button low
   in the window, as at a phone's foot); from 16px in on the left when it
   doesn't fit beside it. Placed by anchor positioning; a browser without it
   shows the popover in the middle of the window. */
[popovertarget] { anchor-name: --opener; }
/* A long one (the import page's filters, with their topics) scrolls, short enough to fit above or below its button. */
/* (Its scrolling stays in it: at its end the page behind doesn't scroll or bounce.) */
[popover].by-button { max-block-size: min(70dvh, 40rem); overflow-y: auto; overscroll-behavior: contain; }
/* Below its button at its full height first (to 16px from the window's foot at most); when that
   doesn't fit, the place with the most room (most-height) of: below, above, and each 16px from
   the left; each reaching to 16px from the window's edge on its far side and only as tall as its
   items and no taller than the room there (max-block-size: stretch), so a menu taller than the
   room scrolls there instead of running off the window; above the button the menu sits against
   it (align-self: end). (The first place isn't shrunk to fit: Safari always takes the first that
   fits and sorts only the others by room, so a shrunk one would always be taken, the menu
   squeezed under a button at the window's foot.) */
@supports (position-anchor: --opener) {
  [popover].by-button {
    position-anchor: --opener;
    inset: auto;
    top: anchor(bottom);
    bottom: auto;
    right: max(16px, anchor(right));
    height: auto;
    align-self: start;
    margin: 8px 0 0;
    position-try-order: most-height;
    position-try-fallbacks: --by-button-below, --by-button-above, --by-button-left, --by-button-left-above;
  }
}
@position-try --by-button-below { top: anchor(bottom); bottom: 16px; right: max(16px, anchor(right)); left: auto; align-self: start; margin: 8px 0 0; max-block-size: -webkit-fill-available; max-block-size: stretch; }
@position-try --by-button-above { top: 16px; bottom: anchor(top); right: max(16px, anchor(right)); left: auto; align-self: end; margin: 0 0 8px; max-block-size: -webkit-fill-available; max-block-size: stretch; }
@position-try --by-button-left { top: anchor(bottom); bottom: 16px; right: auto; left: 16px; align-self: start; margin: 8px 0 0; max-block-size: -webkit-fill-available; max-block-size: stretch; }
@position-try --by-button-left-above { top: 16px; bottom: anchor(top); right: auto; left: 16px; align-self: end; margin: 0 0 8px; max-block-size: -webkit-fill-available; max-block-size: stretch; }
@supports not (position-anchor: --opener) {
  [popover].by-button { inset: 0; margin: auto; height: fit-content; }
  [popover].by-button.menu-popover { width: fit-content; }
}

/* A media guide note's colour, by its kind (data-kind): subtitles, guide, transcript, the bar's ticks. */
[data-kind="idiom"], [data-kind="expression"] { --gloss: var(--gloss-idiom); }
[data-kind="word"] { --gloss: var(--gloss-word); }
[data-kind="dialect"] { --gloss: var(--gloss-dialect); }
[data-kind="heard"] { --gloss: var(--gloss-heard); }
[data-kind="culture"] { --gloss: var(--gloss-culture); }

/* Quotation marks (open-quote, <q>) in the page's language, as shared/spoken-text.ts
   has them: German's »…«, Russian's and Portuguese's «…», else “…”. */
:root { quotes: "“" "”" "‘" "’"; }
:root:lang(de) { quotes: "»" "«" "›" "‹"; }
:root:lang(ru), :root:lang(pt) { quotes: "«" "»" "„" "“"; }

/* A misheard phrase shown corrected (app/corrections.ts): its words as usual, a small † after
   them, quiet; hovering on it or tapping it shows what was transcribed. */
.corrected { white-space: nowrap; }
.correction-mark { display: inline; margin: 0 0 0 0.05em; padding: 0; border: 0; background: none; color: inherit; opacity: 0.55; font: inherit; font-size: 0.65em; line-height: 1; vertical-align: super; cursor: default; }
.correction-mark:hover, .correction-mark:focus-visible { opacity: 1; }
.correction-note { max-inline-size: min(22rem, calc(100vw - 32px)); padding: 0.45rem 0.65rem; border: 1px solid var(--line); border-radius: 0.6rem; background: var(--surface); color: var(--text); font-size: 0.85rem; font-weight: normal; line-height: 1.35; white-space: normal; box-shadow: 0 8px 24px color-mix(in srgb, var(--text) 15%, transparent); }

/* A quick second tap is a second tap, not Safari's zoom (double-tap-to-zoom off, and the
   wait for it gone); pinching still zooms. Shadow roots inherit nothing of it, so every
   element, in the document and in each component's (theme.css is in all of them). */
*, *::before, *::after { touch-action: manipulation; }

/* The word and sentence the app's menu is for, lit while it shows (selection-analysis.ts). */
::highlight(press-sentence) { background-color: color-mix(in srgb, var(--accent) 12%, transparent); }
::highlight(press-word) { background-color: color-mix(in srgb, var(--accent) 32%, transparent); }

/* Text found (find-bar, ⌘F): each match, and the one at, as Safari's. */
::highlight(find) { background-color: color-mix(in srgb, #ffd60a 45%, transparent); }
::highlight(find-current) { background-color: #ffd60a; color: #1c1c1e; }

/* How long texts are read (web/app/reading.ts: the »Aa« of a book, a text from the web, a Kultur
   article; one set for all of them): the face, size, line height and margins as the --reading-*
   properties each page's text reads, from the steps set on the document. --reading-measure is
   the column's widest, --reading-margin the room either side of it, --reading-inline its own
   inline margin (centred, or reaching halfway into the page's gutter at the whole width). */
:root { --reading-face: var(--serif); --reading-size: 1.25rem; --reading-lines: 1.7; --reading-measure: 38rem; --reading-margin: 0px; --reading-inline: auto; }
:root[data-reading-font="sans"] { --reading-face: system-ui, sans-serif; }
:root[data-reading-font="book"] { --reading-face: "Iowan Old Style", Palatino, "Palatino Linotype", "Book Antiqua", "URW Palladio L", P052, serif; }
:root[data-reading-size="0"] { --reading-size: 0.95rem; }
:root[data-reading-size="1"] { --reading-size: 1.05rem; }
:root[data-reading-size="2"] { --reading-size: 1.15rem; }
:root[data-reading-size="3"] { --reading-size: 1.25rem; }
:root[data-reading-size="4"] { --reading-size: 1.4rem; }
:root[data-reading-size="5"] { --reading-size: 1.55rem; }
:root[data-reading-size="6"] { --reading-size: 1.75rem; }
:root[data-reading-size="7"] { --reading-size: 2rem; }
:root[data-reading-spacing="0"] { --reading-lines: 1.30; }
:root[data-reading-spacing="1"] { --reading-lines: 1.35; }
:root[data-reading-spacing="2"] { --reading-lines: 1.40; }
:root[data-reading-spacing="3"] { --reading-lines: 1.45; }
:root[data-reading-spacing="4"] { --reading-lines: 1.50; }
:root[data-reading-spacing="5"] { --reading-lines: 1.55; }
:root[data-reading-spacing="6"] { --reading-lines: 1.60; }
:root[data-reading-spacing="7"] { --reading-lines: 1.65; }
:root[data-reading-spacing="8"] { --reading-lines: 1.70; }
:root[data-reading-spacing="9"] { --reading-lines: 1.75; }
:root[data-reading-spacing="10"] { --reading-lines: 1.80; }
:root[data-reading-spacing="11"] { --reading-lines: 1.85; }
:root[data-reading-spacing="12"] { --reading-lines: 1.90; }
:root[data-reading-spacing="13"] { --reading-lines: 1.95; }
:root[data-reading-spacing="14"] { --reading-lines: 2.00; }
:root[data-reading-margin="0"] { --reading-measure: none; --reading-inline: calc(var(--page-pad, 1rem) / -2); }
:root[data-reading-margin="1"] { --reading-measure: 42rem; }
:root[data-reading-margin="2"] { --reading-measure: 40rem; }
:root[data-reading-margin="3"] { --reading-measure: 38rem; }
:root[data-reading-margin="4"] { --reading-measure: 36rem; --reading-margin: 0.5rem; }
:root[data-reading-margin="5"] { --reading-measure: 34rem; --reading-margin: 1rem; }
:root[data-reading-margin="6"] { --reading-measure: 32rem; --reading-margin: 1.5rem; }
:root[data-reading-margin="7"] { --reading-measure: 30rem; --reading-margin: 2rem; }
:root[data-reading-margin="8"] { --reading-measure: 28rem; --reading-margin: 2.5rem; }
