:root {
  color-scheme: dark;
  --reader-bg: #0c1b19;
  --reader-surface: #182c28;
  --surface-raised: #203a35;
  --line: rgb(255 255 255 / 12%);
  --text: #f7f4ea;
  --muted: #a8bbb5;
  --gold: #f3bd55;
  --gold-ink: #2c371c;
  --teal: #0f6b62;
  --focus: #f3bd55;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--reader-bg);
}

body {
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button:not(:disabled) {
  cursor: pointer;
}

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

[hidden] {
  display: none !important;
}

svg {
  display: block;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reader-app {
  position: fixed;
  inset: 0;
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 12%, rgb(49 94 84 / 34%), transparent 34%),
    var(--reader-bg);
}

.reader-header {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(0, 1.3fr) minmax(90px, 1fr);
  align-items: center;
  gap: 12px;
  padding:
    max(12px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    10px
    max(18px, env(safe-area-inset-left));
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  display: block;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--teal);
}

.brand-mark::before {
  position: absolute;
  top: 11px;
  left: 10px;
  width: 17px;
  height: 15px;
  border: 2px solid #fff8eb;
  border-top: 0;
  border-radius: 1px 1px 4px 4px;
  content: "";
}

.brand-mark::after {
  position: absolute;
  top: 8px;
  right: 4px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--gold);
  border-bottom-color: transparent;
  border-left-color: transparent;
  border-radius: 50%;
  content: "";
  transform: rotate(45deg);
}

.brand-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.1;
}

.brand-copy strong {
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
  font-size: 21px;
  letter-spacing: 0.04em;
}

.brand-copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.book-heading {
  min-width: 0;
  text-align: center;
}

.book-heading strong,
.book-heading span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-heading strong {
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
  font-size: 18px;
  line-height: 1.35;
}

.book-heading span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.round-button {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #d8e5e1;
  background: rgb(255 255 255 / 6%);
  transition:
    background-color 160ms ease,
    color 160ms ease,
    transform 120ms ease;
}

.round-button:hover,
.round-button[aria-pressed="true"] {
  color: var(--text);
  background: rgb(255 255 255 / 12%);
}

.round-button:active {
  transform: scale(0.96);
}

.reader-stage {
  position: relative;
  display: grid;
  min-height: 0;
  flex: 1;
  place-items: center;
  padding: 4px 18px;
}

.page-canvas {
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  background: #e7e7df;
  box-shadow: 0 18px 60px rgb(0 0 0 / 35%);
  line-height: 0;
  touch-action: manipulation;
  user-select: none;
}

.page-canvas img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

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

.hotspot {
  position: absolute;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px dashed transparent;
  border-radius: 7px;
  background: transparent;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    transform 120ms ease;
}

.show-hints .hotspot {
  border-color: rgb(255 255 255 / 58%);
  background: rgb(255 255 255 / 5%);
  box-shadow: inset 0 0 0 1px rgb(9 25 21 / 14%);
}

.hotspot::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  content: "";
  background: transparent;
  transform: translate(-50%, -50%);
  transition: all 160ms ease;
}

.show-hints .hotspot::after {
  background: rgb(255 255 255 / 78%);
  box-shadow: 0 0 0 5px rgb(15 107 98 / 28%);
}

.hotspot:hover {
  background: rgb(255 255 255 / 11%);
}

.hotspot.playing {
  border-color: var(--gold);
  background: rgb(243 189 85 / 18%);
  animation: hotspot-pulse 1.1s ease-in-out infinite;
}

.hotspot-label {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  max-width: 190px;
  padding: 5px 8px;
  overflow: hidden;
  border-radius: 4px;
  color: var(--text);
  background: rgb(8 23 20 / 88%);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 150ms ease,
    transform 150ms ease;
}

.hotspot.playing .hotspot-label {
  opacity: 1;
  transform: translate(-50%, 0);
}

.reader-footer {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding:
    10px
    max(22px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(22px, env(safe-area-inset-left));
}

.page-audio-button {
  display: inline-flex;
  min-width: 220px;
  align-items: center;
  gap: 10px;
  padding: 7px 15px 7px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgb(255 255 255 / 7%);
  text-align: left;
  transition: background-color 160ms ease;
}

.page-audio-button:hover {
  background: rgb(255 255 255 / 12%);
}

.audio-icon {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 50%;
  color: var(--gold-ink);
  background: var(--gold);
}

.audio-icon svg {
  width: 19px;
  height: 19px;
}

.audio-copy {
  display: block;
  min-width: 0;
}

.audio-copy strong,
.audio-copy small {
  display: block;
}

.audio-copy strong {
  font-size: 13px;
}

.audio-copy small {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.now-playing {
  display: inline-flex;
  max-width: min(44vw, 340px);
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #d8e5e1;
  background: rgb(255 255 255 / 6%);
  font-size: 11px;
}

.now-playing > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sound-bars {
  display: inline-flex;
  height: 14px;
  align-items: flex-end;
  gap: 2px;
}

.sound-bars i {
  display: block;
  width: 2px;
  height: 5px;
  border-radius: 2px;
  background: var(--gold);
  animation: sound-bar 0.8s ease-in-out infinite alternate;
}

.sound-bars i:nth-child(2) {
  animation-delay: 0.18s;
}

.sound-bars i:nth-child(3) {
  animation-delay: 0.34s;
}

.toast {
  position: fixed;
  z-index: 20;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 82px);
  left: 50%;
  max-width: calc(100vw - 32px);
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgb(6 20 17 / 92%);
  box-shadow: 0 10px 32px rgb(0 0 0 / 30%);
  font-size: 12px;
  text-align: center;
  transform: translateX(-50%);
}

@keyframes sound-bar {
  to {
    height: 13px;
  }
}

@keyframes hotspot-pulse {
  50% {
    box-shadow: 0 0 0 8px rgb(243 189 85 / 5%);
  }
}

@media (max-width: 640px) {
  .reader-header {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 8px;
    padding-inline: max(12px, env(safe-area-inset-left));
  }

  .brand-copy {
    display: none;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .book-heading strong {
    font-size: 16px;
  }

  .header-actions {
    gap: 6px;
  }

  .round-button {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .reader-stage {
    padding-inline: 14px;
  }

  .reader-footer {
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
    padding-inline: 16px;
  }

  .page-audio-button {
    width: min(100%, 320px);
    min-width: 0;
    align-self: center;
  }

  .now-playing {
    max-width: 100%;
    align-self: center;
  }
}

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