/* LiteraryWorm Author Platform: tokens and components from the Figma wireframes
   (file N3i2LoRrqpEExaqwPWKXeP, variable collection "Dark" mode).
   Breakpoints follow the four frames: ≥1200 sidebar (1440 desktop, 1280 laptop/Chromebook),
   768–1199 icon rail (834 tablet), <768 mobile top bar + bottom tab bar (390). */
:root {
  --bg: #0b0d0f;
  --surface: #111416;
  --surface-raised: #181c1e;
  --surface-high: #232729;
  --field: #0e1112;
  --line: #292d30;
  --line-strong: #3a3e40;
  --ink: #f6f1e8;
  --ink-soft: #d6d3cc;
  --muted: #a3a7a9;
  --faint: #868b8e;
  --rust: #b85e3d;
  --rust-bright: #d47652;
  --rust-deep: #633421;
  --rust-wash: #3a241c;
  --rust-ink: #efb095;
  --on-accent: #150f0b;
  --success: #8cc59a;
  --success-wash: #25302b;
  --star: #d99154;
  --star-wash: #352b21;
  --danger: #e5826f;
  --danger-wash: #3a2220;
  --pad: 32px;
  color-scheme: dark;
  font-optical-sizing: auto;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/22px "DM Sans", system-ui, sans-serif; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--rust-bright); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 16px; z-index: 10; background: var(--surface); padding: 8px 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Type styles (Figma text styles) */
.h1 { font: 800 28px/36px Manrope, system-ui, sans-serif; letter-spacing: -0.28px; margin: 0; }
.h2 { font: 700 20px/28px Manrope, system-ui, sans-serif; letter-spacing: -0.1px; margin: 0; }
.h3 { font: 700 16px/22px Manrope, system-ui, sans-serif; margin: 0; }
.body-strong { font-weight: 600; }
.small { font-size: 13px; line-height: 18px; }
.small-strong { font-size: 13px; line-height: 18px; font-weight: 600; }
.caps { font-size: 11px; line-height: 16px; font-weight: 600; letter-spacing: 0.88px; text-transform: uppercase; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.soft { color: var(--ink-soft); }
.accent { color: var(--rust-ink); }
.success { color: var(--success); }
.warning { color: var(--star); }
p { margin: 0; }

/* Icons: a 20×20 box; the Figma glyph SVG keeps its own width/height and sits where Figma puts it. */
.ic { position: relative; display: inline-block; flex: none; width: 20px; height: 20px; }
.ic > img { position: absolute; left: calc(50% + var(--dx, 0px)); top: calc(50% + var(--dy, 0px)); transform: translate(-50%, -50%); display: block; max-width: none; }
.ic-18 { width: 18px; height: 18px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; flex: none; width: 248px;
  display: flex; flex-direction: column; gap: 4px; padding: 20px 16px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; font: 800 20px/24px Manrope, system-ui, sans-serif; letter-spacing: -0.2px; white-space: nowrap; }
.logo-mark { position: relative; width: 34px; height: 34px; flex: none; }
.logo-mark img { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: block; }
.sidebar .caps { color: var(--faint); }
.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink-soft); white-space: nowrap; }
.nav:hover { background: var(--surface-raised); }
.nav[aria-current="page"] { background: var(--rust-wash); color: var(--rust-ink); font-weight: 600; }
.spacer { flex: 1 1 0; min-width: 1px; min-height: 1px; }
.plan-card { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 12px; background: var(--surface-raised); border: 1px solid var(--line); }

