/*
 * Personal FE design tokens.
 * Derived from project-tracker's system (kept close to verbatim — it's the
 * one you like), with anime-tracker's restraint folded in: tighter type
 * scale, calmer chrome, content gets the visual weight, not the frame.
 *
 * Usage: copy this file into a project's client as e.g. src/tokens.css and
 * import it before any other stylesheet. Components then use var(--x) only —
 * never hardcode a color/radius/shadow value inline.
 */

:root {
  /* Color: light (default) */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1c1e21;
  --text-dim: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --info: #2563eb;
  color-scheme: light;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 24px;
  --leading: 1.5;

  /* Space (4px scale) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Shape */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.18);

  --transition-fast: 0.15s ease;
}

/* Explicit toggle wins in both directions; prefers-color-scheme covers
   projects that never build a toggle at all. Same pattern project-tracker
   already used for its own light/dark split. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #17181b;
    --surface: #232427;
    --border: #35373c;
    --text: #e7e8ea;
    --text-dim: #9a9ea6;
    --primary: #818cf8;
    --primary-hover: #a5b0fc;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fbbf24;
    --info: #60a5fa;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #17181b;
  --surface: #232427;
  --border: #35373c;
  --text: #e7e8ea;
  --text-dim: #9a9ea6;
  --primary: #818cf8;
  --primary-hover: #a5b0fc;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --info: #60a5fa;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  background: var(--bg);
  color: var(--text);
}

/* Base link color — components with their own link treatment (.btn,
   .breadcrumbs a, a.card, .list-row-title) override color/text-decoration
   below; this only covers plain inline links that don't opt into one of
   those. */
a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--primary-hover);
}

/* ---------- Layout shell ---------- */

.page {
  width: 95%;
  /* Both source projects converged on this same cap for every page, not
     just wide board/grid layouts (project-tracker's kanban board always
     used it; anime-tracker's show/watch/season pages used to opt out
     entirely with max-width:none, which just made those three pages feel
     jarringly wider than the rest of the app — anime-tracker's AT-136).
     1800px is generous enough for a 3-column episode/card grid on a wide
     monitor while still being a bound every page shares. */
  max-width: 1800px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-7);
}

.page--narrow {
  max-width: 760px;
}

/* Wraps just .page-header so the @container query below can key off its
   width — deliberately NOT set on .page itself (anime-tracker's AT-147):
   container-type applies layout containment, which makes the element a
   containing block for every position:fixed/absolute descendant, not just
   size-query descendants. .page typically wraps every fixed-position modal
   in a project (alert/confirm popups, pickers, page-specific modals), so
   putting containment there breaks every one of them — instead of sizing
   against the actual viewport, a modal sizes itself against .page's full
   (often much taller than one screen) content height, rendering as a huge,
   top-anchored box. This wrapper has no padding/margin of its own, so its
   content-box width matches .page's — the breakpoint fires at the same
   width as before, just without also being a containing block for
   anything else on the page. */
.page-header-container {
  container-type: inline-size;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  margin: 0;
  font-size: var(--text-lg);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.section-heading {
  margin: var(--space-6) 0 var(--space-4);
  color: var(--text-dim);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Stack the header instead of letting actions get crushed against the
   title when .page itself is narrow — see "Space-aware layout" in
   SKILL.md. A container query (keyed off .page-header-container's width,
   set above), not a viewport media query, so this fires correctly even
   when .page is narrow for a reason other than the browser window being
   narrow. */
@container (max-width: 640px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-header-actions {
    flex-wrap: wrap;
  }
}

/* ---------- Breadcrumbs ---------- */

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-dim);
}

.breadcrumbs a {
  color: var(--text-dim);
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.breadcrumbs .breadcrumb-current {
  color: var(--text);
}

.breadcrumbs .breadcrumb-sep {
  color: var(--border);
}

/* ---------- Buttons ---------- */
/* Compact by default (anime-tracker's sizing) with project-tracker's
   rounded/color-mix polish layered on top. */

button,
.btn {
  display: inline-block;
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 12px;
  line-height: 1.3;
  text-decoration: none;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

button:hover,
.btn:hover {
  border-color: var(--text-dim);
}

button:focus-visible,
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary);
}

/* Explicit, not left to the browser default — the native disabled look
   (slightly dimmed text, same border/background) reads fine in light mode
   by accident but is indistinguishable from a default enabled button in
   dark mode. Dim + flatten to --bg regardless of variant (primary/danger
   included, via the general button/.btn selector's specificity) and drop
   the hover affordance. */
button:disabled,
.btn:disabled,
button[aria-disabled='true'],
.btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg);
  border-color: var(--border);
  color: var(--text-dim);
}

button:disabled:hover,
.btn:disabled:hover,
button[aria-disabled='true']:hover,
.btn[aria-disabled='true']:hover {
  background: var(--bg);
  border-color: var(--border);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-dim);
}

.btn-ghost:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
  color: var(--text);
}

.btn-icon {
  padding: 6px 8px;
  font-size: var(--text-md);
  line-height: 1;
}

/* ---------- Inputs ---------- */

