/* Kyourinrin v2 — global stylesheet.
 *
 * Palette: Flexoki Dark (https://stephango.com/flexoki). Dark only.
 * Hex values mirror the published Flexoki tokens; comments name the role
 * each variable plays in the layout so subsequent issues can reach for the
 * right token without re-deriving it from the source palette.
 */

:root {
  /* Flexoki base — neutrals.
   * `--paper` is the canvas (deepest), `--ink` is the foreground text.
   * Intermediate `--bg-*` lift surfaces (cards, drawers); `--tx-*` step
   * text down to muted / disabled. */
  --paper: #100f0f; /* base.black — page background */
  --bg-2: #1c1b1a; /* base.950 — raised surface (cards, drawer) */
  --ui: #282726; /* base.900 — interactive surface (buttons) */
  --ui-2: #343331; /* base.850 — hovered/active surface */
  --ui-3: #403e3c; /* base.800 — borders, dividers */
  --tx-3: #575653; /* base.700 — faint / disabled text */
  --tx-2: #878580; /* base.500 — secondary text */
  --ink: #cecdc3; /* base.200 — primary text */

  /* Flexoki accents — dark-scheme 400 stops (legible on dark surfaces). */
  --red: #d14d41;
  --orange: #da702c;
  --yellow: #d0a215;
  --green: #879a39;
  --cyan: #3aa99f;
  --blue: #4385be;
  --purple: #8b7ec8;
  --magenta: #ce5d97;

  /* Typography — system stack avoids a webfont fetch and matches the
   * minimal-toolchain decision in §3 of the project plan. The mono stack
   * is reserved for code/diagnostic text. */
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, "Helvetica Neue", "Noto Sans CJK JP", "Hiragino Sans", sans-serif;
  --font-mono:
    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --font-size-base: 1rem;
  --line-height-base: 1.5;

  /* Spacing scale — 4 px base, doubling for larger steps. Used directly
   * (e.g. `padding: var(--space-3)`) so the rhythm stays consistent. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
  --space-7: 4rem;
}

/* Minimal reset — box-sizing for predictable layout, body defaults set the
 * palette, no margin reset on headings (left to component-level styles). */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--blue);
}
a:hover {
  color: var(--cyan);
}

code,
kbd,
pre,
samp {
  font-family: var(--font-mono);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--ink);
  margin: 0 0 var(--space-3);
}

/* Error pages — 404, 500, etc. Rendered by `templates/error.html` via the
 * `AppError` IntoResponse impl. Centred card with the status code as the
 * dominant element; the orange accent token (Flexoki `--orange`) contrasts
 * cleanly against the `--bg-2` raised surface. */
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.error-card {
  background-color: var(--bg-2);
  border: 1px solid var(--ui-3);
  border-radius: 0.5rem;
  padding: var(--space-6) var(--space-5);
  max-width: 32rem;
  width: 100%;
  text-align: center;
}

.error-status {
  font-family: var(--font-mono);
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--orange);
  margin-bottom: var(--space-4);
}

.error-message {
  font-size: 1.5rem;
  color: var(--ink);
  margin: 0 0 var(--space-3);
}

.error-detail {
  color: var(--tx-2);
  margin: 0 0 var(--space-5);
}

.error-link {
  margin: 0;
}

.error-link a {
  color: var(--blue);
  text-decoration: none;
}

.error-link a:hover {
  color: var(--cyan);
  text-decoration: underline;
}

/* Home / library page. Vertical list of comics; each row pairs a thumbnail
 * (linked to the comic page) with the title and a chip strip of the most
 * recent unread chapters. Layout uses CSS Grid for the row so the chip strip
 * wraps cleanly under the title on narrow viewports without losing the
 * thumbnail alignment. */
.home {
  max-width: 64rem;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
}

.home-title {
  font-size: 1.75rem;
  color: var(--ink);
  margin: 0 0 var(--space-5);
}

.home-empty {
  color: var(--tx-2);
  background-color: var(--bg-2);
  border: 1px solid var(--ui-3);
  border-radius: 0.5rem;
  padding: var(--space-4);
}

