/* Fiction Units - simple, fast, mobile-first theme. No frameworks.
   Motion: Emil Kowalski philosophy - custom curves, <300ms UI, transform+opacity only,
   press feedback, stagger, reduced-motion safe. */
:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #5b6470;
  --line: #e3e6ea;
  --brand: #4f46e5;
  --brand-dark: #3c37c4;
  --accent: #f59e0b;
  --ok: #15803d;
  --warn-bg: #fffbeb;
  --warn-line: #fcd34d;
  --col-a: #4f46e5;
  --col-b: #0e9f6e;
  --col-u: #b45309;
  --radius: 12px;
  --max: 1080px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  /* Motion tokens - strong custom curves, never bare ease/ease-in for UI */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-press: 160ms;
  --dur-fast: 125ms;
  --dur-ui: 200ms;
  --dur-chart: 250ms;
  --stagger: 45ms;
}
[data-theme="dark"] {
  --bg: #12141a;
  --bg-soft: #1a1d24;
  --card: #1a1d24;
  --text: #eef0f4;
  --muted: #a7b0bd;
  --line: #2b303b;
  --brand: #818cf8;
  --brand-dark: #a5b4fc;
  --warn-bg: #2a230f;
  --warn-line: #92690e;
  --col-a: #a5b4fc;
  --col-b: #34d399;
  --col-u: #fbbf24;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
@media (hover: hover) and (pointer: fine) {
  a:hover { text-decoration: underline; }
}
img, svg { max-width: 100%; height: auto; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center; gap: 12px;
  max-width: var(--max); margin: 0 auto; padding: 10px 16px;
}
.logo { font-weight: 800; font-size: 1.15rem; color: var(--text); display: flex; align-items: center; gap: 8px; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 0.95rem;
}
.logo small { font-weight: 500; color: var(--muted); font-size: 0.72rem; display: block; line-height: 1.1; }
.nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.nav a { color: var(--text); font-weight: 600; font-size: 0.92rem; padding: 8px 10px; border-radius: 8px; transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-fast) ease, color var(--dur-fast) ease; }
@media (hover: hover) and (pointer: fine) {
  .nav a:hover { background: var(--bg-soft); text-decoration: none; }
}
.nav a:active { transform: scale(0.97); transition-duration: 100ms; }
.nav a.active { color: var(--brand); }
.icon-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: 0.9rem;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.icon-btn:active { transform: scale(0.97); }
.search-link { border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; }
.search-link.search-icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border-radius: 999px; color: var(--text); }
.search-link.search-icon svg { display: block; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; padding: 12px 16px; }
.btn-icon svg { display: block; }
@media (max-width: 640px) {
  .nav a.hide-m { display: none; }
  .logo small { display: none; }
}

/* Hero */
.hero { background: var(--bg-soft); border-bottom: 1px solid var(--line); }
.hero-inner { max-width: var(--max); margin: 0 auto; padding: 36px 16px 30px; }
.hero h1 { font-size: clamp(1.6rem, 4.5vw, 2.4rem); line-height: 1.2; margin: 0 0 10px; letter-spacing: -0.01em; }
.hero p { color: var(--muted); margin: 0 0 18px; max-width: 640px; font-size: 1.02rem; }
.hero-search { display: flex; gap: 8px; max-width: 560px; }
.hero-search input {
  flex: 1; padding: 12px 14px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) var(--ease-out);
}
.search-link { transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-fast) ease; }
.search-link:active { transform: scale(0.97); }
.btn {
  display: inline-block; border: none; cursor: pointer; font-weight: 700;
  background: var(--brand); color: #fff; border-radius: 10px; padding: 12px 18px; font-size: 0.98rem;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-fast) ease;
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--brand-dark); text-decoration: none; }
}
.btn:active { transform: scale(0.97); }
.btn-ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.quick-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.quick-tags a {
  font-size: 0.85rem; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
@media (hover: hover) and (pointer: fine) {
  .quick-tags a:hover { background: var(--bg-soft); text-decoration: none; }
}
.quick-tags a:active { transform: scale(0.97); }

/* Sections + cards */
.section { padding: 28px 0 8px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.section-head h2 { font-size: 1.3rem; margin: 0; }
.section-head a { margin-left: auto; font-size: 0.9rem; font-weight: 600; white-space: nowrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
/* Stagger: occasional page/section entry only, 45ms steps, never blocks interaction */
.grid > * { animation: card-in var(--dur-ui) var(--ease-out) backwards; }
.grid > *:nth-child(2) { animation-delay: calc(var(--stagger) * 1); }
.grid > *:nth-child(3) { animation-delay: calc(var(--stagger) * 2); }
.grid > *:nth-child(4) { animation-delay: calc(var(--stagger) * 3); }
.grid > *:nth-child(5) { animation-delay: calc(var(--stagger) * 4); }
.grid > *:nth-child(6) { animation-delay: calc(var(--stagger) * 5); }
.grid > *:nth-child(7) { animation-delay: calc(var(--stagger) * 6); }
.grid > *:nth-child(8) { animation-delay: calc(var(--stagger) * 7); }
.grid > *:nth-child(n+9) { animation-delay: calc(var(--stagger) * 8); }
@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
  transition: transform var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out), box-shadow var(--dur-ui) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .card:hover { box-shadow: 0 6px 22px rgba(0, 0, 0, 0.08); transform: translateY(-2px); border-color: color-mix(in srgb, var(--brand) 30%, var(--line)); }
}
.card:active { transform: scale(0.98); transition-duration: 100ms; }
.card h3 { margin: 0; font-size: 1.02rem; line-height: 1.4; }
.card h3 a { color: var(--text); }
.card p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, transparent);
  border-radius: 999px; padding: 3px 10px; align-self: flex-start;
}
.card-meta { font-size: 0.78rem; color: var(--muted); margin-top: auto; }

