/* =====================================================================
   MEB Grade 3 Interactive Digital Textbook — Minimalist Side-Rail Layout
   Zero top/bottom bars: book pages fill ~98% of smartboard screen height!
   ===================================================================== */
:root {
  --cream: #fff6df;
  --paper: #fffdf6;
  --ink: #1f1a2e;
  --ink-soft: #524b66;
  --ink-muted: #7a728e;
  --yellow: #ffd23f;
  --pink: #ff4f87;
  --sky: #38bdf8;
  --green: #4ade80;
  --green-deep: #15803d;
  --purple: #a78bfa;
  --red: #f04452;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 2.5px 3px 0 var(--ink);
  --font-h: "Lilita One", "Trebuchet MS", sans-serif;
  --font-b: "DM Sans", "Segoe UI", sans-serif;
  --rail-w: 72px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background-color: var(--cream);
  background-image: radial-gradient(rgba(31, 26, 46, 0.11) 1.3px, transparent 1.4px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-b);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; }

/* ==================== BOOK PRELOADER SCREEN ==================== */
.book-loader {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background-color: var(--cream);
  background-image: radial-gradient(rgba(31, 26, 46, 0.1) 1.3px, transparent 1.4px);
  background-size: 22px 22px;
  transition: opacity 0.28s ease;
}
.book-loader.fade-out { opacity: 0; pointer-events: none; }
.book-loader[hidden] { display: none; }
.bl-card {
  display: flex;
  align-items: center;
  gap: 26px;
  width: min(94vw, 620px);
  padding: 24px 28px;
  background: var(--paper);
  border: 3.5px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 18px 44px rgba(31, 26, 46, 0.16), 6px 6px 0 var(--ink);
}
.bl-cover-wrap {
  position: relative;
  width: 148px;
  aspect-ratio: 553 / 780;
  flex: none;
  border-radius: 8px 14px 14px 8px;
  overflow: hidden;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: -5px 6px 0 rgba(31, 26, 46, 0.14), 0 10px 22px rgba(31, 26, 46, 0.18);
}
.bl-cover-wrap::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 10px;
  background: linear-gradient(90deg, rgba(31, 26, 46, 0.18), rgba(255, 255, 255, 0.5) 45%, transparent);
  pointer-events: none;
  z-index: 2;
}
.bl-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.bl-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.bl-pill {
  align-self: flex-start;
  font-family: var(--font-h);
  font-size: 12px;
  letter-spacing: 0.5px;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--yellow);
  border: 2px solid var(--ink);
}
.bl-title { margin: 0; font-family: var(--font-h); font-size: clamp(26px, 3vw, 34px); line-height: 1.05; color: var(--ink); }
.bl-sub { margin: 0; font-size: 14px; font-weight: 600; color: var(--ink-soft); line-height: 1.4; }
.bl-bar-wrap {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: #f1e6d2;
  border: 2.5px solid var(--ink);
  overflow: hidden;
  margin-top: 4px;
}
.bl-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--pink), var(--yellow), var(--green));
  border-radius: 999px;
  transition: width 0.15s ease-out;
}
.bl-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}
.bl-meta strong { font-family: var(--font-h); font-size: 15px; color: var(--ink); }
.bl-skip {
  align-self: flex-start;
  margin-top: 6px;
  height: 42px;
  padding: 0 20px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--pink);
  color: #fff;
  font-family: var(--font-h);
  font-size: 16px;
  box-shadow: 3px 3px 0 var(--ink);
}
.bl-skip:hover { background: var(--yellow); color: var(--ink); }
@media (max-width: 600px) {
  .bl-card { flex-direction: column; text-align: center; padding: 20px; gap: 16px; }
  .bl-cover-wrap { width: 118px; }
  .bl-info { align-items: center; width: 100%; }
  .bl-pill, .bl-skip { align-self: center; }
  .bl-meta { width: 100%; }
}

/* ==================== FIRST-VISIT VIDEO GUIDE POPUP ==================== */
.rail-guide { background: #e8f2ff; color: #0058b3; }
.guide-backdrop {
  position: fixed;
  inset: 0;
  z-index: 115;
  background: rgba(18, 18, 24, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.guide-backdrop[hidden] { display: none; }
.guide-card {
  width: min(94vw, 760px);
  max-height: 92dvh;
  background: #ffffff;
  border-radius: 26px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.32);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "DM Sans", "Segoe UI", sans-serif;
  color: #1d1d1f;
}
.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
  background: #fafafc;
}
.guide-head-l { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.guide-pill {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #0071e3;
  background: #e8f2ff;
  padding: 3px 10px;
  border-radius: 999px;
}
.guide-head h2 { margin: 0; font-size: clamp(18px, 2.2vw, 23px); font-weight: 700; letter-spacing: -0.02em; }
.guide-close {
  width: 36px; height: 36px; flex: none;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 50%;
  background: #f5f5f7;
  color: #1d1d1f;
  display: inline-flex; align-items: center; justify-content: center;
}
.guide-close:hover { background: #e8e8ed; }
.guide-close svg { width: 17px; height: 17px; }
.guide-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.guide-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 46dvh;
  border-radius: 16px;
  background: #111;
  border: 1px solid rgba(0, 0, 0, 0.08);
  display: block;
}
.guide-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.guide-chip {
  background: #f5f5f7;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 14px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.guide-chip b { font-size: 13px; font-weight: 700; color: #1d1d1f; }
.guide-chip span { font-size: 11.5px; font-weight: 500; color: #6e6e73; line-height: 1.32; }
.guide-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 13px 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.07);
  background: #fafafc;
}
.guide-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: #515154;
  cursor: pointer;
}
.guide-check input { width: 16px; height: 16px; accent-color: #0071e3; flex: none; }
.guide-start {
  height: 42px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: #0071e3;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 4px 12px -3px rgba(0, 113, 227, 0.5);
}
.guide-start:hover { filter: brightness(1.07); }
@media (max-width: 640px) {
  .guide-head, .guide-body, .guide-foot { padding: 12px 14px; }
  .guide-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guide-start { width: 100%; }
}

/* 3-column layout: [Left Rail] [Full-Height Book] [Right Rail] */
.book-app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--rail-w);
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  position: relative;
}

