:root {
  --ink: #203044;
  --muted: #677386;
  --paper: #fffdf6;
  --cream: #f8f3e7;
  --sun: #f5c84c;
  --sun-deep: #dca921;
  --coral: #ef765f;
  --sky: #8fc9dc;
  --leaf: #72ad82;
  --shadow: 0 18px 48px rgb(35 48 66 / 16%);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

[hidden] {
  display: none !important;
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 14%, rgb(245 200 76 / 22%) 0 7%, transparent 7.2%),
    radial-gradient(circle at 91% 28%, rgb(143 201 220 / 24%) 0 8%, transparent 8.2%),
    linear-gradient(135deg, #f8f4e9, #edf5f2);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 3px;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.topbar {
  min-height: 76px;
  padding: 12px clamp(16px, 3vw, 36px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgb(255 253 246 / 92%);
  border-bottom: 1px solid rgb(32 48 68 / 10%);
  backdrop-filter: blur(14px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand__mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--sun);
  border: 2px solid var(--ink);
  border-radius: 17px 13px 18px 12px;
  box-shadow: 4px 4px 0 var(--ink);
  font-family: Georgia, serif;
  font-size: 14px;
  font-weight: 900;
  transform: rotate(-2deg);
}

.brand__eyebrow,
.rail-title,
.now-playing__hint {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 0;
  font-family: Georgia, "Microsoft YaHei UI", serif;
  font-size: clamp(20px, 2.2vw, 28px);
  line-height: 1;
}

.brand > div {
  min-width: 0;
}

.brand__title-row {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.brand__title-row h1 {
  flex: 0 0 auto;
}

.brand__reader-hint {
  min-width: 0;
  max-width: clamp(120px, 24vw, 320px);
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.soft-button,
.icon-button,
.page-button,
.unit-audio-button,
.transport-button,
.play-button {
  min-height: 46px;
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.soft-button:hover,
.icon-button:hover,
.page-button:hover,
.unit-audio-button:hover,
.transport-button:hover,
.play-button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.soft-button {
  padding: 0 15px;
  border-radius: 14px;
  background: #edf0eb;
  font-weight: 800;
}

.soft-button.is-active {
  background: #fff0ae;
  box-shadow: inset 0 0 0 2px var(--sun-deep);
}

.icon-button,
.page-button,
.transport-button {
  width: 46px;
  border-radius: 14px;
  background: white;
  box-shadow: 0 5px 16px rgb(35 48 66 / 12%);
  font-size: 22px;
  font-weight: 900;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
}

.chapter-rail {
  padding: 20px 13px;
  background: rgb(32 48 68 / 94%);
  color: white;
  overflow-y: auto;
}

.chapter-rail .rail-title {
  color: rgb(255 255 255 / 54%);
  text-align: center;
}

.unit-nav,
.extra-nav {
  display: grid;
  gap: 8px;
}

.unit-link,
.extra-link {
  min-height: 48px;
  padding: 8px 5px;
  border: 0;
  border-radius: 14px;
  color: white;
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.unit-link {
  font-family: Georgia, serif;
  font-size: 18px;
}

.unit-link:hover,
.extra-link:hover {
  background: rgb(255 255 255 / 10%);
}

.unit-link.is-active {
  color: var(--ink);
  background: var(--sun);
  box-shadow: 3px 3px 0 var(--coral);
}

.extra-link {
  min-height: 40px;
  font-size: 11px;
  line-height: 1.2;
}

.rail-divider {
  height: 1px;
  margin: 15px 4px;
  background: rgb(255 255 255 / 18%);
}

.reader {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.reader-toolbar {
  min-height: 64px;
  padding: 9px clamp(12px, 2vw, 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgb(248 243 231 / 88%);
  border-bottom: 1px solid rgb(32 48 68 / 9%);
}

.page-status {
  display: flex;
  align-items: center;
  gap: 9px;
}

.page-status input {
  width: 62px;
  height: 43px;
  padding: 0 6px;
  border: 2px solid rgb(32 48 68 / 14%);
  border-radius: 12px;
  background: white;
  text-align: center;
  font-weight: 900;
}

.unit-audio-button {
  margin-left: 9px;
  padding: 0 17px;
  border-radius: 14px;
  color: white;
  background: var(--coral);
  box-shadow: 0 6px 0 #b84f41;
  font-weight: 900;
}

.book-stage {
  min-height: 0;
  position: relative;
  padding: clamp(14px, 2vw, 28px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 38%) 1px, transparent 1px),
    linear-gradient(rgb(255 255 255 / 38%) 1px, transparent 1px),
    #dbe8e4;
  background-size: 24px 24px;
}

.loading-card {
  margin: auto;
  min-width: min(320px, 86vw);
  padding: 32px;
  display: grid;
  justify-items: center;
  gap: 8px;
  border: 2px solid var(--ink);
  border-radius: 24px 18px 25px 20px;
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--sun);
}

.loading-card__pencil {
  font-size: 34px;
  animation: scribble 900ms ease-in-out infinite alternate;
}

.loading-card small {
  color: var(--muted);
}

@keyframes scribble {
  to { transform: translateX(9px) rotate(-8deg); }
}

.page-wrap {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 4px;
  background: white;
  box-shadow: var(--shadow), 0 0 0 1px rgb(32 48 68 / 9%);
  cursor: zoom-in;
  touch-action: pan-x pinch-zoom;
}

.page-wrap.is-swiping {
  will-change: transform, opacity;
}

.app-shell.is-page-focus {
  grid-template-rows: 1fr;
  background: #172433;
}

.app-shell.is-page-focus .topbar,
.app-shell.is-page-focus .chapter-rail,
.app-shell.is-page-focus .reader-toolbar,
.app-shell.is-page-focus .player {
  display: none;
}

.app-shell.is-page-focus .workspace {
  grid-template-columns: 1fr;
}

.app-shell.is-page-focus .reader {
  grid-template-rows: 1fr;
}

.app-shell.is-page-focus .book-stage {
  padding: 8px;
  align-items: center;
  background: #172433;
}

.app-shell.is-page-focus .page-wrap {
  cursor: zoom-out;
  box-shadow: 0 18px 60px rgb(0 0 0 / 42%);
}

#pdfCanvas {
  display: block;
  background: white;
}

.hotspot-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspot {
  position: absolute;
  padding: 0;
  border: 2px dashed transparent;
  border-radius: 16px;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.show-targets .hotspot {
  border-color: rgb(220 169 33 / 72%);
  background: rgb(245 200 76 / 10%);
}

.hotspot:hover,
.hotspot:focus-visible,
.hotspot.is-playing {
  border-color: var(--coral);
  background: rgb(245 200 76 / 23%);
  box-shadow: inset 0 0 0 3px rgb(255 255 255 / 60%);
}

.hotspot--speaker {
  width: clamp(46px, 5vw, 64px);
  height: clamp(46px, 5vw, 64px);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.show-targets .hotspot--speaker {
  border: 3px solid rgb(245 200 76 / 92%);
  background: rgb(245 200 76 / 18%);
  box-shadow: 0 0 0 6px rgb(245 200 76 / 18%);
}

.hotspot--speaker:hover,
.hotspot--speaker:focus-visible,
.hotspot--speaker.is-playing {
  border: 3px solid var(--coral);
  background: rgb(239 118 95 / 18%);
  box-shadow: 0 0 0 7px rgb(239 118 95 / 20%);
}

.hotspot--speaker .hotspot__badge {
  display: none;
}

.hotspot--word-title {
  border-radius: 3px;
}

.show-targets .hotspot--word-title {
  border: 2px solid var(--coral);
  background: rgb(239 118 95 / 8%);
}

.hotspot--word-title .hotspot__badge {
  top: 50%;
  right: auto;
  left: calc(100% + 8px);
  min-height: 34px;
  max-width: none;
  padding: 6px 10px;
  white-space: nowrap;
  opacity: 1;
  transform: translateY(-50%);
}

.hotspot__badge {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 36px;
  max-width: calc(100% - 16px);
  padding: 7px 11px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 2px solid var(--ink);
  border-radius: 12px 9px 12px 10px;
  color: var(--ink);
  background: var(--sun);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: clamp(10px, 1.5vw, 13px);
  font-weight: 900;
  line-height: 1.1;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.show-targets .hotspot__badge,
.hotspot:hover .hotspot__badge,
.hotspot:focus-visible .hotspot__badge,
.hotspot.is-playing .hotspot__badge {
  opacity: 1;
  transform: translateY(0);
}

.hotspot.is-playing .hotspot__badge {
  color: white;
  background: var(--coral);
}

.show-targets .hotspot--word-title .hotspot__badge,
.hotspot--word-title:hover .hotspot__badge,
.hotspot--word-title:focus-visible .hotspot__badge,
.hotspot--word-title.is-playing .hotspot__badge {
  transform: translateY(-50%);
}

.player {
  min-height: 92px;
  padding: 12px clamp(14px, 3vw, 34px) max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(190px, 1.25fr) auto minmax(240px, 2fr) auto;
  align-items: center;
  gap: clamp(12px, 2vw, 24px);
  background: var(--paper);
  border-top: 1px solid rgb(32 48 68 / 12%);
  box-shadow: 0 -10px 30px rgb(32 48 68 / 8%);
  z-index: 30;
}

.now-playing {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.now-playing-button {
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 12px;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 150ms ease;
}

.now-playing-button:not(:disabled):hover,
.now-playing-button:not(:disabled):focus-visible {
  background: rgb(245 200 76 / 16%);
}

.now-playing-button:disabled {
  cursor: default;
}

.now-playing__content {
  min-width: 0;
}

.now-playing__return {
  margin-left: auto;
  color: var(--coral);
  font-size: 18px;
  font-weight: 900;
  opacity: 1;
}

.now-playing-button:disabled .now-playing__return {
  opacity: 0;
}

.now-playing strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.playing-dot {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 3px solid white;
  border-radius: 50%;
  background: #aab1bb;
  box-shadow: 0 0 0 2px #aab1bb;
}

.playing-dot.is-playing {
  background: var(--leaf);
  box-shadow: 0 0 0 2px var(--leaf), 0 0 0 7px rgb(114 173 130 / 20%);
  animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
  50% { transform: scale(1.12); }
}

.transport {
  display: flex;
  align-items: center;
  gap: 9px;
}

.play-button {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  color: white;
  background: var(--ink);
  box-shadow: 0 7px 0 #101a27;
  font-size: 22px;
}

.play-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.loop-control {
  min-height: 44px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.loop-control input {
  width: 19px;
  height: 19px;
  accent-color: var(--coral);
}

.timeline {
  display: grid;
  grid-template-columns: 42px minmax(100px, 1fr) 42px;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.timeline input {
  width: 100%;
  accent-color: var(--coral);
  cursor: pointer;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.speed-control select {
  height: 42px;
  padding: 0 8px;
  border: 2px solid rgb(32 48 68 / 14%);
  border-radius: 12px;
  color: var(--ink);
  background: white;
  font-weight: 900;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 112px;
  z-index: 100;
  max-width: min(420px, 86vw);
  padding: 12px 17px;
  border-radius: 12px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .chapter-rail {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
  }

  .chapter-rail .rail-title,
  .rail-divider {
    display: none;
  }

  .unit-nav,
  .extra-nav {
    display: flex;
    gap: 6px;
  }

  .unit-link,
  .extra-link {
    min-width: 54px;
    min-height: 42px;
    padding: 7px 10px;
    white-space: nowrap;
  }

  .reader {
    grid-template-rows: 1fr;
  }

  .player {
    min-height: 98px;
    padding: 7px 12px max(7px, env(safe-area-inset-bottom));
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "page-controls transport"
      "now-playing timeline";
    gap: 5px 12px;
  }

  .player .reader-toolbar {
    grid-area: page-controls;
    min-width: 0;
    min-height: 0;
    padding: 0;
    justify-content: flex-start;
    gap: 6px;
    background: transparent;
    border: 0;
  }

  .player .page-button {
    width: 38px;
    min-height: 38px;
    border-radius: 11px;
    font-size: 18px;
  }

  .player .page-status input {
    width: 50px;
    height: 38px;
    border-radius: 10px;
  }

  .player .unit-audio-button {
    min-height: 38px;
    margin-left: 0;
    padding: 0 10px;
    border-radius: 11px;
    font-size: 11px;
  }

  .player .transport-button {
    width: 42px;
    min-height: 42px;
  }

  .player .play-button {
    width: 50px;
    height: 50px;
  }

  .transport {
    grid-area: transport;
  }

  .player > .now-playing {
    grid-area: now-playing;
  }

  .timeline {
    grid-area: timeline;
    grid-template-columns: 32px minmax(80px, 1fr) 32px;
    gap: 5px;
    font-size: 11px;
  }

  .speed-control {
    display: none;
  }
}

@media (min-width: 681px) and (max-width: 820px) {
  .topbar .brand {
    min-width: 0;
  }

  .topbar .unit-audio-button {
    min-height: 40px;
    margin-left: 0;
    padding: 0 11px;
    border-radius: 12px;
    font-size: 11px;
    box-shadow: 0 4px 0 #b84f41;
  }

  .player {
    grid-template-columns: minmax(150px, 0.9fr) 34px 36px minmax(200px, 1.5fr) auto;
    grid-template-areas:
      "page-controls page-controls page-controls page-controls page-controls"
      "now-playing restart play timeline loop";
    column-gap: 8px;
  }

  .player .reader-toolbar {
    justify-content: center;
  }

  .player .transport {
    display: contents;
    grid-area: auto;
  }

  .player #restartButton {
    grid-area: restart;
    width: 34px;
    min-height: 34px;
    border-radius: 10px;
    background: #edf0eb;
    box-shadow: none;
    font-size: 17px;
  }

  .player #playButton {
    grid-area: play;
    width: 36px;
    height: 36px;
    min-height: 36px;
    box-shadow: none;
    font-size: 16px;
  }

  .player .timeline {
    grid-area: timeline;
  }

  .player .loop-control {
    grid-area: loop;
    min-height: 34px;
    padding: 0 5px;
    gap: 4px;
    font-size: 11px;
  }

  .player .loop-control input {
    width: 17px;
    height: 17px;
  }

  .player > .now-playing {
    padding: 2px 4px;
    gap: 7px;
  }

  .player .now-playing__hint {
    font-size: 9px;
  }

  .player .now-playing strong {
    font-size: 12px;
  }

  .player .now-playing__return {
    font-size: 15px;
  }
}

@media (max-width: 680px) {
  .player {
    min-height: 108px;
    padding: 4px 10px max(4px, env(safe-area-inset-bottom));
    grid-template-areas:
      "page-controls page-controls"
      "now-playing transport"
      "timeline timeline";
    gap: 3px 10px;
  }

  .player .reader-toolbar {
    justify-content: center;
  }

  .player .page-status {
    gap: 5px;
  }

  .player .page-button {
    width: 36px;
    min-height: 36px;
  }

  .player .page-status input {
    width: 48px;
    height: 36px;
  }

  .player .unit-audio-button {
    min-height: 36px;
  }

  .player .play-button {
    width: 40px;
    height: 40px;
    min-height: 40px;
    box-shadow: 0 5px 0 #101a27;
    font-size: 18px;
  }

  .player .transport {
    gap: 5px;
  }

  .player > .now-playing {
    gap: 7px;
    font-size: 12px;
  }

  .player .playing-dot {
    width: 10px;
    height: 10px;
    border-width: 2px;
  }

  .player .loop-control {
    min-height: 34px;
    padding: 0 6px;
  }

  .player .loop-control input {
    width: 16px;
    height: 16px;
  }

  .player .timeline {
    grid-template-columns: 27px minmax(70px, 1fr) 27px;
    gap: 4px;
    font-size: 10px;
  }

  .toast {
    bottom: 122px;
  }
}

@media (max-width: 560px) {
  .topbar {
    min-height: 62px;
    padding: 8px 11px;
  }

  .brand__mark {
    width: 43px;
    height: 43px;
    font-size: 11px;
  }

  .brand__eyebrow {
    display: none;
  }

  .brand h1 {
    font-size: 18px;
  }

  .soft-button {
    width: 46px;
    padding: 0;
    font-size: 0;
  }

  .soft-button span {
    font-size: 18px;
  }

  .icon-button {
    display: none;
  }

  .reader-toolbar {
    gap: 8px;
  }

  .unit-audio-button {
    margin-left: 0;
    padding: 0 12px;
    font-size: 12px;
  }

  .book-stage {
    padding: 9px;
  }

  .player {
    min-height: 108px;
    padding: 4px 10px max(4px, env(safe-area-inset-bottom));
  }

  .now-playing__hint,
  .transport-button,
  .loop-control span {
    display: none;
  }

  .toast {
    bottom: 122px;
  }
}

@media (max-width: 380px) {
  #unitFullAudioLabel {
    display: none;
  }

  .player .unit-audio-button {
    width: 42px;
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
