@font-face {
  font-family: "Grundschrift";
  src: url("fonts/Grundschrift-Regular.otf") format("opentype");
  font-display: swap;
}

:root {
  --bg-top: #f7f3d5;
  --bg-bottom: #dff1ff;
  --card: rgba(255, 255, 255, 0.88);
  --card-border: rgba(34, 71, 138, 0.15);
  --text: #183153;
  --muted: #5e7290;
  --accent: #ff9f1c;
  --accent-strong: #ef7f1a;
  --highlight: #ffe66d;
  --highlight-ring: #f4b400;
  --blue: #005bbb;
  --red: #d7263d;
  --button: #ffffff;
  --shadow: 0 18px 45px rgba(24, 49, 83, 0.16);
  --radius-xl: 28px;
  --radius-lg: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Grundschrift", "Comic Sans MS", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 28%),
    radial-gradient(circle at right 15% top 10%, rgba(255, 209, 102, 0.55), transparent 20%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.app-shell {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 2.25rem;
}

.hero-card {
  padding: 1.4rem;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.is-hidden {
  display: none !important;
}

.home-view {
  display: grid;
  gap: 1.5rem;
}

.home-hero {
  display: grid;
  gap: 1rem;
  align-items: stretch;
}

.home-copy {
  display: grid;
  gap: 0.45rem;
  padding: 1.25rem 1.35rem;
  border-radius: 24px;
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.95), transparent 34%),
    linear-gradient(135deg, rgba(255, 240, 202, 0.98), rgba(220, 241, 255, 0.95));
}

.section-kicker {
  margin: 0;
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.home-kicker {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.home-title {
  margin: 0;
  font-size: clamp(2.1rem, 4vw, 3.3rem);
  line-height: 1.05;
}

.home-lead {
  max-width: 28ch;
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.35;
  color: var(--muted);
}

.library-panel {
  display: grid;
  gap: 1rem;
  padding: 1.15rem;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: inset 0 0 0 1px rgba(24, 49, 83, 0.08);
}

.library-panel-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: end;
}

.section-title {
  margin: 0.15rem 0 0;
  font-size: clamp(1.6rem, 3vw, 2.25rem);
}

.section-note {
  margin: 0;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 232, 179, 0.72);
}

.level-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.tab-button {
  min-height: 50px;
  padding: 0.7rem 1rem;
  border: 0;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 2px rgba(24, 49, 83, 0.1);
}

.tab-button[aria-selected="true"] {
  background: linear-gradient(135deg, #ffe8b3, #dff1ff);
  box-shadow: inset 0 0 0 2px rgba(24, 49, 83, 0.18);
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.story-tile {
  min-height: 180px;
  padding: 1rem 1rem 1.1rem;
  border: 0;
  border-radius: 24px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(255, 232, 179, 0.9), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(242, 248, 255, 0.96));
  box-shadow: inset 0 0 0 1px rgba(24, 49, 83, 0.08), 0 12px 24px rgba(24, 49, 83, 0.08);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.story-tile-inner {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0.75rem;
}

.story-tile-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  border-radius: 18px;
  box-shadow: inset 0 0 0 1px rgba(24, 49, 83, 0.08);
  transform: scale(1);
  transition: transform 180ms ease, filter 180ms ease;
}

.story-title-text {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.18;
}

.story-tile-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.story-open-label {
  font-size: 1rem;
  color: var(--accent-strong);
}

.story-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef7f1a, #f4b400);
  box-shadow: 0 0 0 6px rgba(244, 180, 0, 0.14);
}

.story-tile:hover,
.story-tile:focus-visible,
.tab-button:hover,
.tab-button:focus-visible {
  transform: translateY(-2px);
  outline: none;
}

.story-tile:not(.is-disabled):hover,
.story-tile:not(.is-disabled):focus-visible {
  box-shadow: inset 0 0 0 1px rgba(24, 49, 83, 0.08), 0 18px 30px rgba(24, 49, 83, 0.14);
}

.story-tile:not(.is-disabled):hover .story-tile-image,
.story-tile:not(.is-disabled):focus-visible .story-tile-image {
  transform: scale(1.035);
  filter: saturate(1.04);
}

.story-tile.is-selected {
  box-shadow:
    inset 0 0 0 3px rgba(0, 91, 187, 0.22),
    0 18px 30px rgba(24, 49, 83, 0.14);
}

.story-tile.is-disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.reader-view {
  display: grid;
  gap: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.toolbar {
  justify-content: space-between;
}

.reader-toolbar {
  align-items: start;
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.toolbar-group-wide {
  flex: 1;
  justify-content: flex-end;
}

.control-button,
.toggle-button {
  min-height: 52px;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: var(--radius-lg);
  font: inherit;
}

.toggle-button,
.control-button {
  cursor: pointer;
  color: var(--text);
  background: var(--button);
  box-shadow: inset 0 0 0 2px rgba(24, 49, 83, 0.1);
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.media-button,
.icon-button {
  min-width: 88px;
}

.icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 0.75rem;
  line-height: 1;
}

.toolbar-icon {
  width: 1.4rem;
  height: 1.4rem;
  display: block;
}

.toggle-button:hover,
.control-button:hover,
.toggle-button:focus-visible,
.control-button:focus-visible,
#speed-slider:focus-visible {
  transform: translateY(-1px);
  box-shadow: inset 0 0 0 3px rgba(24, 49, 83, 0.2);
  outline: none;
}

.toggle-button[aria-checked="true"] {
  background: linear-gradient(135deg, #d9efff, #fff4da);
  box-shadow: inset 0 0 0 2px rgba(0, 91, 187, 0.25);
}

.speed-control {
  flex: 0 1 360px;
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(255, 245, 228, 0.9), rgba(223, 241, 255, 0.9));
}

.volume-control {
  position: relative;
}

.volume-panel {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  width: 160px;
  padding: 0.85rem 0.9rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 30px rgba(24, 49, 83, 0.18);
  z-index: 5;
}

.volume-panel input {
  width: 100%;
}

.speed-icon {
  width: 1.6rem;
  height: 1.6rem;
  flex: 0 0 auto;
}

.speed-slider-wrap {
  position: relative;
  flex: 0 1 210px;
  width: 210px;
  padding-bottom: 0.7rem;
}

.speed-ticks {
  position: absolute;
  left: 0.55rem;
  right: 0.55rem;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.speed-ticks span {
  width: 2px;
  height: 9px;
  border-radius: 999px;
  background: rgba(24, 49, 83, 0.42);
}

.story-stage {
  position: relative;
  min-height: 280px;
  padding: 1.35rem 1.35rem 1.35rem 1.35rem;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 251, 255, 0.95));
  box-shadow: inset 0 0 0 1px rgba(24, 49, 83, 0.08);
}

.story-text {
  font-size: clamp(1.7rem, 3vw, 2.5rem);
  line-height: 1.75;
  word-break: break-word;
  padding-right: min(40%, 360px);
  padding-bottom: 2.5rem;
}

.story-text[data-level="1"] {
  font-size: clamp(1.9rem, 3.2vw, 2.8rem);
}

.story-text[data-level="2"] {
  font-size: clamp(1.75rem, 3vw, 2.55rem);
}

.story-text[data-level="3"] {
  font-size: clamp(1.55rem, 2.7vw, 2.2rem);
}

.story-text[data-level="4"] {
  font-size: clamp(1.35rem, 2.3vw, 1.95rem);
}

.story-illustration {
  position: absolute;
  right: 1.25rem;
  bottom: 0.75rem;
  width: min(36%, 320px);
  margin: 0;
  pointer-events: none;
}

.story-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  display: block;
}

