:root {
  --bg: #0f2a33;
  --bg2: #163944;
  --paper: #f7f1e6;
  --ink: #1c2b33;
  --accent: #e4572e;
  --accent2: #2a9d8f;
  --chip: rgba(255, 255, 255, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-h: 56px;
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #f4f7f5;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100%;
  display: grid;
  grid-template-rows: calc(var(--bar-h) + var(--safe-top)) 1fr calc(var(--nav-h) + var(--safe-bottom));
}

.topbar, .navbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, #1a3d48, #123038);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.navbar {
  border-bottom: 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-bottom: var(--safe-bottom);
}
.topbar { padding-top: var(--safe-top); }

.title-wrap { flex: 1; min-width: 0; }
.title-wrap h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.title-wrap p {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.7;
}

.top-actions { display: flex; gap: 8px; }
.icon-btn, .chip, .nav-btn, .primary {
  border: 0;
  border-radius: 12px;
  background: var(--chip);
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.icon-btn {
  width: 40px;
  height: 40px;
  font-size: 18px;
}
.chip {
  padding: 8px 12px;
  font-size: 13px;
}
.nav-btn {
  padding: 10px 14px;
  font-size: 14px;
  white-space: nowrap;
}
.primary {
  background: var(--accent);
  color: #fff;
  padding: 12px 18px;
  font-weight: 700;
  width: 100%;
}

#pageSlider {
  flex: 1;
  accent-color: var(--accent2);
}

.reader {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(42,157,143,0.18), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(228,87,46,0.16), transparent 45%),
    var(--bg2);
  display: grid;
  place-items: center;
}

.stage {
  position: relative;
  /* 宽高由 JS 按课本比例精确写入，保证横竖屏热点不窜位 */
  width: min(100%, calc((100dvh - var(--bar-h) - var(--nav-h) - var(--safe-top) - var(--safe-bottom)) * var(--page-ratio, 0.72)));
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: var(--page-ratio, 0.72);
  background: var(--paper);
  box-shadow: 0 18px 50px rgba(0,0,0,0.35);
  border-radius: 4px;
  overflow: hidden;
}
.stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  background: var(--paper);
}
.hot-layer {
  position: absolute;
  inset: 0;
}
.hotspot {
  position: absolute;
  border-radius: 8px;
  border: 1.5px solid transparent;
  background: transparent;
}
.hotspot.word:active,
.hotspot.word.active {
  background: rgba(42, 157, 143, 0.28);
  border-color: rgba(42, 157, 143, 0.8);
}
.hotspot.sentence {
  border-radius: 6px;
  background: rgba(42, 157, 143, 0.08);
  border: 1.5px dashed rgba(42, 157, 143, 0.35);
}
.hotspot.sentence:active,
.hotspot.sentence.active {
  background: rgba(42, 157, 143, 0.22);
  border-style: solid;
  border-color: rgba(42, 157, 143, 0.85);
}
.hotspot.sentence.reading,
.hotspot.word.reading {
  background: rgba(255, 196, 0, 0.42);
  border-color: #ffb703;
  border-style: solid;
  box-shadow:
    0 0 0 3px rgba(255, 183, 3, 0.55),
    0 8px 24px rgba(255, 150, 0, 0.35);
  z-index: 5;
  animation: reading-pulse 0.9s ease-in-out infinite;
}
.hotspot.word.pic-vocab {
  border-radius: 50%;
  background: rgba(255, 183, 3, 0.14);
  border: 2px solid rgba(255, 183, 3, 0.55);
}
.hotspot.word.pic-vocab:active,
.hotspot.word.pic-vocab.active,
.hotspot.word.pic-vocab.reading {
  background: rgba(255, 196, 0, 0.38);
  border-color: #ffb703;
}
.chip.is-on {
  background: rgba(42, 157, 143, 0.85);
  color: #fff;
  font-weight: 700;
}
.hotspot.word.glossary-entry {
  background: rgba(42, 157, 143, 0.1);
  border: 1px solid rgba(42, 157, 143, 0.35);
  border-radius: 6px;
}
.hotspot.word.glossary-entry:active,
.hotspot.word.glossary-entry.active {
  background: rgba(42, 157, 143, 0.28);
  border-color: rgba(42, 157, 143, 0.85);
}
.mode-glossary .hotspot.sentence { display: none; }
@keyframes reading-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
.show-guides .hotspot.word {
  background: rgba(42, 157, 143, 0.12);
  border-color: rgba(42, 157, 143, 0.35);
}
.show-guides .hotspot.mnemonic {
  background: rgba(228, 87, 46, 0.1);
  border-color: rgba(228, 87, 46, 0.3);
}