.home-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.home-comic {
  display: grid;
  grid-template-columns: 6rem 1fr;
  gap: var(--space-4);
  align-items: start;
  background-color: var(--bg-2);
  border: 1px solid var(--ui-3);
  border-radius: 0.5rem;
  padding: var(--space-3);
}

.home-comic-thumb {
  display: block;
  background-color: var(--ui);
  border: 1px solid var(--ui-3);
  border-radius: 0.25rem;
  overflow: hidden;
  aspect-ratio: 2 / 3;
}

.home-comic-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.home-comic-meta {
  min-width: 0;
}

.home-comic-title {
  font-size: 1.125rem;
  margin: 0 0 var(--space-2);
  line-height: 1.3;
}

.home-comic-title a {
  color: var(--ink);
  text-decoration: none;
}

.home-comic-title a:hover {
  color: var(--blue);
  text-decoration: underline;
}

.home-caught-up {
  color: var(--tx-2);
  font-style: italic;
  margin: 0;
}

.home-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Chip styling: dark interactive surface (`--ui`) with the primary ink as the
 * contrasting text colour. Hover swaps to the slightly lighter `--ui-2` and
 * tints the text with the Flexoki blue accent; active state pins the accent
 * as the chip background to mimic a "selected" state for keyboard focus. */
.home-chip {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  background-color: var(--ui);
  color: var(--ink);
  border: 1px solid var(--ui-3);
  border-radius: 999px;
  font-size: 0.875rem;
  text-decoration: none;
  line-height: 1.4;
  transition: background-color 80ms ease, color 80ms ease, border-color 80ms ease;
}

.home-chip:hover {
  background-color: var(--ui-2);
  color: var(--blue);
  border-color: var(--blue);
}

.home-chip:active,
.home-chip:focus-visible {
  background-color: var(--blue);
  color: var(--paper);
  border-color: var(--blue);
  outline: none;
}

/* Library page — paginated grid of every comic. The column count is fed in
 * from the server via `--library-cols` so the layout responds to the
 * `EnvConfig::comics_per_row` knob without a stylesheet change. */
.library {
  max-width: 80rem;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
}

.library-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.library-title {
  font-size: 1.75rem;
  margin: 0;
}

.library-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.library-search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.library-search input[type="search"] {
  background-color: var(--bg-2);
  color: var(--ink);
  border: 1px solid var(--ui-3);
  border-radius: 0.25rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  min-width: 16rem;
}

.library-search input[type="search"]:focus {
  outline: none;
  border-color: var(--blue);
}

.library-search button {
  background-color: var(--ui);
  color: var(--ink);
  border: 1px solid var(--ui-3);
  border-radius: 0.25rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  cursor: pointer;
}

.library-search button:hover {
  background-color: var(--ui-2);
  border-color: var(--blue);
  color: var(--blue);
}

.library-empty {
  color: var(--tx-2);
  background-color: var(--bg-2);
  border: 1px solid var(--ui-3);
  border-radius: 0.5rem;
  padding: var(--space-4);
}

.library-grid {
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--library-cols, 4), minmax(0, 1fr));
  gap: var(--space-4);
}

.library-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background-color: var(--bg-2);
  border: 1px solid var(--ui-3);
  border-radius: 0.5rem;
  padding: var(--space-3);
  min-width: 0;
}

.library-card-thumb {
  display: block;
  background-color: var(--ui);
  border: 1px solid var(--ui-3);
  border-radius: 0.25rem;
  overflow: hidden;
  aspect-ratio: 2 / 3;
}

.library-card-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.library-card-title {
  color: var(--ink);
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.library-card-title:hover {
  color: var(--blue);
  text-decoration: underline;
}

.library-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--ui-3);
  color: var(--tx-2);
}

.library-pagination-link {
  color: var(--blue);
  text-decoration: none;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--ui-3);
  border-radius: 0.25rem;
  background-color: var(--bg-2);
}

.library-pagination-link:hover {
  background-color: var(--ui-2);
  border-color: var(--blue);
}

.library-pagination-current {
  font-variant-numeric: tabular-nums;
}

/* Comic detail page. The header pairs a tall thumbnail with the title block
 * and action buttons; the chapter grid below uses `--chapters-cols` so the
 * column count is server-driven from `EnvConfig::chapters_per_row` without a
 * stylesheet edit. Read tiles are visually muted via the `chapter-tile-read`
 * modifier — lower opacity and a dim background, no underline on the title
 * since the chapter is finished. */
