:root {
  color-scheme: light;
  --paper: #f4f1ea;
  --paper-deep: #eae5da;
  --surface: rgba(255, 253, 248, 0.78);
  --ink: #1f2925;
  --muted: #6f7771;
  --line: rgba(35, 52, 45, 0.12);
  --green: #1c3b32;
  --green-soft: #dce6de;
  --accent: #eead49;
  --danger: #a4493f;
  --reader-size: 21px;
  --shadow: 0 20px 60px rgba(43, 52, 46, 0.09);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 4%, rgba(238, 173, 73, 0.12), transparent 28rem),
    radial-gradient(circle at 4% 80%, rgba(59, 105, 89, 0.08), transparent 32rem),
    var(--paper);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100dvh; }

.library {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 88px;
  animation: page-in 480ms var(--ease) both;
}

.brand-row, .reader-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand { display: inline-flex; align-items: center; gap: 11px; }
.brand-mark { width: 34px; height: 34px; filter: drop-shadow(0 6px 10px rgba(28, 59, 50, 0.12)); }
.brand-word { font-weight: 680; letter-spacing: -0.025em; }
.brand-slash { color: var(--accent); padding: 0 2px; }
.brand-sub { color: var(--muted); font-size: 13px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.settings-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--green);
  background: rgba(255, 253, 248, .52);
  cursor: pointer;
  font-size: 11px;
  font-weight: 680;
  transition: transform 180ms var(--ease), background 180ms ease, border-color 180ms ease;
}
.settings-link:hover { transform: translateY(-1px); border-color: rgba(28,59,50,.24); background: rgba(255,255,255,.82); }
.settings-link:active { transform: scale(.96); }

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}
.status-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5a9375;
  box-shadow: 0 0 0 4px rgba(90, 147, 117, 0.11);
}
.status-dot.offline::before { background: var(--danger); box-shadow: 0 0 0 4px rgba(164, 73, 63, 0.1); }

.hero { padding: clamp(72px, 10vw, 132px) 0 clamp(48px, 7vw, 84px); max-width: 820px; }
.eyebrow {
  margin: 0 0 18px;
  color: #587066;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.hero h1 {
  max-width: 760px;
  margin: 0;
  font-family: Iowan Old Style, Charter, Georgia, serif;
  font-size: clamp(46px, 7vw, 82px);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 0.99;
}
.hero h1 em { color: var(--green); font-weight: 500; text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 0.08em; text-underline-offset: 0.12em; }
.hero-copy { max-width: 540px; margin: 28px 0 0; color: var(--muted); font-size: 16px; line-height: 1.65; }