.word {
  display: inline-block;
  position: relative;
  margin-right: 0.16em;
  padding: 0.06em 0.12em;
  border-radius: 0.38em;
  transition: background-color 80ms linear, box-shadow 80ms linear, color 80ms linear, opacity 80ms linear;
}

.word.title-word {
  font-weight: 700;
}

.story-text[data-support-mode="frame"] .word.is-active {
  background: var(--highlight);
  box-shadow: 0 0 0 3px var(--highlight-ring);
}

.story-text[data-support-mode="underline"] .word.is-active {
  box-shadow: inset 0 -0.22em 0 0 var(--highlight);
}

.story-text[data-support-mode="dot"] .word.is-active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -0.24em;
  width: 0.34em;
  height: 0.34em;
  border-radius: 50%;
  background: var(--highlight-ring);
  transform: translateX(-50%);
}

.story-text[data-support-mode="none"] .word.is-active {
  box-shadow: none;
  background: transparent;
}

.syllable {
  display: inline-block;
}

.syllable.blue {
  color: var(--blue);
}

.syllable.red {
  color: var(--red);
}

#speed-slider {
  width: 100%;
}

.status-message {
  min-height: 1.5rem;
  margin: 1rem 0 0;
  color: var(--muted);
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 1rem, 100%);
    padding-top: 0.5rem;
  }

  .hero-card {
    padding: 1rem;
    border-radius: 22px;
  }

  .home-hero,
  .library-panel-header,
  .level-tabs,
  .toolbar,
  .speed-control,
  .toolbar-group,
  .toolbar-group-wide {
    align-items: stretch;
  }

  .home-hero,
  .story-grid {
    grid-template-columns: 1fr;
  }

  .toggle-button,
  .control-button,
  .speed-control,
  .volume-control,
  .toolbar-group,
  .toolbar-group-wide {
    width: 100%;
  }

  .speed-slider-wrap {
    flex: 1;
    width: 100%;
  }

  .volume-panel {
    left: 0;
    right: auto;
    width: 100%;
  }

  .story-stage {
    min-height: 220px;
    padding: 1rem;
  }

  .story-illustration {
    position: static;
    width: min(100%, 340px);
    margin: 1rem 0 0 auto;
  }

  .story-text {
    line-height: 1.65;
    padding-right: 0;
    padding-bottom: 0;
  }
}
