:root {
  color-scheme: light;
  --cream: #fbf4df;
  --paper: #fffaf0;
  --leaf: #25523f;
  --leaf-soft: #3e7256;
  --moss: #78935f;
  --bark: #6d5030;
  --sun: #d9a441;
  --ink: #203327;
  --muted: #637262;
  --line: #ded0ad;
  --danger: #9a3f31;
  --focus: #143f2b;
  font-family: ui-serif, "Songti TC", "Noto Serif CJK TC", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--cream);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(37, 82, 63, 0.08), transparent 18rem),
    var(--cream);
}

button,
a {
  font: inherit;
}

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

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 20;
  transform: translateY(-160%);
  padding: 0.7rem 1rem;
  background: var(--leaf);
  color: white;
  border-radius: 0.5rem;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 1rem;
}

.hero {
  min-height: 30vh;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 3rem 0 1.25rem;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--leaf-soft);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  max-width: 100%;
  margin: 0;
  color: var(--leaf);
  font-size: clamp(2.35rem, 10vw, 5.25rem);
  line-height: 1.03;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

h1 span {
  display: block;
}

.subtitle {
  margin: 0.7rem 0 0;
  color: var(--bark);
  font-size: clamp(1.15rem, 5vw, 1.8rem);
  font-weight: 700;
}

.status-card {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  max-width: 18rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 250, 240, 0.82);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
}

.status-dot {
  width: 0.7rem;
  height: 0.7rem;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--sun);
  box-shadow: 0 0 0 4px rgba(217, 164, 65, 0.22);
}

.language-bar {
  display: flex;
  gap: 0.7rem;
  padding: 1rem 0;
  overflow-x: auto;
}

.language-pill {
  min-height: 2.9rem;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--leaf);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  white-space: nowrap;
}

.language-pill.active {
  background: var(--leaf);
  color: white;
  border-color: var(--leaf);
}

.language-pill:disabled {
  color: var(--muted);
  background: #eee4cd;
  cursor: not-allowed;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(12rem, 18rem) 1fr;
  gap: 1rem;
  align-items: start;
}

.page-panel {
  position: sticky;
  top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 250, 240, 0.9);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.1rem;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
}

.page-button {
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: white;
  color: var(--leaf);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
}

.page-button.current {
  background: var(--leaf);
  color: white;
  border-color: var(--leaf);
}

.story-card {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.art-wrap {
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 0.5rem;
  overflow: hidden;
  background: #e9dec3;
  border: 1px solid var(--line);
}

.art-wrap img {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 3 / 2;
  object-fit: contain;
}

.story-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--paper);
}

.page-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 800;
}

#pageTitle {
  margin: 0.55rem 0 0.25rem;
  color: var(--leaf);
  font-size: clamp(1.6rem, 8vw, 2.55rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.draft-badge {
  align-self: flex-start;
  margin: 0.45rem 0 0.9rem;
  padding: 0.38rem 0.55rem;
  border: 1px solid rgba(154, 63, 49, 0.28);
  border-radius: 0.35rem;
  color: var(--danger);
  background: #fff1e8;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
}

.story-text {
  white-space: pre-line;
  font-size: clamp(1.25rem, 6vw, 1.75rem);
  line-height: 1.72;
}

.story-text.compact {
  margin-top: 0.7rem;
  font-size: 1rem;
  line-height: 1.65;
  color: var(--muted);
}

.printed-details {
  margin-top: auto;
  padding-top: 1rem;
  color: var(--muted);
}

.printed-details summary {
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
}

.player-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin: 1rem -1rem 0;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--line);
  background: rgba(251, 244, 223, 0.96);
  backdrop-filter: blur(10px);
}

.player-status {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
}

.transport,
.route-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
}

.route-controls {
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  margin-top: 0.65rem;
}

.control-button,
.icon-text,
.route-button {
  width: 100%;
  min-width: 0;
  min-height: 3.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  text-align: center;
  text-decoration: none;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 850;
  line-height: 1.2;
  cursor: pointer;
}

.control-button.primary {
  background: var(--leaf);
  color: white;
  border-color: var(--leaf);
}

.control-button.secondary,
.icon-text,
.route-button {
  background: var(--paper);
  color: var(--leaf);
}

.control-button.download {
  background: var(--sun);
  color: #2b2213;
  border-color: #c28c29;
}

.control-button[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.55;
}

.subtle {
  min-height: 2.3rem;
  padding: 0.35rem 0.65rem;
}

.route-button.choice {
  background: var(--leaf-soft);
  color: white;
  border-color: var(--leaf-soft);
}

.offline-note {
  max-width: 65rem;
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.88rem;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 0.8rem;
  }

  .hero {
    min-height: 25vh;
    display: block;
    padding-top: 2.2rem;
  }

  .status-card {
    margin-top: 1rem;
  }

  .reader-layout,
  .story-card {
    grid-template-columns: 1fr;
  }

  .page-panel {
    position: static;
  }

  .page-grid {
    grid-template-columns: repeat(8, minmax(2.15rem, 1fr));
    overflow-x: auto;
  }

  .story-card {
    min-height: 0;
  }

  .art-wrap {
    aspect-ratio: 16 / 10;
    min-height: 0;
  }

  .story-content {
    padding: 1rem;
  }

  .player-bar {
    margin-right: -0.8rem;
    margin-left: -0.8rem;
    padding-right: 0.8rem;
    padding-left: 0.8rem;
  }

  .player-status {
    grid-template-columns: 1fr 1fr;
  }

  .player-status {
    display: grid;
  }

  .transport {
    display: grid;
    grid-template-columns: 1fr;
  }

  .route-controls {
    grid-template-columns: 1fr;
  }

  .route-button {
    min-height: 3.7rem;
  }

  .control-button.download {
    grid-column: auto;
  }
}

@media (min-width: 520px) and (max-width: 760px) {
  .transport {
    grid-template-columns: 1fr 1fr;
  }

  .control-button.download {
    grid-column: 1 / -1;
  }
}

@media (max-width: 380px) {
  .page-grid {
    grid-template-columns: repeat(6, minmax(2.15rem, 1fr));
  }

  .transport {
    grid-template-columns: 1fr;
  }

  .control-button.download {
    grid-column: auto;
  }

  h1 {
    font-size: clamp(2rem, 9vw, 2.8rem);
  }
}
