:root {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background: #f8f8ff;
  color: #222640;
  font-size: 14px;
  --p: #6254d9;
  --t: #27304b;
  --muted: #737991;
  --line: #e8eaf4;
  --bg: #f8f8ff;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: #f8f8ff;
}

button, input, textarea {
  font: inherit;
  max-width: 100%;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: .48;
  cursor: not-allowed;
}

.app-shell {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: #f8f8ff;
  overflow-x: hidden;
  position: relative;
}

#root {
  width: 100%;
  max-width: 100%;
  padding: 16px 15px calc(96px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
}

.tabs {
  min-height: 68px;
  height: calc(68px + env(safe-area-inset-bottom, 0px));
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 760px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: rgba(255, 255, 255, .98);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 -8px 28px #20224a0d;
  border-top: 1px solid var(--line);
  padding: 4px 4px env(safe-area-inset-bottom, 4px);
  z-index: 20;
}

.tabs button {
  background: transparent;
  border: 0;
  color: #8489a0;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px 2px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs button span {
  font-size: 20px;
  line-height: 20px;
}

.tabs button.active {
  color: var(--p);
}

h1, h2, h3, p {
  margin-top: 0;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

h1 {
  font-size: clamp(20px, 5.5vw, 24px);
  line-height: 1.22;
  letter-spacing: -.5px;
  margin-bottom: 8px;
}

h2 {
  font-size: clamp(16px, 4.5vw, 18px);
  line-height: 1.35;
  letter-spacing: -.25px;
  margin-bottom: 11px;
}

h3 {
  font-size: 15px;
  line-height: 1.35;
  margin-bottom: 8px;
}

p {
  line-height: 1.6;
  margin-bottom: 12px;
}

.muted { color: var(--muted); }
.small { font-size: 12px; color: var(--muted); }
.tiny { font-size: 11px; color: var(--muted); }

.eyebrow {
  text-transform: uppercase;
  color: var(--p);
  letter-spacing: .08em;
  font-size: 10px;
  font-weight: 800;
  display: block;
  overflow-wrap: anywhere;
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 13px;
  box-shadow: 0 5px 16px #35327808;
  width: 100%;
  max-width: 100%;
}

.hero {
  border: 0;
  background: linear-gradient(130deg, #ebe6ff, #f5f2ff 70%, #fff1e8);
  position: relative;
  overflow: hidden;
  padding: 20px 16px;
  min-height: 164px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hero .copy {
  max-width: 65%;
  position: relative;
  z-index: 2;
}

.hero img {
  position: absolute;
  right: -8px;
  bottom: 4px;
  width: 42%;
  max-width: 160px;
  height: auto;
  object-fit: contain;
  pointer-events: none;
}

.hero h1 {
  font-size: clamp(19px, 5vw, 23px);
}

.primary, .secondary, .quiet {
  padding: 11px 14px;
  border-radius: 12px;
  border: 0;
  font-weight: 700;
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.3;
}

.primary { background: var(--p); color: #fff; }
.secondary { background: #eeecff; color: #5145c2; }
.quiet { background: #f5f6fb; color: #535c7a; }
.full { width: 100%; display: flex; }

.grid2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.tile {
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 14px;
  text-align: left;
  background: #fff;
  min-height: 92px;
  min-width: 0;
  width: 100%;
}

.tile .emoji {
  display: block;
  font-size: 22px;
  margin-bottom: 9px;
}

.tile strong {
  font-size: 13px;
  display: block;
}

.tile small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: 22px 0 12px;
  flex-wrap: wrap;
}

.section-head h2 { margin: 0; }

.pill {
  font-size: 11px;
  border-radius: 20px;
  background: #eeecff;
  color: #5949c3;
  padding: 5px 9px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.progress-line {
  height: 7px;
  background: #eeeff7;
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
}

.progress-line > span {
  height: 100%;
  background: linear-gradient(90deg, #7874ed, #55bacc);
  border-radius: 8px;
  display: block;
}

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

.topline > div {
  min-width: 0;
  flex: 1;
}

.back {
  font-size: 13px;
  color: #5145c2;
  border: 0;
  background: #eeecff;
  border-radius: 10px;
  padding: 9px 12px;
  white-space: nowrap;
}

.lessonline {
  display: flex;
  gap: 6px;
  margin-bottom: 15px;
  width: 100%;
}

.lessonline span {
  height: 5px;
  flex: 1;
  background: #e9eaf4;
  border-radius: 6px;
}

.lessonline span.done {
  background: var(--p);
}

.label {
  font-size: 12px;
  color: #5f647d;
  font-weight: 700;
  margin: 15px 0 7px;
  display: block;
}

.input, .writing-box {
  width: 100%;
  max-width: 100%;
  border: 1px solid #dadeed;
  border-radius: 13px;
  background: #fff;
  padding: 13px 14px;
  color: var(--t);
  outline: 0;
  line-height: 1.6;
  font-size: 16px; /* Prevents auto-zoom on iOS & Android */
}

.input:focus, .writing-box:focus {
  border-color: var(--p);
  box-shadow: 0 0 0 3px #6254d91b;
}

.writing-box {
  min-height: 160px;
  resize: vertical;
}

.hint {
  background: #fff8e8;
  border: 1px solid #ffedca;
  border-radius: 12px;
  padding: 12px 13px;
  font-size: 12px;
  color: #785629;
  margin: 13px 0;
  overflow-wrap: break-word;
}

.tip {
  background: #f0eeff;
  border-radius: 13px;
  padding: 12px 13px;
  color: #544c88;
  font-size: 12px;
  line-height: 1.6;
  margin-top: 13px;
  overflow-wrap: break-word;
}

.example {
  border-radius: 12px;
  border: 1px solid #e8e8f8;
  padding: 13px;
  margin: 9px 0;
  background: #fbfbff;
  line-height: 1.6;
  overflow-wrap: break-word;
}

.example strong {
  display: block;
  margin-bottom: 4px;
  color: var(--t);
}

.example .translation {
  display: block;
  color: #71768b;
  font-size: 12px;
  margin-top: 6px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  max-width: 100%;
}

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

.lesson-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 13px 12px;
  margin-bottom: 8px;
  min-width: 0;
}

.bubble {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #eeebff;
  color: var(--p);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-weight: 800;
}

.lesson-entry small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
  font-size: 11px;
}

.stage-card {
  margin: 0 0 12px;
  border-radius: 17px;
  border: 1px solid var(--line);
  background: white;
  padding: 15px;
  width: 100%;
}

.stage-card.open {
  border-color: #ada6f6;
}

.mini {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.55;
}

.speak {
  border: 0;
  background: #e8efff;
  color: #435bd0;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 12px;
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.wordrow {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fbfbff;
  border: 1px solid #eaeaf7;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.wordrow b {
  font-size: 15px;
  color: #5246cc;
  min-width: 64px;
}

.wordrow .desc {
  flex: 1;
  min-width: 120px;
  font-size: 12px;
}

.wordrow small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.answer-options {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  margin: 10px 0;
}

.option {
  background: #f3f1ff;
  color: #5548be;
  border: 1px solid #e7e3ff;
  padding: 10px 16px;
  border-radius: 11px;
}

.option.sel {
  background: #6254d9;
  color: white;
}

.review-card {
  border-left: 4px solid #ff797f;
  background: #fff2f2;
  padding: 13px;
  border-radius: 10px;
  margin-bottom: 10px;
  overflow-wrap: break-word;
}

.good-card {
  border-left: 4px solid #35b882;
  background: #ecfcf4;
  padding: 13px;
  border-radius: 10px;
  margin-bottom: 10px;
  overflow-wrap: break-word;
}

.review-card p, .good-card p {
  white-space: pre-wrap;
  margin: 0;
  overflow-wrap: anywhere;
}

.review-card small, .good-card small {
  display: block;
  margin-bottom: 5px;
  font-weight: 700;
}

.compare {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  width: 100%;
}

.compare > div {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.65;
  border-radius: 12px;
  padding: 12px;
}

.compare > div:first-child { background: #fff0f1; }
.compare > div:last-child { background: #edf9f3; }

.score {
  font-size: 29px;
  font-weight: 800;
  color: var(--p);
}

.ai-list {
  padding-left: 18px;
  line-height: 1.6;
  color: #49516c;
  font-size: 12px;
  overflow-wrap: break-word;
}

.ai-list li {
  margin-bottom: 8px;
}

.badge-line {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  flex-wrap: wrap;
}

.complete {
  text-align: center;
  padding: 24px 12px;
}

.complete .medal {
  font-size: 56px;
  margin: 0 0 14px;
}

.fixed-next {
  position: sticky;
  bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  background: linear-gradient(transparent, #f8f8ff 22%);
  padding-top: 14px;
}

.statgrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.stat {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 13px;
  min-width: 0;
}

.stat strong {
  font-size: 20px;
  color: #5b51cd;
  display: block;
}

.stat small {
  display: block;
  font-size: 11px;
  color: #7e8399;
  margin-top: 3px;
}

.subnav {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  max-width: 100%;
  padding: 3px 0 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.subnav::-webkit-scrollbar {
  display: none;
}

.subnav button {
  white-space: nowrap;
  padding: 8px 12px;
  border: 1px solid #e4e4f4;
  border-radius: 20px;
  color: #747991;
  background: white;
  font-size: 11px;
  flex-shrink: 0;
}

.subnav button.active {
  color: white;
  background: var(--p);
  border-color: var(--p);
}

.verb {
  border-radius: 15px;
  padding: 14px;
  margin-bottom: 11px;
}

.verb h3 { font-size: 19px; }

.status {
  font-size: 12px;
  color: #7a5260;
  line-height: 1.6;
  min-height: 18px;
}

.toast {
  background: #f1efff;
  color: #5348bc;
  border-radius: 10px;
  padding: 11px;
  margin: 10px 0;
}

.mascot-note {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f3f0ff;
  border-radius: 14px;
  padding: 10px 12px;
  margin: 14px 0;
}

.mascot-note img {
  width: 64px;
  height: 50px;
  object-fit: contain;
  flex-shrink: 0;
}

.mascot-note p {
  margin: 0;
  font-size: 12px;
  color: #554a90;
}

.settings { margin: 12px 0; }
.spacer { height: 16px; }

/* English Writing Lab 3.2 — native-feeling searchable writing library */
.library-mode {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  background: #ebeafb;
  padding: 5px;
  border-radius: 14px;
  margin: 14px 0 6px;
  width: 100%;
}

.library-mode button {
  border: 0;
  border-radius: 11px;
  padding: 11px 6px;
  color: #6b6c87;
  background: transparent;
  font-weight: 750;
  font-size: 12px;
  min-width: 0;
}

.library-mode button.active {
  background: #fff;
  color: #5b4ccc;
  box-shadow: 0 3px 10px #29226b12;
}

.library-categories {
  margin: 12px 0 8px;
}

.lib-card {
  background: #fff;
  border: 1px solid #e8e8f3;
  border-radius: 17px;
  padding: 15px;
  margin-bottom: 13px;
  box-shadow: 0 3px 14px #33326308;
  width: 100%;
}

.topic-chip {
  font-size: 10px;
  color: #6253c6;
  font-weight: 750;
  border-radius: 8px;
  padding: 6px 9px;
  background: #f0eeff;
}

.bookmark {
  border: 0;
  background: #f4f4fa;
  color: #9294ab;
  border-radius: 10px;
  padding: 5px 11px;
  font-size: 20px;
  line-height: 22px;
}

.bookmark.saved {
  color: #d5951f;
  background: #fff5d9;
}

.lib-word {
  font-size: 17px;
  margin: 0 0 3px;
  color: #292444;
}

.lib-meaning {
  font-size: 12px;
  color: #72768d;
  margin: 0;
  line-height: 1.5;
}

.lib-example {
  border-radius: 12px;
  background: #f5f7fc;
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
  color: #343a59;
  overflow-wrap: anywhere;
}

.lib-example .speak {
  margin: 7px 0 0;
  display: inline-block;
  font-size: 11px;
}

.ladder-row {
  border-radius: 11px;
  background: #f4f5f9;
  padding: 11px 12px;
  margin: 9px 0;
  line-height: 1.55;
  overflow-wrap: break-word;
}

.ladder-row.natural { background: #eef4ff; }
.ladder-row.professional { background: #eaf8f2; }

.ladder-row p {
  font-size: 13px;
  color: #2d344e;
  margin: 5px 0 8px;
}

.ladder-row .speak {
  font-size: 11px;
  padding: 5px 8px;
}

.ladder-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .035em;
  color: #6c6f8a;
}

.natural .ladder-label { color: #4368ac; }
.professional .ladder-label { color: #268467; }

.random-highlight {
  border-color: #6d5de1;
  box-shadow: 0 0 0 3px #6655dd20;
}

/* Mobile Responsive Adjustments */
@media (max-width: 520px) {
  #root {
    padding: 14px 13px calc(92px + env(safe-area-inset-bottom, 0px));
  }
  .card, .stage-card, .lib-card {
    padding: 14px;
    border-radius: 15px;
  }
  .hero {
    padding: 18px 15px;
    min-height: 150px;
  }
  .hero .copy {
    max-width: 68%;
  }
  .hero img {
    width: 36%;
    right: -4px;
    bottom: 4px;
  }
  .compare {
    grid-template-columns: 1fr;
  }
  .row > .primary, .row > .secondary {
    flex: 1 1 auto;
  }
}

@media (max-width: 380px) {
  .grid2, .statgrid {
    grid-template-columns: 1fr;
  }
  .hero .copy {
    max-width: 72%;
  }
  .hero img {
    width: 30%;
  }
  .tabs button {
    font-size: 9.5px;
  }
  .tabs button span {
    font-size: 18px;
  }
  .lib-card {
    padding: 12px;
  }
  .library-mode button {
    font-size: 11px;
  }
  .lib-example {
    font-size: 12px;
  }
}

@media (min-width: 630px) {
  .app-shell {
    box-shadow: 0 0 40px #24274c12;
  }
  #root {
    padding: 25px 28px 115px;
  }
  .hero img {
    width: 35%;
    max-width: 210px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