.read-tip {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: baseline;
  gap: 8px;
  max-width: calc(100% - 20px);
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(16, 40, 48, 0.92);
  color: #fff;
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
  pointer-events: none;
  white-space: nowrap;
}
.read-tip[hidden] { display: none !important; }
.read-tip .read-idx {
  font-size: 12px;
  opacity: 0.75;
  flex-shrink: 0;
}
.read-tip .read-word {
  font-size: 22px;
  font-weight: 800;
  color: #ffd166;
}
.read-tip .read-zh {
  font-size: 14px;
  opacity: 0.9;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip.is-reading {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.tap-flash {
  position: absolute;
  pointer-events: none;
  border-radius: 10px;
  background: rgba(255, 220, 80, 0.35);
  box-shadow: 0 0 0 2px rgba(255, 200, 40, 0.6);
  animation: flash 0.45s ease-out forwards;
}
@keyframes flash {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(1.05); }
}

.drawer[hidden], .popup[hidden], .tap-flash[hidden], .read-tip[hidden],
.video-modal[hidden] { display: none !important; }

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(360px, 88vw);
  background: #102830;
  z-index: 30;
  box-shadow: 12px 0 40px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

.video-modal {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
}
.video-card {
  width: min(920px, 100%);
  background: #102830;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.video-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.video-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 14px 0;
}
.video-tabs button {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255,255,255,0.08);
  color: inherit;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.video-tabs button.is-on {
  background: var(--accent2);
  color: #fff;
  font-weight: 700;
}
.unit-video {
  width: 100%;
  max-height: min(70dvh, 560px);
  background: #000;
  display: block;
  margin-top: 10px;
}
.drawer.right {
  left: auto;
  right: 0;
  box-shadow: -12px 0 40px rgba(0,0,0,0.35);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.toc, .word-list {
  overflow: auto;
  padding: 10px;
  flex: 1;
}
.toc button, .word-list button {
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: inherit;
  font: inherit;
}
.word-list .w {
  font-size: 18px;
  font-weight: 700;
}
.word-list .meta {
  opacity: 0.75;
  font-size: 13px;
  margin-top: 4px;
}

.popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: grid;
  place-items: end center;
  z-index: 40;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
}
.popup[hidden] { display: none !important; }
.popup-card {
  width: min(460px, 100%);
  max-height: min(78dvh, 640px);
  background: #fff8ef;
  color: var(--ink);
  border-radius: 20px;
  padding: 16px 16px 12px;
  position: relative;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.popup-close { position: absolute; right: 10px; top: 10px; color: var(--ink); background: rgba(0,0,0,0.06); z-index: 2; }
.popup-scroll {
  overflow: auto;
  flex: 1;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}
.popup-head { display: flex; align-items: baseline; gap: 10px; padding-right: 36px; }
.popup-word { margin: 4px 0 0; font-size: 32px; font-weight: 800; letter-spacing: 0.02em; }
.popup-pos {
  margin: 0;
  font-size: 13px;
  color: #fff;
  background: var(--accent2);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
}
.popup-pos:empty { display: none; }
.popup-ipa { margin: 4px 0 0; color: #5b6b73; font-size: 15px; }
.popup-zh { margin: 8px 0 4px; font-size: 20px; font-weight: 700; }
.popup-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(28,43,51,0.1);
}
.popup-section[hidden] { display: none !important; }
.popup-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: #7a8790;
  font-weight: 700;
}
.popup-section p { margin: 0; font-size: 15px; line-height: 1.55; }
.popup-mnemonic {
  margin-top: 6px !important;
  color: #a14a2a;
  font-weight: 600;
}
.def-item {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.5;
}
.def-item .pos-tag {
  display: inline-block;
  font-size: 12px;
  color: var(--accent2);
  font-weight: 700;
  margin-right: 6px;
}
.ex-item {
  background: rgba(42, 157, 143, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.ex-item .en {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
}
.ex-item .zh {
  margin: 4px 0 0;
  font-size: 14px;
  color: #5b6b73;
}
.ex-item .src {
  margin: 6px 0 0;
  font-size: 11px;
  color: #9aa4ab;
}
.popup-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
}
.ghost {
  border: 0;
  border-radius: 12px;
  background: rgba(28,43,51,0.08);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 12px 14px;
  cursor: pointer;
}
.primary { width: auto; }

.boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background:
    linear-gradient(160deg, #e4572e 0%, #e4572e 42%, #f4c430 42%, #f4c430 100%);
  color: #1c2b33;
}
.boot[hidden] { display: none !important; }
.boot-card {
  text-align: center;
  background: rgba(255,255,255,0.88);
  padding: 28px 32px;
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.boot-card h2 { margin: 0 0 6px; font-size: 28px; }
.boot-card p { margin: 6px 0; }


.boot-progress {
  margin-top: 16px;
  text-align: left;
}
.boot-bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(28, 43, 51, 0.12);
  overflow: hidden;
}
#bootBarFill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e4572e, #f4c430);
  transition: width 0.18s ease;
}
.boot-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-size: 13px;
  color: #3a4a52;
}
#bootPct {
  font-weight: 700;
  flex-shrink: 0;
}

/* === phone-portrait === */
@media (max-width: 720px) {
  :root {
    --bar-h: 48px;
    --nav-h: 54px;
  }
  .topbar {
    gap: 6px;
    padding: 0 8px;
  }
  .title-wrap {
    flex: 0 1 auto;
    max-width: 34vw;
  }
  .title-wrap h1 {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .title-wrap p {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .top-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: none;
  }
  .top-actions::-webkit-scrollbar { display: none; }
  .chip {
    padding: 7px 10px;
    font-size: 12px;
    flex: 0 0 auto;
    border-radius: 10px;
  }
  .icon-btn {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
  }
  .reader {
    padding: 0;
  }
  .stage {
    border-radius: 0;
    box-shadow: none;
  }
  .hotspot.word,
  .hotspot.sentence {
    min-width: 28px;
    min-height: 22px;
  }
  .navbar {
    gap: 8px;
    padding: 0 8px;
  }
  .nav-btn {
    padding: 8px 10px;
    font-size: 13px;
  }
  .popup {
    place-items: end stretch;
    padding: 0;
  }
  .popup-card {
    width: 100%;
    max-height: min(72dvh, 560px);
    border-radius: 18px 18px 0 0;
  }
  .video-modal {
    padding: 0;
    place-items: end stretch;
  }
  .video-card {
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 92dvh;
  }
  .unit-video {
    max-height: min(56dvh, 420px);
    margin-top: 0;
  }
  .drawer {
    width: min(100vw, 100%);
  }
  .boot-card {
    width: min(92vw, 380px);
    padding: 22px 18px;
  }
}
