:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #5f6b82;
  --line: #dfe5ef;
  --page: #eef3f7;
  --panel: #ffffff;
  --blue: #1f5fbf;
  --blue-weak: #dbeafe;
  --green: #14735a;
  --green-weak: #ddf4ea;
  --amber: #9b5c00;
  --amber-weak: #fff3d6;
  --teal-weak: #dff4f1;
  --surface-soft: #f8fbfd;
  --rose: #ca3b58;
  --shadow: 0 18px 45px rgba(28, 40, 67, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top left, rgba(223, 244, 241, 0.8), transparent 34rem),
    linear-gradient(180deg, #f8fbfd 0%, var(--page) 46%, #f4f7f9 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 3vw, 36px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #0f766e;
  color: white;
  font-weight: 900;
}

.nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.nav button,
.ghost-button,
.primary-button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  background: transparent;
  color: var(--ink);
  white-space: nowrap;
}

.nav button.active {
  background: var(--blue-weak);
  color: #1742a5;
}

.primary-button {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
  font-weight: 750;
}

.ghost-button {
  border-color: var(--line);
  background: white;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  padding: 0;
  border-color: var(--line);
  background: white;
}

.main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 28px clamp(14px, 3vw, 32px) 48px;
}

.hero-band {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 28px;
  align-items: stretch;
  margin-bottom: 22px;
  padding: clamp(20px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, #e4f3f1 0%, #f7fbfd 48%, #eef4fb 100%);
}

.hero-band h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 4.5vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.hero-band p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
  line-height: 1.6;
}

.hero-art {
  display: grid;
  min-height: 230px;
  place-items: center;
}

.reader-illustration {
  position: relative;
  width: min(360px, 100%);
  aspect-ratio: 1.2;
}

.book {
  position: absolute;
  inset: 21% 7% 9%;
  border-radius: 16px 16px 22px 22px;
  background: #ffffff;
  border: 3px solid #1f2a44;
  box-shadow: 0 14px 0 #bfdedc;
}

.book::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  background: #1f2a44;
}

.book-line {
  position: absolute;
  left: 12%;
  right: 56%;
  height: 7px;
  border-radius: 99px;
  background: #9bb4cc;
}

.book-line:nth-child(1) { top: 24%; }
.book-line:nth-child(2) { top: 39%; width: 30%; }
.book-line:nth-child(3) { top: 55%; }
.book-line:nth-child(4) { top: 24%; left: 58%; right: 12%; }
.book-line:nth-child(5) { top: 39%; left: 58%; right: 20%; }
.book-line:nth-child(6) { top: 55%; left: 58%; right: 12%; }

.chunk-bubble {
  position: absolute;
  top: 0;
  right: 5%;
  display: grid;
  width: 124px;
  height: 82px;
  place-items: center;
  border: 3px solid #1f2a44;
  border-radius: 18px;
  background: #ecf8f6;
  color: #184b45;
  font-weight: 900;
  transform: rotate(5deg);
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 18px;
  align-items: start;
}

.panel,
.passage-card,
.stat-card,
.setup-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(23, 32, 51, 0.03);
}

.panel {
  padding: clamp(16px, 2vw, 24px);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-title h2,
.panel h2,
.setup-card h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.4vw, 1.9rem);
  letter-spacing: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.9rem;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
}

.field textarea {
  min-height: 150px;
  padding: 12px;
  line-height: 1.5;
  resize: vertical;
}

.field input[type="range"] {
  padding: 0;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  align-self: end;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-weight: 750;
}

.toggle-field input {
  width: 18px;
  height: 18px;
}

.reader-stage {
  min-height: 260px;
  padding: clamp(18px, 4vw, 34px);
  border-radius: 8px;
  background: #fbf8ef;
  border: 1px solid #eadfca;
  font-size: clamp(1.25rem, 2.8vw, 2rem);
  line-height: 1.85;
}

.reader-stage.small-font {
  font-size: clamp(1rem, 2.2vw, 1.45rem);
}

.reader-stage.large-font {
  font-size: clamp(1.55rem, 3.4vw, 2.6rem);
}

.reader-stage.cool-theme {
  background: #eef8f7;
  border-color: #c7e3df;
}

.reader-stage.sepia-theme {
  background: #f7ecd8;
  border-color: #e3ccb0;
}

.reader-stage.dark-theme {
  background: #172033;
  border-color: #2e3a52;
  color: #f7fbfd;
}

.focus-stage {
  display: grid;
  place-items: center;
  text-align: center;
  background: #eef8f7;
  border-color: #c7e3df;
}

.focus-label {
  align-self: end;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
}

.focus-chunk {
  align-self: start;
  max-width: 760px;
  padding: 16px 18px;
  border-radius: 8px;
  background: white;
  color: #102044;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.14);
  font-size: clamp(2rem, 5vw, 4.4rem);
  font-weight: 900;
  line-height: 1.12;
}

