/* /read — the reading window. Chrome primitives live in style.css.
   The page takes its colour from the Hiển thị panel (#reader[data-page]);
   the grey chrome around it never changes. */

.reader-body { overflow: hidden; }
/* Phones, upright or on their side (the landscape phone matches by its short
   height + touch): the taskbar is hidden here (shell.css), so the window takes
   the full height. read.html is viewport-fit=cover, so on its side the page
   keeps clear of the notch and the rounded corners. */
@media (max-width: 640px), (max-height: 500px) and (pointer: coarse) {
  body.shell-reader .win {
    height: 100dvh; padding-bottom: calc(3px + var(--safe-b));
    padding-left: max(3px, env(safe-area-inset-left)); padding-right: max(3px, env(safe-area-inset-right));
  }
}

/* ===== Toolbar ===== */
.reader-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.reader-bar .tb[aria-expanded="true"] { box-shadow: var(--bevel-in); background: var(--dither); }
.reader-bar .tb:disabled { color: var(--shadow); cursor: default; box-shadow: none; padding: 4px 9px; }
.reader-bar .tb:disabled img { opacity: .4; filter: grayscale(1); }
.reader-bar .tb[hidden] { display: none; }
.guest-hint { padding: 0 var(--s3); color: var(--muted); font-size: var(--t-xs); white-space: nowrap; }
.guest-hint:hover { color: var(--sel); }
.guest-hint[hidden] { display: none; }
@media (max-width: 900px) { .guest-hint { display: none; } }
@media (pointer: coarse) { .guest-hint { line-height: var(--tap); } }   /* touch: the full toolbar height to hit */

/* ===== The page ===== */
/* Page themes as custom properties: the swatches below (.sw-sepia/.sw-dark)
   reuse the same values instead of repeating the hex codes. */
#reader {
  --sepia-bg: #f4ecd8; --sepia-fg: #3b2d1f;
  --dark-bg: #1a1a1a; --dark-fg: #e2e2de;
}
#stage {
  --page-bg: var(--light); --page-fg: #1a1a1a;
  position: relative; flex: 1 1 auto; min-height: 0; margin-top: 3px; overflow: hidden;
  background: var(--page-bg); color: var(--page-fg); box-shadow: var(--bevel-field);
}
#reader[data-page="sepia"] #stage { --page-bg: var(--sepia-bg); --page-fg: var(--sepia-fg); }
#reader[data-page="dark"] #stage { --page-bg: var(--dark-bg); --page-fg: var(--dark-fg); }
#viewer { position: absolute; inset: 3px; }

/* Page turns: the whole edge is the target; the raised chip only says so on hover. */
.page-arrow {
  position: absolute; top: 3px; bottom: 3px; z-index: 2; width: 12%; min-width: 44px; max-width: 96px;
  display: grid; place-items: center; padding: 0; border: 0; background: none; color: var(--text); cursor: pointer;
}
.page-arrow.prev { left: 3px; }
.page-arrow.next { right: 3px; }
.page-arrow:focus-visible { outline: none; }
.arrow-chip {
  display: grid; place-items: center; width: 24px; height: 40px;
  background: var(--face); box-shadow: var(--bevel-out); opacity: 0; transition: opacity .15s;
}
.arrow-chip svg { fill: currentColor; shape-rendering: crispEdges; }
#stage:hover .arrow-chip { opacity: .55; }
.page-arrow:hover .arrow-chip, .page-arrow:focus-visible .arrow-chip { opacity: 1; }
.page-arrow:focus-visible .arrow-chip { outline: 1px dotted var(--dark); outline-offset: -4px; }
.page-arrow:active .arrow-chip { box-shadow: var(--bevel-in); }
.page-arrow:active svg { transform: translate(1px, 1px); }
@media (hover: none) {
  .arrow-chip { display: none; }   /* touch: invisible tap zones… */
  .page-arrow:focus-visible .arrow-chip { display: grid; }   /* …but a keyboard still sees where it is */
}

/* ===== Mục lục drawer ===== */
#toc-backdrop { position: absolute; inset: 0; z-index: 19; background: repeating-conic-gradient(rgba(0,0,0,.28) 0 25%, transparent 0 50%) 0 0 / 2px 2px; }
#toc {
  position: absolute; top: 3px; bottom: 3px; left: 3px; z-index: 20; width: min(86vw, 340px);
  display: flex; flex-direction: column; padding: 3px; background: var(--face); color: var(--text);
  box-shadow: var(--bevel-window), 4px 4px 0 rgba(0,0,0,.3); animation: drawer-in .12s steps(3, end);
}
@keyframes drawer-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } }
#toc[hidden], #toc-backdrop[hidden] { display: none; }
#toc .toc-head { flex: none; margin-bottom: 3px; }
#toc > ul {
  flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 2px; list-style: none;
  background: var(--paper); box-shadow: var(--bevel-field); overscroll-behavior: contain;
}
#toc ul ul { list-style: none; margin: 0; padding: 0; }
#toc li a {
  position: relative; display: block; padding: 6px 10px 6px calc(12px + var(--depth, 0) * 14px);
  color: var(--text); font-size: var(--t-sm); line-height: 1.35;
}
@media (pointer: coarse) { #toc li a { display: flex; align-items: center; min-height: var(--tap); } }
#toc li a.untitled { color: var(--muted); font-style: italic; }
#toc li a:hover { background: var(--sel); color: var(--sel-text); text-decoration: none; }
/* "You are here": bold, with a pixel pointer in the indent. */
#toc li a[aria-current="true"] { font-weight: 600; }
#toc li a[aria-current="true"]::before {
  content: ""; position: absolute; top: 50%; left: calc(3px + var(--depth, 0) * 14px); width: 4px; height: 7px; margin-top: -4px;
  background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%);
}