.comic {
  max-width: 80rem;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
}

.comic-header {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: var(--space-5);
  align-items: start;
  margin-bottom: var(--space-5);
}

.comic-thumb {
  display: block;
  background-color: var(--ui);
  border: 1px solid var(--ui-3);
  border-radius: 0.5rem;
  overflow: hidden;
  aspect-ratio: 2 / 3;
}

.comic-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.comic-meta {
  min-width: 0;
}

.comic-title {
  font-size: 1.75rem;
  margin: 0 0 var(--space-3);
  line-height: 1.2;
}

.comic-description {
  color: var(--tx-2);
  margin: 0 0 var(--space-3);
  line-height: 1.4;
}

.comic-counts {
  color: var(--tx-2);
  margin: 0 0 var(--space-4);
  font-variant-numeric: tabular-nums;
}

.comic-count-separator {
  margin: 0 var(--space-2);
  color: var(--tx-3);
}

.comic-count-read {
  color: var(--ink);
}

.comic-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.comic-action {
  background-color: var(--ui);
  color: var(--ink);
  border: 1px solid var(--ui-3);
  border-radius: 0.25rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  cursor: pointer;
  transition: background-color 80ms ease, border-color 80ms ease, color 80ms ease;
}

.comic-action:hover {
  background-color: var(--ui-2);
  border-color: var(--blue);
  color: var(--blue);
}

/* Destructive action — red accent so it visually separates from the
 * mark-as-read action above. */
.comic-delete {
  border-color: var(--ui-3);
}

.comic-delete:hover {
  background-color: var(--ui-2);
  border-color: var(--red);
  color: var(--red);
}

.comic-empty {
  color: var(--tx-2);
  background-color: var(--bg-2);
  border: 1px solid var(--ui-3);
  border-radius: 0.5rem;
  padding: var(--space-4);
}

.comic-chapters {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--chapters-cols, 6), minmax(0, 1fr));
  gap: var(--space-3);
}

.chapter-tile {
  background-color: var(--bg-2);
  border: 1px solid var(--ui-3);
  border-radius: 0.375rem;
  min-width: 0;
}

.chapter-tile a {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  align-items: flex-start;
  padding: var(--space-2) var(--space-3);
  text-decoration: none;
  color: var(--ink);
}

.chapter-tile a:hover {
  color: var(--blue);
  border-color: var(--blue);
}

.chapter-key {
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.chapter-badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 var(--space-1);
  border-radius: 0.25rem;
  background-color: var(--ui);
  color: var(--tx-2);
}

.chapter-badge-unread {
  background-color: var(--ui);
  color: var(--blue);
}

.chapter-badge-read {
  background-color: var(--ui);
  color: var(--tx-3);
}

/* Read tiles: lower opacity and faint text so the eye skips past them on
 * the way to the next unread chapter. */
.chapter-tile-read {
  background-color: var(--paper);
  border-color: var(--ui);
}

.chapter-tile-read a {
  color: var(--tx-3);
}

.chapter-tile-read a:hover {
  color: var(--tx-2);
}

/* ----- Reader (continuous vertical webtoon layout) ---------------------- */

.reader {
  /* The reader column itself centres in the viewport; pages stretch to
   * `--reader-cols-max` so very wide screens don't stretch a 1000 px-wide
   * webtoon strip to 100 vw. */
  margin: 0 auto;
  max-width: 900px;
  padding: 0;
}

.reader-scroll-progress {
  /* Track pinned to the top of the reader. The faint `--bg-2` paper variant
   * keeps the unfilled portion just visible against the `--paper` page. */
  position: sticky;
  top: 0;
  height: 0.25rem;
  background-color: var(--bg-2);
  z-index: 2;
}

.reader-scroll-progress-bar {
  /* Foreground fill — Flexoki accent-1 (red). Width is driven directly by
   * app.js per animation frame, so no CSS transition (it would lag behind the
   * scroll position rather than track it). */
  height: 100%;
  width: 0;
  background-color: var(--red);
}

.reader-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background-color: var(--bg-2);
  border-bottom: 1px solid var(--ui-3);
}