/* Converter tool */
.tool {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 20px 0;
}
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tool-grid .full { grid-column: 1 / -1; }
.tool-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.tool-col { display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--line); border-top: 4px solid var(--cv, var(--line)); border-radius: 10px; padding: 12px; background: var(--cv-soft, transparent); }
.tool-col.col-a { --cv: var(--col-a); --cv-soft: color-mix(in srgb, var(--col-a) 8%, transparent); }
.tool-col.col-b { --cv: var(--col-b); --cv-soft: color-mix(in srgb, var(--col-b) 8%, transparent); }
.tool-col.col-u { --cv: var(--col-u); --cv-soft: color-mix(in srgb, var(--col-u) 10%, transparent); }
.tool-col.col-a > .field label { color: var(--col-a); }
.tool-col.col-b > .field label { color: var(--col-b); }
.tool-col.col-u > .field label { color: var(--col-u); }
.tool-col.col-a input:focus, .tool-col.col-a select:focus { outline: 2px solid var(--col-a); outline-offset: 1px; }
.tool-col.col-b input:focus, .tool-col.col-b select:focus { outline: 2px solid var(--col-b); outline-offset: 1px; }
.tool-col.col-u input:focus, .tool-col.col-u select:focus { outline: 2px solid var(--col-u); outline-offset: 1px; }
@media (max-width: 640px) { .tool-cols { grid-template-columns: 1fr; } }
.field label { display: block; font-weight: 700; font-size: 0.85rem; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 12px; font-size: 1rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) var(--ease-out);
}
.result {
  grid-column: 1 / -1; background: var(--bg-soft); border: 1px dashed var(--line);
  border-radius: 10px; padding: 14px; font-size: 1.02rem; overflow-wrap: anywhere;
}
/* Blur masks the text swap so value changes feel like one morph, not two objects overlapping */
.result-content { display: block; transition: opacity var(--dur-ui) ease, filter var(--dur-ui) ease; }
.result.updating .result-content { opacity: 0.7; filter: blur(2px); }
.result strong { font-size: 1.25rem; }
.result strong.res-a { color: var(--col-a); }
.result strong.res-b { color: var(--col-b); }
.result strong.res-u { color: var(--col-u); }
.compare-line { font-size: 0.95rem; color: var(--muted); margin-top: 4px; }
@media (max-width: 640px) { .tool-grid { grid-template-columns: 1fr; } }

/* Bars - true proportional chart: track is the axis, fill scaleX encodes value (GPU, off main thread) */
.bars { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.scale-note { font-size: 0.8rem; color: var(--muted); margin: 0 0 6px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr auto; gap: 10px; align-items: center; font-size: 0.88rem; padding: 2px 4px; border-radius: 6px; }
.bar-row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 6px; height: 18px; overflow: hidden; display: block; width: 100%; }
.bar-fill { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--brand), #7c3aed); border-radius: 5px; min-width: 2px; transform-origin: left center; transform: scaleX(0); transition: transform var(--dur-chart) var(--ease-out); }
.bar-fill.is-in { transform: scaleX(var(--fill, 0)); }
.bar-row .val { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-row.selected { outline: 2px solid var(--accent); }
@media (max-width: 640px) { .bar-row { grid-template-columns: 110px 1fr auto; font-size: 0.8rem; } }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); margin: 18px 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; min-width: 560px; }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.data th { background: var(--bg-soft); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
table.data tr:last-child td { border-bottom: none; }
table.data td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-link { cursor: pointer; }
.row-link td { transition: background-color var(--dur-fast) ease; }
@media (hover: hover) and (pointer: fine) {
  .row-link:hover td { background: var(--bg-soft); }
}
.row-link:active td { background: var(--bg-soft); }

/* Article */
.article { max-width: 1024px; }
.article h2 { font-size: 1.25rem; margin-top: 30px; }
.breadcrumb { font-size: 0.85rem; color: var(--muted); margin: 18px 0 0; }
.breadcrumb a { color: var(--muted); }
.notice {
  background: var(--warn-bg); border: 1px solid var(--warn-line);
  border-radius: 10px; padding: 12px 14px; font-size: 0.9rem; margin: 16px 0;
}
.faq details { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--card); transition: border-color var(--dur-fast) ease; }
.faq summary { cursor: pointer; font-weight: 700; padding: 12px 14px; }
.faq details p { padding: 0 14px 12px; margin: 0; color: var(--muted); }
.faq details[open] > p { animation: faq-in var(--dur-ui) var(--ease-out); }
@keyframes faq-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.sources { font-size: 0.88rem; color: var(--muted); }
.updated { font-size: 0.82rem; color: var(--muted); }