.queue-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 24px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 253, 248, .5);
}
.queue-status-title { color: var(--muted); font-size: 9px; font-weight: 760; letter-spacing: .12em; text-transform: uppercase; }
.queue-status-items { display: flex; align-items: center; gap: 16px; }
.queue-status-item { display: flex; align-items: center; gap: 9px; min-width: 150px; }
.queue-status-item > span:last-child { display: grid; gap: 2px; }
.queue-status-item strong { font-size: 11px; font-weight: 720; }
.queue-status-item small { color: var(--muted); font-size: 10px; white-space: nowrap; }
.queue-status-light { position: relative; width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #9ba39e; }
.queue-status-item.active .queue-status-light { background: var(--accent); }
.queue-status-item.active .queue-status-light::after { position: absolute; inset: -4px; border: 1px solid rgba(238, 173, 73, .42); border-radius: inherit; content: ""; animation: queue-pulse 1.8s ease-out infinite; }
.queue-status-item.error .queue-status-light { background: var(--danger); }
.queue-status-divider { width: 1px; height: 25px; background: var(--line); }

.library-main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.section-title { margin: 0 0 18px; font-size: 13px; font-weight: 680; letter-spacing: -0.01em; }

.book-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.book-card-shell { position: relative; min-width: 0; }
.book-card {
  position: relative;
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 18px;
  min-height: 136px;
  width: 100%;
  height: 100%;
  padding: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 2px 0 rgba(255, 255, 255, 0.6) inset;
  cursor: pointer;
  transition: transform 260ms var(--ease), box-shadow 260ms var(--ease), border-color 260ms ease;
  text-align: left;
}
.book-card-shell:hover .book-card, .book-card-shell:focus-within .book-card { transform: translateY(-3px); border-color: rgba(35, 52, 45, 0.2); box-shadow: var(--shadow); }
.book-card:active { transform: scale(0.985); }
.book-cover {
  display: flex;
  align-items: flex-end;
  width: 84px;
  height: 100px;
  padding: 11px;
  border-radius: 6px 11px 11px 6px;
  color: rgba(255, 255, 255, 0.85);
  background: linear-gradient(145deg, var(--cover-a), var(--cover-b));
  box-shadow: -3px 0 rgba(255,255,255,.18) inset, 0 12px 22px rgba(28, 59, 50, 0.16);
  font-family: Iowan Old Style, Charter, Georgia, serif;
  font-size: 28px;
}
.book-info { min-width: 0; padding: 4px 30px 0 0; }
.book-info h3 { display: -webkit-box; overflow: hidden; margin: 0 0 7px; font-family: Iowan Old Style, Charter, Georgia, serif; font-size: 20px; font-weight: 550; line-height: 1.16; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-author { overflow: hidden; margin: 0; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.book-progress { position: absolute; right: 18px; bottom: 18px; left: 120px; height: 3px; overflow: hidden; border-radius: 9px; background: var(--paper-deep); }
.book-progress span { display: block; width: var(--progress); height: 100%; border-radius: inherit; background: var(--accent); transition: width 500ms var(--ease); }
.book-meta { position: absolute; right: 18px; bottom: 27px; color: #8b918c; font-size: 10px; }
.book-delete-button {
  position: absolute;
  z-index: 2;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  color: #8d7068;
  background: rgba(255, 253, 248, .9);
  box-shadow: 0 4px 14px rgba(35, 52, 45, .08);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 160ms ease, transform 160ms ease, color 160ms ease, background 160ms ease;
}
.book-card-shell:hover .book-delete-button, .book-delete-button:focus-visible, .book-delete-button.confirming, .book-delete-button.deleting { opacity: 1; transform: translateY(0); }
.book-delete-button:hover { color: var(--danger); background: #fff7f4; }
.book-delete-button.confirming { color: white; background: var(--danger); font-size: 10px; font-weight: 720; }
.book-delete-button.deleting { color: white; background: #8d7068; font-size: 10px; font-weight: 720; }
.book-delete-button:disabled { cursor: default; }

.upload-card {
  position: sticky;
  top: 24px;
  min-height: 250px;
  padding: 30px;
  border: 1px dashed rgba(28, 59, 50, 0.28);
  border-radius: 22px;
  background: rgba(226, 233, 226, 0.38);
  text-align: center;
  transition: background 220ms ease, border-color 220ms ease, transform 220ms var(--ease);
}
.upload-card.dragging { transform: scale(1.015); border-color: var(--green); background: rgba(220, 230, 222, 0.82); }
.upload-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 6px auto 22px;
  border-radius: 50%;
  color: white;
  background: var(--green);
  box-shadow: 0 12px 24px rgba(28, 59, 50, 0.18);
}
.upload-card h2 { margin: 0 0 9px; font-size: 16px; }
.upload-card p { margin: 0 auto 24px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.primary-button, .ghost-button, .icon-button {
  border: 0;
  cursor: pointer;
  transition: transform 180ms var(--ease), background 180ms ease, opacity 180ms ease;
}
.primary-button { padding: 11px 17px; border-radius: 999px; color: white; background: var(--green); font-size: 12px; font-weight: 650; }
.primary-button:hover { transform: translateY(-1px); }
.primary-button:active, .icon-button:active { transform: scale(0.94); }
.primary-button:disabled { cursor: default; opacity: .42; transform: none; }
.file-input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.upload-working { display: grid; place-items: center; min-height: 188px; }
.upload-orbit { position: relative; width: 58px; height: 58px; margin-bottom: 20px; }
.upload-orbit::before, .upload-orbit::after { content: ""; position: absolute; border-radius: 50%; }
.upload-orbit::before { inset: 0; border: 1px solid rgba(28,59,50,.14); }
.upload-orbit::after { inset: 4px; border: 2px solid transparent; border-top-color: var(--accent); animation: orbit 900ms linear infinite; }
.upload-working strong { font-size: 14px; }
.upload-working span { margin-top: 8px; color: var(--muted); font-size: 11px; }
.empty-library { padding: 50px 24px; border: 1px solid var(--line); border-radius: 18px; color: var(--muted); text-align: center; }

.reader { min-height: 100dvh; animation: page-in 340ms var(--ease) both; }
.reader-bar {
  position: sticky;
  z-index: 20;
  top: 0;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 234, 0.87);
  backdrop-filter: blur(20px) saturate(1.2);
}
.reader-bar-inner { width: min(1120px, calc(100% - 28px)); height: 64px; margin: 0 auto; }
.reader-title-wrap { min-width: 0; text-align: center; }
.reader-title { overflow: hidden; max-width: 400px; margin: 0; font-family: Iowan Old Style, Charter, Georgia, serif; font-size: 15px; font-weight: 560; text-overflow: ellipsis; white-space: nowrap; }
.translation-indicator { display: inline-flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 10px; }
.translation-indicator.working::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.bar-actions { display: flex; gap: 5px; }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border-radius: 50%; background: transparent; }
.icon-button:hover { background: rgba(28,59,50,.07); }
.icon-button:disabled { cursor: default; opacity: .32; transform: none; }
.audio-reading-toggle.active { color: white; background: var(--green); box-shadow: 0 7px 20px rgba(28,59,50,.18); }
.audio-reading-toggle.active:hover { background: #294b41; }
.reader-progress { height: 2px; background: transparent; }
.reader-progress span { display: block; width: var(--progress); height: 100%; background: var(--accent); transition: width 240ms linear; }

.reader-page {
  width: min(720px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(68px, 9vw, 110px) 0 130px;
}
.chapter-kicker { margin-bottom: 12px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.chapter-title { margin: 0 0 54px; font-family: Iowan Old Style, Charter, Georgia, serif; font-size: clamp(35px, 7vw, 54px); font-weight: 520; letter-spacing: -.04em; line-height: 1.02; }
.text-block-row { position: relative; margin: 0 0 1.26em; }
.text-block-row::before {
  content: "";
  position: absolute;
  top: 0;
  right: 100%;
  width: 54px;
  height: 44px;
}
.text-block { margin: 0; font-family: Iowan Old Style, Charter, Georgia, serif; font-size: var(--reader-size); line-height: 1.72; }
.text-block-row.heading { margin: 2.2em 0 .8em; }
.text-block.heading { font-size: calc(var(--reader-size) * 1.35); font-weight: 600; line-height: 1.25; }
.text-block.quote { margin-left: 0; padding-left: 22px; border-left: 2px solid var(--accent); color: #32473f; }
.text-block.list { padding-left: 18px; }
.new-words {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 10px;
  align-items: baseline;
  margin-top: 7px;
  padding-left: 1px;
  color: #596961;
  font-size: 11px;
  line-height: 1.55;
}
.new-words[hidden] { display: none; }
.new-words-label {
  flex: 0 0 auto;
  color: #9a6d28;
  font-size: 8px;
  font-weight: 780;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.new-words-items { display: inline-flex; flex-wrap: wrap; gap: 2px 7px; min-width: 0; }
.new-word { white-space: normal; }
.new-word strong { color: var(--green); font-weight: 720; }
.new-word small { color: #748078; font-size: .92em; }
.new-word-translation { color: #596961; }
.new-word-divider { color: rgba(89,105,97,.42); }
.paragraph-audio-button {
  position: absolute;
  z-index: 1;
  top: .18em;
  right: calc(100% + 14px);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgba(28,59,50,.13);
  border-radius: 50%;
  opacity: 0;
  color: var(--green);
  background: rgba(251,249,244,.92);
  box-shadow: 0 6px 20px rgba(28,59,50,.08);
  cursor: pointer;
  pointer-events: none;
  transform: translateX(5px);
  transition: opacity 160ms ease, transform 180ms var(--ease), background 180ms ease, color 180ms ease, border-color 180ms ease;
}
.text-block-row:hover .paragraph-audio-button,
.paragraph-audio-button:focus-visible,
.paragraph-audio-button.loading,
.paragraph-audio-button.playing,
.paragraph-audio-button.paused {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}
.paragraph-audio-button:hover { border-color: rgba(28,59,50,.3); background: white; }
.paragraph-audio-button:active { transform: scale(.93); }
.paragraph-audio-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.paragraph-audio-button:disabled { cursor: default; transform: translateX(0); }
.text-block-row:hover .paragraph-audio-button:disabled { opacity: .26; }
.paragraph-audio-button.playing { color: white; border-color: var(--green); background: var(--green); animation: speech-pulse 1.8s ease-in-out infinite; }
.paragraph-audio-button.paused { border-color: rgba(28,59,50,.3); background: var(--green-soft); }
.paragraph-audio-button.playing .speech-speaker-icon { display: none; }
.paragraph-audio-button.playing .speech-pause-icon { display: grid; }
.paragraph-audio-button.loading .speech-speaker-icon { opacity: .18; }
.paragraph-audio-button.loading .speech-spinner {
  position: absolute;
  display: block;
  inset: 5px;
  border: 1.5px solid transparent;
  border-top-color: var(--accent);
  border-right-color: rgba(238,173,73,.35);
  border-radius: 50%;
  animation: orbit 780ms linear infinite;
}
.text-block-row.audio-active .text-block { text-shadow: 0 0 24px rgba(238,173,73,.1); }
.sentence {
  display: inline;
  margin: 0;
  padding: 2px 1px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  font: inherit;
  line-height: inherit;
  text-align: left;
  cursor: pointer;
  overflow: visible;
  transition: background 180ms ease, color 180ms ease;
}
.sentence strong, .sheet-original strong, .sheet-translation strong { font-weight: 750; }
.sentence em, .sheet-original em, .sheet-translation em { font-style: italic; }
.sentence u, .sheet-original u, .sheet-translation u { text-decoration-thickness: .07em; text-underline-offset: .12em; }
.sentence s, .sheet-original s, .sheet-translation s { text-decoration-thickness: .07em; }
.sentence code, .sheet-original code, .sheet-translation code { padding: .08em .22em; border-radius: 4px; background: rgba(28,59,50,.07); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84em; }
.sentence mark, .sheet-original mark, .sheet-translation mark { padding: 0 .08em; color: inherit; background: rgba(238,173,73,.26); }
.sentence:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.syntax-fragment {
  --syntax-edge-color: rgba(28, 59, 50, .18);
  --syntax-left-cap: 0px;
  --syntax-right-cap: 0px;
  background-image: linear-gradient(var(--syntax-edge-color), var(--syntax-edge-color)),
    linear-gradient(var(--syntax-edge-color), var(--syntax-edge-color)),
    linear-gradient(var(--syntax-edge-color), var(--syntax-edge-color)),
    linear-gradient(var(--syntax-edge-color), var(--syntax-edge-color));
  background-position: left top, left bottom, right top, right bottom;
  background-size: var(--syntax-left-cap) 1px, var(--syntax-left-cap) 1px,
    var(--syntax-right-cap) 1px, var(--syntax-right-cap) 1px;
  background-repeat: no-repeat;
  padding-top: .12em;
  padding-bottom: .15em;
  -webkit-box-decoration-break: slice;
  box-decoration-break: slice;
}
.syntax-start { --syntax-left-cap: .2em; border-left: 1px solid var(--syntax-edge-color); }
.syntax-end { --syntax-right-cap: .2em; border-right: 1px solid var(--syntax-edge-color); }
.syntax-panel { margin: 18px 0; padding: 15px 16px; border: 1px solid var(--line); border-radius: 12px; }
.syntax-frame { display: flex; flex-wrap: wrap; gap: 6px 9px; margin: 0; font-size: 14px; line-height: 1.6; font-weight: 600; }
.syntax-arrow { color: var(--muted); font-weight: 400; }
.syntax-block-glosses { margin-top: 12px; }
.syntax-block-glosses p { display: grid; gap: 3px; margin: 10px 0 0; font-size: 12px; line-height: 1.5; }
.syntax-block-glosses p > span:first-child { color: var(--muted); }
.syntax-setting { display: flex; align-items: center; justify-content: space-between; gap: 20px; cursor: pointer; font-size: 15px; }
.syntax-setting input { width: 20px; height: 20px; accent-color: var(--green); flex: 0 0 auto; }
.word-token {
  --word-difficulty: 0;
  margin: 0 -.02em;
  padding: .04em .02em;
  border-radius: .2em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  cursor: help;
  background:
    linear-gradient(
      rgb(69 166 224 / calc(var(--word-difficulty) * .34)),
      rgb(69 166 224 / calc(var(--word-difficulty) * .34))
    ),
    transparent;
  transition: background 520ms ease, box-shadow 150ms ease;
}
.word-token:hover {
  background:
    linear-gradient(
      rgb(69 166 224 / calc(var(--word-difficulty) * .34)),
      rgb(69 166 224 / calc(var(--word-difficulty) * .34))
    ),
    rgba(28, 59, 50, .075);
}
.word-token.new-word-token {
  background:
    linear-gradient(
      rgb(69 166 224 / calc(var(--word-difficulty) * .34)),
      rgb(69 166 224 / calc(var(--word-difficulty) * .34))
    ),
    rgba(238, 173, 73, .14);
  box-shadow: 0 .08em 0 rgba(238, 173, 73, .18);
}
.word-token.new-word-token:hover {
  background:
    linear-gradient(
      rgb(69 166 224 / calc(var(--word-difficulty) * .34)),
      rgb(69 166 224 / calc(var(--word-difficulty) * .34))
    ),
    rgba(238, 173, 73, .22);
}
.sentence.pending {
  position: relative;
  display: inline-block;
  width: min(var(--placeholder-width, 70%), 100%);
  min-width: 120px;
  height: .82em;
  margin: .18em 8px .12em 0;
  overflow: hidden;
  vertical-align: baseline;
  border-radius: 4px;
  background: #e4dfd4;
}
.sentence.pending::after { content: ""; position: absolute; inset: 0; transform: translateX(-110%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.52), transparent); animation: shimmer 1.5s ease-in-out infinite; }
.sentence.just-translated { animation: translated-in 720ms var(--ease) both; }
.word-tooltip {
  position: fixed;
  z-index: 80;
  width: max-content;
  max-width: min(270px, calc(100vw - 24px));
  padding: 10px 12px 11px;
  border: 1px solid rgba(255,255,255,.68);
  border-radius: 11px;
  color: #f7f4ed;
  background: rgba(28, 43, 37, .96);
  box-shadow: 0 14px 38px rgba(20,29,25,.23);
  backdrop-filter: blur(14px) saturate(1.1);
  pointer-events: none;
  animation: tooltip-in 170ms var(--ease) both;
}
.word-tooltip[hidden] { display: none; }
.word-tooltip-head { display: flex; align-items: baseline; gap: 7px; margin-bottom: 3px; }
.word-tooltip-head strong { font-family: Iowan Old Style, Charter, Georgia, serif; font-size: 15px; font-weight: 700; }
.word-tooltip-lemma { color: #b7c8bf; font-size: 10px; }
.word-tooltip-translation { display: block; color: #f7f4ed; font-size: 12px; line-height: 1.38; text-wrap: pretty; }
.chapter-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 80px; padding-top: 28px; border-top: 1px solid var(--line); }
.chapter-link { min-height: 72px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.28); cursor: pointer; text-align: left; transition: background 180ms ease, transform 180ms var(--ease); }
.chapter-link:hover { background: rgba(255,255,255,.68); transform: translateY(-2px); }
.chapter-link.next { text-align: right; }
.chapter-link span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }

.settings-page {
  width: min(980px, calc(100% - 40px));
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 100px;
  animation: page-in 420ms var(--ease) both;
}
.settings-topbar { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; min-height: 44px; }
.settings-topbar .brand { justify-self: center; }
.settings-top-spacer { width: 40px; }
.settings-hero { max-width: 650px; padding: clamp(64px, 9vw, 104px) 0 54px; }
.settings-hero h1 {
  margin: 0 0 18px;
  font-family: Iowan Old Style, Charter, Georgia, serif;
  font-size: clamp(42px, 7vw, 68px);
  font-weight: 520;
  letter-spacing: -.05em;
  line-height: 1;
}
.settings-hero > p:last-child { max-width: 540px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.settings-form { display: grid; gap: 18px; }
.settings-section {
  padding: clamp(24px, 4vw, 42px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 253, 248, .7);
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset;
}
.settings-heading { display: grid; grid-template-columns: minmax(240px, .8fr) minmax(280px, 1.2fr); gap: 32px; align-items: end; margin-bottom: 28px; }
.settings-heading > div { display: flex; align-items: baseline; gap: 13px; }
.settings-number { color: var(--accent); font-size: 10px; font-weight: 760; letter-spacing: .08em; }
.settings-heading h2 { margin: 0; font-size: 19px; letter-spacing: -.025em; }
.settings-heading p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.level-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.level-card {
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 11px;
  min-height: 88px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(244, 241, 234, .52);
  cursor: pointer;
  text-align: left;
  transition: transform 200ms var(--ease), background 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}
.level-card:hover { transform: translateY(-2px); border-color: rgba(28,59,50,.24); background: rgba(255,255,255,.72); }
.level-card.selected { border-color: var(--green); background: var(--green-soft); box-shadow: 0 0 0 1px var(--green) inset; }
.level-code { display: grid; place-items: center; align-self: start; min-height: 32px; border-radius: 9px; color: var(--green); background: rgba(255,255,255,.58); font-size: 11px; font-weight: 780; }
.level-copy { min-width: 0; padding-right: 10px; }
.level-copy strong { display: block; margin: 1px 0 5px; font-size: 12px; }
.level-copy small { display: block; color: var(--muted); font-size: 10px; line-height: 1.4; }
.level-check { position: absolute; top: 9px; right: 10px; color: var(--green); font-size: 10px; opacity: 0; transform: scale(.7); transition: opacity 180ms ease, transform 180ms var(--ease); }
.level-card.selected .level-check { opacity: 1; transform: scale(1); }
.instruction-field { position: relative; display: block; }
.instruction-field textarea {
  display: block;
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 20px 20px 38px;
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
  color: var(--ink);
  background: rgba(244, 241, 234, .62);
  font-size: 14px;
  line-height: 1.6;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
.instruction-field textarea::placeholder { color: #969c97; }
.instruction-field textarea:focus { border-color: rgba(28,59,50,.5); background: rgba(255,255,255,.72); box-shadow: 0 0 0 3px rgba(28,59,50,.07); }
.instruction-count { position: absolute; right: 16px; bottom: 13px; color: #929993; font-size: 10px; }
.settings-save-row {
  position: sticky;
  z-index: 10;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 14px 14px 22px;
  border: 1px solid rgba(28,59,50,.12);
  border-radius: 18px;
  background: rgba(244, 241, 234, .88);
  box-shadow: 0 12px 42px rgba(31,41,37,.1);
  backdrop-filter: blur(18px);
}
.settings-save-row p { max-width: 570px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.settings-save-row p.warning { color: #8b4d36; }
.settings-save { flex: 0 0 auto; min-width: 176px; }
.settings-save.saving { opacity: .72; }
.translation-reset-section { border-color: rgba(164,73,63,.16); background: rgba(255,250,247,.56); }
.translation-reset-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 8px 4px; }
.translation-reset-row p { max-width: 620px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.danger-button { flex: 0 0 auto; min-width: 176px; padding: 11px 16px; border: 1px solid rgba(164,73,63,.25); border-radius: 999px; color: var(--danger); background: rgba(255,255,255,.58); cursor: pointer; font-size: 11px; font-weight: 700; transition: transform 180ms var(--ease), color 180ms ease, background 180ms ease, opacity 180ms ease; }
.danger-button:hover { transform: translateY(-1px); border-color: rgba(164,73,63,.5); background: rgba(255,255,255,.9); }
.danger-button.confirming { color: white; background: var(--danger); }
.danger-button.resetting { opacity: .7; cursor: wait; transform: none; }

.sheet-layer { position: fixed; z-index: 100; inset: 0; }
.sheet-layer[hidden] { display: none; }
.sheet-scrim { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(20,29,25,.26); backdrop-filter: blur(4px); animation: fade-in 220ms ease both; }
.sheet {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(620px, calc(100% - 20px));
  max-height: min(76dvh, 620px);
  margin: 0 auto max(10px, env(safe-area-inset-bottom));
  padding: 10px 28px 30px;
  overflow: auto;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 24px;
  background: #fbf9f4;
  box-shadow: 0 24px 80px rgba(20,29,25,.24);
  animation: sheet-in 360ms var(--ease) both;
}
.sheet.analysis-mode { width: min(860px, calc(100% - 20px)); max-height: min(88dvh, 820px); }
.sheet-handle { width: 34px; height: 4px; margin: 0 auto 24px; border-radius: 9px; background: #d3cec3; }
.sheet-title-row { display: flex; align-items: center; justify-content: space-between; min-height: 42px; margin-bottom: 8px; }
.sheet-title-row .sheet-eyebrow { margin: 0; }
.sheet-eyebrow { margin: 0 0 12px; color: #587066; font-size: 10px; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; }
.sentence-speech-button {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(28,59,50,.13);
  border-radius: 50%;
  color: var(--green);
  background: rgba(255,255,255,.62);
  box-shadow: 0 5px 18px rgba(28,59,50,.06);
  cursor: pointer;
  transition: transform 180ms var(--ease), color 180ms ease, background 180ms ease, border-color 180ms ease, opacity 180ms ease;
}
.sentence-speech-button:hover { transform: translateY(-1px); border-color: rgba(28,59,50,.28); background: white; }
.sentence-speech-button:active { transform: scale(.93); }
.sentence-speech-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sentence-speech-button:disabled { opacity: .34; cursor: default; transform: none; }
.sentence-speech-button.playing { color: white; border-color: var(--green); background: var(--green); animation: speech-pulse 1.8s ease-in-out infinite; }
.sentence-speech-button.paused { border-color: rgba(28,59,50,.3); background: var(--green-soft); }
.speech-pause-icon, .speech-spinner { display: none; }
.sentence-speech-button.playing .speech-speaker-icon { display: none; }
.sentence-speech-button.playing .speech-pause-icon { display: grid; }
.sentence-speech-button.loading .speech-speaker-icon { opacity: .18; }
.sentence-speech-button.loading .speech-spinner {
  position: absolute;
  display: block;
  inset: 5px;
  border: 1.5px solid transparent;
  border-top-color: var(--accent);
  border-right-color: rgba(238,173,73,.35);
  border-radius: 50%;
  animation: orbit 780ms linear infinite;
}
.sheet-original { margin: 0 0 24px; font-family: Iowan Old Style, Charter, Georgia, serif; font-size: 20px; line-height: 1.55; }
.sheet-translation { margin: 0; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; line-height: 1.55; }
.analysis-original { margin-bottom: 0; }
.analysis-loading {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 15px;
  align-items: center;
  min-height: 94px;
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.analysis-loading .analysis-orbit { width: 38px; height: 38px; margin: 0; }
.analysis-loading .analysis-orbit::after { inset: 3px; }
.analysis-loading strong { display: block; margin-bottom: 6px; font-size: 13px; }
.analysis-loading span { display: block; color: var(--muted); font-size: 11px; line-height: 1.45; }
.alignment-diagram {
  position: relative;
  min-height: 250px;
  padding: 18px 20px 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(244,241,234,.52);
}
.alignment-language { position: relative; z-index: 3; margin-bottom: 10px; color: var(--muted); font-size: 9px; font-weight: 760; letter-spacing: .12em; text-transform: uppercase; }
.alignment-language.target-label { margin: 10px 0 0; text-align: right; }
.alignment-row {
  position: relative;
  z-index: 3;
  font-family: Iowan Old Style, Charter, Georgia, serif;
  font-size: clamp(18px, 3vw, 23px);
  line-height: 2.05;
  white-space: pre-wrap;
}
.alignment-row.target { margin-top: 104px; text-align: right; }
.alignment-literal { color: var(--ink); }
.alignment-token {
  display: inline;
  margin: 0;
  padding: .09em .2em .12em;
  border: 1px solid color-mix(in srgb, var(--token-color) 34%, transparent);
  border-radius: 6px;
  color: var(--ink);
  background: color-mix(in srgb, var(--token-color) 10%, rgba(255,255,255,.52));
  font: inherit;
  line-height: inherit;
  cursor: pointer;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: opacity 180ms ease, color 180ms ease, background 180ms ease, border-color 180ms ease, transform 180ms var(--ease);
}
.alignment-token:hover, .alignment-token.active { border-color: var(--token-color); color: color-mix(in srgb, var(--token-color) 72%, #17211d); background: color-mix(in srgb, var(--token-color) 17%, white); }
.alignment-token:active { transform: translateY(1px); }
.alignment-token:focus-visible { outline: 2px solid var(--token-color); outline-offset: 2px; }
.alignment-ghosts { display: inline-flex; gap: 5px; margin-left: 10px; }
.alignment-ghost { border-style: dashed; color: var(--token-color); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72em; }
.alignment-arrows { position: absolute; z-index: 2; inset: 0; overflow: visible; pointer-events: none; }
.alignment-arrow { fill: none; stroke-width: 1.65; stroke-linecap: round; opacity: .58; pointer-events: stroke; cursor: pointer; transition: opacity 180ms ease, stroke-width 180ms ease; }
.alignment-arrow:hover, .alignment-arrow.active { stroke-width: 2.6; opacity: 1; }
.alignment-diagram.has-selection .alignment-token:not(.active) { opacity: .23; }
.alignment-diagram.has-selection .alignment-arrow:not(.active) { opacity: .07; }
.analysis-details { min-height: 70px; margin-top: 14px; }
.analysis-hint { margin: 0; padding: 17px 18px; border-radius: 13px; color: var(--muted); background: rgba(244,241,234,.6); font-size: 11px; line-height: 1.5; text-align: center; }
.analysis-detail-card { margin-top: 10px; padding: 16px 17px; border-left: 3px solid var(--detail-color); border-radius: 12px; background: rgba(244,241,234,.72); animation: detail-in 220ms var(--ease) both; }
.analysis-detail-heading { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; margin-bottom: 8px; }
.analysis-detail-heading span { color: var(--detail-color); font-size: 9px; font-weight: 760; letter-spacing: .08em; text-transform: uppercase; }
.analysis-detail-heading strong { font-size: 13px; }
.analysis-detail-card > p { margin: 0; color: #48554f; font-size: 12px; line-height: 1.55; }
.analysis-literal-gloss { display: block; margin-top: 7px; color: var(--ink); }
.analysis-literal-gloss strong { color: var(--muted); font-size: 10px; font-weight: 760; letter-spacing: .04em; text-transform: uppercase; }
.analysis-error { display: grid; gap: 8px; margin-top: 24px; padding: 20px; border-top: 1px solid var(--line); text-align: center; }
.analysis-error strong { font-size: 13px; }
.analysis-error span { color: var(--muted); font-size: 11px; line-height: 1.5; }
.note-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.note-list li { padding: 13px 14px; border-radius: 12px; background: var(--paper); }
.note-list strong { display: block; margin-bottom: 5px; font-size: 11px; }
.note-list span { color: var(--muted); font-size: 12px; line-height: 1.45; }
.difficulty-stats-title { margin-bottom: 18px; }
.difficulty-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-bottom: 22px; }
.difficulty-summary > span { display: grid; gap: 3px; padding: 12px 13px; border: 1px solid rgba(35,52,45,.08); border-radius: 12px; background: var(--paper); }
.difficulty-summary strong { font-family: Iowan Old Style, Charter, Georgia, serif; font-size: 23px; font-weight: 580; }
.difficulty-summary small { color: var(--muted); font-size: 9px; line-height: 1.3; }
.difficulty-stat-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.difficulty-stat-section + .difficulty-stat-section { margin-top: 25px; padding-top: 22px; border-top: 1px solid var(--line); }
.difficulty-stat-section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.difficulty-stat-section-title strong { font-size: 12px; }
.difficulty-stat-section-title span { min-width: 24px; padding: 3px 7px; border-radius: 999px; color: var(--muted); background: var(--paper); font-size: 9px; font-weight: 700; text-align: center; }
.difficulty-stat-explanation { margin: -3px 0 11px; color: var(--muted); font-size: 9px; line-height: 1.45; }
.difficulty-stat-placeholder { margin: 0; padding: 16px; border-radius: 12px; color: var(--muted); background: rgba(244,241,234,.58); font-size: 10px; text-align: center; }
.difficulty-stat-item { padding: 13px 14px 12px; border: 1px solid rgba(35,52,45,.08); border-radius: 13px; background: rgba(244,241,234,.72); }
.difficulty-stat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.difficulty-stat-word { display: grid; min-width: 0; gap: 3px; }
.difficulty-stat-word > span:first-child { display: flex; flex-wrap: wrap; align-items: baseline; gap: 7px; }
.difficulty-stat-word strong { font-family: Iowan Old Style, Charter, Georgia, serif; font-size: 16px; font-weight: 650; }
.difficulty-stat-word small, .difficulty-stat-form { color: var(--muted); font-size: 9px; }
.difficulty-stat-translation { color: #48554f; font-size: 11px; line-height: 1.35; }
.difficulty-stat-count { flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; color: #456c7f; background: rgba(69,166,224,.1); font-size: 9px; font-weight: 700; }
.difficulty-stat-level { display: flex; align-items: center; gap: 9px; margin-top: 10px; }
.difficulty-stat-level small { flex: 0 0 auto; color: var(--muted); font-size: 9px; }
.difficulty-stat-meter { display: block; flex: 1 1 auto; height: 4px; overflow: hidden; border-radius: 999px; background: rgba(69,166,224,.09); }
.difficulty-stat-meter > span { display: block; width: var(--difficulty-level); height: 100%; border-radius: inherit; background: rgb(69 166 224 / .72); transition: width 420ms var(--ease); }
.familiar-word-stat .difficulty-stat-count { color: #3f725d; background: rgba(77,139,108,.1); }
.familiar-word-stat .difficulty-stat-meter { background: rgba(77,139,108,.09); }
.familiar-word-stat .difficulty-stat-meter > span { background: rgba(77,139,108,.72); }
.difficulty-stats-empty { margin-top: 8px; }
.font-controls { display: flex; align-items: center; justify-content: center; gap: 14px; }
.font-controls .icon-button { border: 1px solid var(--line); background: var(--paper); }
.font-sample { min-width: 56px; text-align: center; }

.toast-region { position: fixed; z-index: 200; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.toast { max-width: 340px; padding: 12px 16px; border-radius: 12px; color: white; background: var(--green); box-shadow: 0 12px 40px rgba(20,29,25,.22); font-size: 12px; animation: toast-in 320ms var(--ease) both; }
.toast.error { background: var(--danger); }
.loading-page { display: grid; place-items: center; min-height: 100dvh; }

@keyframes page-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(110%); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: scale(1.65); opacity: .5; } }
@keyframes shimmer { to { transform: translateX(110%); } }
@keyframes translated-in { from { opacity: .25; color: #587066; background: rgba(238,173,73,.16); } }
@keyframes detail-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes speech-pulse { 50% { box-shadow: 0 0 0 5px rgba(28,59,50,.08), 0 7px 20px rgba(28,59,50,.13); } }
@keyframes tooltip-in { from { opacity: 0; transform: translateY(3px) scale(.985); } }
@keyframes queue-pulse { 70%, 100% { opacity: 0; transform: scale(1.65); } }

@media (max-width: 840px) {
  .library-main { grid-template-columns: 1fr; }
  .upload-card { position: static; grid-row: 1; min-height: 0; padding: 24px; }
  .upload-icon { margin-bottom: 15px; }
  .upload-card p { margin-bottom: 18px; }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reader-page { width: min(720px, calc(100% - 72px)); }
  .paragraph-audio-button { right: calc(100% + 2px); width: 32px; height: 32px; }
}

@media (max-width: 600px) {
  .library { width: min(100% - 28px, 520px); padding-top: calc(20px + env(safe-area-inset-top)); }
  .brand-sub, .status-dot span { display: none; }
  .header-actions { gap: 4px; }
  .settings-link { padding: 0 10px; }
  .hero { padding: 68px 0 45px; }
  .hero h1 { font-size: clamp(43px, 14vw, 64px); }
  .hero-copy { font-size: 14px; }
  .queue-status { align-items: flex-start; flex-direction: column; gap: 10px; padding: 13px 14px; }
  .queue-status-items { width: 100%; gap: 10px; }
  .queue-status-item { min-width: 0; flex: 1; }
  .queue-status-item small { white-space: normal; }
  .book-grid { grid-template-columns: 1fr; }
  .reader-page { width: min(100% - 72px, 720px); padding-top: 58px; }
  .reader-bar-inner { width: calc(100% - 16px); gap: 6px; }
  .bar-actions { gap: 0; }
  .bar-actions .icon-button { width: 34px; height: 34px; }
  .reader-title { max-width: 32vw; }
  .chapter-title { margin-bottom: 44px; }
  .new-words { gap: 3px 8px; margin-top: 6px; font-size: 10.5px; }
  .new-words-items { gap: 1px 6px; }
  .chapter-nav { margin-top: 58px; }
  .sheet { width: calc(100% - 12px); padding-right: 22px; padding-left: 22px; border-radius: 22px; }
  .sheet.analysis-mode { width: calc(100% - 12px); max-height: 90dvh; padding-right: 14px; padding-left: 14px; }
  .difficulty-summary { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .difficulty-summary > span { padding: 10px 9px; }
  .difficulty-stat-head { gap: 9px; }
  .alignment-diagram { padding: 15px 13px 17px; border-radius: 15px; }
  .alignment-row { font-size: 18px; line-height: 2.12; }
  .alignment-row.target { margin-top: 92px; }
  .settings-page { width: calc(100% - 24px); padding-top: max(14px, env(safe-area-inset-top)); }
  .settings-hero { padding: 54px 4px 38px; }
  .settings-hero h1 { font-size: clamp(40px, 13vw, 54px); }
  .settings-section { padding: 20px 14px; border-radius: 19px; }
  .settings-heading { grid-template-columns: 1fr; gap: 10px; margin-bottom: 20px; padding: 0 4px; }
  .level-grid { grid-template-columns: 1fr; gap: 8px; }
  .level-card { min-height: 78px; }
  .instruction-field textarea { min-height: 220px; }
  .settings-save-row { position: static; align-items: stretch; flex-direction: column; gap: 12px; padding: 14px; }
  .settings-save-row p { padding: 0 4px; }
  .settings-save { width: 100%; }
  .translation-reset-row { align-items: stretch; flex-direction: column; gap: 14px; padding: 0 4px 4px; }
  .danger-button { width: 100%; }
}

@media (hover: none) {
  .book-delete-button { opacity: .62; transform: translateY(0); }
  .new-words { display: none; }
  .sentence { touch-action: manipulation; }
  .word-token { cursor: pointer; }
  .word-token.tooltip-open {
    background:
      linear-gradient(
        rgb(69 166 224 / calc(var(--word-difficulty) * .34)),
        rgb(69 166 224 / calc(var(--word-difficulty) * .34))
      ),
      rgba(28, 59, 50, .075);
  }
  .word-token.new-word-token.tooltip-open {
    background:
      linear-gradient(
        rgb(69 166 224 / calc(var(--word-difficulty) * .34)),
        rgb(69 166 224 / calc(var(--word-difficulty) * .34))
      ),
      rgba(238, 173, 73, .22);
  }
  .paragraph-audio-button:not(:disabled) {
    opacity: .62;
    pointer-events: auto;
    transform: translateX(0);
  }
}

@media (hover: hover) and (pointer: fine) {
  .new-words { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* Background work */
.queue-status { display: block; }
.queue-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.queue-progress { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.queue-progress progress { appearance: none; flex: 1; min-width: 0; width: 100%; height: 6px; overflow: hidden; border: 0; border-radius: 999px; background: var(--line); color: var(--accent); }
.queue-progress progress::-webkit-progress-bar { background: var(--line); border-radius: 999px; }
.queue-progress progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.queue-progress progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
.queue-progress > span { min-width: 4ch; color: var(--muted); text-align: right; font-size: 10px; font-variant-numeric: tabular-nums; }
.queue-progress-value { display: grid; flex-shrink: 0; gap: 2px; white-space: nowrap; }
.queue-progress-value small { font-size: 9px; }
.queue-clear { flex-shrink: 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: none; color: inherit; font: inherit; font-size: 10px; cursor: pointer; }
.queue-clear:disabled { opacity: .4; cursor: default; }
.codex-usage { display: grid; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.usage-heading { display: flex; align-items: baseline; gap: 12px; font-size: 12px; }
.usage-heading small { margin-left: auto; }
.usage-windows { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: 20px; }
.usage-window { display: grid; gap: 5px; font-size: 11px; }
.usage-window > span { display: flex; justify-content: space-between; gap: 10px; }
.usage-window meter { width: 100%; height: 10px; }
.codex-usage small, .task-list small, .task-pages small { color: var(--muted); font-size: 10px; }
.task-panels { display: grid; gap: 4px; margin-top: 14px; }
.task-panels details { border-top: 1px solid var(--line); }
.task-panels summary { cursor: pointer; padding: 12px 0; font-size: 12px; font-weight: 650; }
.task-panels summary span { margin-left: 7px; color: var(--muted); }
.task-list { padding: 0; margin: 0; list-style: none; }
.task-list li { display: grid; gap: 5px; padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.task-main { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 11px; }
.task-main strong { font-weight: 600; }
.task-state { flex-shrink: 0; color: var(--muted); }
.task-state.running { color: var(--accent); }
.task-state.failed, .task-list .task-error, .codex-usage .task-error { color: var(--danger); }
.task-empty { font-size: 12px; color: var(--muted); }
.task-pages { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.task-pages button { background: none; border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; color: inherit; cursor: pointer; font: inherit; font-size: 11px; }
.task-pages button:disabled { opacity: .4; cursor: default; }
@media (max-width: 600px) {
  .queue-summary { align-items: flex-start; flex-direction: column; gap: 12px; }
  .usage-heading { flex-wrap: wrap; }
}

.chapter-picker { border: 0; display: inline-flex; align-items: center; gap: 8px; padding: 0; background: none; text-align: left; cursor: pointer; }
.chapter-picker:hover { color: var(--green); }
.chapter-title.has-original { margin-bottom: 12px; }
.chapter-original-title { margin: 0 0 44px; color: var(--muted); font-size: 16px; line-height: 1.5; overflow-wrap: anywhere; }
.chapter-sheet-heading { position: sticky; top: -10px; z-index: 1; background: #fbf9f4; padding: 8px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.chapter-sheet-heading h2 { margin: 0; }
.chapter-sheet-heading .icon-button { flex-shrink: 0; font-size: 26px; }
.chapter-list { list-style: none; margin: 0; padding: 0; }
.chapter-list button { border: 0; cursor: pointer; display: flex; align-items: baseline; gap: 14px; width: 100%; padding: 13px 12px; border-radius: 10px; background: none; text-align: left; line-height: 1.45; }
.chapter-list button:hover { background: rgba(28,59,50,.05); }
.chapter-list button[aria-current="page"] { background: rgba(28,59,50,.1); color: var(--green); }
.chapter-number { flex: 0 0 28px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chapter-list-titles { display: grid; gap: 3px; min-width: 0; overflow-wrap: anywhere; }
.chapter-list-titles strong { font-size: 14px; font-weight: 600; }
.chapter-list-titles > span { color: var(--muted); font-size: 12px; }
.chapter-link { overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .bar-actions { gap: 1px; }
  .bar-actions .icon-button { width: 32px; height: 36px; }
}

#chaptersButton, #closeChapters { border: 0; }
.chapter-list button:focus-visible, .chapter-picker:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.book-card-shell { display: flex; flex-direction: column; }
.book-card { height: auto; flex: 1; }
.book-prefetch-button { min-height: 40px; margin-top: 5px; padding: 8px 12px; border: 0; border-radius: 10px; background: none; color: var(--green); font-size: 11px; cursor: pointer; }
.book-prefetch-button:hover, .chapter-prefetch-button:hover { background: rgba(28,59,50,.06); }
.chapter-prefetch-button { min-height: 44px; width: 100%; margin-bottom: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: none; color: var(--green); font-size: 12px; cursor: pointer; }
.prefetch-book-title { margin: 0 0 22px; font-size: 16px; font-weight: 600; }
.prefetch-fields { min-width: 0; margin: 0; padding: 0; border: 0; }
.prefetch-fields legend { padding: 0; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.prefetch-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.prefetch-presets label { position: relative; cursor: pointer; }
.prefetch-presets input { position: absolute; width: 1px; height: 1px; margin: -1px; clip-path: inset(50%); overflow: hidden; }
.prefetch-presets span { display: grid; place-items: center; min-height: 48px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.prefetch-presets input:checked + span { background: var(--green-soft); border-color: var(--green); }
.prefetch-presets input:focus-visible + span { outline: 2px solid var(--green); outline-offset: 2px; }
.prefetch-custom { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 18px 0; font-size: 13px; }
.prefetch-custom input { width: 110px; min-height: 48px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: inherit; font-size: 16px; }
.prefetch-custom input:disabled { opacity: .4; }
.prefetch-submit { width: 100%; }
.prefetch-fields:disabled { opacity: .6; }
.prefetch-status { min-height: 1.5em; margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.prefetch-status.error { color: var(--danger); }
#closePrefetch { border: 0; }

.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-form { width: min(100%, 320px); display: grid; gap: 16px; }
.login-form h1 { margin: 0 0 12px; }
.login-form input { width: 100%; padding: 12px; border: 1px solid #d5d0c7; border-radius: 10px; background: #fffaf3; font: inherit; }
.login-form [role="alert"] { min-height: 1.5em; color: #a13428; }
.server-mode .library-main { grid-template-columns: 1fr; }
.server-mode .book-card-shell { padding-bottom: 0; }
.server-mode .translation-indicator { display: none; }