/* ==================== LEFT & RIGHT FLOATING BUTTONS (NO SOLID SIDE COLUMN) ==================== */
.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 8px;
  background: transparent;
  pointer-events: none;
  z-index: 30;
}
.rail > * { pointer-events: auto; }
.rail-left { border-right: 0; }
.rail-right { border-left: 0; }
.rail-spacer { flex: 1; pointer-events: none; }

.rail-btn {
  width: 54px;
  min-height: 52px;
  padding: 6px 2px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  font-family: var(--font-h);
  font-size: 12px;
  line-height: 1;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
}
.rail-btn svg { width: 21px; height: 21px; flex: none; }
.rail-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.rail-btn.on { background: var(--ink); color: #fff; }
.rail-back { background: var(--cream); }
.rail-toc { background: var(--yellow); }
.rail-answers.on { background: var(--green); color: var(--ink); }
.rail-pen.on { background: var(--pink); color: #fff; }

.rail-page {
  width: 54px;
  padding: 6px 4px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: var(--font-h);
}
.rail-page input {
  width: 42px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  text-align: center;
  font-family: var(--font-h);
  font-size: 16px;
  padding: 2px 0;
}
.rail-page small { font-size: 11px; color: var(--ink-soft); }

/* ==================== BOARD TOOLS POPOVER ==================== */
.board-tools {
  position: fixed;
  right: calc(var(--rail-w) + 10px);
  bottom: 16px;
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.board-tools[hidden] { display: none; }
.bt-sep-h { height: 2px; background: rgba(31, 26, 46, 0.15); margin: 2px 0; }
.bt-btn {
  height: 40px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: #fff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}
.bt-btn svg { width: 17px; height: 17px; }
.bt-btn .swatch {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--ink); display: inline-block;
}
.bt-btn.on { background: var(--yellow); box-shadow: 2px 2px 0 var(--ink); }

/* ==================== AUDIO SUBTITLE PILL (TOP-CENTER SPINE) ==================== */
.speech-toast {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 38;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(76vw, 540px);
  padding: 6px 10px 6px 14px;
  background: rgba(31, 26, 46, 0.94);
  color: #fff;
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(31, 26, 46, 0.25);
  font-size: 15px;
  font-weight: 700;
  opacity: 1;
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.speech-toast.fading {
  opacity: 0;
  transform: translate(-50%, -8px);
  pointer-events: none;
}
.st-close {
  width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, 0.16); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.st-close:hover { background: rgba(255, 255, 255, 0.3); }
.st-close svg { width: 14px; height: 14px; }
.speech-toast[hidden] { display: none; }
.st-wave { display: inline-flex; align-items: center; gap: 3px; height: 16px; }
.st-wave i {
  display: block; width: 3.5px; height: 7px; border-radius: 4px;
  background: var(--yellow);
  animation: waveBar 0.7s ease-in-out infinite alternate;
}
.st-wave i:nth-child(2) { animation-delay: 0.18s; height: 14px; }
.st-wave i:nth-child(3) { animation-delay: 0.36s; height: 10px; }
@keyframes waveBar { from { transform: scaleY(0.45); } to { transform: scaleY(1.15); } }
.st-ans {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: var(--yellow);
  color: var(--ink);
  font-family: var(--font-h);
  font-size: 14px;
  letter-spacing: 0.2px;
  flex: none;
}
.st-ans[hidden] { display: none; }
.st-ans:hover { background: var(--green); }
.st-replay {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid #fff; background: var(--pink); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.st-replay svg { width: 16px; height: 16px; }

/* ==================== FULL-HEIGHT BOOK STAGE ==================== */
.stage-wrap {
  --book-zoom: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  position: relative;
  overflow: hidden;
}
.stage-wrap.is-zoomed {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}
.stage-wrap.is-zoomed .spread {
  width: auto;
  height: auto;
  margin: auto;
  padding: 10px;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
}

.page-sheet {
  position: relative;
  flex: 0 0 auto;
  width: calc(min(calc(100vw - var(--rail-w) * 2 - 24px), calc((100vh - 18px) * 0.70897)) * var(--book-zoom));
  width: calc(min(calc(100vw - var(--rail-w) * 2 - 24px), calc((100dvh - 18px) * 0.70897)) * var(--book-zoom));
  aspect-ratio: 553 / 780;
  height: auto;
  background: #fff;
  border: 3.5px solid var(--ink);
  border-radius: 12px;
  box-shadow: 5px 5px 0 var(--ink);
  overflow: hidden;
  contain: layout paint style;
  transition: transform 0.24s cubic-bezier(.22, 1, .36, 1), opacity 0.2s ease;
}

.spread[data-mode="spread"] .page-sheet {
  width: calc(min(calc((100vw - var(--rail-w) * 2 - 24px) / 2), calc((100vh - 18px) * 0.70897)) * var(--book-zoom));
  width: calc(min(calc((100vw - var(--rail-w) * 2 - 24px) / 2), calc((100dvh - 18px) * 0.70897)) * var(--book-zoom));
}

/* Activity Focus Magnifier Mode */
.stage-wrap.has-focus .page-sheet:not(.is-focused) {
  opacity: 0.12;
  pointer-events: none;
}
.page-sheet.is-focused {
  z-index: 28;
  box-shadow: 0 24px 64px rgba(31, 26, 46, 0.42);
}
.focus-zoom-btn {
  position: absolute;
  z-index: 8;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: rgba(255, 253, 246, 0.92);
  color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transform: translate(-100%, -100%);
  transition: transform 0.14s, background 0.14s;
}
.focus-zoom-btn svg { width: 15px; height: 15px; }
.focus-zoom-btn:hover { background: var(--yellow); transform: translate(-100%, -100%) scale(1.12); }
.focus-zoom-btn.active { background: var(--pink); color: #fff; }
.exit-focus-btn {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--pink);
  color: #fff;
  font-family: var(--font-h);
  font-size: 15.5px;
  box-shadow: 0 6px 18px rgba(31, 26, 46, 0.28), 3px 3px 0 var(--ink);
}
.exit-focus-btn[hidden] { display: none; }
.exit-focus-btn svg { width: 18px; height: 18px; }
.exit-focus-btn:hover { background: var(--yellow); color: var(--ink); }
.spread[data-mode="spread"] .page-sheet.left-page {
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
  border-right-width: 1.5px;
  box-shadow: -5px 8px 22px rgba(31, 26, 46, 0.15), inset -16px 0 22px -16px rgba(31, 26, 46, 0.32);
}
.spread[data-mode="spread"] .page-sheet.right-page {
  border-top-left-radius: 3px;
  border-bottom-left-radius: 3px;
  border-left-width: 1.5px;
  box-shadow: 5px 8px 22px rgba(31, 26, 46, 0.15), 5px 5px 0 var(--ink), inset 16px 0 22px -16px rgba(31, 26, 46, 0.32);
}

.page-img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  pointer-events: none;
}

.overlay-layer { position: absolute; inset: 0; z-index: 4; }
.ink-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  z-index: 9; pointer-events: none; touch-action: none;
}
.ink-canvas.drawing { pointer-events: auto; cursor: crosshair; }

/* ==================== SUBTLE INTERACTIVE HOTSPOTS ==================== */
.hs {
  position: absolute;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 9px;
  transition: background 0.15s, box-shadow 0.15s, transform 0.15s;
}
.hs:hover {
  background: rgba(56, 189, 248, 0.16);
  box-shadow: inset 0 0 0 2px rgba(56, 189, 248, 0.85);
}
.hs.speaking {
  background: rgba(255, 210, 63, 0.28) !important;
  box-shadow: inset 0 0 0 3px var(--pink) !important;
}
/* Subtle Read-All hint badge on sequential instruction headings */
.hs.hs-seq::after {
  content: "▶";
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--pink);
  color: #fff;
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  font-size: 10px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.hs.hs-seq:hover::after { background: var(--yellow); color: var(--ink); }
/* Real-time golden light highlight synced with official MEB Listening Tracks! */
.hs.sync-glow {
  background: rgba(255, 224, 102, 0.28) !important;
  box-shadow: inset 0 0 0 4px #ffd23f, 0 0 22px 6px rgba(255, 210, 63, 0.85) !important;
  z-index: 6;
  animation: lightGlow 0.9s ease-in-out infinite alternate;
}
@keyframes lightGlow {
  from { box-shadow: inset 0 0 0 4px #ffd23f, 0 0 14px 4px rgba(255, 210, 63, 0.72); }
  to   { box-shadow: inset 0 0 0 5px #ff4f87, 0 0 26px 8px rgba(255, 210, 63, 0.98); }
}

/* Compact Fixed Bottom-Center Liquid Glass Mini-Player (NEVER covers page pictures or questions!) */
.inline-player {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 65;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(255, 248, 252, 0.92));
  border: 2px solid rgba(31, 26, 46, 0.2);
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(31, 26, 46, 0.2);
  white-space: nowrap;
}
.ip-btn {
  width: 32px;
  height: 32px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-h);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  flex: none;
}
.ip-btn svg { width: 16px; height: 16px; }
.ip-btn.ip-play { background: var(--pink); color: #fff; }
.ip-btn:hover { background: var(--yellow); color: var(--ink); }
.ip-btn.ip-play:hover { background: #e11d48; color: #fff; }
.ip-vol {
  font-family: var(--font-h);
  font-size: 12px;
  min-width: 34px;
  text-align: center;
  color: var(--ink);
}
.ip-time {
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  padding: 0 3px;
}
.ip-text-btn {
  height: 30px;
  padding: 0 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  font-family: var(--font-h);
  font-size: 12px;
  color: var(--ink);
  flex: none;
}
.ip-text-btn.on, .ip-text-btn:hover { background: var(--yellow); }
.ip-script-card {
  position: fixed;
  left: 50%;
  bottom: 66px;
  transform: translateX(-50%);
  z-index: 66;
  width: min(90vw, 440px);
  max-height: 38vh;
  overflow-y: auto;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.97), rgba(255, 250, 242, 0.95));
  border: 2px solid rgba(31, 26, 46, 0.18);
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(31, 26, 46, 0.22);
  font-size: 13.5px;
  line-height: 1.45;
}
.ip-script-card[hidden] { display: none; }
.ip-script-card h4 {
  margin: 0 0 6px;
  font-family: var(--font-h);
  font-size: 14.5px;
  color: var(--ink);
}
.ip-script-line {
  padding: 3px 6px;
  border-radius: 7px;
  margin-bottom: 3px;
  font-weight: 600;
}
.ip-script-line b { color: #6d28d9; }
.ip-script-line.now { background: #fff3c4; box-shadow: inset 0 0 0 1.5px var(--ink); }
.hs.selected {
  background: rgba(167, 139, 250, 0.26) !important;
  box-shadow: inset 0 0 0 2.5px #6d28d9 !important;
}

.hs-word { border-radius: 8px; }
.hs-word.used {
  background: rgba(74, 222, 128, 0.20);
  box-shadow: inset 0 0 0 2px rgba(21, 128, 61, 0.55);
}
.hs-word.crossed::after {
  content: "";
  position: absolute; left: 4%; right: 4%; top: 50%;
  height: 3.5px; background: var(--pink);
  transform: rotate(-4deg); border-radius: 4px;
}

/* Match Answer Boxes (p. 42) */
.hs-box {
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.5);
  border: 2px dashed rgba(31, 26, 46, 0.42);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-h);
  font-size: clamp(10px, 1.1vw, 17px);
  line-height: 1;
  color: var(--ink);
}
.hs-box:hover {
  background: rgba(255, 210, 63, 0.78);
  border-style: solid; border-color: var(--ink);
  transform: scale(1.08);
}
.hs-box.example { background: transparent; border-color: transparent; cursor: default; }
.hs-box.ok { background: #dcfce7; border: 2.5px solid var(--green-deep); color: var(--green-deep); }
.hs-box.wrong { background: #ffe4e6; border: 2.5px solid var(--red); color: var(--red); animation: nudge 0.35s ease; }
@keyframes nudge { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }

/* Fill-in-the-blank slots (p. 45) */
.hs-blank {
  border-radius: 7px;
  background: rgba(255, 246, 223, 0.92);
  border: 2px dashed var(--pink);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-h);
  font-size: clamp(9.5px, 1vw, 15px);
  line-height: 1;
  color: #1d4ed8;
  padding: 0 2px;
  overflow: hidden;
  white-space: nowrap;
}
.hs-blank:hover { background: #fff3c4; border-style: solid; border-color: var(--ink); }
.hs-blank.ok { background: #dcfce7; border: 2px solid var(--green-deep); color: var(--green-deep); }
.hs-blank.wrong { background: #ffe4e6; border: 2px solid var(--red); color: var(--red); animation: nudge 0.35s ease; }

/* Spoiler-free 1-tap tick table cells (e.g., p. 78 Act 4) */
.hs-tick {
  border-radius: 7px;
  background: transparent;
  border: 2px solid transparent;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-h);
  font-size: clamp(14px, 1.4vw, 22px);
  color: var(--ink);
}
.hs-tick:hover { background: rgba(255, 210, 63, 0.25); border-color: rgba(31, 26, 46, 0.35); }
.hs-tick.ok { background: rgba(220, 252, 231, 0.85); border-color: var(--green-deep); color: var(--green-deep); }
.hs-tick.wrong { background: rgba(255, 228, 230, 0.85); border-color: var(--red); color: var(--red); animation: nudge 0.35s ease; }

/* Timetable cells (p. 44) */
.hs-tt { border-radius: 6px; }
.hs-tt.row-hl, .hs-tt.col-hl { background: rgba(255, 210, 63, 0.22); }
.hs-tt.active-cell {
  background: rgba(255, 79, 135, 0.22) !important;
  box-shadow: inset 0 0 0 2.5px var(--pink) !important;
}

/* Key-only wordsearch / circle solution highlights */
.key-pill {
  border: 2.5px solid var(--kp-c, #e11d48);
  background: var(--kp-bg, rgba(225, 29, 72, 0.14));
  border-radius: 999px;
  z-index: 6;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.14s ease;
}
.key-pill:hover {
  background: var(--kp-bg, rgba(225, 29, 72, 0.24));
  transform: scale(1.02);
}

/* Transparent Liquid Glass Bonus Mini-Game Pill Bar (top empty margin of page!) */
.page-fab-bar {
  position: absolute;
  top: 1.0%;
  z-index: 8;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.page-fab-bar.pos-right { right: 2.0%; }
.page-fab-bar.pos-left  { left: 2.0%; }
/* Hide redundant Read All button in 2-page spread mode when left-page heading reads both pages */
.spread[data-mode="spread"] .page-fab[data-read-all="1"] { display: none; }
.page-fab {
  position: relative;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 9px;
  border: 1.5px solid rgba(31, 26, 46, 0.22);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.88), rgba(255, 248, 252, 0.78));
  color: rgba(31, 26, 46, 0.94);
  font-family: var(--font-h);
  font-size: clamp(10.5px, 0.95vw, 13.5px);
  letter-spacing: 0.2px;
  box-shadow: 0 4px 14px rgba(31, 26, 46, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.88);
  white-space: nowrap;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}
.page-fab svg { width: 13px; height: 13px; flex: none; opacity: 0.86; }
.page-fab:hover {
  transform: translateY(-1.5px) scale(1.03);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.68), rgba(255, 240, 248, 0.42));
  box-shadow: 0 6px 18px rgba(31, 26, 46, 0.2), inset 0 1px 0 #fff;
}
.page-fab.fab-soft,
.page-fab.fab-pink,
.page-fab.fab-sky,
.page-fab.fab-green {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.18));
  color: rgba(31, 26, 46, 0.92);
}
.page-fab .fab-bang {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 79, 135, 0.82);
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, 0.88);
  font-family: var(--font-h);
  font-size: 11px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 1px;
  flex: none;
}

