:root {
  --bg: #f4efe7;
  --paper: #fffaf2;
  --ink: #1c1a18;
  --muted: #746b61;
  --line: rgba(33, 28, 21, .14);
  --shadow: 0 30px 80px rgba(31, 25, 17, .22);
  --button: #24201c;
  --button-ink: #fff7eb;
  --accent: #a04a28;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(160, 74, 40, .16), transparent 34rem),
    linear-gradient(135deg, #f8f2e8, var(--bg));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.1rem clamp(1rem, 3vw, 2.4rem);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 242, .76);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; gap: .9rem; align-items: center; min-width: 220px; }
.brand-mark {
  display: grid; place-items: center;
  width: 2.55rem; height: 2.55rem; border-radius: 50%;
  color: var(--button-ink); background: var(--button);
  box-shadow: 0 8px 22px rgba(0,0,0,.18);
}
h1 { margin: 0; font-size: clamp(1.05rem, 2vw, 1.45rem); line-height: 1.1; }
.brand p { margin: .2rem 0 0; color: var(--muted); font-size: .91rem; }
.controls { display: flex; align-items: center; justify-content: flex-end; gap: .55rem; flex-wrap: wrap; }
button, .download, .file-button {
  border: 0; border-radius: 999px; padding: .68rem .95rem;
  font: inherit; font-weight: 700; color: var(--button-ink); background: var(--button);
  text-decoration: none; cursor: pointer; box-shadow: 0 9px 22px rgba(0,0,0,.13);
  transition: transform .15s ease, opacity .15s ease;
}
button:hover, .download:hover, .file-button:hover { transform: translateY(-1px); }
button:disabled { opacity: .38; cursor: not-allowed; transform: none; }
#soundBtn[aria-pressed="false"] { background: #8a8177; }
.page-indicator { min-width: 5.5rem; text-align: center; color: var(--muted); font-weight: 800; }
.stage { min-height: calc(100vh - 8.5rem); display: grid; place-items: center; padding: clamp(1rem, 3vw, 2.6rem); }
.book-shell { width: min(96vw, 1220px); margin-inline: auto; display: grid; place-items: center; filter: drop-shadow(0 22px 42px rgba(35, 28, 18, .20)); }
#book { width: 100%; }
.page { background: var(--paper); overflow: hidden; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.07); }
.page img { width: 100%; height: 100%; object-fit: contain; display: block; background: #fff; user-select: none; -webkit-user-drag: none; }
.status, .fallback {
  width: min(92vw, 520px); padding: 2rem; border: 1px solid var(--line);
  border-radius: 28px; background: rgba(255, 250, 242, .88); box-shadow: var(--shadow); text-align: center;
}
.status strong, .status span { display: block; }
.status span { margin-top: .45rem; color: var(--muted); }
.spinner { width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 4px solid rgba(160,74,40,.2); border-top-color: var(--accent); margin: 0 auto 1rem; animation: spin .8s linear infinite; }
.fallback h2 { margin-top: 0; }
.fallback p { color: var(--muted); }
.foot { padding: 1rem; text-align: center; color: var(--muted); font-size: .88rem; display:flex; justify-content:center; gap:1rem; }
.foot a { color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 800px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .controls { justify-content: flex-start; }
  .brand p { display: none; }
  button, .download, .file-button { padding: .62rem .78rem; }
  .page-indicator { min-width: 4.6rem; }
}