.rail {
  display: none; position: sticky; top: 0; height: 100vh; flex: none; width: 80px;
  flex-direction: column; align-items: center; gap: 6px; padding: 20px 12px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.rail .nav { padding: 10px 12px; }

.main { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; height: 72px; padding: 0 var(--pad); background: var(--bg); border-bottom: 1px solid var(--line); }
.search { display: flex; align-items: center; gap: 8px; width: 340px; max-width: 100%; padding: 10px 12px; border-radius: 10px; background: var(--field); border: 1px solid var(--line); color: var(--faint); }
.search input { all: unset; flex: 1; min-width: 0; color: var(--ink); }
.search input::placeholder { color: var(--faint); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; background: none; }
.avatar { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 32px; height: 32px; border-radius: 16px; background: var(--rust-deep); color: var(--rust-ink); font-size: 13px; line-height: 18px; font-weight: 600; }
.topbar-m { display: none; position: sticky; top: 0; z-index: 5; align-items: center; gap: 16px; height: 60px; padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.tabbar { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; padding: 6px 8px calc(22px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--line); }
.tab { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 6px; color: var(--muted); font-size: 13px; line-height: 18px; }
.tab[aria-current="page"] { color: var(--rust-bright); font-weight: 600; }

.content { display: flex; flex-direction: column; gap: 24px; padding: var(--pad); }

/* ---------- Components ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 10px; border: 0; font-weight: 600; white-space: nowrap; }
.btn-primary { background: var(--rust-bright); color: var(--on-accent); }
.btn-primary:hover { background: #dd8564; }
.btn-secondary { background: var(--surface-high); color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--line-strong); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.page-header { display: flex; align-items: center; gap: 12px; }
.page-header > .titles { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.page-header .titles p { color: var(--muted); }

.card { display: flex; flex-direction: column; gap: 14px; padding: 20px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.card-header { display: flex; align-items: center; gap: 8px; }
.card-header .link { font-size: 13px; line-height: 18px; font-weight: 600; color: var(--rust-ink); }

.chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 13px; line-height: 18px; font-weight: 600; white-space: nowrap; background: var(--rust-wash); color: var(--rust-ink); }
.chip-success { background: var(--success-wash); color: var(--success); }
.chip-warning { background: var(--star-wash); color: var(--star); }
.chip-neutral { background: var(--surface-high); color: var(--ink-soft); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { display: flex; flex-direction: column; gap: 6px; padding: 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.stat .label { font-size: 13px; line-height: 18px; color: var(--muted); }
.stat .value { font: 800 28px/36px Manrope, system-ui, sans-serif; letter-spacing: -0.28px; }
.stat .delta { font-size: 13px; line-height: 18px; color: var(--success); }

.progress { position: relative; height: 6px; border-radius: 3px; background: var(--surface-high); overflow: hidden; width: 100%; }
.progress > span { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--rust-bright); }

.split { display: grid; grid-template-columns: minmax(0, 734fr) minmax(0, 378fr); gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.book-row { display: flex; align-items: center; gap: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.book-row .info { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.book-row .title { display: flex; align-items: center; gap: 8px; font-weight: 600; flex-wrap: wrap; }
.cover {
  flex: none; width: 43.2px; height: 64.8px; padding: 4.5px; border-radius: 2.7px; border: .45px solid var(--line-strong);
  display: flex; flex-direction: column; justify-content: space-between;
  background-image: linear-gradient(131.6deg, #633321 14.3%, #242629 85.7%);
}
.cover::before { content: ""; display: block; width: 10.8px; height: 1.35px; border-radius: .9px; background: var(--rust-bright); }
.cover span { font: 600 6.3px/8.1px Literata, Georgia, serif; color: var(--ink); }

.check-row { display: flex; align-items: center; gap: 12px; }
.check-row.done { color: var(--muted); }
.date-badge { flex: none; display: flex; flex-direction: column; align-items: center; padding: 6px 8px; border-radius: 8px; background: var(--rust-wash); color: var(--rust-ink); font-size: 11px; line-height: 16px; font-weight: 600; letter-spacing: .88px; text-transform: uppercase; white-space: nowrap; }
.event-row { display: flex; align-items: center; gap: 12px; }
.event-row > div:last-child { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 18px; }
.metrics { display: flex; gap: 32px; flex-wrap: wrap; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric .num { font: 700 20px/28px Manrope, system-ui, sans-serif; letter-spacing: -0.1px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; }
.bars > span { flex: 1 1 0; min-width: 1px; border-radius: 4px; background: var(--rust); }
.bars > span.now { background: var(--rust-bright); }
.usage { display: flex; flex-direction: column; gap: 8px; }
.usage > div { display: flex; align-items: center; gap: 8px; font-size: 13px; line-height: 18px; }

/* Shared form controls for pages that need them */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; line-height: 18px; font-weight: 600; color: var(--ink-soft); }
.input, .select, .textarea { width: 100%; padding: 10px 12px; border-radius: 10px; background: var(--field); border: 1px solid var(--line); color: var(--ink); font: inherit; }
.textarea { min-height: 120px; resize: vertical; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs .tab-item { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs .tab-item[aria-selected="true"], .tabs .tab-item[aria-current="page"] { color: var(--ink); border-bottom-color: var(--rust-bright); font-weight: 600; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.toggle { position: relative; width: 40px; height: 24px; border-radius: 12px; background: var(--surface-high); border: 1px solid var(--line); flex: none; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .15s; }
.toggle[aria-checked="true"] { background: var(--rust-bright); border-color: var(--rust-bright); }
.toggle[aria-checked="true"]::after { transform: translateX(16px); background: var(--on-accent); }

/* ---------- Responsive ---------- */
@media (max-width: 1399px) { :root { --pad: 24px; } }
@media (max-width: 1199px) {
  .sidebar { display: none; }
  .rail { display: flex; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .split > .stack { gap: 24px; }
  .page-header { align-items: flex-start; flex-wrap: wrap; }
}
@media (max-width: 767px) {
  :root { --pad: 16px; }
  .rail, .topbar { display: none; }
  .topbar-m { display: flex; }
  .tabbar { display: flex; }
  .content { gap: 20px; padding-bottom: calc(16px + 80px + env(safe-area-inset-bottom, 0px)); }
  .stats { gap: 12px; }
  .stat .value { font-size: 24px; line-height: 32px; }
  .page-header { flex-direction: column; align-items: stretch; gap: 20px; }
  .page-header .btn { align-self: flex-start; }
  .hide-m { display: none !important; }
  .metrics { gap: 20px; }
}
@media (min-width: 768px) { .only-m { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
