:root {
  color-scheme: dark;
  --green: #123c2f;
  --green-deep: #09251d;
  --gold: #c9aa62;
  --paper: #f6f3e9;
  --ink: #edf3ef;
  --muted: #aebdb6;
  --line: rgba(201, 170, 98, 0.44);
  --zoom: 1;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #071b15;
  font-family: Aptos, "Segoe UI", Arial, sans-serif;
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, rgba(44, 96, 74, 0.55), transparent 48%),
    linear-gradient(180deg, #0d2b21 0%, #061712 100%);
}

button, a { font: inherit; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.toolbar {
  min-height: 76px;
  padding: 12px clamp(16px, 3vw, 42px);
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr);
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 24, 18, 0.9);
  backdrop-filter: blur(14px);
}

.identity { min-width: 0; }

.identity .unit {
  display: block;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.identity h1 {
  margin: 2px 0 0;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.page-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 9px;
  background: rgba(255,255,255,0.05);
}

.tab,
.zoom-controls button,
.edge-control {
  border: 0;
  color: var(--ink);
  cursor: pointer;
}

.tab {
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 6px;
  background: transparent;
  font-size: 0.86rem;
  font-weight: 700;
}

.tab:hover { background: rgba(255,255,255,0.08); }
.tab.is-active { color: #0b241b; background: var(--gold); }

.toolbar-actions { justify-self: end; }

.download {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255,255,255,0.06);
  font-size: 0.86rem;
  font-weight: 700;
  text-decoration: none;
}

.download:hover { border-color: var(--gold); }

.reader {
  min-height: 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  align-items: stretch;
  padding: 20px clamp(8px, 2vw, 24px) 10px;
}

.page-stage {
  min-height: 300px;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.035) 25%, transparent 25%) 0 0 / 24px 24px,
    rgba(0,0,0,0.21);
  box-shadow: inset 0 0 50px rgba(0,0,0,0.24);
  scrollbar-color: var(--gold) rgba(255,255,255,0.06);
}

.page-shell {
  position: relative;
  flex: 0 0 auto;
  transform-origin: center center;
  transition: transform 260ms ease, opacity 180ms ease;
  filter: drop-shadow(0 18px 26px rgba(0,0,0,0.38));
}

.page-shell.is-turning-next { transform: perspective(1400px) rotateY(-9deg) translateX(-18px); opacity: 0.25; }
.page-shell.is-turning-previous { transform: perspective(1400px) rotateY(9deg) translateX(18px); opacity: 0.25; }

.page-shell img {
  display: block;
  height: auto;
  max-width: none;
  background: var(--paper);
  user-select: none;
  -webkit-user-drag: none;
}

.page-shell.cover-view {
  overflow: hidden;
  border-radius: 3px;
}

.page-shell.cover-view img {
  width: auto !important;
  height: 100%;
  max-height: none;
  transform: translateX(-66.6667%);
}

.edge-control {
  align-self: center;
  width: 46px;
  height: 72px;
  border-radius: 8px;
  background: rgba(255,255,255,0.065);
  font-size: 2.4rem;
  line-height: 1;
}

.edge-control:hover:not(:disabled) { color: #0b241b; background: var(--gold); }
.edge-control:disabled { opacity: 0.18; cursor: default; }

.reader-footer {
  min-height: 74px;
  padding: 9px clamp(16px, 3vw, 42px) 14px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
}

.page-status {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.page-status strong { color: var(--gold); }
.page-status span { color: var(--muted); font-size: 0.82rem; }

.zoom-controls {
  display: flex;
  gap: 5px;
}

.zoom-controls button {
  min-width: 40px;
  min-height: 36px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  background: rgba(255,255,255,0.055);
  font-weight: 800;
}

.zoom-controls button:hover { border-color: var(--gold); }

.hint {
  justify-self: end;
  max-width: 370px;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  text-align: right;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #f4d47e;
  outline-offset: 3px;
}

@media (max-width: 820px) {
  .toolbar {
    grid-template-columns: 1fr auto;
    gap: 9px 14px;
    padding: 10px 14px;
  }

  .page-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .tab { flex: 1; padding-inline: 6px; }
  .toolbar-actions { grid-column: 2; grid-row: 1; }
  .download { padding-inline: 10px; }

  .reader {
    grid-template-columns: 38px minmax(0, 1fr) 38px;
    padding: 10px 2px 4px;
  }

  .edge-control {
    width: 34px;
    height: 60px;
    border-radius: 6px;
  }

  .page-stage { padding: 5px; border-radius: 8px; }

  .reader-footer {
    grid-template-columns: 1fr auto;
    padding: 7px 14px 12px;
  }

  .hint { grid-column: 1 / -1; justify-self: start; text-align: left; }
}

@media (max-width: 500px) {
  .identity h1 { font-size: 1rem; }
  .download { font-size: 0.78rem; }
  .reader-footer { gap: 8px; }
  .hint { font-size: 0.72rem; }
}

@media (prefers-reduced-motion: reduce) {
  .page-shell { transition: none; }
}