.focus-stage.small-font .focus-chunk {
  font-size: clamp(1.5rem, 4vw, 3rem);
}

.focus-stage.large-font .focus-chunk {
  font-size: clamp(2.4rem, 6vw, 5.4rem);
}

.focus-stage.dark-theme .focus-chunk {
  background: #222d44;
  color: #f7fbfd;
}

.focus-stage.sepia-theme .focus-chunk {
  background: #fff8eb;
}

.orp {
  color: var(--rose);
}

.word {
  display: inline;
  padding: 3px 4px;
  border-radius: 6px;
  transition: background 180ms ease, color 180ms ease;
}

.word.active {
  background: #ffe08a;
  color: #1b2538;
  box-shadow: 0 0 0 2px rgba(185, 106, 0, 0.14);
}

.session-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.passage-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.custom-import {
  display: grid;
  gap: 14px;
  margin: 4px 0 20px;
  padding: 16px;
  border: 1px solid #cbd8e6;
  border-radius: 8px;
  background: var(--surface-soft);
}

.custom-import h3 {
  margin: 0 0 5px;
}

.custom-grid {
  display: grid;
  grid-template-columns: 1fr 190px 220px;
  gap: 12px;
}

.url-import-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.baseline-reader {
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8ef;
  font-size: clamp(1.1rem, 2.2vw, 1.45rem);
  line-height: 1.75;
}

.baseline-reader h3 {
  margin: 0 0 12px;
}

.baseline-reader p {
  margin: 0;
}

.active-baseline {
  border-color: #9acdc5;
  box-shadow: 0 0 0 4px rgba(20, 115, 90, 0.12);
}

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

.vocab-chip {
  min-height: 34px;
  padding: 0 10px;
  text-transform: capitalize;
}

.vocab-chip:disabled {
  cursor: default;
  opacity: 0.62;
}

.saved-vocab {
  margin-top: 16px;
  box-shadow: none;
}

.passage-card {
  padding: 14px;
}

.passage-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.tag {
  border-radius: 999px;
  padding: 4px 9px;
  background: #edf2fb;
  color: #31456c;
  font-size: 0.78rem;
  font-weight: 800;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 15px;
}

.stat-card strong {
  display: block;
  margin-top: 5px;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
}

.chart {
  width: 100%;
  min-height: 260px;
}

.quiz-options {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.quiz-options button {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  text-align: left;
  padding: 10px 12px;
}

.quiz-options button.selected {
  border-color: var(--blue);
  background: var(--blue-weak);
}

.reward {
  margin-top: 14px;
  padding: 14px;
  border-radius: 8px;
  background: var(--green-weak);
  color: #0d513b;
  font-weight: 800;
}

.level-up {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  align-items: center;
  margin: 12px 0 16px;
  padding: 14px;
  border: 1px solid #bfe8d8;
  border-radius: 8px;
  background: var(--green-weak);
  color: #0d513b;
}

.level-up span {
  color: #22634d;
}

.level-up button {
  grid-row: 1 / span 2;
  grid-column: 2;
}

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

.badge {
  border-radius: 8px;
  padding: 9px 10px;
  background: #eef6ff;
  border: 1px solid #cfe5ff;
  color: #163c76;
  font-weight: 800;
}

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

.techniques-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}

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

.technique-card {
  min-height: 210px;
  padding: 18px;
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 8px;
  background: #ffffff;
}

.technique-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.technique-title span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
}

.technique-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.technique-card p {
  color: var(--muted);
  line-height: 1.55;
}

.technique-ideal {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  line-height: 1.45;
}

.red-accent {
  border-left-color: #d65555;
}

.blue-accent {
  border-left-color: var(--blue);
}

.green-accent {
  border-left-color: var(--green);
}

.amber-accent {
  border-left-color: var(--amber);
}

.purple-accent {
  border-left-color: #7c5cc4;
}

