:root {
  color-scheme: light;
  --ink: #17302e;
  --muted: #536663;
  --paper: #f5f1e8;
  --card: #fffdf8;
  --line: #d8d0c1;
  --green: #1f6758;
  --green-dark: #154c41;
  --green-pale: #e1eee8;
  --orange: #bd5c28;
  --orange-pale: #f7e3d5;
  --red: #a93631;
  --red-pale: #f9e5e2;
  --shadow: 0 18px 55px rgba(30, 49, 45, 0.09);
  font-family: Inter, Aptos, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 5%, rgba(189, 92, 40, 0.11), transparent 28rem),
    linear-gradient(180deg, #faf7f0, var(--paper));
}
button, input, select { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, audio:focus-visible,
a:focus-visible, [tabindex]:focus-visible { outline: 3px solid #d87842; outline-offset: 3px; }

.skip-link {
  position: fixed; z-index: 100; top: .75rem; left: .75rem; padding: .8rem 1rem;
  color: white; background: var(--ink); border-radius: .55rem; transform: translateY(-160%);
}
.skip-link:focus { transform: none; }
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: 74px; padding: .75rem clamp(1rem, 5vw, 5rem); border-bottom: 1px solid var(--line);
  background: rgba(250, 247, 240, .94);
}
.brand { display: inline-flex; align-items: center; gap: .7rem; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid; width: 42px; height: 42px; place-items: center; color: #fff;
  background: var(--ink); border-radius: 12px 12px 12px 3px; font: 700 1.4rem Georgia, serif;
}
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .15em; }
.brand small { color: var(--muted); font-size: .72rem; }
.connection {
  display: inline-flex; align-items: center; gap: .55rem; padding: .6rem .85rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-weight: 700; font-size: .84rem;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #8d887f; }
.connection.online .status-dot { background: #258261; box-shadow: 0 0 0 4px rgba(37, 130, 97, .14); }
.connection.offline .status-dot { background: var(--red); }

main { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding-bottom: 4rem; }
.intro { max-width: 850px; padding: clamp(3rem, 7vw, 6rem) 0 2.4rem; }
.eyebrow { margin: 0 0 .55rem; color: var(--orange); font-size: .73rem; font-weight: 850; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 1rem; font: 500 clamp(2.4rem, 5.4vw, 4.9rem)/1 Georgia, serif; letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: clamp(1.25rem, 2.5vw, 1.7rem); }
.intro > p:last-child { max-width: 760px; color: var(--muted); font-size: 1.08rem; line-height: 1.65; }
.workload-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 1.1rem; align-items: center;
  margin-bottom: 1.25rem; padding: clamp(1.2rem, 3vw, 1.7rem); border: 1px solid #bdd8cc;
  border-radius: 1.25rem; background: var(--green-pale); box-shadow: var(--shadow);
}
.workload-icon { display: grid; width: 50px; height: 50px; place-items: center; border-radius: 50%; color: white; background: var(--green); font-size: 1.5rem; font-weight: 900; }
.workload-copy h2 { margin-bottom: .35rem; }
.workload-copy > p:last-of-type { margin-bottom: 0; color: var(--muted); line-height: 1.5; }
.workload-facts { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin: .7rem 0 0; }
.workload-facts > div { display: flex; gap: .4rem; min-width: 0; }
.workload-facts dt { color: var(--muted); }
.workload-facts dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-weight: 850; }
.workload-dialog-next { padding: .85rem; border: 1px solid #e9c4a9; border-radius: .75rem; background: var(--orange-pale); }
.workload-copy .error-text { margin-top: .75rem; }
.workload-action { display: grid; min-width: 220px; gap: .7rem; justify-items: stretch; }
.workload-action .state-badge { justify-self: end; }
.workload-card[data-status="audiobooks"] { border-color: #e9c4a9; background: var(--orange-pale); }
.workload-card[data-status="audiobooks"] .workload-icon { background: var(--orange); }
.workload-card[data-status="switching"] { border-color: var(--line); background: #f0eee8; }
.workload-card[data-status="error"] { border-color: #e5b7b2; background: var(--red-pale); }
.workload-card[data-status="error"] .workload-icon { background: var(--red); }
.library {
  margin-bottom: 1.25rem; padding: clamp(1.2rem, 3vw, 2rem); border: 1px solid var(--line);
  border-radius: 1.25rem; background: rgba(255, 253, 248, .82); box-shadow: var(--shadow);
}
.library-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.25rem; }
.library-heading > div { max-width: 760px; }
.library-heading h2 { margin-bottom: .55rem; }
.library-heading p:last-child { margin-bottom: 0; color: var(--muted); line-height: 1.5; }
.library-loading { display: flex; min-height: 94px; align-items: center; justify-content: center; gap: .75rem; color: var(--muted); }
.library-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: .65rem; margin: 0 0 1rem; }
.library-summary > div { min-width: 0; padding: .8rem; border: 1px solid var(--line); border-radius: .8rem; background: #faf8f2; }
.library-summary dt { color: var(--muted); font-size: .76rem; font-weight: 750; }
.library-summary dd { margin: .2rem 0 0; overflow-wrap: anywhere; font-size: 1.15rem; font-weight: 850; }
.library-empty { padding: 1.5rem; border: 1px dashed var(--line); border-radius: 1rem; text-align: center; background: var(--card); }
.library-empty h3 { margin: 0 0 .4rem; font-size: 1.15rem; }
.library-empty p { margin-bottom: 1rem; color: var(--muted); line-height: 1.5; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 305px), 1fr)); gap: 1rem; }
.library-card { display: flex; min-width: 0; padding: 1.15rem; flex-direction: column; border: 1px solid var(--line); border-radius: 1rem; background: var(--card); }
.library-card[data-current="true"] { border-color: #9ac6b5; box-shadow: inset 0 0 0 1px #9ac6b5; }
.library-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem; }
.library-card-heading h3 { margin: 0; overflow-wrap: anywhere; font-size: 1.18rem; line-height: 1.25; }
.project-id { margin: .35rem 0 0; color: var(--muted); font-size: .78rem; }
.project-id code, .delete-dialog code { overflow-wrap: anywhere; color: var(--ink); font: 750 .92em ui-monospace, SFMono-Regular, Consolas, monospace; }
.library-card .state-badge[data-state="working"] { color: #70401f; background: var(--orange-pale); }
.library-card .state-badge[data-state="attention"] { color: var(--red); background: var(--red-pale); }
.library-card .state-badge[data-state="draft"] { color: var(--muted); background: #eeece6; }
.library-stats { display: grid; gap: 0; margin: 1rem 0; }
.library-stats > div { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid #e8e2d8; }
.library-stats dt { color: var(--muted); }
.library-stats dd { margin: 0; text-align: right; font-weight: 800; }
.library-card-note { min-height: 2.8em; margin: 0 0 .85rem; color: var(--muted); font-size: .85rem; line-height: 1.4; }
.library-card-actions { display: grid; grid-template-columns: 1fr auto auto; gap: .45rem; margin-top: auto; }
.library-card-actions .button { min-height: 46px; padding: .6rem .75rem; }
.button-text-danger { color: var(--red); border-color: transparent; background: transparent; }
.button-text-danger:hover:not(:disabled) { border-color: #e5b7b2; background: var(--red-pale); }
.library-download-status { margin: .65rem 0 0; color: var(--muted); font-size: .8rem; line-height: 1.4; }
.delete-dialog { width: min(92vw, 560px); max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem); padding: 0; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 1.1rem; color: var(--ink); background: var(--card); box-shadow: 0 24px 80px rgba(23, 48, 46, .28); }
.delete-dialog::backdrop { background: rgba(12, 28, 26, .58); backdrop-filter: blur(3px); }
.delete-dialog form { padding: clamp(1.2rem, 4vw, 2rem); }
.delete-dialog h2 { margin-bottom: .8rem; }
.delete-dialog p { line-height: 1.5; }
.delete-project-summary { display: grid; gap: .65rem; margin: .9rem 0; padding: .85rem; border: 1px solid var(--line); border-radius: .75rem; background: #f8f6f1; }
.delete-project-summary > div { display: grid; grid-template-columns: minmax(5.5rem, auto) minmax(0, 1fr); gap: .75rem; align-items: baseline; }
.delete-project-summary dt { color: var(--muted); font-size: .84rem; font-weight: 750; }
.delete-project-summary dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-weight: 800; }
.delete-warning { padding: .9rem; border: 1px solid #e5b7b2; border-radius: .75rem; color: var(--red); background: var(--red-pale); font-weight: 750; line-height: 1.45; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin-top: .25rem; }
.workload-dialog #confirm-book-mining { grid-column: 1 / -1; }
.layout { display: grid; grid-template-columns: minmax(300px, .72fr) minmax(420px, 1.28fr); gap: 1.25rem; align-items: start; }
.card { padding: clamp(1.2rem, 3vw, 2rem); border: 1px solid var(--line); border-radius: 1.25rem; background: var(--card); box-shadow: var(--shadow); }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.state-badge, .page-number { padding: .5rem .7rem; border-radius: 999px; color: var(--green-dark); background: var(--green-pale); font-size: .78rem; font-weight: 800; white-space: nowrap; }
form { display: grid; gap: .9rem; }
label { font-weight: 800; }
select, input[type="text"], input[type="number"] {
  width: 100%; min-height: 48px; padding: .65rem .8rem; border: 1px solid var(--line);
  border-radius: .65rem; color: var(--ink); background: white;
}
input:disabled, select:disabled { color: #687572; background: #f0eee8; }
input[type="range"] { width: 100%; accent-color: var(--green); }
.field-group { display: grid; gap: .75rem; margin: .25rem 0 0; padding: 1rem; border: 1px solid var(--line); border-radius: .8rem; }
.field-group legend { padding: 0 .35rem; color: var(--orange); font-weight: 850; }
.field-help { margin: -.35rem 0 .2rem; color: var(--muted); font-size: .84rem; line-height: 1.45; }
.checkbox-row { display: flex; align-items: flex-start; gap: .7rem; margin-top: .3rem; line-height: 1.45; }
.checkbox-row input { width: 1.15rem; height: 1.15rem; flex: none; margin-top: .15rem; accent-color: var(--green); }
.settings-panel { border: 1px solid var(--line); border-radius: .85rem; background: #faf8f2; }
.settings-panel summary {
  display: flex; min-height: 52px; padding: .75rem 1rem; align-items: center; justify-content: space-between; gap: 1rem;
  cursor: pointer; font-weight: 850; list-style-position: inside;
}
.settings-panel summary small { color: var(--muted); font-size: .78rem; font-weight: 650; text-align: right; }
.settings-panel[open] summary { border-bottom: 1px solid var(--line); }
.settings-content { display: grid; gap: .75rem; padding: 1rem; }
.project-checkpoint {
  margin: -.2rem 0 1rem; padding: 1rem; border: 1px solid #bdd8cc; border-radius: .85rem;
  background: var(--green-pale);
}
.project-checkpoint > span { display: block; color: var(--muted); font-size: .78rem; font-weight: 750; }
.project-checkpoint strong { display: block; margin-top: .15rem; font-size: 1.45rem; line-height: 1.2; }
.project-checkpoint p { margin: .45rem 0 0; color: var(--muted); font-size: .84rem; line-height: 1.45; }
.workflow-actions { margin-top: .15rem; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin-top: .8rem; }
.button {
  min-height: 48px; padding: .7rem 1rem; border: 1px solid transparent; border-radius: .7rem;
  font-weight: 850; cursor: pointer; text-align: center; text-decoration: none;
}
.button:disabled { cursor: not-allowed; opacity: .5; }
.button-primary { color: white; background: var(--green); }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.button-secondary { color: var(--ink); border-color: var(--line); background: white; }
.button-danger { color: var(--red); border-color: #e5b7b2; background: var(--red-pale); }
.button-download { color: white; background: var(--orange); }
.button-download:hover:not(:disabled) { background: #99471f; }
#download { grid-column: 1 / -1; }
.button.is-primary-action { grid-column: 1 / -1; order: -1; }
.status-message { margin: 0 0 1rem; padding: 1rem; border-radius: .75rem; color: var(--green-dark); background: var(--green-pale); line-height: 1.45; }
.status-message.is-warning { color: #70401f; background: var(--orange-pale); }
.status-message.is-error { color: var(--red); background: var(--red-pale); }
.status-message.is-success { color: var(--green-dark); background: var(--green-pale); font-weight: 750; }
.error-text { margin: 0 0 1rem; padding: .85rem 1rem; border-radius: .75rem; color: var(--red); background: var(--red-pale); font-weight: 750; line-height: 1.45; }
.download-help { margin: .75rem 0 0; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.waiting { display: flex; align-items: center; gap: .8rem; min-height: 250px; justify-content: center; color: var(--muted); text-align: center; }
.spinner { width: 22px; height: 22px; flex: none; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.audio-panel { padding: 1rem; border-radius: .85rem; background: var(--green-pale); }
audio { display: block; width: 100%; margin-top: .7rem; }
.audio-status { margin: .65rem 0 0; color: var(--muted); font-size: .88rem; }
.translation { max-height: 44vh; margin-top: 1rem; padding: 1rem; overflow: auto; border: 1px solid var(--line); border-radius: .8rem; white-space: pre-wrap; font: 1.08rem/1.72 Georgia, serif; }
.project-details { display: grid; gap: .8rem; margin: 0; }
.project-details > div { display: grid; grid-template-columns: minmax(6.5rem, .4fr) 1fr; gap: 1rem; padding: .85rem 0; border-bottom: 1px solid var(--line); }
.project-details dt { color: var(--muted); font-weight: 750; }
.project-details dd { margin: 0; overflow-wrap: anywhere; font-weight: 800; }
.privacy-note { margin: 1.2rem 0 0; padding: 1rem; border: 1px solid var(--line); border-radius: .8rem; color: var(--muted); background: #f8f6f0; line-height: 1.5; }
.advance-rule, .notice {
  display: flex; gap: 1rem; margin-top: 1.25rem; padding: 1.3rem 1.5rem; border: 1px solid #e9c4a9;
  border-radius: 1rem; background: var(--orange-pale);
}
.advance-rule > span { display: grid; width: 40px; height: 40px; flex: none; place-items: center; border-radius: 50%; color: white; background: var(--orange); }
.advance-rule p, .notice p { margin: .45rem 0 0; color: var(--muted); line-height: 1.55; }
.notice { display: block; margin: 0 0 1.25rem; }
.notice .button { display: inline-flex; align-items: center; margin-top: .8rem; }
.notice-error { border-color: #e6b8b3; background: var(--red-pale); }
noscript { display: block; padding: 1rem; color: white; background: var(--red); text-align: center; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .intro { padding-top: 3rem; }
  .translation { max-height: none; }
}
@media (max-width: 520px) {
  .site-header { min-height: 60px; padding: .55rem .75rem; }
  .brand-mark { width: 36px; height: 36px; border-radius: 10px 10px 10px 3px; font-size: 1.2rem; }
  .brand small { display: none; }
  .connection { padding: .5rem .6rem; font-size: .76rem; }
  main { width: min(100% - 1rem, 1180px); padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
  .intro { padding: 1.35rem .25rem 1rem; }
  .intro .eyebrow { margin-bottom: .35rem; }
  h1 { margin-bottom: .65rem; font-size: clamp(2rem, 10vw, 2.7rem); }
  .intro > p:last-child { margin-bottom: 0; font-size: .95rem; line-height: 1.5; }
  .workload-card { grid-template-columns: auto 1fr; padding: 1rem; }
  .workload-icon { width: 42px; height: 42px; }
  .workload-action { grid-column: 1 / -1; min-width: 0; }
  .workload-action .state-badge { justify-self: start; }
  .library { padding: 1rem; border-radius: 1rem; }
  .library-heading { display: grid; gap: .9rem; }
  .library-heading > .button { width: 100%; min-height: 54px; }
  .library-grid { grid-template-columns: 1fr; }
  .library-summary { grid-template-columns: 1fr 1fr; }
  .library-card { padding: 1rem; }
  .library-card-actions { grid-template-columns: 1fr 1fr; }
  .library-card-actions [data-action="download"] { grid-column: 1 / -1; min-height: 54px; }
  .library-card-actions [data-action="open"], .library-card-actions [data-action="delete"] { min-height: 48px; }
  .dialog-actions { grid-template-columns: 1fr; }
  .dialog-actions .button { min-height: 54px; }
  .card { padding: 1rem; border-radius: 1rem; }
  .card-heading { margin-bottom: 1rem; }
  .state-badge, .page-number { padding: .45rem .6rem; font-size: .72rem; }
  .project-checkpoint { margin-bottom: .75rem; }
  .project-checkpoint strong { font-size: 1.3rem; }
  .settings-panel summary { min-height: 54px; padding: .75rem; }
  .settings-panel summary small { max-width: 45%; }
  .settings-content, .field-group { padding: .85rem; }
  select, input[type="text"], input[type="number"] { min-height: 52px; font-size: 16px; }
  .checkbox-row input { width: 24px; height: 24px; margin-top: 0; }
  .button { min-height: 54px; padding: .8rem .9rem; }
  .button-row { grid-template-columns: 1fr; }
  #download, .button.is-primary-action { grid-column: auto; }
  #start-form[data-prioritize-actions="true"] .workflow-actions { order: -1; }
  #start-form[data-prioritize-actions="true"] .workflow-actions {
    position: sticky; z-index: 20; bottom: calc(.5rem + env(safe-area-inset-bottom));
    margin: 0 -.25rem; padding: .65rem; border: 1px solid var(--line); border-radius: .9rem;
    background: rgba(255, 253, 248, .96); box-shadow: 0 12px 32px rgba(23, 48, 46, .18);
    backdrop-filter: blur(10px);
  }
  #start-form[data-prioritize-actions="true"] .button-row { margin-top: 0; }
  .project-details > div { grid-template-columns: 1fr; gap: .25rem; }
  .waiting { min-height: 130px; }
  .advance-rule { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