/* Pagination */
.pagination { display: flex; gap: 8px; justify-content: center; padding: 26px 0; flex-wrap: wrap; }
.pagination a, .pagination span {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; font-weight: 600; font-size: 0.9rem;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.pagination a:active { transform: scale(0.97); }
.pagination span.current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Search page - instant filtering for keyboard input, gentle opacity-only entrance */
.search-results { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.search-hit { animation: search-in var(--dur-fast) var(--ease-out); }
@keyframes search-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Recently updated list */
ul.recent { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
ul.recent li { display: flex; gap: 10px; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 0.93rem; }
ul.recent li:last-child { border-bottom: none; }
ul.recent span { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.search-hit { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--card); }
.search-hit h3 { margin: 0 0 4px; font-size: 1rem; }
.search-hit p { margin: 0; color: var(--muted); font-size: 0.88rem; }
mark { background: #fef08a; border-radius: 3px; padding: 0 2px; }
[data-theme="dark"] mark { background: #713f12; color: #fff; }

/* Footer */
.site-footer { border-top: 1px solid var(--line); margin-top: 40px; background: var(--bg-soft); }
.footer-inner {
  max-width: var(--max); margin: 0 auto; padding: 28px 16px;
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 20px; font-size: 0.9rem;
}
.footer-inner h4 { margin: 0 0 8px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.footer-inner ul { list-style: none; margin: 0; padding: 0; }
.footer-inner li { margin: 4px 0; }
.footer-bottom { max-width: var(--max); margin: 0 auto; padding: 0 16px 22px; font-size: 0.8rem; color: var(--muted); }
.footer-bottom a { color: var(--muted); }
@media (max-width: 640px) { .footer-inner { grid-template-columns: 1fr; } }
.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--muted); font-size: 0.8rem; text-decoration: underline; text-underline-offset: 2px;
}
.link-btn:hover { color: var(--text); }

/* Static / legal pages */
.article ul { padding-left: 22px; }
.article li { margin: 6px 0; }
.article code { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 0.85em; }
.contact-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 16px 0;
}
.btn-small { padding: 10px 18px; font-size: 0.9rem; }

/* Cookie consent banner - minimal, no dependencies, bottom sheet */
.cookie-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.cookie-banner[hidden] { display: none; }
.cookie-inner {
  pointer-events: auto;
  max-width: var(--max); margin: 0 auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
  padding: 14px 16px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  animation: cookie-in var(--dur-ui) var(--ease-drawer) backwards;
}
.cookie-inner p { margin: 0; font-size: 0.88rem; flex: 1 1 260px; }
.cookie-actions { display: flex; gap: 8px; flex: none; }
@keyframes cookie-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Skip link + a11y */
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: var(--brand); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Accessibility: reduced motion means gentler, not zero.
   Keep opacity fades that aid comprehension, drop all movement. */
@media (prefers-reduced-motion: reduce) {
  .grid > *,
  .search-hit,
  .cookie-inner,
  .faq details[open] > p { animation: none; }
  .card, .btn, .icon-btn, .nav a, .quick-tags a, .pagination a, .search-link,
  .field input, .field select, .hero-search input,
  .row-link td, .faq details { transition-duration: 0.01ms !important; }
  .card:hover { transform: none; box-shadow: none; }
  .btn:active, .icon-btn:active, .nav a:active, .card:active,
  .quick-tags a:active, .pagination a:active { transform: none; }
  .bar-fill { transition: none; transform: scaleX(var(--fill, 0)); }
  .result-content { transition: opacity 0.2s ease; }
  .result.updating .result-content { filter: none; opacity: 0.85; }
}