/* ===== Hiển thị panel ===== */
#view-panel {
  position: absolute; top: 3px; right: 3px; z-index: 30; width: 300px; max-height: calc(100% - 6px); overflow-y: auto;
  animation: unfold .12s steps(4, end);
}
#view-panel[hidden] { display: none; }
#view-panel .dlg-title { margin-bottom: var(--s2); }
.view-body { display: flex; flex-direction: column; gap: var(--s3); padding: 0 var(--s2) var(--s2); }
/* Win95 group box: an etched frame the legend sits in. */
.group95 {
  min-width: 0; margin: 0; padding: var(--s2) var(--s2) var(--s2);
  border: 1px solid var(--shadow); box-shadow: inset 1px 1px var(--light), 1px 1px var(--light);
}
.group95 legend { padding: 0 var(--s1); background: var(--face); font: 500 var(--t-sm)/1 var(--font-ui); }
.size-row { display: grid; grid-template-columns: auto 1fr auto; gap: var(--s2); align-items: center; }
.size-readout {
  display: grid; place-items: center; min-height: var(--tap); background: var(--paper); box-shadow: var(--bevel-field);
  font: 500 var(--t-sm)/1 var(--font-ui); font-variant-numeric: tabular-nums;
}
/* Equal boxes whatever the glyph size: min-height (--tap) sets the height, not the text. */
#font-dec, #font-inc { --px: 1px; --py: 1px; min-width: 48px; font-family: var(--font-book); font-weight: 600; line-height: 1; }
#font-dec { font-size: var(--t-xs); }
#font-inc { font-size: var(--d-sm); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--s1); }
.seg .btn { --px: 6px; }
.seg .btn[aria-checked="true"] {
  box-shadow: var(--bevel-in); background: var(--hilite); font-weight: 600;
  padding: calc(var(--py) + 1px) calc(var(--px) - 1px) calc(var(--py) - 1px) calc(var(--px) + 1px);
}
.face-serif { font-family: var(--font-book); }
.swatch { width: 12px; height: 12px; flex: none; box-shadow: 0 0 0 1px var(--dark); }
.sw-light { background: var(--light); }
.sw-sepia { background: var(--sepia-bg); }
.sw-dark { background: var(--dark-bg); }
#view-panel .btn[aria-disabled="true"] { color: var(--shadow); text-shadow: 1px 1px var(--light); cursor: default; }
#view-panel .btn[aria-disabled="true"]:active { box-shadow: var(--bevel-out); padding: var(--py) var(--px); }
/* Phones: a sheet from the bottom edge, in thumb reach. Column width is moot at this size. */
@media (max-width: 640px), (max-height: 500px) and (pointer: coarse) {
  #view-panel {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 80dvh;
    padding: 3px max(3px, env(safe-area-inset-right)) calc(3px + var(--safe-b)) max(3px, env(safe-area-inset-left));
    animation: sheet-in .14s steps(4, end);
  }
}
/* Page width only matters when the screen is wider than a comfortable line. */
@media (max-width: 640px) { .width-group { display: none; } }
@keyframes sheet-in { from { clip-path: inset(100% 0 0 0); } to { clip-path: inset(0); } }

/* ===== Opening (and failing to open) ===== */
.reader-msg {
  position: absolute; inset: 3px; z-index: 40; display: grid; place-items: center; overflow: auto;
  padding: var(--s4); background: var(--page-bg);
}
.reader-msg[hidden] { display: none; }
.fail-dlg { width: min(440px, 100%); }
.fail-dlg .msgbox-text b { display: block; margin-bottom: var(--s1); font-weight: 600; }
.load-dlg { width: min(360px, 100%); box-shadow: var(--bevel-window); }
.load-body { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s1) var(--s4) var(--s4); }
.load-book { display: flex; flex-direction: column; gap: 2px; min-height: 42px; margin: 0; }
.load-book b {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font: 600 var(--t-lg)/1.3 var(--font-book); text-wrap: balance;
}
.load-book span { color: var(--muted); font-size: var(--t-sm); }
.load-dlg .progress95 { width: 100%; }
.load-note { margin: 0; color: var(--muted); font-size: var(--t-xs); font-variant-numeric: tabular-nums; }
/* Download progress is known: fill whole 12px segments, like the file-copy dialog. */
.progress95.determinate i {
  animation: none; transform: none; opacity: 1;
  width: calc((100% - 6px) * var(--p, 0));
  width: round(down, calc((100% - 6px) * var(--p, 0)), 12px);
}

/* ===== Status bar ===== */
.reader-status { flex: none; }
.status-page { flex: 0 0 auto; min-width: 104px; text-align: right; }
.reader-status .status-cell:empty::before { content: "\a0"; }

/* ===== "Đã xong?" (reader-progress.js) ===== */
#done-suggest {
  position: absolute; left: 50%; bottom: var(--s4); z-index: 22; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 24px);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); padding: var(--s2) var(--s3);
  background: var(--face); color: var(--text); font-size: var(--t-sm);
  box-shadow: var(--bevel-window), 3px 3px 0 rgba(0,0,0,.3);
}
#done-suggest img { width: 16px; height: 16px; flex: none; image-rendering: pixelated; }
