:root {
  --canvas: #efe7d7;
  --ink: #382e25;
  --muted: #75685c;
  --leaf: #356b3a;
  --sun: #d7a744;
  --paper: #fffaf0;
  --r-small: 8px;
  --r-medium: 14px;
  --r-large: 24px;
}
* { box-sizing: border-box; }
html { background: var(--canvas); -webkit-font-smoothing: antialiased; }
body { margin: 0; min-height: 100vh; color: var(--ink); font-family: Aptos, "Segoe UI", sans-serif; background: #efe7d7; background: radial-gradient(circle at 50% 0%, #fffaf0, var(--canvas) 58%); touch-action: manipulation; }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 20; padding: 10px 14px; background: var(--paper); color: var(--ink); border-radius: var(--r-small); }
.skip-link:focus { top: 12px; }
.topbar { min-height: 72px; display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 10px max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left)); background: rgba(255, 250, 240, .96); box-shadow: 0 1px 12px rgba(69, 51, 28, .12); position: sticky; top: 0; z-index: 8; }
.book-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50% 45% 52% 44%; color: var(--paper); background: var(--leaf); font: 700 23px Georgia, serif; transform: rotate(-3deg); }
.book-title { min-width: 0; display: grid; gap: 2px; }
.book-title strong { font: 700 18px Georgia, serif; letter-spacing: -.012em; }
.book-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.page-jump { min-height: 42px; display: flex; align-items: center; gap: 5px; padding: 0 10px 0 12px; border-radius: var(--r-medium); color: var(--muted); background: #f1e9da; font-size: 13px; font-variant-numeric: tabular-nums; cursor: pointer; }
.page-jump select { width: 30px; min-height: 40px; padding: 0; border: 0; appearance: none; background: transparent; color: var(--ink); font: 700 14px/1 Aptos, "Segoe UI", sans-serif; text-align: right; cursor: pointer; }
.page-jump select:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; border-radius: 5px; }
.jump-chevron { margin-left: 2px; color: var(--leaf); font-size: 16px; transform: translateY(-1px); }
.offline-button { min-width: 58px; min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 0 10px; border: 0; border-radius: var(--r-medium); background: #e2eadc; color: #315c35; cursor: pointer; font-size: 12px; font-weight: 750; transition: transform 100ms ease-out, background-color 120ms ease-out; }
.offline-button:active { transform: scale(.96); }
.offline-button.downloading { min-width: 72px; background: #eadcaa; color: #625334; }
.offline-button.ready { background: #d8ead7; color: #276033; }
.offline-button.update { background: #f0c86c; color: #4f3b12; }
.offline-button.error { background: #f0c3b9; color: #6b2f25; }
.reader { padding: 14px 12px calc(48px + env(safe-area-inset-bottom)); }
.tip { max-width: 620px; margin: 0 auto 12px; min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 8px 14px; background: #eadcaa; border-radius: var(--r-medium); color: #625334; font-size: 14px; }
.tip button { min-height: 36px; padding: 0 12px; border: 0; border-radius: var(--r-small); background: rgba(255, 250, 240, .72); cursor: pointer; }
.page-stage { display: grid; grid-template-columns: 48px minmax(0, 620px) 48px; justify-content: center; align-items: center; gap: 12px; }
.page-shell { position: relative; width: 100%; line-height: 0; background: var(--paper); box-shadow: 0 16px 45px rgba(72, 52, 25, .2), 0 2px 5px rgba(72, 52, 25, .12); }
.page-shell img { display: block; width: 100%; height: auto; outline: 1px solid rgba(55, 40, 20, .12); outline-offset: -1px; }
.word-layer { position: absolute; inset: 0; }
.word-hit { position: absolute; min-width: 8px; min-height: 8px; padding: 0; border: 0; border-radius: 3px; background: transparent; cursor: pointer; transition: background-color 120ms ease-out, box-shadow 120ms ease-out, transform 100ms ease-out; }
.word-hit.active { background: rgba(215, 167, 68, .42); box-shadow: 0 0 0 2px rgba(215, 167, 68, .68); }
.word-hit:active { transform: scale(.96); }
.nav-button { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--paper); box-shadow: 0 3px 12px rgba(72, 52, 25, .16); font: 28px/1 Georgia, serif; cursor: pointer; transition: transform 100ms ease-out, opacity 120ms ease-out; }
.nav-button:active { transform: scale(.94); }
.nav-button:disabled { opacity: .25; cursor: default; }
.word-sheet { position: fixed; z-index: 12; isolation: isolate; left: 50%; bottom: 18px; width: min(560px, calc(100% - 24px)); padding: 10px 22px 20px; background: #fffaf0; background-color: var(--paper); border-radius: var(--r-large); box-shadow: 0 22px 70px rgba(50, 35, 18, .28); transform: translate(-50%, calc(100% + 48px)); opacity: 0; pointer-events: none; transition: transform 260ms cubic-bezier(.16,1,.3,1), opacity 150ms ease-out; overscroll-behavior: contain; -webkit-backdrop-filter: none; backdrop-filter: none; }
.word-sheet.open { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.sheet-handle { width: 42px; height: 4px; margin: 0 auto 14px; border-radius: 999px; background: #c8bfb3; }
.word-heading { display: flex; justify-content: space-between; gap: 16px; }
.eyebrow { color: var(--leaf); font-size: 11px; font-weight: 700; letter-spacing: .12em; }
.word-heading h2 { margin: 2px 0 0; font: 700 32px/1.05 Georgia, serif; letter-spacing: -.022em; }
.word-heading p { margin: 7px 0 0; color: var(--muted); font-family: Georgia, serif; min-height: 24px; }
.phonetic-part { display: inline-block; padding: 2px 3px; border-radius: 5px; transition: transform 120ms ease-out, background-color 120ms ease-out, color 120ms ease-out; }
.phonetic-part.reading { color: var(--paper); background: var(--leaf); transform: translateY(-1px); }
.phonetic-divider { color: #9b8f82; padding-inline: 1px; }
.close-button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--canvas); cursor: pointer; font-size: 24px; }
.meaning-row { margin: 16px 0 10px; display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.meaning { margin: 0; font-size: 20px; font-weight: 700; }
.pos-badge { padding: 4px 8px; border-radius: var(--r-small); background: #d8ead7; color: #276033; font-size: 12px; font-weight: 750; white-space: nowrap; }
.sentence { margin: 0; font: 17px/1.5 Georgia, serif; color: var(--ink); }
.translation { margin: 6px 0 16px; padding-top: 6px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.sheet-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sheet-actions button { min-height: 44px; padding: 8px; border: 0; border-radius: var(--r-medium); background: var(--canvas); cursor: pointer; font-size: 13px; font-weight: 650; transition: transform 100ms ease-out, background-color 120ms ease-out; }
.sheet-actions button:first-child { background: var(--leaf); color: var(--paper); }
.sheet-actions button:nth-child(2) { background: #ead59c; color: #56451d; }
.sheet-actions button:active { transform: scale(.96); }
.sheet-actions button.saved { background: #ead59c; }
.sheet-actions button:disabled { opacity: .45; cursor: default; }
@media (hover:hover) { .word-hit:hover { background: rgba(215, 167, 68, .30); } .nav-button:hover { transform: translateY(-1px); } }
@media (max-width: 720px) {
  .topbar { min-height: 62px; }
  .book-mark { width: 38px; height: 38px; }
  .header-actions { gap: 5px; }
  .offline-button { min-width: 44px; padding-inline: 8px; }
  .offline-button #offlineLabel { display: none; }
  .offline-button.downloading, .offline-button.update, .offline-button.error { min-width: 62px; }
  .offline-button.downloading #offlineLabel, .offline-button.ready #offlineLabel, .offline-button.update #offlineLabel, .offline-button.error #offlineLabel { display: inline; }
  .page-stage { grid-template-columns: 1fr; }
  .nav-button { position: fixed; z-index: 7; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .nav-button.previous { left: 14px; }
  .nav-button.next { right: 14px; }
  .reader { padding-inline: 0; }
  .tip { margin-inline: 12px; }
  .page-shell { box-shadow: 0 8px 28px rgba(72, 52, 25, .17); }
  .word-sheet { bottom: 0; width: 100%; border-radius: var(--r-large) var(--r-large) 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .sheet-actions { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { .word-sheet, .word-hit, .nav-button, .sheet-actions button { transition-duration: 1ms; } }