/* Real Printed EBA QR Hotspot + Liquid Glass Badge Below QR (never covers QR!) */
.hs-qr-real {
  border: 2.5px solid rgba(255, 79, 135, 0.82);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 2px rgba(255, 210, 63, 0.45);
  overflow: visible;
}
.hs-qr-real::after {
  content: "EBA";
  position: absolute;
  left: 50%;
  top: calc(100% + 3px);
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 234, 243, 0.88));
  color: var(--ink);
  font-family: var(--font-h);
  font-size: 9.5px;
  letter-spacing: 0.3px;
  line-height: 1.1;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 12px rgba(31, 26, 46, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  pointer-events: none;
}
.hs-qr-real.is-video { border-color: rgba(109, 40, 217, 0.82); }
.hs-qr-real.is-video::after {
  content: "EBA VIDEO";
  background: linear-gradient(135deg, rgba(245, 240, 255, 0.78), rgba(221, 214, 254, 0.62));
  border-color: rgba(255, 255, 255, 0.88);
  color: #3b0764;
}

/* ==================== TOC DRAWER ==================== */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(31, 26, 46, 0.48);
  display: flex;
}
.drawer-backdrop[hidden] { display: none; }
.drawer {
  width: min(94vw, 520px);
  height: 100%;
  background: var(--paper);
  border-right: 4px solid var(--ink);
  display: flex; flex-direction: column;
}
.drawer-head {
  padding: 16px 18px;
  border-bottom: 3px solid var(--ink);
  background: var(--cream);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-pill {
  display: inline-block;
  font-family: var(--font-h); font-size: 12.5px;
  background: var(--ink); color: var(--yellow);
  padding: 2px 10px; border-radius: 999px; margin-bottom: 4px;
}
.drawer-head h2 { margin: 0; font-family: var(--font-h); font-size: 22px; }
.toc-size-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  padding: 3px;
  border: 2px solid var(--ink);
  border-radius: 10px;
}
.toc-sz-btn {
  width: 30px; height: 30px;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--ink);
  font-family: var(--font-h); font-size: 14px;
}
.toc-sz-btn.on { background: var(--yellow); box-shadow: inset 0 0 0 1.8px var(--ink); }
.drawer-body {
  padding: 14px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.toc-theme {
  border: 2.5px solid var(--ink);
  border-radius: 16px; background: #fff; padding: 12px;
  box-shadow: 3px 3px 0 var(--ink);
}
.toc-theme.soon { opacity: 0.55; border-style: dashed; box-shadow: none; }
.toc-theme h3 {
  margin: 0; font-family: var(--font-h); font-size: 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.toc-theme.ready h3 { cursor: pointer; user-select: none; }
.toc-theme:not(.collapsed) .toc-pages { margin-top: 10px; }
.toc-theme.collapsed .toc-pages { display: none; }
.toc-chev { display: inline-block; transition: transform 0.16s; margin-right: 4px; }
.toc-theme.collapsed .toc-chev { transform: rotate(-90deg); }
.toc-tag {
  font-family: var(--font-b); font-size: 11.5px; font-weight: 800;
  padding: 2px 8px; border-radius: 999px; background: var(--green); border: 2px solid var(--ink);
}
.toc-tag.soon { background: var(--cream); }
.toc-pages { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.drawer-body[data-sz="md"] .toc-pages { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.drawer-body[data-sz="md"] .toc-page-btn { padding: 5px; gap: 5px; font-size: 11px; }
.drawer-body[data-sz="md"] .toc-page-btn strong { font-size: 13px; padding: 1px 7px; }
.drawer-body[data-sz="sm"] .toc-pages { grid-template-columns: repeat(4, 1fr); gap: 6px; }
.drawer-body[data-sz="sm"] .toc-page-btn { padding: 4px; gap: 4px; font-size: 0; }
.drawer-body[data-sz="sm"] .toc-page-btn strong { font-size: 12px; padding: 1px 6px; margin: 0 auto; }
.toc-page-btn {
  padding: 8px; border: 2.5px solid var(--ink); border-radius: 14px;
  background: var(--cream); text-align: left;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  font-weight: 700; font-size: 13px; line-height: 1.25;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 0.14s, background 0.14s, box-shadow 0.14s;
}
.toc-page-btn img {
  width: 100%;
  aspect-ratio: 553 / 780;
  height: auto;
  object-fit: cover;
  background: #fff;
  border-radius: 8px;
  border: 2px solid var(--ink);
  display: block;
}
.toc-page-btn span {
  display: flex; flex-direction: column; gap: 2px;
  padding: 0 2px 2px;
}
.toc-page-btn strong {
  display: inline-block; align-self: flex-start;
  font-family: var(--font-h); font-size: 15.5px;
  background: var(--ink); color: var(--yellow);
  padding: 1px 9px; border-radius: 999px; margin-bottom: 2px;
}
.toc-page-btn.active, .toc-page-btn:hover {
  background: var(--yellow);
  transform: translateY(-2px);
  box-shadow: 3px 4px 0 var(--ink);
}
.toc-page-btn.active strong {
  background: var(--pink); color: #fff;
}

/* ==================== CLEAN MODAL & EBA EMBED ==================== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(31, 26, 46, 0.58);
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
}
.modal-backdrop[hidden] { display: none; }
/* Non-blocking docked quizzes so the active textbook page stays 100% visible & clickable! */
.modal-backdrop.dock-right,
.modal-backdrop.dock-left {
  background: transparent;
  pointer-events: none;
  padding: 18px calc(var(--rail-w) + 14px);
}
.modal-backdrop.dock-right { justify-content: flex-end; align-items: center; }
.modal-backdrop.dock-left  { justify-content: flex-start; align-items: center; }
.modal-backdrop.dock-right .modal-card,
.modal-backdrop.dock-left .modal-card {
  pointer-events: auto;
  width: min(44vw, 470px);
  max-height: 86vh;
  box-shadow: 0 14px 36px rgba(31, 26, 46, 0.25), 6px 6px 0 var(--ink);
}
.modal-backdrop.dock-right .ws-layout,
.modal-backdrop.dock-left .ws-layout {
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 12px;
}
.modal-backdrop.dock-right .ws-cell,
.modal-backdrop.dock-left .ws-cell {
  width: 33px;
  height: 33px;
  font-size: 16px;
}
@media (max-width: 960px) {
  .modal-backdrop.dock-right,
  .modal-backdrop.dock-left {
    justify-content: center;
    align-items: flex-end;
    padding: 10px calc(var(--rail-w) + 8px);
  }
  .modal-backdrop.dock-right .modal-card,
  .modal-backdrop.dock-left .modal-card {
    width: 100%;
    max-height: 42vh;
  }
}
.modal-card {
  width: min(94vw, 900px);
  max-height: 92vh;
  background: var(--paper);
  border: 3.5px solid var(--ink);
  border-radius: 22px;
  box-shadow: 6px 6px 0 var(--ink);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  padding: 12px 18px;
  background: var(--cream);
  border-bottom: 3px solid var(--ink);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.modal-title-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.modal-badge {
  font-family: var(--font-h); font-size: 13.5px;
  padding: 3px 10px; border-radius: 999px;
  border: 2px solid var(--ink); background: var(--yellow);
}
.modal-head h2 { margin: 0; font-family: var(--font-h); font-size: 22px; }
.close-btn {
  width: 40px; height: 40px; flex: none;
  border: 2.5px solid var(--ink); border-radius: 11px;
  background: #fff; box-shadow: 2px 2px 0 var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
}
.close-btn svg { width: 20px; height: 20px; }
.modal-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}

.eba-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 66vh;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #111;
  display: block;
}
.eba-frame {
  width: 100%;
  height: min(64vh, 520px);
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
}
.eba-frame.eba-frame-clean {
  height: min(74vh, 590px);
  background: #111;
}
.eba-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
}
.eba-note { font-size: 13.5px; font-weight: 700; color: var(--ink-soft); }

.clean-stack { display: flex; flex-direction: column; gap: 12px; }
.clean-card {
  border: 2.5px solid var(--ink);
  border-radius: 16px; background: #fff;
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.clean-card h3 { margin: 0 0 3px; font-family: var(--font-h); font-size: 19px; }
.clean-card p { margin: 0; color: var(--ink-soft); font-size: 14px; font-weight: 600; }

.action-btn {
  min-height: 46px;
  padding: 8px 16px;
  border: 2.5px solid var(--ink);
  border-radius: 13px;
  background: var(--yellow);
  font-family: var(--font-h);
  font-size: 17px;
  box-shadow: 3px 3px 0 var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  text-decoration: none; color: var(--ink);
}
.action-btn svg { width: 18px; height: 18px; flex: none; }
.action-btn.pink { background: var(--pink); color: #fff; }
.action-btn.sky { background: var(--sky); }
.action-btn.green { background: var(--green); }
.action-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

/* ==================== PICKER & PUZZLES ==================== */
.picker-pop {
  position: fixed; z-index: 90;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 16px;
  box-shadow: 5px 5px 0 var(--ink); padding: 9px;
  display: flex; flex-wrap: wrap; gap: 6px;
  max-width: min(90vw, 370px);
}
.picker-pop[hidden] { display: none; }
/* Compact floating popover anchored right beside a clicked Games! button */
.fab-menu {
  position: fixed;
  z-index: 92;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 10px 26px rgba(31, 26, 46, 0.24), 4px 4px 0 var(--ink);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 215px;
  max-width: min(86vw, 270px);
}
.fab-menu-item {
  width: 100%;
  min-height: 40px;
  padding: 7px 12px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: var(--green);
  color: var(--ink);
  font-family: var(--font-h);
  font-size: 15.5px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 0.12s, background 0.12s;
}
.fab-menu-item.ext { background: var(--pink); color: #fff; }
.fab-menu-item:hover { transform: translateY(-1px); background: var(--yellow); color: var(--ink); }
.fab-menu-item svg { width: 16px; height: 16px; flex: none; }
.pick-chip {
  min-height: 42px; padding: 5px 11px;
  border: 2px solid var(--ink); border-radius: 11px; background: #fff;
  font-weight: 800; font-size: 14.5px;
  display: inline-flex; align-items: center; gap: 6px;
}
.pick-chip:hover { background: var(--yellow); }
.pick-chip .p-num {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--ink); color: #fff;
  font-family: var(--font-h); font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
}
.pick-chip.used { opacity: 0.45; }

.ws-layout { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: start; }
.ws-grid {
  display: grid; gap: 4px; padding: 9px;
  background: var(--cream); border: 2.5px solid var(--ink); border-radius: 14px;
  touch-action: none;
}
.ws-cell {
  width: 38px; height: 38px; border: 2px solid var(--ink); border-radius: 8px;
  background: #fff; font-family: var(--font-h); font-size: 19px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.ws-cell.sel { background: var(--yellow); }
.ws-cell.found { background: var(--green); }
.ws-words { display: flex; flex-wrap: wrap; gap: 7px; }
.ws-word {
  padding: 6px 12px; border: 2px solid var(--ink); border-radius: 11px;
  background: #fff; font-family: var(--font-h); font-size: 16px;
}
.ws-word.found { background: var(--green); text-decoration: line-through; }

.quiz-box {
  border: 2.5px solid var(--ink); border-radius: 16px; background: #fff;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.quiz-q { font-family: var(--font-h); font-size: 23px; margin: 0; }
.quiz-opts { display: flex; flex-wrap: wrap; gap: 9px; }
.quiz-opt {
  min-height: 50px; padding: 7px 16px;
  border: 2.5px solid var(--ink); border-radius: 13px;
  background: var(--cream); font-family: var(--font-h); font-size: 18px;
  box-shadow: 2.5px 3px 0 var(--ink);
}
.quiz-opt:hover { background: var(--yellow); }
.quiz-opt.ok { background: var(--green); }
.quiz-opt.no { background: #ffe4e6; animation: nudge 0.35s ease; }

.cw-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 9px 12px;
  border: 2px solid var(--ink); border-radius: 13px; background: #fff; flex-wrap: wrap;
}
.cw-clue { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.cw-slots { display: flex; gap: 5px; flex-wrap: wrap; }
.cw-in {
  width: 36px; height: 40px; border: 2px solid var(--ink); border-radius: 8px;
  text-align: center; font-family: var(--font-h); font-size: 20px;
  text-transform: uppercase; background: var(--cream);
}
.cw-in.ok { background: #dcfce7; border-color: var(--green-deep); color: var(--green-deep); }
.cw-in.wrong { background: #ffe4e6; border-color: var(--red); }

.tile-row { display: flex; flex-wrap: wrap; gap: 7px; }
.letter-tile {
  min-width: 46px; height: 46px; border: 2.5px solid var(--ink); border-radius: 11px;
  background: var(--yellow); font-family: var(--font-h); font-size: 20px;
  box-shadow: 2px 2.5px 0 var(--ink);
}
.letter-tile.used { opacity: 0.3; pointer-events: none; }
.answer-slots {
  min-height: 50px; padding: 7px 12px;
  border: 2.5px dashed var(--ink); border-radius: 13px; background: var(--cream);
  font-family: var(--font-h); font-size: 24px; letter-spacing: 3px;
  display: flex; align-items: center; gap: 6px;
}

.track-lines { display: flex; flex-direction: column; gap: 7px; }
.track-line {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; border: 2px solid var(--ink); border-radius: 12px;
  background: #fff; font-weight: 700; font-size: 15px;
}
.track-line.playing { background: #fff3c4; border-color: var(--pink); }
.track-line .who {
  font-family: var(--font-h); font-size: 12.5px; padding: 2px 8px;
  border-radius: 999px; background: var(--sky); border: 1.5px solid var(--ink); margin-right: 6px;
}
.mini-icon-btn {
  width: 36px; height: 36px; border: 2px solid var(--ink); border-radius: 10px;
  background: #fff; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.mini-icon-btn svg { width: 17px; height: 17px; }

/* ==================== SPOTLIGHT & CALIBRATOR ==================== */
.spotlight-layer {
  position: fixed; inset: 0; z-index: 35; cursor: move;
  background: radial-gradient(circle 160px at var(--sx, 50%) var(--sy, 50%), transparent 0%, rgba(18, 14, 28, 0.72) 100%);
}
.spotlight-layer[hidden] { display: none; }
.calib-hud {
  position: fixed; left: 82px; bottom: 14px; z-index: 95;
  background: var(--ink); color: #fff; border: 2.5px solid var(--yellow);
  border-radius: 12px; padding: 8px 12px; font-size: 13px;
}
.calib-hud[hidden] { display: none; }
.calib-box { position: absolute; border: 2px dashed #ff4f87; background: rgba(255, 79, 135, 0.2); pointer-events: none; z-index: 20; }

/* ==================== RESPONSIVE: LAPTOPS, TABLETS, PHONES & ASPECT RATIOS ==================== */
/* 1. Standard 720p/768p teacher laptops (e.g. 1366x768 with browser chrome ~640px tall) */
@media (max-height: 760px) and (min-width: 901px) and (min-aspect-ratio: 105/100) {
  :root { --rail-w: 64px; }
  .rail { padding: 8px 6px; gap: 6px; overflow-y: auto; scrollbar-width: none; }
  .rail::-webkit-scrollbar { display: none; }
  .rail-btn { width: 48px; min-height: 44px; padding: 4px 2px; font-size: 11px; border-radius: 12px; }
  .rail-btn svg { width: 18px; height: 18px; }
  .rail-page { width: 48px; padding: 4px 2px; border-radius: 12px; }
  .rail-page input { width: 38px; font-size: 14px; }
}

/* 2. Ultra-short landscape screens (landscape phones: 844x390, 667x375) */
@media (max-height: 540px) and (min-aspect-ratio: 105/100) {
  :root { --rail-w: 52px; }
  .rail { padding: 5px 4px; gap: 5px; overflow-y: auto; scrollbar-width: none; }
  .rail::-webkit-scrollbar { display: none; }
  .rail-spacer { flex: 0 0 2px; }
  .rail-btn { width: 42px; min-height: 36px; padding: 3px 2px; font-size: 9px; border-radius: 10px; border-width: 2px; box-shadow: 2px 2px 0 var(--ink); }
  .rail-btn svg { width: 16px; height: 16px; }
  .rail-page { width: 42px; padding: 3px 2px; border-radius: 10px; border-width: 2px; }
  .rail-page input { width: 34px; font-size: 13px; padding: 1px 0; }
  .rail-page small { font-size: 9px; }
  .stage-wrap { padding: 4px 6px; }
  .speech-toast { top: 6px; font-size: 13px; padding: 4px 8px 4px 11px; max-width: calc(100vw - 120px); }
  .inline-player { bottom: 6px !important; padding: 5px 10px !important; }
}

/* 3. Portrait tablets, phones & narrow/square aspect ratios (top nav + full-width stage + bottom dock) */
@media (max-aspect-ratio: 105/100), (max-width: 600px) {
  .book-app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  .rail {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail-left {
    order: 1;
    border-right: 0;
    border-bottom: 0;
    background: transparent;
    padding-top: max(6px, env(safe-area-inset-top, 0px));
    justify-content: flex-start;
  }
  .stage-wrap {
    order: 2;
    padding: 6px 8px;
    -webkit-overflow-scrolling: touch;
  }
  .rail-right {
    order: 3;
    border-left: 0;
    border-top: 0;
    background: transparent;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
    justify-content: space-between;
  }
  .rail-right .rail-spacer { display: none; }
  .rail-left .rail-spacer { flex: 1 1 auto; min-width: 4px; }
  .rail-btn {
    flex: 0 0 auto;
    width: auto;
    min-width: 44px;
    min-height: 42px;
    padding: 4px 9px;
    font-size: 11px;
    border-radius: 12px;
    border-width: 2px;
    box-shadow: 2px 2px 0 var(--ink);
  }
  .rail-btn svg { width: 17px; height: 17px; }
  .rail-page {
    flex: 0 0 auto;
    width: auto;
    flex-direction: row;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 12px;
    border-width: 2px;
    min-height: 42px;
  }
  .rail-page input { width: 42px; font-size: 14.5px; padding: 2px 0; }
  .rail-page small { font-size: 11.5px; }

  /* Full-width page sizing without side rails stealing horizontal space */
  .page-sheet {
    width: calc(min(calc(100vw - 16px), calc((100vh - 128px) * 0.70897)) * var(--book-zoom));
    width: calc(min(calc(100vw - 16px), calc((100dvh - 128px) * 0.70897)) * var(--book-zoom));
    border-width: 2.5px;
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(31, 26, 46, 0.16), 3px 3px 0 var(--ink);
  }
  .spread[data-mode="spread"] .page-sheet {
    width: calc(min(calc((100vw - 18px) / 2), calc((100vh - 128px) * 0.70897)) * var(--book-zoom));
    width: calc(min(calc((100vw - 18px) / 2), calc((100dvh - 128px) * 0.70897)) * var(--book-zoom));
  }

  /* Reposition floating overlays clear of top & bottom bars */
  .speech-toast {
    top: calc(56px + env(safe-area-inset-top, 0px));
    width: min(94vw, 390px);
    max-width: calc(100vw - 14px);
    font-size: 11.5px;
    line-height: 1.25;
    padding: 4px 7px 4px 10px;
    gap: 6px;
  }
  .speech-toast .st-text { flex: 1; min-width: 0; }
  .speech-toast .st-wave { height: 12px; gap: 2px; }
  .speech-toast .st-wave i { width: 2.5px; }
  .speech-toast .st-replay,
  .speech-toast .st-close { width: 24px; height: 24px; border-width: 1.5px; }
  .speech-toast .st-replay svg { width: 12px; height: 12px; }
  .speech-toast .st-close svg { width: 11px; height: 11px; }
  .speech-toast .st-ans { height: 24px; padding: 0 9px; font-size: 11.5px; border-width: 1.5px; }

  /* Full-width non-scrolling mobile quiz / docked modals above bottom bar */
  .modal-backdrop.dock-right,
  .modal-backdrop.dock-left {
    justify-content: center;
    align-items: flex-end;
    padding: 8px 10px calc(62px + env(safe-area-inset-bottom, 0px)) 10px;
  }
  .modal-backdrop.dock-right .modal-card,
  .modal-backdrop.dock-left .modal-card {
    width: 100%;
    max-width: 480px;
    max-height: 76dvh;
  }
  .modal-head { padding: 9px 12px; }
  .modal-title-wrap { gap: 6px; }
  .modal-badge { font-size: 11px; padding: 2px 8px; }
  .modal-head h2 { font-size: 16px; }
  .close-btn { width: 32px; height: 32px; border-radius: 9px; }
  .close-btn svg { width: 16px; height: 16px; }
  .modal-body { padding: 10px 12px 12px; gap: 10px; }
  .quiz-box { padding: 10px 12px; gap: 8px; border-radius: 14px; }
  .quiz-q { font-size: 17px; line-height: 1.25; }
  .quiz-opts { gap: 7px; }
  .quiz-opt { min-height: 40px; padding: 6px 12px; font-size: 15px; border-radius: 11px; }
  .exit-focus-btn {
    top: calc(56px + env(safe-area-inset-top, 0px));
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    padding: 6px 14px;
    font-size: 13.5px;
  }
  .board-tools {
    right: 10px;
    left: 10px;
    bottom: calc(62px + env(safe-area-inset-bottom, 0px));
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    padding: 8px;
  }
  .bt-sep-h { display: none; }
  .bt-btn { height: 36px; padding: 0 10px; font-size: 13px; }
  .inline-player {
    bottom: calc(62px + env(safe-area-inset-bottom, 0px)) !important;
    max-width: calc(100vw - 16px) !important;
    padding: 6px 10px !important;
    gap: 6px !important;
    flex-wrap: wrap;
    justify-content: center;
  }
  .ip-script-card {
    bottom: calc(118px + env(safe-area-inset-bottom, 0px)) !important;
    width: min(94vw, 440px) !important;
    max-height: 42dvh !important;
  }
  .drawer { width: min(96vw, 480px); }
  .modal-card { width: min(96vw, 900px); max-height: 90dvh; border-radius: 18px; }
  .modal-head { padding: 10px 14px; }
  .modal-head h2 { font-size: 18px; }
  .modal-body { padding: 12px 14px 16px; }
  .eba-frame, .eba-frame.eba-frame-clean { height: min(62dvh, 460px); }
  .ws-layout { grid-template-columns: 1fr; }
  .ws-cell { width: 32px; height: 32px; font-size: 16px; }
  .focus-zoom-btn { width: 24px; height: 24px; }
  .focus-zoom-btn svg { width: 13px; height: 13px; }
  .hs-qr-real::after { font-size: 8px; padding: 1px 5px; }
}

@media (max-width: 480px) {
  .rail { padding: 5px 6px; gap: 4px; }
  .rail-btn { min-width: 38px; min-height: 38px; padding: 3px 6px; font-size: 10px; }
  .rail-btn svg { width: 15px; height: 15px; }
  .rail-page { min-height: 38px; padding: 3px 6px; }
  .rail-page input { width: 36px; font-size: 13.5px; }
  .rail-page small { display: none; }
  .drawer-body[data-sz="md"] .toc-pages { grid-template-columns: repeat(2, 1fr); }
  .drawer-body[data-sz="sm"] .toc-pages { grid-template-columns: repeat(3, 1fr); }
  .page-fab { padding: 3px 7px; font-size: 10px; gap: 3px; }
  .page-fab svg { width: 11px; height: 11px; }
  .page-fab .fab-bang { width: 14px; height: 14px; font-size: 9.5px; }
}