input,
textarea,
select {
  font: inherit;
  font-size: var(--text-sm);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent);
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-sm);
  color: var(--text-dim);
}

/* ---------- Badges & chips ---------- */
/* The signature project-tracker element: color-mix tints derived straight
   from a semantic variable, so a new status/label never needs a bespoke
   color picked by hand. */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--primary) 15%, var(--surface));
  color: var(--primary);
  white-space: nowrap;
}

.badge-success { background: color-mix(in srgb, var(--success) 15%, var(--surface)); color: var(--success); }
.badge-warning { background: color-mix(in srgb, var(--warning) 15%, var(--surface)); color: var(--warning); }
.badge-danger  { background: color-mix(in srgb, var(--danger) 15%, var(--surface));  color: var(--danger); }
.badge-neutral { background: color-mix(in srgb, var(--text-dim) 15%, var(--surface)); color: var(--text-dim); }

/* Tighter padding for a badge sitting inside a dense row (.list-row,
   .task-card-meta, table cells) alongside other metadata — a real variant,
   not a one-off inline `style="padding:..."` per instance. */
.badge-sm {
  padding: 2px 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

/* Deterministic per-name palette (hash the name -> one of these 8 classes),
   same trick as project-tracker's labelColorClass(). */
.chip-0 { background: color-mix(in srgb, #0891b2 18%, var(--surface)); color: #0891b2; }
.chip-1 { background: color-mix(in srgb, #db2777 18%, var(--surface)); color: #db2777; }
.chip-2 { background: color-mix(in srgb, #65a30d 18%, var(--surface)); color: #65a30d; }
.chip-3 { background: color-mix(in srgb, #7c3aed 18%, var(--surface)); color: #7c3aed; }
.chip-4 { background: color-mix(in srgb, #ea580c 18%, var(--surface)); color: #ea580c; }
.chip-5 { background: color-mix(in srgb, #0d9488 18%, var(--surface)); color: #0d9488; }
.chip-6 { background: color-mix(in srgb, #9333ea 18%, var(--surface)); color: #9333ea; }
.chip-7 { background: color-mix(in srgb, #b45309 18%, var(--surface)); color: #b45309; }

/* ---------- Cards ---------- */

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  color: var(--text);
  text-decoration: none;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

a.card:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.card-header h3 {
  margin: 0;
  font-size: var(--text-md);
}

.card-meta {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--text-dim);
  align-items: center;
}

/* Space-aware grid: fills the row with as many columns as fit at
   --min-col width, and wraps down to fewer (eventually one) as the
   container narrows — no fixed column-count/breakpoint pair to maintain.
   Set --min-col (default 240px) to change density; .card-grid/.kanban
   below are just named presets over this same mechanism. */
.auto-grid,
.card-grid,
.kanban {
  --min-col: 240px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--min-col), 1fr));
  gap: var(--space-4);
}

/* ---------- Kanban ---------- */
/* .kanban is an .auto-grid preset (see above) — as many --min-col-wide
   columns as fit per row, wrapping to fewer (down to one, effectively a
   stack) rather than a fixed 3-up grid squeezing on narrow viewports. */

.kanban {
  --min-col: 220px;
}

.kanban-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.kanban-col h4 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.task-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.task-card-title {
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
}

.task-card-meta {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- Tables ---------- */
/* Wrap any .table in .table-wrap: on a viewport too narrow for every
   column, the table scrolls horizontally within its own box instead of
   forcing the page to scroll or columns to crush — same "use the space
   you have, don't reflow content into illegibility" instinct as the grids
   above. Reach for a card-grid/list-row layout instead of a table if a
   dataset is narrow-screen-first (few columns, read as a unit per row). */

.table-wrap {
  overflow-x: auto;
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th,
.table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  white-space: nowrap;
}

.table thead th {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.table tbody tr {
  border-bottom: 1px solid var(--border);
}

.table tbody tr:last-child {
  border-bottom: none;
}

.table tbody tr:hover {
  background: color-mix(in srgb, var(--text) 3%, transparent);
}

.table-zebra tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--text) 2.5%, transparent);
}

/* ---------- Long lists ---------- */
/* Two distinct patterns — don't combine them on the same list:
   1. .scroll-list: a BOUNDED PREVIEW of a larger dataset, embedded as one
      section on a page that has other content too (a "recent activity"
      widget, a related-items panel). Caps height, scrolls internally, and
      pairs with a "View all ->" link to the full list — never with
      .pagination on the same list, since a paginated list doesn't need an
      internal scroll cap too.
   2. .pagination alone, no .scroll-list wrapper: when the paginated list
      IS the page's main content (a dedicated "all tasks" list page). The
      list flows in normal page layout and the page itself scrolls;
      .pagination controls sit at the bottom like any other page content.
      Wrapping this case in .scroll-list would nest one scroll region
      inside another for no reason. */

.scroll-list {
  max-height: 360px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

.scroll-list::-webkit-scrollbar {
  width: 8px;
}

.scroll-list::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: var(--radius-pill);
}

.scroll-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-pill);
}

.scroll-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-dim);
}

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

/* ---------- Alphabetical index ---------- */
/* A "browse all" / category-listing page: a jump-nav of letters at the top,
   content below grouped into one section per letter — the wiki/glossary
   pattern (Wikipedia category pages, MDN's index, etc), not a generic
   table/card component. Purely structural: .index-nav's links are plain
   `<a href="#idx-a">` anchors to matching `.index-section#idx-a` ids, no JS
   needed at all. Generic on purpose — .index-items below is one option for
   a section's body (simple icon+link entries), but the body can just as
   easily be a .card-grid, a .table, or a .list-row group instead; grouping
   by letter doesn't care what the items inside a letter look like. */

.index-nav {
  display: flex;
  flex-wrap: wrap;
  row-gap: var(--space-2);
  font-weight: 700;
  margin-bottom: var(--space-6);
}

.index-nav a,
.index-nav span {
  padding: 0 var(--space-1);
}

.index-nav a {
  text-decoration: none;
}

.index-nav a:hover {
  text-decoration: underline;
}

/* A letter with nothing under it: shown for completeness (so the alphabet
   reads as a whole) but not a link — nothing to jump to. */
.index-nav .index-nav-inactive {
  color: var(--text-dim);
  font-weight: 400;
  cursor: default;
}

.index-section {
  margin-bottom: var(--space-6);
  /* Anchor-scroll lands right at the heading, not flush under a sticky
     page header covering it — matches .page-header's own height/padding
     roughly; adjust per project if its header is taller. */
  scroll-margin-top: var(--space-4);
}

.index-section-heading {
  font-size: var(--text-lg);
  margin: 0 0 var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

/* Default body for a section: simple icon+link entries in an .auto-grid
   (fills available width, wraps to fewer columns as it narrows — see
   "Space-aware layout" in SKILL.md). Swap in a .card-grid/.table/.list-row
   group instead when the items need more than a single link to represent. */
.index-items {
  --min-col: 220px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--min-col), 1fr));
  gap: var(--space-2) var(--space-4);
}

.index-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--primary);
  text-decoration: none;
}

.index-item:hover {
  text-decoration: underline;
}

.index-item-icon {
  flex-shrink: 0;
  color: var(--text-dim);
}

/* ---------- Activity feed ---------- */
/* A vertical timeline of timestamped events — project-tracker's
   activity_log (created/updated/deleted/link_*) is the reference use case.
   Put it inside .scroll-list when the log can get long. */

.activity-feed {
  list-style: none;
  margin: 0;
  padding: 0;
}

.activity-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  position: relative;
}

.activity-item::before {
  /* Connecting rail between dots, drawn per-item so it only spans between
     consecutive entries (none above the first, none below the last). */
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.activity-item:first-child::before {
  top: 50%;
}

.activity-item:last-child::before {
  bottom: 50%;
}

.activity-dot {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--primary);
}

.activity-body {
  flex: 1;
  min-width: 0;
}

.activity-text {
  margin: 0 0 2px;
  font-size: var(--text-sm);
}

.activity-time {
  font-size: var(--text-xs);
}

/* ---------- i18n ---------- */
/* Generalized version of anime-tracker's EN/JP toggle. CSS attribute
   selectors can't compare [data-lang-field] against <html>'s data-lang
   generically (a rule per language code would defeat the point), so the
   toggle script does that match in JS instead and adds/removes this class
   — see demo.html's lang-toggle script for the exact ~10-line pattern.
   Works for any set of language codes without touching this stylesheet. */

[data-lang-field] {
  display: none;
}

[data-lang-field].lang-field-active {
  display: revert;
}

/* ---------- Progress ---------- */

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: var(--space-3);
}

.progress-fill {
  height: 100%;
  background: var(--primary);
}

/* ---------- Empty / dim states ---------- */

.empty-state {
  color: var(--text-dim);
  text-align: center;
  padding: var(--space-7) 0;
}

.dim {
  color: var(--text-dim);
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  width: 420px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  margin: 0 0 var(--space-1);
}

/* ---------- List rows (for compact, content-first views) ---------- */

.list-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child {
  border-bottom: none;
}

/* The row's title/primary text — always this class, never a bare <strong>
   or <span> per instance, so weight stays consistent across every place a
   .list-row appears (compact lists, long lists, feature lists, etc). */
.list-row-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

a.list-row-title:hover {
  color: var(--primary);
}

/* "Done"/muted state: strikethrough, not just dimmed color. A dimmed color
   at the same weight/size reads as visually un-bolded even though the
   font-weight is unchanged (low contrast makes bold strokes hard to
   perceive) — strikethrough signals the state unambiguously regardless of
   how bold it happens to look. Same convention as project-tracker's
   .link-done. */
.list-row-title.dim {
  text-decoration: line-through;
}

/* A whole .list-row acting as a single link (the entire row navigates,
   not just a piece of text inside it) — same "no default anchor styling"
   treatment a.card already gets. */
a.list-row {
  color: inherit;
  text-decoration: none;
}

a.list-row:hover .list-row-title {
  color: var(--primary);
}
