:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --surface: #fffdf8;
  --ink: #182a2c;
  --muted: #6e7470;
  --teal: #243c3f;
  --teal-soft: #d9e7e3;
  --red: #d24735;
  --blue: #3d66b8;
  --gold: #d9a441;
  --green: #3f7f63;
  --line: rgba(24, 42, 44, 0.13);
  --shadow: 0 18px 44px rgba(24, 42, 44, 0.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  background: linear-gradient(155deg, #f7f5ef 0%, #edf3f1 46%, #fff8ed 100%);
  color: var(--ink);
}

body.lesson-active {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 12vw, 4.4rem);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.06;
  letter-spacing: 0;
}

h3 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.14;
  letter-spacing: 0;
}

.hero-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-panel p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.35;
}

.primary-button,
.small-button,
.icon-button,
.chip,
.section-tab,
.lesson-card,
.play-button {
  border: 0;
  cursor: pointer;
}

.primary-button {
  min-height: 48px;
  padding: 0 20px;
  border-radius: 999px;
  background: var(--teal);
  color: white;
  font-weight: 800;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--teal);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 1.4rem;
  font-weight: 700;
}

.icon-button.available {
  background: var(--gold);
  color: var(--ink);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.search-row input {
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.86);
  color: var(--ink);
  padding: 0 16px;
  outline: none;
}

.search-row input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(61, 102, 184, 0.14);
}

.small-button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-weight: 800;
}

.small-button.active {
  background: var(--teal);
  color: white;
}

.lesson-screen[hidden] {
  display: none;
}

.chip-row,
.section-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar,
.section-tabs::-webkit-scrollbar {
  display: none;
}

.chip,
.section-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: 38px;
  max-width: 76vw;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.74);
  color: var(--teal);
  font-weight: 800;
  white-space: nowrap;
}

.chip.active,
.section-tab.active {
  background: var(--red);
  color: white;
}

.section-tab.review {
  box-shadow: inset 0 0 0 1px rgba(217, 164, 65, 0.5);
}

.section-tab.review::after {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--gold);
}

.section-tab.review.active::after {
  background: rgba(255, 255, 255, 0.86);
}

.lesson-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.lesson-card {
  display: grid;
  gap: 10px;
  width: 100%;
  min-height: 132px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  color: inherit;
  text-align: left;
  box-shadow: 0 10px 26px rgba(24, 42, 44, 0.08);
}

.lesson-card.audio-review {
  border-color: rgba(217, 164, 65, 0.55);
}

.lesson-card-top {
  display: grid;
  gap: 5px;
}

