:root {
  color-scheme: light;
  --paper: #f7f6f1;
  --surface: #ffffff;
  --ink: #202322;
  --muted: #666d69;
  --line: #d8dcd8;
  --teal: #087f79;
  --teal-soft: #e5f3f1;
  --coral: #e85d4a;
  --coral-soft: #fff0ec;
  --focus: #1067a6;
  --shadow: 0 12px 30px rgba(32, 35, 34, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

button, select { font: inherit; }
button { color: inherit; }

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 38%, transparent);
  outline-offset: 3px;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 76px;
  padding: 11px clamp(18px, 3vw, 44px);
  display: grid;
  grid-template-columns: minmax(190px, auto) minmax(240px, 520px) auto;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 246, 241, 0.96);
  backdrop-filter: blur(12px);
}

.global-search {
  position: relative;
  min-width: 0;
}

.global-search > label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.search-field {
  height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.search-field:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.search-field input {
  min-width: 0;
  padding: 0 4px 0 13px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
}

.search-field input::-webkit-search-cancel-button { display: none; }

.clear-search {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
}

.clear-search:hover { color: var(--coral); }

.search-results {
  position: absolute;
  z-index: 40;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  max-height: min(460px, 70vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(32, 35, 34, 0.18);
}

.search-result {
  width: 100%;
  min-height: 62px;
  padding: 10px 13px;
  display: grid;
  grid-template-columns: minmax(90px, 0.7fr) minmax(0, 1.5fr);
  align-items: center;
  gap: 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.search-result:last-child { border-bottom: 0; }
.search-result:hover,
.search-result.is-active { background: var(--teal-soft); }

.search-result-word {
  overflow-wrap: anywhere;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
}

.search-result-context {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.search-result-context strong {
  color: var(--coral);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}

.search-result-context span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-empty {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
}

.brand-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.brand-copy strong {
  font-size: 16px;
  letter-spacing: 0;
}

.brand-copy span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.audio-toolbar,
.segmented,
.speed-control {
  display: flex;
  align-items: center;
}

.audio-toolbar {
  justify-content: flex-end;
  gap: 12px;
}

.segmented {
  height: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.segment {
  height: 30px;
  min-width: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
}

.segment.is-selected {
  background: var(--ink);
  color: #fff;
}

.speed-control {
  height: 38px;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.speed-control select {
  height: 36px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--coral);
  cursor: pointer;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--coral);
  background: var(--coral-soft);
}

.app-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 32px clamp(18px, 3vw, 44px) 80px;
  display: grid;
  grid-template-columns: 226px minmax(0, 1fr);
  gap: clamp(28px, 4vw, 56px);
}

.lesson-rail {
  position: sticky;
  top: 108px;
  align-self: start;
  max-height: calc(100vh - 132px);
  overflow: auto;
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}

.lesson-picker {
  padding: 0 16px 14px 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.lesson-picker label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.lesson-picker select {
  width: 100%;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
}

.rail-heading {
  padding: 0 22px 16px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.rail-heading span {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.rail-heading strong { font-size: 12px; }

#word-navigation {
  padding: 10px 16px 20px 0;
  display: grid;
  gap: 2px;
}

.word-nav-link {
  min-height: 38px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  border-left: 3px solid transparent;
  border-radius: 0 4px 4px 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.word-nav-link span:first-child {
  color: #929894;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

.word-nav-link:hover,
.word-nav-link.is-current {
  border-left-color: var(--teal);
  background: var(--teal-soft);
  color: var(--ink);
}

main { min-width: 0; }

.lesson-intro {
  min-height: 188px;
  padding: 12px 0 32px;
  display: grid;
  align-content: end;
  border-bottom: 1px solid var(--line);
}

.intro-kicker {
  margin-bottom: 10px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.lesson-intro h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(36px, 5vw, 64px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: 0;
}

.lesson-intro p {
  margin: 14px 0 18px;
  color: var(--muted);
  font-size: 16px;
}

.voice-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--coral);
}

.voice-status.is-ready .status-dot { background: var(--teal); }

.word-cards {
  display: grid;
  gap: 18px;
  padding-top: 28px;
}

.word-card {
  scroll-margin-top: 96px;
  padding: clamp(22px, 3vw, 34px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.word-card.is-speaking {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft), var(--shadow);
}

.word-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.word-number {
  display: block;
  margin-bottom: 4px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.word-play {
  max-width: 100%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.word-label {
  overflow-wrap: anywhere;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1.02;
  letter-spacing: 0;
}

.play-symbol {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--teal);
  border-radius: 50%;
  color: var(--teal);
  font-size: 12px;
}

.word-play:hover .play-symbol,
.word-play.is-speaking .play-symbol {
  background: var(--teal);
  color: #fff;
}

.frequency-tag {
  max-width: 42%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  text-align: right;
}

.pronunciation-row {
  margin-top: 14px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--muted);
}

.pronunciation-row.is-empty { display: none; }

.pronunciation-label {
  color: var(--teal);
  font-size: 10px;
  font-weight: 850;
}

.pronunciation-value {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
}

.core-scene {
  margin: 26px 0 22px;
  padding: 18px 0;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.core-scene > span {
  padding-top: 3px;
  color: var(--coral);
  font-size: 11px;
  font-weight: 850;
}

.core-scene p {
  margin: 0;
  font-size: 17px;
  line-height: 1.7;
}

.word-details {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(90px, 132px) minmax(0, 1fr);
  gap: 10px 16px;
  font-size: 14px;
  line-height: 1.65;
}

.word-details dt {
  color: var(--muted);
  font-weight: 750;
}

.word-details dd { margin: 0; }

code {
  padding: 1px 4px;
  border-radius: 3px;
  background: #f0f1ee;
  color: #174f4c;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

.examples-section { margin-top: 28px; }

.examples-section h2 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.example-list { border-top: 1px solid var(--line); }

.example-play {
  width: 100%;
  min-height: 54px;
  padding: 13px 8px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.example-play .play-symbol {
  width: 24px;
  height: 24px;
  border-color: var(--line);
  font-size: 8px;
}

.example-text {
  overflow-wrap: anywhere;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.5;
}

.example-play:hover,
.example-play.is-speaking { background: var(--teal-soft); }

.example-play:hover .play-symbol,
.example-play.is-speaking .play-symbol {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.lesson-pager {
  margin-top: 28px;
  padding-top: 24px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.lesson-pager button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 19px;
}

.lesson-pager button:hover:not(:disabled) {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.lesson-pager button:disabled {
  cursor: default;
  opacity: 0.35;
}

.lesson-pager span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-align: center;
}

@media (max-width: 1020px) {
  .app-header {
    grid-template-columns: minmax(170px, 1fr) minmax(240px, 1.5fr);
  }

  .audio-toolbar { grid-column: 1 / -1; }
  .app-shell { padding-top: 24px; }
  .lesson-rail { top: 148px; }
}

@media (max-width: 760px) {
  html { scroll-padding-top: 176px; }

  .app-header {
    min-height: 122px;
    padding: calc(8px + env(safe-area-inset-top)) 14px 10px;
    grid-template-columns: minmax(140px, 1fr) auto;
    align-items: center;
    gap: 8px;
  }

  .brand img { width: 42px; height: 42px; }
  .brand-copy span { display: none; }

  .global-search {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .search-results {
    position: fixed;
    top: calc(116px + env(safe-area-inset-top));
    right: 10px;
    left: 10px;
    max-height: calc(100vh - 132px - env(safe-area-inset-top));
  }

  .audio-toolbar {
    width: auto;
    grid-column: auto;
    gap: 6px;
  }

  .segmented { flex: 0 0 auto; }
  .segment { min-width: 38px; padding: 0 7px; }
  .speed-control { padding-left: 8px; }

  .speed-control > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .app-shell {
    padding: 20px 14px 60px;
    display: block;
  }

  .lesson-rail {
    position: sticky;
    z-index: 10;
    top: calc(122px + env(safe-area-inset-top));
    max-height: none;
    margin: 0 -14px 20px;
    overflow: hidden;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
  }

  .rail-heading { display: none; }
  .lesson-picker { display: none; }

  #word-navigation {
    padding: 8px 14px;
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
  }

  #word-navigation::-webkit-scrollbar { display: none; }

  .word-nav-link {
    min-height: 34px;
    flex: 0 0 auto;
    display: block;
    padding: 7px 11px;
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
  }

  .word-nav-link span:first-child { display: none; }
  .word-nav-link.is-current { border-bottom-color: var(--teal); }

  .lesson-intro {
    min-height: 170px;
    padding-top: 0;
  }

  .lesson-intro h1 { font-size: 38px; }

  .word-card {
    scroll-margin-top: 188px;
    padding: 22px 18px;
  }

  .word-card-header { display: block; }

  .frequency-tag {
    max-width: 100%;
    margin-top: 10px;
    display: inline-block;
    text-align: left;
  }

  .word-label { font-size: 38px; }

  .core-scene {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .word-details {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .word-details dd + dt { margin-top: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
