:root {
  color-scheme: light;
  --ink: #000000;
  --muted: #555555;
  --line: #000000;
  font-family: Arial, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: #ffffff;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.level-screen,
.story-screen,
.end-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
  width: min(720px, calc(100% - 40px));
  margin: 0 auto;
  padding: 40px 0;
}

h1 {
  margin: 0;
  font-size: clamp(3rem, 10vw, 6rem);
  line-height: 1;
}

.end-screen h2 {
  margin: 0 0 42px;
  font-size: clamp(3rem, 9vw, 6.5rem);
  line-height: 1.05;
}

.level-screen p,
.story-screen p {
  margin: 20px 0 40px;
  color: var(--muted);
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 700;
}

.level-list {
  display: grid;
  gap: 16px;
}

.level-button {
  display: block;
  text-align: left;
  min-height: 88px;
  padding: 20px 24px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  cursor: pointer;
}

.level-button[data-active="true"] {
  border-width: 4px;
}

.level-button span {
  font-size: clamp(1.5rem, 4vw, 2.3rem);
  font-weight: 800;
}

.screen-back {
  align-self: flex-start;
  margin-top: 24px;
}

.reader {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 24px;
  height: 100vh;
  height: 100svh;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  padding: 28px;
  background: #ffffff;
}

.sentence-card {
  display: grid;
  grid-template-rows: min-content min-content minmax(0, auto);
  align-content: center;
  gap: 24px;
  min-height: 0;
  padding: 0;
  background: #ffffff;
}

.story-title {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-size: clamp(1.2rem, 3vw, 2rem);
  font-weight: 800;
}

.sentence {
  margin: 0;
  text-align: center;
  font-size: clamp(4rem, 12vw, 10rem);
  font-weight: 900;
  line-height: 1.05;
}

.picture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
  align-items: center;
  max-height: 100%;
  width: min(980px, 100%);
  margin: 0 auto;
  overflow: hidden;
}

.picture-tile {
  display: grid;
  place-items: center;
  min-height: 240px;
  margin: 0;
  background: #ffffff;
}

.picture-tile img {
  width: min(260px, 100%);
  height: 220px;
  object-fit: contain;
}

.picture-tile figcaption {
  display: none;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.end-actions {
  display: grid;
  gap: 16px;
}

.primary-action {
  min-height: 64px;
  padding: 0 28px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: #000000;
  background: #ffffff;
  font-size: 1.25rem;
  font-weight: 900;
  cursor: pointer;
}

.text-action {
  min-height: 48px;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.primary-action:focus-visible,
.text-action:focus-visible,
.level-button:focus-visible {
  outline: 4px solid #000000;
  outline-offset: 3px;
}

@media (max-width: 820px) {
  .reader {
    grid-template-rows: minmax(0, 1fr) min-content;
    gap: 12px;
    padding: 12px;
  }

  .sentence-card {
    grid-template-rows: min-content min-content min-content;
    gap: 18px;
  }

  .actions {
    align-items: center;
    gap: 12px;
  }

  .sentence {
    font-size: clamp(2rem, 9.5vw, 3.8rem);
    line-height: 1.08;
    text-wrap: balance;
  }

  .story-title {
    font-size: clamp(1rem, 4vw, 1.35rem);
  }

  .picture-grid {
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
    gap: 8px;
    align-content: center;
  }

  .picture-grid[data-image-count="1"] {
    grid-template-columns: minmax(140px, 1fr);
    max-width: 220px;
  }

  .picture-tile {
    min-height: 0;
    height: clamp(86px, 23svh, 128px);
  }

  .picture-tile img {
    width: 100%;
    max-width: 132px;
    height: 100%;
    max-height: 128px;
  }

  .primary-action {
    min-height: 54px;
    padding: 0 18px;
    font-size: 1.05rem;
  }

  .text-action {
    min-height: 44px;
  }
}

@media (max-width: 420px) and (max-height: 680px) {
  .reader {
    gap: 10px;
    padding: 10px;
  }

  .sentence-card {
    gap: 14px;
  }

  .sentence {
    font-size: clamp(1.8rem, 8.6vw, 3.1rem);
  }

  .picture-tile {
    height: clamp(76px, 21svh, 108px);
  }

  .picture-tile img {
    max-height: 108px;
  }
}
