:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --panel: #ffffff;
  --ink: #1d2a44;
  --muted: #68758f;
  --accent: #ffb84d;
  --accent-strong: #f08f2e;
  --line: rgba(29, 42, 68, 0.12);
  --shadow: 0 14px 36px rgba(29, 42, 68, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 200, 120, 0.34), transparent 28%),
    radial-gradient(circle at top right, rgba(140, 194, 255, 0.20), transparent 24%),
    var(--bg);
  color: var(--ink);
}

button, select { font: inherit; }
img { display: block; max-width: 100%; }

.app-shell {
  min-height: 100vh;
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
}

.topbar, .panel, .footer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

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

.brand-badge {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #ffe4a5);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #7b3d00;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.brand h1, .panel h2 {
  margin: 0;
  line-height: 1.1;
}

.brand h1 { font-size: clamp(1.5rem, 2.4vw, 2.15rem); }

.status-pill, .chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid rgba(240, 143, 46, 0.18);
  background: rgba(255, 184, 77, 0.14);
  color: #7b4a05;
  padding: 8px 12px;
  font-size: 0.92rem;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.sidebar .panel {
  position: sticky;
  top: 16px;
}

.mobile-select {
  display: none;
  margin-bottom: 12px;
}

.mobile-select label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.mobile-select select {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  background: #fff;
  color: var(--ink);
}

.story-nav {
  display: grid;
  gap: 10px;
}

.story-button {
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 18px;
  padding: 14px 14px;
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.story-button:hover { transform: translateY(-1px); }
.story-button.is-active {
  border-color: rgba(240, 143, 46, 0.52);
  background: rgba(255, 184, 77, 0.16);
}

.story-button .title {
  display: block;
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: 5px;
}

.story-button .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.story-button .locked {
  color: #8b5b00;
  background: rgba(255, 184, 77, 0.18);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 700;
}

.main-column {
  display: grid;
  gap: 16px;
}

.hero-card {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 18px;
  align-items: stretch;
}

.hero-copy {
  display: grid;
  align-content: center;
  gap: 10px;
}

.hero-copy h2 {
  font-size: clamp(2rem, 3vw, 3rem);
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-note {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 1.02rem;
}

.hero-media, .sentence-media, .asset-fallback {
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fbff, #edf2fb);
  overflow: hidden;
}

.hero-media {
  min-height: 260px;
}

.hero-media img, .sentence-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-fallback {
  min-height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 18px;
  text-align: center;
  font-weight: 700;
}

.sentence-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.sentence-speed {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 14px;
}

.sentence-speed-label {
  color: var(--muted);
  font-weight: 800;
}

.sentence-speed-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.speed-button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 11px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.speed-button:hover, .speed-button:focus-visible, .speed-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #6a3300;
}

@media (min-width: 781px) {
  .sentence-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    max-width: min(100%, 760px);
    justify-self: center;
  }
}

.sentence-card {
  border-radius: 20px;
  border: 1px solid var(--line);
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 12px;
}

.sentence-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sentence-badge {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(255, 184, 77, 0.18);
  color: #8c4b00;
  font-weight: 900;
}

.sentence-text {
  margin: 0;
  font-size: 1.03rem;
  line-height: 1.55;
}

.sentence-media {
  min-height: 180px;
}

.media-meta {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-button, .nav-button {
  min-height: 48px;
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 800;
}

.action-button {
  background: var(--accent);
  color: #6a3300;
}

.action-button.secondary {
  background: #eef3fb;
  color: var(--ink);
}

.nav-button {
  background: #f0f4fb;
  color: var(--ink);
}

.word-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.word-chip {
  border: 1px solid rgba(29, 42, 68, 0.12);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fafcff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
}

.word-chip:hover {
  border-color: rgba(240, 143, 46, 0.42);
  background: rgba(255, 184, 77, 0.14);
}

.word-practice {
  margin-top: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}
.word-practice h3 { margin: 0; color: var(--ink); }
.word-practice-hint { margin: 6px 0 14px; color: var(--muted); }
.word-practice-list { display: flex; flex-wrap: wrap; gap: 8px; }
.practice-word {
  border: 1px solid #dbe3ef;
  border-radius: 999px;
  padding: 9px 13px;
  background: #f8fbff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.practice-word:hover, .practice-word.is-playing { background: #ffb647; border-color: #ffb647; color: #38230a; }
.practice-word[disabled] { cursor: not-allowed; opacity: .5; }
.karaoke-text { line-height: 1.8; }
.karaoke-token { transition: background-color .12s ease, color .12s ease; border-radius: 5px; padding: 1px 2px; }
.karaoke-token.is-active, .karaoke-chip.is-active { background: #ffb647; color: #38230a; font-weight: 800; }

.footer {
  padding: 14px 18px;
  color: var(--muted);
  font-size: 0.95rem;
}

.warning, .empty-state {
  border-left: 5px solid #ef7d57;
  background: #fff6f1;
  border-radius: 16px;
  padding: 14px 16px;
  color: #7d4326;
  line-height: 1.55;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar .panel { position: static; }
  .mobile-select { display: block; }
}

@media (max-width: 780px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .hero-card, .sentence-grid { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; }
  .story-nav-controls { width: 100%; display: flex; gap: 8px; }
  .story-nav-controls .nav-button { flex: 1; }
  .story-nav { display: none; }
  .mobile-select { display: block; }
  .sentence-card:last-child:nth-child(odd) {
    grid-column: auto;
    max-width: none;
  }
}

@media (max-width: 420px) {
  .app-shell { padding: 12px; }
  .panel, .topbar, .footer { border-radius: 18px; }
  .hero-copy h2 { font-size: 1.8rem; }
  .story-button, .action-button, .nav-button, .mobile-select select { min-height: 50px; }
  .sentence-text { font-size: 1rem; }
  .word-chip { min-height: 44px; }
}