.reader-back {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.reader-back:hover {
  color: var(--blue);
}

.reader-separator {
  color: var(--tx-3);
}

.reader-chapter-key {
  color: var(--tx-2);
}

.reader-pages {
  /* Zero gap between adjacent <img> elements — the whole point of the
   * webtoon layout. `font-size: 0` neutralises the whitespace between
   * inline-block image siblings that some browsers render as a 1 px gap;
   * the flex column below is the structural answer. */
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 0;
  line-height: 0;
  background-color: var(--paper);
}

.reader-page {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  padding: 0;
  /* Tapping a page opens the vocab drawer on that page (see app.js). */
  cursor: pointer;
}

.reader-empty {
  padding: var(--space-5);
  text-align: center;
  color: var(--tx-2);
}

.reader-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background-color: var(--bg-2);
  border-top: 1px solid var(--ui-3);
}

.reader-nav-button {
  display: inline-block;
  padding: var(--space-2) var(--space-3);
  background-color: var(--ui);
  border: 1px solid var(--ui-3);
  border-radius: 0.375rem;
  color: var(--ink);
  text-decoration: none;
}

.reader-nav-button:hover {
  background-color: var(--ui-2);
  color: var(--blue);
  border-color: var(--blue);
}

.reader-prev-disabled {
  color: var(--tx-3);
  cursor: not-allowed;
}

.reader-prev-disabled:hover {
  background-color: var(--ui);
  color: var(--tx-3);
  border-color: var(--ui-3);
}

/* ----- Vocab side-drawer + toggle --------------------------------------- */

/* Toggle — pinned to the right edge of the viewport on desktop (vertically
 * centred), relocated to the bottom-right on mobile. Sits above the drawer so
 * it stays reachable when the drawer is open. */
.vocab-toggle {
  position: fixed;
  z-index: 5;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-2);
  background-color: var(--ui);
  color: var(--ink);
  border: 1px solid var(--ui-3);
  border-right: none;
  border-radius: 0.375rem 0 0 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  /* Stack the [ABC] glyphs along the edge tab on desktop. */
  writing-mode: vertical-rl;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.vocab-toggle:hover {
  background-color: var(--ui-2);
  color: var(--blue);
  border-color: var(--blue);
}

/* Off-screen text for the toggle / close affordances. */
.vocab-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Scrim — catches outside taps on the mobile bottom-sheet. Suppressed on
 * desktop (see the min-width media query) where the side panel doesn't dim
 * the page. */
.vocab-scrim {
  position: fixed;
  inset: 0;
  z-index: 3;
  background-color: rgba(16, 15, 15, 0.5);
  border: 0;
}

.reader-vocab-drawer {
  /* Desktop default: right-side panel slid off-screen until `.is-open`. The
   * fixed positioning lifts it out of the centred `.reader` column so it
   * hugs the true viewport edge. */
  position: fixed;
  z-index: 4;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  background-color: var(--bg-2);
  border-left: 1px solid var(--ui-3);
  transform: translateX(100%);
  transition: transform 200ms ease;
}

.reader-vocab-drawer.is-open {
  transform: translateX(0);
}

.vocab-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3);
  background-color: var(--bg-2);
  border-bottom: 1px solid var(--ui-3);
}

.vocab-drawer-title {
  font-size: 1.05rem;
  margin: 0;
}

.vocab-drawer-close {
  background: none;
  border: none;
  color: var(--tx-2);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 var(--space-1);
  cursor: pointer;
}

.vocab-drawer-close:hover {
  color: var(--red);
}

.vocab-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-3);
}

.vocab-empty {
  color: var(--tx-2);
  margin: 0;
}

.vocab-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.vocab-entry {
  background-color: var(--ui);
  border: 1px solid var(--ui-3);
  border-radius: 0.375rem;
  padding: var(--space-3);
}

.vocab-entry-headword {
  margin: 0 0 var(--space-2);
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.vocab-surface {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
}

.vocab-reading {
  font-size: 0.95rem;
  color: var(--tx-2);
}

.vocab-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0 0 var(--space-2);
}

.vocab-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  color: var(--paper);
}

