:root {
  --bg: #f2f2f7;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: #ffffff;
  --ink: #111827;
  --muted: rgba(60, 60, 67, 0.72);
  --line: rgba(60, 60, 67, 0.14);
  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff3b30;
  --teal: #32ade6;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --radius: 20px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 30%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 240px),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100svh;
  margin: 0 auto;
  position: relative;
  background: rgba(242, 242, 247, 0.92);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  min-height: calc(72px + env(safe-area-inset-top));
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  background: rgba(248, 248, 248, 0.86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.12;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  display: inline-grid;
  place-items: center;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
}

.icon-button svg,
.nav-item svg,
.small-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-button {
  opacity: 0;
  pointer-events: none;
}

.back-button.visible {
  opacity: 1;
  pointer-events: auto;
}

.view {
  padding: 18px 16px calc(92px + env(safe-area-inset-bottom));
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 25;
  width: min(100%, 560px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  background: rgba(248, 248, 248, 0.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.nav-item {
  height: 56px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
}

.nav-item svg {
  width: 21px;
  height: 21px;
}

.nav-item.active {
  background: rgba(0, 122, 255, 0.12);
  color: var(--blue);
}

.stack {
  display: grid;
  gap: 18px;
}

.band {
  margin-inline: -16px;
  padding: 18px 16px;
  background: rgba(255, 255, 255, 0.38);
  border-block: 1px solid rgba(31, 39, 35, 0.06);
}

.hero {
  display: grid;
  gap: 14px;
}

.hero h2 {
  margin: 0;
  font-size: clamp(30px, 8vw, 38px);
  line-height: 1.05;
  letter-spacing: 0;
}

.hero p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.compact-hero {
  gap: 10px;
}

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

.section-title h2,
.section-title h3 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0;
}

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

.metric {
  min-height: 122px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.metric .small-icon {
  margin-bottom: 12px;
}

.metric strong {
  display: block;
  font-size: 23px;
  line-height: 1;
}

.metric span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.small-icon {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  color: var(--blue);
  background: rgba(0, 122, 255, 0.12);
}

.small-icon.green {
  color: var(--green);
  background: rgba(52, 199, 89, 0.14);
}

.small-icon.orange {
  color: var(--orange);
  background: rgba(255, 159, 10, 0.14);
}

.small-icon.teal {
  color: var(--teal);
  background: rgba(50, 173, 230, 0.14);
}

.card,
.lesson-row,
.word-row,
.dialogue-line {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.card {
  padding: 16px;
}

.lesson-row,
.word-row,
.dialogue-line {
  padding: 14px;
}

.card-button,
.topic-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  padding: 15px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.card-button,
.topic-card,
.lesson-row {
  display: block;
  color: inherit;
  text-decoration: none;
}

.topic-card + .topic-card,
.lesson-row + .lesson-row,
.word-row + .word-row,
.dialogue-line + .dialogue-line {
  margin-top: 10px;
}

.topic-card h3,
.card h3,
.lesson-row h3,
.word-row h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.topic-card p,
.lesson-row p,
.word-row p,
.card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

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

.row.start {
  align-items: flex-start;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(120, 120, 128, 0.12);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.chip.blue {
  background: rgba(0, 122, 255, 0.12);
  color: var(--blue);
}

.chip.green {
  background: rgba(52, 199, 89, 0.14);
  color: var(--green);
}

.chip.orange {
  background: rgba(255, 159, 10, 0.14);
  color: var(--orange);
}

.chip.red {
  background: rgba(255, 59, 48, 0.14);
  color: var(--red);
}

.progress {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(120, 120, 128, 0.14);
  margin-top: 12px;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0a84ff, #5ac8fa);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 48px;
  border-radius: 15px;
  border: 1px solid transparent;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}

.primary-button svg,
.secondary-button svg,
.ghost-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  opacity: 0.45;
}

.primary-button {
  background: linear-gradient(180deg, #1590ff, #007aff);
  color: #fff;
  box-shadow: 0 14px 28px rgba(0, 122, 255, 0.2);
}

.secondary-button {
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button {
  min-height: 38px;
  background: transparent;
  color: var(--blue);
  padding: 0 8px;
}

.primary-button.full,
.secondary-button.full {
  width: 100%;
}

.button-row > :last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: rgba(118, 118, 128, 0.12);
  overflow-x: auto;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  min-height: 38px;
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.segmented button.active {
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
}

.dialogue-line .role {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.dialogue-line .english {
  margin-top: 8px;
  font-weight: 800;
  line-height: 1.4;
}

.dialogue-line .translation {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.sentence-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.sentence-card .target {
  font-size: 24px;
  line-height: 1.22;
  font-weight: 900;
  letter-spacing: 0;
}

.transcript-box,
.text-input {
  width: 100%;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 12px;
  background: rgba(248, 248, 248, 0.95);
  resize: vertical;
  color: var(--ink);
  line-height: 1.45;
}

.transcript-box:focus,
.text-input:focus {
  outline: 3px solid rgba(45, 108, 223, 0.18);
  border-color: rgba(45, 108, 223, 0.48);
}

.score-ring {
  --score: 0;
  width: 118px;
  height: 118px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.98) 0 55%, transparent 56%),
    conic-gradient(var(--green) calc(var(--score) * 1%), rgba(120, 120, 128, 0.14) 0);
}

.score-ring strong {
  font-size: 30px;
  line-height: 1;
}

.score-ring span {
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.score-list {
  display: grid;
  gap: 8px;
}

.score-item {
  display: grid;
  grid-template-columns: 74px 1fr 34px;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
}

.score-item .progress {
  margin: 0;
  height: 7px;
}

.empty {
  text-align: center;
  padding: 34px 20px;
  color: var(--muted);
}

.empty h3 {
  margin: 0 0 8px;
  color: var(--ink);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  background: rgba(31, 39, 35, 0.32);
}

.sheet[hidden] {
  display: none;
}

.sheet-panel {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 -24px 60px rgba(31, 39, 35, 0.18);
}

.sheet-panel h2 {
  margin: 12px 0 8px;
  font-size: 22px;
}

.sheet-panel p,
.sheet-panel li {
  color: var(--muted);
  line-height: 1.55;
}

.sheet-panel ol {
  padding-left: 20px;
}

.sheet-grip {
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: rgba(31, 39, 35, 0.18);
  margin: 0 auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 60;
  transform: translateX(-50%);
  width: min(calc(100% - 32px), 520px);
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(31, 39, 35, 0.94);
  color: #fff;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.select-input {
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 0 14px;
  background: rgba(248, 248, 248, 0.95);
  color: var(--ink);
}

.helper-text {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.helper-text code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(120, 120, 128, 0.12);
  color: var(--ink);
}

.content-editor {
  min-height: 360px;
  margin-top: 12px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}

@media (min-width: 700px) {
  body {
    background: #eef1f8;
  }

  .app-shell {
    box-shadow: 0 0 0 1px var(--line), 0 30px 80px rgba(31, 39, 35, 0.12);
  }
}

@media (max-width: 360px) {
  .grid-2,
  .button-row {
    grid-template-columns: 1fr;
  }

  .sentence-card .target {
    font-size: 21px;
  }
}