.mind-map-panel {
  display: grid;
  gap: 16px;
  padding: clamp(16px, 2vw, 22px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.mind-map-panel h3 {
  margin: 0 0 5px;
}

.flowchart-wrap {
  overflow-x: visible;
  padding: clamp(14px, 2vw, 22px);
  border: 1px solid #d5e0eb;
  border-radius: 8px;
  background: #ffffff;
}

.clear-flowchart {
  display: grid;
  gap: 22px;
}

.flow-row {
  display: grid;
  grid-template-columns: minmax(145px, 1fr) 54px minmax(145px, 1fr) 54px minmax(155px, 1fr) 54px minmax(145px, 0.9fr);
  gap: 8px;
  align-items: center;
}

.flow-card,
.flow-result {
  display: grid;
  gap: 8px;
  min-height: 128px;
  padding: 16px;
  border: 2px solid #b8c7d8;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(28, 40, 67, 0.06);
}

.flow-card strong,
.flow-result strong,
.flow-diamond strong {
  color: var(--ink);
  font-size: clamp(1rem, 1.4vw, 1.2rem);
}

.flow-card p,
.flow-result p,
.flow-diamond span {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.flow-step {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-weak);
  color: #1742a5;
  font-weight: 900;
}

.source-card {
  background: #ecf8f6;
  border-color: #7bbdb4;
}

.image-card,
.create-card {
  background: #fff8eb;
  border-color: var(--amber);
}

.attach-card,
.flow-result {
  background: #f3fbf8;
  border-color: var(--green);
}

.flow-connector {
  position: relative;
  color: #1742a5;
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.flow-connector::before {
  content: "";
  position: absolute;
  top: -12px;
  right: 0;
  left: 0;
  height: 3px;
  background: #49647f;
}

.flow-connector::after {
  content: "";
  position: absolute;
  top: -18px;
  right: -1px;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 11px solid #49647f;
}

.flow-diamond {
  display: grid;
  width: 150px;
  height: 150px;
  place-items: center;
  justify-self: center;
  padding: 24px;
  border: 2px solid #7c5cc4;
  background: #f4efff;
  text-align: center;
  transform: rotate(45deg);
}

.flow-diamond strong,
.flow-diamond span {
  display: block;
  transform: rotate(-45deg);
}

.branch-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  max-width: 760px;
  margin-left: auto;
}

.branch-path {
  display: grid;
  gap: 8px;
}

.branch-label {
  width: fit-content;
  padding: 5px 11px;
  border-radius: 999px;
  color: white;
  font-size: 0.85rem;
  font-weight: 900;
}

.yes-path .branch-label {
  background: var(--green);
}

.no-path .branch-label {
  background: var(--amber);
}

.flow-result {
  max-width: 560px;
  min-height: 0;
  margin: 0 auto;
  text-align: center;
}

.example-box {
  display: grid;
  gap: 6px;
  padding: 14px;
  border-left: 5px solid var(--green);
  border-radius: 8px;
  background: white;
  line-height: 1.55;
}

.example-box span {
  color: var(--muted);
}

.tutorial-step {
  min-height: 260px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.tutorial-step h3 {
  margin: 12px 0 8px;
  font-size: 1.15rem;
}

.tutorial-step p {
  color: var(--muted);
  line-height: 1.55;
}

.step-number {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-weak);
  color: #1742a5;
  font-weight: 900;
}

.phrase-demo {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.phrase-demo span {
  width: fit-content;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--amber-weak);
  color: #5f3700;
  font-weight: 900;
}

.meter-demo {
  height: 16px;
  margin-top: 28px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6edf8;
}

.meter-demo span {
  display: block;
  width: 68%;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.score-demo {
  display: grid;
  width: 110px;
  height: 110px;
  margin-top: 18px;
  place-items: center;
  border-radius: 50%;
  background: var(--green-weak);
  color: var(--green);
  font-size: 1.7rem;
  font-weight: 900;
}

.setup-overlay {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
  background: linear-gradient(135deg, #e4f3f1 0%, #f8fbfd 52%, #eef4fb 100%);
}

.setup-card {
  width: min(560px, 100%);
  padding: clamp(20px, 4vw, 34px);
  box-shadow: var(--shadow);
}

.setup-card form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.empty {
  padding: 22px;
  border: 1px dashed #b8c2d4;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero-band,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .controls,
  .stats-grid,
  .tutorial-grid,
  .technique-grid,
  .custom-grid,
  .url-import-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .level-up {
    grid-template-columns: 1fr;
  }

  .flow-row,
  .branch-row {
    grid-template-columns: 1fr;
  }

  .flow-connector {
    min-height: 34px;
  }

  .flow-connector::before {
    top: 0;
    bottom: 0;
    left: 50%;
    width: 3px;
    height: auto;
    transform: translateX(-50%);
  }

  .flow-connector::after {
    top: auto;
    right: auto;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    border-top: 11px solid #49647f;
    border-right: 8px solid transparent;
    border-left: 8px solid transparent;
    border-bottom: 0;
  }

  .flow-diamond {
    width: 170px;
    height: 170px;
  }

  .branch-row {
    max-width: none;
    margin-left: 0;
  }

  .level-up button {
    grid-column: auto;
    grid-row: auto;
    width: fit-content;
  }
}

@media (max-width: 560px) {
  .controls,
  .stats-grid,
  .tutorial-grid,
  .technique-grid,
  .custom-grid,
  .url-import-row {
    grid-template-columns: 1fr;
  }

  .reader-stage {
    min-height: 220px;
  }

  .nav {
    width: 100%;
  }
}
