:root {
  color-scheme: dark;
  --bg: #363636;
  --bar: #171717;
  --line: #505050;
  --text: #f1f1ee;
  --muted: #bbb;
  --accent: #d2c098;
  font-family: Arial, "Malgun Gothic", sans-serif;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button,
input,
a {
  font: inherit;
}
button,
a {
  touch-action: manipulation;
}
button {
  cursor: pointer;
}
button:disabled {
  cursor: default;
  opacity: 0.3;
}
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.reader-symbols {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
.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;
}
.reader-heading {
  height: 52px;
  min-height: 52px;
  padding: 0 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bar);
  border-bottom: 1px solid #454545;
}
.reader-heading h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  flex: 1;
}
.reader-back {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: inherit;
  text-decoration: none;
}
.reader-tag {
  color: #aaa;
  font-size: 12px;
  white-space: nowrap;
}
#reader-main {
  flex: 1;
  position: relative;
  min-height: 0;
}
#book-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 48px;
  overflow: hidden;
}
#book-mount {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.book-host {
  flex: none;
  box-shadow: 0 8px 32px #0004;
}
.reader-page {
  background: white;
  position: relative;
  overflow: hidden;
  color: #333;
}
/* Mirror only the backward curl geometry, never the PDF content. */
.book-host.is-reverse-turn {
  transform: scaleX(-1);
}
.reader-page-content {
  position: relative;
  width: 100%;
  height: 100%;
}
.book-host.is-reverse-turn .reader-page-content {
  transform: scaleX(-1);
}
.reader-page .page-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
.reader-page .page-wait {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: #999;
  background: #f9f9f7;
}
.reader-page.has-image .page-wait {
  display: none;
}
.reader-page .page-index {
  position: absolute;
  right: 8px;
  bottom: 5px;
  font-size: 9px;
  background: #fff9;
  color: #666;
  padding: 1px 3px;
  border-radius: 0;
  pointer-events: none;
}
.edge {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 68px;
  border: 0;
  border-radius: 0;
  color: #ddd;
  background: #17171750;
  display: grid;
  place-items: center;
  z-index: 5;
}
.edge:hover:not(:disabled) {
  background: #171717;
}
.edge.previous {
  left: 6px;
}
.edge.next {
  right: 6px;
}
.reader-toolbar {
  z-index: 10;
  background: var(--bar);
  border-top: 1px solid #454545;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 22px;
  padding: 8px 14px max(8px, env(safe-area-inset-bottom));
  min-height: 62px;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 3px;
}
.tools {
  border-left: 1px solid #505050;
  padding-left: 18px;
}
.reader-toolbar button,
.reader-toolbar a,
.panel-heading button,
.zoom-toolbar button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-decoration: none;
}
.reader-toolbar button:hover:not(:disabled),
.reader-toolbar a:hover,
.panel-heading button:hover,
.zoom-toolbar button:hover {
  background: #454545;
}
.reader-toolbar button[aria-pressed="true"] {
  background: #635943;
  color: #fff;
}
#page-form {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 5px;
  font-size: 14px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#page-number {
  appearance: textfield;
  -moz-appearance: textfield;
  width: 49px;
  border: 1px solid #555;
  border-radius: 0;
  background: #303030;
  color: #fff;
  text-align: center;
  height: 32px;
  font-size: 16px;
}
#page-number::-webkit-inner-spin-button,
#page-number::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
#page-total {
  min-width: 24px;
  color: #ccc;
}
.reader-spinner {
  display: block;
  width: 32px;
  height: 32px;
  border: 2px solid #ffffff33;
  border-top-color: #eee;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 18px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
#loading,
#reader-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  text-align: center;
  padding: 24px;
  z-index: 9;
}
#loading strong {
  font-size: 17px;
  font-weight: 500;
}
#loading-detail {
  font-size: 14px;
  color: var(--muted);
}
[hidden] {
  display: none !important;
}
#reader-error p {
  max-width: 500px;
  line-height: 1.7;
  color: #ccc;
}
#reader-error a,
#reader-error button {
  color: #eee;
  background: #222;
  padding: 12px 18px;
  border: 1px solid #777;
  border-radius: 0;
  margin: 5px;
  text-decoration: none;
}
dialog {
  color: var(--text);
  border: 1px solid #555;
  background: #232323;
  padding: 0;
}
dialog::backdrop {
  background: #0006;
}
#reader-panel {
  position: fixed;
  inset: 52px auto 63px 0;
  width: 320px;
  height: calc(100dvh - 115px);
  max-width: calc(100vw - 24px);
  max-height: none;
  margin: 0;
  border-left: 0;
  border-radius: 0;
}
.panel-heading {
  height: 56px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 8px 20px;
  border-bottom: 1px solid #454545;
}
.panel-heading h2 {
  font-size: 17px;
  margin: 0;
  font-weight: 500;
}
.panel-content {
  padding: 18px;
  overflow: auto;
  height: calc(100% - 56px);
}
#thumb-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 12px;
}
.thumb-button {
  border: 1px solid #555;
  background: #303030;
  color: #ddd;
  padding: 7px;
  min-width: 0;
}
.thumb-button[aria-current="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.thumb-image {
  display: flex;
  aspect-ratio: 190/260;
  background: #eee;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 12px;
}
.thumb-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.thumb-button span:last-child {
  display: block;
  margin-top: 7px;
  font-size: 13px;
}
#search-form label {
  display: block;
  font-size: 14px;
  margin-bottom: 9px;
}
.search-row {
  display: flex;
  gap: 6px;
}
.search-row input {
  width: 0;
  min-width: 0;
  flex: 1;
  padding: 10px;
  border: 1px solid #666;
  border-radius: 0;
  background: #151515;
  font-size: 16px;
}
.search-row button,
#add-bookmark {
  background: #ddd;
  color: #151515;
  border: 0;
  padding: 9px 13px;
  border-radius: 0;
  font-size: 14px;
}
#search-status,
.panel-note {
  font-size: 13px;
  color: #aaa;
  line-height: 1.6;
}
#search-results,
#toc-list,
#bookmark-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
}
#search-results li,
#toc-list li,
#bookmark-list li {
  border-bottom: 1px solid #454545;
}
#search-results button,
#toc-list button,
#bookmark-list button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #ddd;
  border: 0;
  padding: 12px 2px;
  line-height: 1.6;
  font-size: 14px;
}
#search-results button strong {
  display: block;
  color: var(--accent);
  font-size: 13px;
}
#search-results button:hover,
#toc-list button:hover,
#bookmark-list button:hover {
  color: #fff;
  background: #333;
}
#bookmark-list li {
  display: flex;
}
#bookmark-list .remove-bookmark {
  width: 40px;
  text-align: center;
  flex-shrink: 0;
}
#zoom-dialog {
  inset: 18px;
  margin: auto;
  width: calc(100vw - 36px);
  height: calc(100dvh - 36px);
  max-width: none;
  max-height: none;
  border-radius: 0;
}
.zoom-toolbar {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 8px 14px;
  gap: 6px;
  border-bottom: 1px solid #555;
}
.zoom-toolbar h2 {
  font-size: 16px;
  font-weight: 500;
  margin: 0 auto 0 0;
}
.zoom-toolbar output {
  font-size: 13px;
  min-width: 40px;
  text-align: center;
}
#zoom-scroll {
  height: calc(100% - 100px);
  width: 100%;
  overflow: auto;
  touch-action: pan-x pan-y;
  overscroll-behavior: contain;
  background: #444;
  padding: 12px;
}
#zoom-image {
  display: block;
  height: auto;
  max-width: none;
  background: #fff;
  margin: 0 auto;
  user-select: none;
  -webkit-user-drag: none;
}
.zoom-hint {
  min-height: 34px;
  line-height: 1.4;
  font-size: 12px;
  color: #bbb;
  text-align: center;
  margin: 5px;
}
body.playing [data-action="play"] svg use {
  color: var(--accent);
}
@media (max-width: 1050px) {
  .reader-toolbar {
    gap: 4px 12px;
  }
  .tools {
    padding-left: 10px;
  }
  .reader-toolbar button,
  .reader-toolbar a {
    width: 34px;
    height: 36px;
  }
  .toolbar-group {
    gap: 1px;
  }
}
@media (max-width: 760px) {
  .reader-heading {
    height: 44px;
    min-height: 44px;
    padding-right: 12px;
  }
  .reader-heading h1 {
    font-size: 13px;
  }
  .reader-tag {
    display: none;
  }
  #book-stage {
    padding: 8px 16px;
  }
  .edge {
    width: 24px;
    height: 48px;
    background: #17171770;
  }
  .edge svg {
    width: 18px;
  }
  .edge.previous {
    left: 0;
  }
  .edge.next {
    right: 0;
  }
  .reader-toolbar {
    padding: 6px 8px max(8px, env(safe-area-inset-bottom));
    gap: 3px;
    min-height: 94px;
    flex-direction: column;
  }
  .tools {
    padding: 0;
    border: 0;
    justify-content: center;
    width: 100%;
    gap: 1px;
  }
  .reader-toolbar .tools button,
  .reader-toolbar .tools a {
    width: calc((100vw - 24px) / 10);
    max-width: 40px;
    height: 36px;
  }
  .reader-toolbar svg {
    width: 20px;
    height: 20px;
  }
  .reader-toolbar .navigation button {
    width: 36px;
    height: 34px;
  }
  #reader-panel {
    top: 44px;
    bottom: 96px;
    height: calc(100dvh - 140px);
  }
  #zoom-dialog {
    inset: 8px;
    width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
  }
  .zoom-toolbar {
    padding: 6px;
    gap: 1px;
  }
  .zoom-toolbar h2 {
    font-size: 14px;
  }
  .zoom-toolbar button {
    width: 34px;
  }
  #zoom-scroll {
    padding: 4px;
  }
  .page-index {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .reader-spinner {
    animation-duration: 2s;
  }
}

/* Page entry stays usable on numeric keyboards and at narrow phone widths. */
.reader-toolbar #page-go { width: 40px; height: 32px; background: #f1ede5; color: #222; font-size: 13px; font-weight: 600; }
.reader-toolbar #page-go:hover:not(:disabled) { background: #fff; }
#page-number[aria-invalid="true"] { border-color: #ffad9a; }
#page-error { position: fixed; z-index: 25; left: 50%; bottom: 80px; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); margin: 0; padding: 10px 14px; border-radius: 0; background: #fff1ed; color: #7c2715; font-size: 14px; line-height: 1.5; }
@media (max-width: 760px) {
  #page-form { gap: 4px; padding: 0 2px; }
  #page-error { bottom: calc(102px + env(safe-area-inset-bottom)); }
}
@media (max-width: 350px) {
  .reader-toolbar .navigation { gap: 1px; }
  .reader-toolbar .navigation button { width: 32px; }
  .reader-toolbar #page-go { width: 36px; }
}