.lesson-card-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.lesson-meta,
.lesson-stats {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.lesson-audio-review {
  flex: 0 0 auto;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(217, 164, 65, 0.18);
  color: #8a5c00;
  font-size: 0.64rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.sound-strip {
  margin: 0;
  color: var(--blue);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 1rem;
  font-weight: 800;
}

.meter {
  display: block;
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(36, 60, 63, 0.1);
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.empty-state {
  margin: 0;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.lesson-screen {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(155deg, #f7f5ef 0%, #edf3f1 52%, #fff8ed 100%);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}

.lesson-header {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  width: min(100%, 760px);
  margin: 0 auto 10px;
}

.lesson-header .icon-button {
  width: 40px;
  height: 40px;
  font-size: 1.25rem;
}

.lesson-header h2 {
  font-size: clamp(1.24rem, 6vw, 2rem);
  line-height: 1.06;
}

.lesson-screen .section-tabs {
  gap: 6px;
  padding: 2px 0 10px;
  touch-action: pan-x;
}

.lesson-screen .section-tab {
  min-height: 32px;
  max-width: 68vw;
  padding: 0 11px;
  font-size: 0.86rem;
  box-shadow: inset 0 0 0 1px rgba(24, 42, 44, 0.06);
}

.lesson-screen .section-tabs,
.lesson-screen .practice-card {
  width: min(100%, 760px);
  margin-right: auto;
  margin-left: auto;
}

.practice-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 15px 16px calc(86px + env(safe-area-inset-bottom));
  border-radius: 8px;
  background: var(--teal);
  color: white;
  position: relative;
  touch-action: none;
  transition: opacity 180ms ease, transform 180ms ease;
  user-select: none;
  will-change: opacity, transform;
}

.practice-card.audio-review {
  box-shadow: inset 0 0 0 1px rgba(255, 213, 138, 0.42);
}

.practice-card.swipe-out-left {
  opacity: 0;
  transform: translateX(-18%) scale(0.985);
}

.practice-card.swipe-out-right {
  opacity: 0;
  transform: translateX(18%) scale(0.985);
}

.practice-card.swipe-in-left {
  opacity: 0;
  transform: translateX(-14%) scale(0.99);
}

.practice-card.swipe-in-right {
  opacity: 0;
  transform: translateX(14%) scale(0.99);
}

.practice-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.practice-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.audio-review-badge {
  flex: 0 0 auto;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255, 213, 138, 0.16);
  color: #ffd58a;
  font-size: 0.66rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.audio-review-badge[hidden] {
  display: none;
}

.item-count {
  margin: 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.8rem;
  font-weight: 800;
}

.transcription-mode-button {
  min-width: 58px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 213, 138, 0.45);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffd58a;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 900;
}

.practice-text {
  align-self: center;
  margin: 0;
  overflow-wrap: normal;
  word-break: normal;
  font-size: 1.9rem;
  line-height: 1.08;
  font-weight: 850;
}

.practice-text.tiny,
.practice-text.short,
.practice-text.medium {
  white-space: nowrap;
}

.practice-text.tiny {
  font-size: 4.1rem;
  line-height: 0.96;
}

.practice-text.short {
  font-size: 2.8rem;
  line-height: 0.98;
}

.practice-text.medium {
  font-size: 2.35rem;
  line-height: 1;
}

.practice-text.long {
  white-space: normal;
  font-size: 1.9rem;
}

.transcription-lines {
  display: grid;
  gap: 6px;
  align-self: end;
}

.transcription-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 8px;
  row-gap: 2px;
  align-items: baseline;
  margin: 0;
  color: #ffd58a;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(0.98rem, 4.2vw, 1.24rem);
  line-height: 1.25;
}

.transcription-row.paired {
  font-size: clamp(0.9rem, 3.8vw, 1.06rem);
}

.transcription-label {
  min-width: 0;
  color: rgba(255, 255, 255, 0.66);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.72em;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.transcription-value {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.audio-panel {
  position: fixed;
  right: max(calc(30px + env(safe-area-inset-right)), calc((100vw - 760px) / 2 + 30px));
  bottom: calc(30px + env(safe-area-inset-bottom));
  z-index: 20;
  display: block;
  width: auto;
  margin: 0;
}

.audio-panel audio {
  display: none;
}

.play-button {
  display: grid;
  place-items: center;
  background: var(--red);
  color: white;
  font-weight: 900;
  box-shadow: 0 16px 34px rgba(210, 71, 53, 0.34);
}

.play-button.off {
  background: rgba(36, 60, 63, 0.74);
  color: rgba(255, 255, 255, 0.78);
  box-shadow: 0 14px 30px rgba(36, 60, 63, 0.2);
}

.fab-button {
  width: 64px;
  height: 64px;
  padding: 0;
  border-radius: 50%;
}

.play-button-icon {
  display: block;
  width: 0;
  height: 0;
  margin-left: 5px;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-left: 18px solid currentColor;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(94px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 30;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 760px) {
  .lesson-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 759px) {
  .lesson-screen {
    padding-right: 0;
    padding-left: 0;
  }

  .lesson-header {
    padding-right: 14px;
    padding-left: 14px;
  }

  .lesson-screen .section-tabs {
    padding-right: 14px;
    padding-left: 14px;
  }

  .lesson-screen .practice-card {
    width: 100%;
    border-radius: 0;
  }
}

@media (max-width: 420px) {
  .hero-panel {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .practice-card {
    transition: none;
  }
}