/* JLPT badges — colour ramps from red (N1, hardest) to green (N5, easiest)
 * using the Flexoki accent tokens, matching the issue's N1 = red / N5 = green.
 * An unrecognised level falls back to the bare `.vocab-jlpt` purple so it is
 * still visible rather than transparent-on-transparent. */
.vocab-jlpt {
  background-color: var(--purple);
}
.jlpt-N1 {
  background-color: var(--red);
}
.jlpt-N2 {
  background-color: var(--orange);
}
.jlpt-N3 {
  background-color: var(--yellow);
}
.jlpt-N4 {
  background-color: var(--blue);
}
.jlpt-N5 {
  background-color: var(--green);
}

.vocab-common {
  background-color: var(--cyan);
}

.vocab-chip {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background-color: var(--ui-2);
  color: var(--tx-2);
  border: 1px solid var(--ui-3);
}

.vocab-meanings {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  color: var(--ink);
}

.vocab-meanings li {
  margin: 0;
}

/* Desktop: the side panel sits beside content, so no dimming scrim. */
@media (min-width: 768px) {
  .vocab-scrim {
    display: none;
  }
}

/* Mobile: full-width bottom sheet sliding up; scrim active for outside-tap
 * dismissal. */
@media (max-width: 767px) {
  .reader-vocab-drawer {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 70vh;
    border-left: none;
    border-top: 1px solid var(--ui-3);
    border-radius: 0.5rem 0.5rem 0 0;
    transform: translateY(100%);
  }

  .reader-vocab-drawer.is-open {
    transform: translateY(0);
  }

  .vocab-toggle {
    top: auto;
    bottom: var(--space-4);
    right: var(--space-4);
    transform: none;
    writing-mode: horizontal-tb;
    border-right: 1px solid var(--ui-3);
    border-radius: 999px;
    padding: var(--space-2) var(--space-4);
  }
}

/* Respect a reduced-motion preference — snap the drawer instead of sliding. */
@media (prefers-reduced-motion: reduce) {
  .reader-vocab-drawer {
    transition: none;
  }
}

/* ----- Toast notifications ---------------------------------------------- */

/* `#toast-stack` ships in base.html and is populated by window.kyourinrin.toast.
 * Pinned bottom-centre and laid out as a column, so appended toasts stack with
 * the newest at the bottom. `pointer-events: none` lets clicks fall through the
 * gaps between cards while each card re-enables them for its close button. Sits
 * above the vocab drawer/toggle so a failure message is never occluded. */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: var(--space-4);
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: max-content;
  max-width: min(90vw, 28rem);
  pointer-events: none;
}

/* A coloured card per kind. The accent tokens (Flexoki Dark green/red/blue)
 * back the card; `--paper` text keeps contrast high, matching the badge
 * treatment elsewhere. Starts shifted down + transparent so adding
 * `.is-visible` slides it up and fades it in; removing the class fades it out. */
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  color: var(--paper);
  border-radius: 0.375rem;
  padding: var(--space-2) var(--space-3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(1rem);
  transition: opacity 200ms ease, transform 200ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-message {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* Close affordance — inherits the card's dark ink, brightens on hover. */
.toast-close {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: inherit;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 var(--space-1);
  margin: -0.1rem -0.2rem -0.1rem 0;
  cursor: pointer;
  opacity: 0.7;
}

.toast-close:hover {
  opacity: 1;
}

.toast-success {
  background-color: var(--green);
}

.toast-error {
  background-color: var(--red);
}

.toast-info {
  background-color: var(--blue);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}

/* ----- Global top navigation -------------------------------------------- */

/* Sticky bar shared by every content page (home, library, comic). Stays in
 * the document flow at the top, then pins on scroll. The login, error, and
 * reader templates override the `chrome` block so this never renders there. */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 8;
  background-color: rgba(28, 27, 26, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--ui-3);
}

.site-nav-inner {
  max-width: 80rem;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.site-brand:hover {
  color: var(--ink);
}

.site-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 0.5rem;
  background: linear-gradient(135deg, var(--red), var(--orange));
  color: var(--paper);
  font-size: 1.1rem;
  line-height: 1;
}

.site-brand-word {
  font-size: 1.1rem;
}

.site-nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.site-nav-link {
  color: var(--tx-2);
  text-decoration: none;
  padding: var(--space-1) var(--space-3);
  border-radius: 0.375rem;
  font-size: 0.95rem;
  transition: background-color 80ms ease, color 80ms ease;
}

.site-nav-link:hover {
  color: var(--ink);
  background-color: var(--ui);
}

/* Push the action cluster to the right edge of the bar. */
.site-nav-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Shared button system used in the nav and the add dialog. */
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background-color: var(--ui);
  color: var(--ink);
  border: 1px solid var(--ui-3);
  border-radius: 0.375rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 80ms ease, border-color 80ms ease, color 80ms ease;
}

