:root {
  color-scheme: light;
  --paper: #f7f7f2;
  --ink: #20221d;
  --muted: #6d7365;
  --olive: #526437;
  --sage: #e9edd7;
  --line: #dce2cc;
  --white: #fbfcf6;
  --viewer-chrome: 180px;
  font-family: "Source Han Sans SC", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .35; }
button, input { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--olive); outline-offset: 4px; }
button { touch-action: auto; }
svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app-shell { min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; }
.topbar { position: relative; z-index: 10; background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1680px; margin: 0 auto; min-height: 92px; padding: 16px 32px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.heading { flex: 1; min-width: 0; }
.brand { display: block; margin: 0 0 5px; color: var(--olive); font-size: 10px; font-weight: 750; letter-spacing: .17em; }
h1 { margin: 0; font-size: 22px; line-height: 1.3; font-weight: 650; letter-spacing: .02em; }
.controls, .paging-controls { display: flex; align-items: center; gap: 8px; }
.controls { flex: none; }
.paging-controls { margin-right: 10px; }
.control { min-height: 42px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: var(--white); display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-size: 13px; line-height: 1; white-space: nowrap; }
.control:hover:not(:disabled), .text-button:hover, .thumbnail-button:hover { background: var(--sage); }
.control[aria-expanded="true"] { background: var(--sage); border-color: var(--olive); }
.icon-only { width: 42px; padding: 9px; }
.share-control { background: var(--ink); border-color: var(--ink); color: var(--white); }
.share-control:hover:not(:disabled) { background: var(--olive); border-color: var(--olive); }
.page-counter { min-width: 58px; text-align: center; white-space: nowrap; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.page-counter strong { color: var(--ink); font-weight: 700; }

.viewer { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.stage-wrap { display: flex; flex: 1; align-items: center; justify-content: center; padding: 28px 32px 14px; }
.slide-frame { position: relative; width: min(100%, calc((100svh - var(--viewer-chrome)) * 16 / 9)); max-width: 1600px; aspect-ratio: 16 / 9; border: 1px solid var(--line); background: white; box-shadow: 0 6px 24px #20221d08; touch-action: auto; }
.slide-image { display: block; width: 100%; height: 100%; object-fit: contain; background: white; -webkit-user-drag: none; }
.stage-message { position: absolute; inset: 0; padding: 24px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 15px; color: var(--muted); background: #fbfcf6f5; text-align: center; font-size: 15px; }
.error-message strong { color: var(--ink); font-size: 19px; }
.error-message p { margin: 0; }
.retry-button { padding: 11px 20px; border: 1px solid var(--olive); border-radius: 10px; color: white; background: var(--olive); font-size: 14px; font-weight: 600; }
.retry-button:hover { background: #405128; }
.viewer-footer { display: flex; align-items: center; justify-content: space-between; gap: 24px; width: 100%; max-width: 1664px; margin: 0 auto; padding: 6px 32px 20px; font-size: 12px; color: var(--muted); }
.viewer-footer p { margin: 0; line-height: 1.6; }
.slide-caption { min-width: 0; }
.keyboard-hint { flex: none; }
.mobile-hint { display: none; }

.directory-panel { position: absolute; left: 0; right: 0; top: 100%; max-height: min(76svh, 720px); overflow-y: auto; padding: 20px 32px 26px; background: var(--paper); border-bottom: 1px solid var(--line); box-shadow: 0 14px 22px #20221d12; }
.directory-heading, .thumbnail-grid { width: 100%; max-width: 1440px; margin: 0 auto; }
.directory-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 16px; }
.directory-heading h2, .share-heading h2 { margin: 0; font-size: 17px; font-weight: 650; }
.text-button { padding: 8px 10px; border: 0; border-radius: 7px; background: transparent; color: var(--olive); font-size: 13px; }
.thumbnail-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 17px; padding: 0; list-style: none; }
.thumbnail-button { width: 100%; padding: 7px; text-align: left; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 9px; }
.thumbnail-button[aria-current="page"] { border: 2px solid var(--olive); padding: 6px; background: var(--sage); }
.thumbnail-visual { display: block; position: relative; aspect-ratio: 16 / 9; background: white; }
.thumbnail-image { display: block; width: 100%; height: 100%; object-fit: contain; }
.thumbnail-fallback { position: absolute; inset: 0; display: none; place-items: center; text-align: center; padding: 8px; color: var(--muted); font-size: 12px; }
.thumbnail-visual.is-unavailable .thumbnail-image { visibility: hidden; }
.thumbnail-visual.is-unavailable .thumbnail-fallback { display: grid; }
.thumbnail-title { display: block; margin: 9px 2px 3px; font-size: 12px; line-height: 1.55; }
.thumbnail-number { display: inline-block; margin-right: 7px; color: var(--olive); font-variant-numeric: tabular-nums; font-weight: 700; }

.toast { position: fixed; z-index: 40; left: 50%; bottom: 28px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 11px; background: var(--ink); color: white; box-shadow: 0 4px 16px #20221d20; font-size: 13px; text-align: center; }
.share-backdrop { position: fixed; inset: 0; z-index: 30; padding: 24px; display: grid; place-items: center; background: #20221d70; }
.share-dialog { width: 100%; max-width: 480px; max-height: calc(100svh - 48px); overflow-y: auto; padding: 26px; border: 1px solid var(--line); border-radius: 20px; background: var(--paper); }
.share-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.share-dialog p { color: var(--muted); font-size: 14px; line-height: 1.7; }
#share-url { display: block; width: 100%; min-width: 0; margin: 18px 0 14px; padding: 13px 12px; border: 1px solid var(--line); border-radius: 9px; background: white; color: var(--ink); font-size: 16px; }
.share-dialog .share-help { margin-bottom: 0; font-size: 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.no-script { max-width: 1440px; margin: 0 auto; padding: 24px; }
.no-script header { margin-bottom: 36px; }
.no-script section { margin: 0 0 38px; }
.no-script h2 { font-size: 16px; margin-bottom: 12px; }
.no-script img { display: block; width: 100%; height: auto; object-fit: contain; background: white; }

@media (max-width: 760px) {
  :root { --viewer-chrome: 220px; }
  .topbar-inner { flex-wrap: wrap; gap: 16px; padding: 16px; }
  h1 { font-size: 20px; }
  .controls { width: 100%; justify-content: space-between; gap: 7px; }
  .paging-controls { margin-right: auto; gap: 4px; }
  .control { min-height: 40px; padding: 9px 11px; }
  .icon-only { width: 38px; padding: 9px; }
  .page-counter { min-width: 48px; }
  .stage-wrap { padding: 24px 12px 14px; }
  .viewer-footer { align-items: flex-start; flex-direction: column; gap: 7px; padding: 6px 16px 18px; }
  .desktop-hint { display: none; }
  .mobile-hint { display: inline; }
  .directory-panel { padding: 18px 16px 24px; }
  .thumbnail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

@media (max-width: 390px) {
  .control { padding: 9px; gap: 5px; }
  .control svg { width: 17px; height: 17px; }
  .controls { gap: 4px; }
  .paging-controls { gap: 2px; }
  .page-counter { min-width: 42px; }
  .control .button-label { font-size: 12px; }
}

@media (max-width: 370px) {
  .controls .button-label { display: none; }
  .controls > .control { width: 38px; }
}

@media (orientation: landscape) and (max-height: 540px) {
  :root { --viewer-chrome: 112px; }
  .topbar-inner { flex-wrap: nowrap; min-height: 58px; padding: 8px 18px; gap: 16px; }
  .brand { display: none; }
  h1 { font-size: 17px; }
  .controls { width: auto; gap: 6px; }
  .paging-controls { margin-right: 6px; }
  .control { min-height: 36px; padding: 8px; }
  .icon-only { width: 36px; }
  .button-label { display: none; }
  .stage-wrap { padding: 10px 16px 6px; }
  .viewer-footer { flex-direction: row; align-items: center; padding: 4px 18px 10px; gap: 12px; font-size: 10px; }
  .slide-caption { max-width: 65%; }
  .mobile-hint { display: none; }
  .keyboard-hint { display: none; }
  .thumbnail-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media print {
  .topbar, .viewer-footer, .toast, .share-backdrop { display: none !important; }
  body { background: white; }
  .stage-wrap { padding: 0; }
  .slide-frame { width: 100%; max-width: none; box-shadow: none; border: 0; }
}