.nav-btn:hover {
  background-color: var(--ui-2);
  border-color: var(--blue);
  color: var(--blue);
}

.nav-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.nav-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Primary call-to-action — filled green accent. */
.nav-btn-primary {
  background-color: var(--green);
  border-color: var(--green);
  color: var(--paper);
  font-weight: 600;
}

.nav-btn-primary:hover {
  background-color: var(--green);
  border-color: var(--green);
  color: var(--paper);
  filter: brightness(1.1);
}

/* Quiet, borderless variant for secondary actions (Sign out, Cancel). */
.nav-btn-ghost {
  background-color: transparent;
  border-color: transparent;
  color: var(--tx-2);
}

.nav-btn-ghost:hover {
  background-color: var(--ui);
  border-color: var(--ui-3);
  color: var(--ink);
}

/* Stack the nav onto two rows on narrow viewports rather than overflowing. */
@media (max-width: 640px) {
  .site-nav-inner {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .site-nav-links {
    order: 3;
    width: 100%;
  }
  .site-nav-actions {
    gap: var(--space-1);
  }
  .nav-btn {
    padding: var(--space-1) var(--space-2);
  }
}

/* ----- Add-manga dialog -------------------------------------------------- */

.add-dialog {
  border: 1px solid var(--ui-3);
  border-radius: 0.75rem;
  background-color: var(--bg-2);
  color: var(--ink);
  padding: 0;
  width: min(28rem, 92vw);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.add-dialog::backdrop {
  background-color: rgba(16, 15, 15, 0.6);
  backdrop-filter: blur(2px);
}

.add-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
}

.add-form-title {
  margin: 0;
  font-size: 1.25rem;
}

.add-form-hint {
  margin: 0;
  color: var(--tx-2);
  font-size: 0.9rem;
  line-height: 1.4;
}

.add-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.add-field-label {
  font-size: 0.85rem;
  color: var(--tx-2);
}

.add-field select,
.add-field input[type="text"] {
  background-color: var(--ui);
  color: var(--ink);
  border: 1px solid var(--ui-3);
  border-radius: 0.375rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
}

.add-field select:focus,
.add-field input[type="text"]:focus {
  outline: none;
  border-color: var(--blue);
}

.add-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* ----- Login page -------------------------------------------------------- */

/* The sign-in screen renders without the global nav: a single centred card on
 * the bare page background. */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.login-card {
  width: 100%;
  max-width: 22rem;
  background-color: var(--bg-2);
  border: 1px solid var(--ui-3);
  border-radius: 0.75rem;
  padding: var(--space-6) var(--space-5);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.login-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.login-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.6rem;
  background: linear-gradient(135deg, var(--red), var(--orange));
  color: var(--paper);
  font-size: 1.3rem;
  line-height: 1;
}

.login-brand-word {
  font-size: 1.5rem;
  font-weight: 700;
}

.login-subtitle {
  margin: 0 0 var(--space-5);
  color: var(--tx-2);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  text-align: left;
}

.login-label {
  font-size: 0.85rem;
  color: var(--tx-2);
}

.login-form input[type="password"] {
  background-color: var(--ui);
  color: var(--ink);
  border: 1px solid var(--ui-3);
  border-radius: 0.375rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
}

.login-form input[type="password"]:focus {
  outline: none;
  border-color: var(--blue);
}

.login-submit {
  margin-top: var(--space-2);
  background-color: var(--blue);
  color: var(--paper);
  border: 1px solid var(--blue);
  border-radius: 0.375rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 80ms ease;
}

.login-submit:hover {
  filter: brightness(1.1);
}

.login-submit:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.login-error {
  margin: var(--space-3) 0 0;
  color: var(--red);
  font-size: 0.9rem;
}
