:root {
  color-scheme: light;
  --paper: #f4efe5;
  --paper-deep: #e9e0d0;
  --ink: #17201d;
  --muted: #6f756f;
  --line: rgba(23, 32, 29, 0.13);
  --green: #173f36;
  --green-soft: #dce7df;
  --orange: #d86f3d;
  --white: #fffdf8;
  --shadow: 0 20px 50px rgba(31, 38, 34, 0.12);
  --library-width: 340px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); overflow: hidden; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { display: grid; grid-template-columns: var(--library-width) 8px minmax(0, 1fr); height: 100vh; }
.library { display: flex; flex-direction: column; min-height: 0; background: var(--green); color: #f7f2e8; border-right: 1px solid rgba(255,255,255,.08); }
.library-resizer { position: relative; z-index: 5; background: var(--green); cursor: col-resize; touch-action: none; outline: 0; }
.library-resizer::after { content: ""; position: absolute; inset: 0 3px; background: rgba(255,255,255,.16); transition: background .15s ease, inset .15s ease; }
.library-resizer:hover::after, .library-resizer:focus-visible::after, .library-resizer.dragging::after { inset: 0 2px; background: var(--orange); }
body.resizing-library { cursor: col-resize; user-select: none; }
.brand { padding: 30px 28px 22px; position: relative; }
.eyebrow { margin: 0 0 7px; color: #a9c2b7; font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.brand h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 36px; font-weight: 500; letter-spacing: -.04em; }
.brand h1 span { color: #ef9b67; font-style: italic; }
.brand-copy { max-width: 250px; margin: 10px 0 0; color: #b9c9c2; font-family: Georgia, "Times New Roman", serif; font-size: 14px; line-height: 1.45; }
.mobile-close { display: none; }

.library-tools { padding: 0 20px 16px; }
.search-box { display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 42px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 11px; }
.search-box span { color: #adc2b8; font-size: 22px; transform: rotate(-15deg); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: white; font-size: 13px; }
.search-box input::placeholder { color: #91a79e; }
.level-filters { display: flex; gap: 5px; margin-top: 10px; }
.filter-button { flex: 1; height: 29px; border: 1px solid rgba(255,255,255,.13); border-radius: 8px; background: transparent; color: #aabdb5; cursor: pointer; font-size: 11px; font-weight: 700; }
.filter-button.active { background: #f5eee2; color: var(--green); border-color: #f5eee2; }

.library-meta { display: flex; justify-content: space-between; align-items: center; padding: 0 22px 10px; color: #91a79e; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.text-button { padding: 0; border: 0; background: transparent; color: #b9c9c2; cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.text-button.active { color: #ef9b67; }
.lesson-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 24px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.22) transparent; }
.lesson-item { width: 100%; display: grid; grid-template-columns: 42px minmax(0,1fr) 22px; gap: 10px; align-items: center; padding: 11px 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.lesson-item:hover { background: rgba(255,255,255,.07); }
.lesson-item.active { background: #f5eee2; color: var(--ink); box-shadow: 0 8px 24px rgba(0,0,0,.13); }
.lesson-index { color: #87a096; font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.lesson-item.active .lesson-index { color: var(--orange); }
.lesson-name { min-width: 0; }
.lesson-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia, "Times New Roman", serif; font-size: 14px; font-weight: 500; }
.lesson-name small { display: block; margin-top: 3px; color: #8da399; font-size: 9px; font-weight: 800; letter-spacing: .1em; }
.lesson-item.active .lesson-name small { color: #718078; }
.completion { color: #65a98d; font-size: 13px; text-align: center; }
.empty-state { padding: 36px 18px; color: #aac0b6; text-align: center; font-family: Georgia, serif; line-height: 1.5; }

.study-area { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr) auto; background: radial-gradient(circle at 70% 0%, #fbf7ef 0, var(--paper) 48%); }
.study-header { min-height: 104px; display: flex; align-items: center; gap: 18px; padding: 18px 32px; border-bottom: 1px solid var(--line); }
.lesson-heading { flex: 1; min-width: 0; }
.lesson-kicker { display: flex; gap: 10px; align-items: center; color: var(--orange); font-size: 10px; font-weight: 800; letter-spacing: .13em; }
.level-pill { padding: 4px 7px; border-radius: 999px; background: var(--green-soft); color: var(--green); letter-spacing: .08em; }
.lesson-heading h2 { margin: 6px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia, "Times New Roman", serif; font-size: clamp(25px, 3vw, 40px); font-weight: 500; letter-spacing: -.035em; }
.header-actions { display: flex; gap: 8px; }
.icon-button { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.45); color: var(--ink); text-decoration: none; cursor: pointer; font-size: 18px; }
.icon-button:hover { background: var(--white); border-color: rgba(23,32,29,.28); }
.icon-button.active { background: var(--orange); border-color: var(--orange); color: white; }
.mobile-menu { display: none; }

.pdf-stage { position: relative; min-height: 0; margin: 0 24px; overflow: hidden; border: 1px solid var(--line); border-radius: 16px 16px 0 0; background: #d8d5cf; box-shadow: var(--shadow); }
.pdf-stage iframe { position: relative; z-index: 2; width: 100%; height: 100%; border: 0; background: white; opacity: 0; transition: opacity .2s ease; }
.pdf-stage iframe.loaded { opacity: 1; }
.pdf-loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; color: var(--muted); z-index: 1; }
.loading-mark { width: 58px; height: 58px; display: grid; place-items: center; border: 1px solid #aaa59d; border-radius: 50%; color: var(--green); font: italic 22px Georgia, serif; }
.pdf-loading p { margin: 12px 0 0; font-size: 12px; }

.player-dock { margin: 0 24px 20px; padding: 14px 18px 13px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 16px 16px; background: rgba(255,253,248,.94); box-shadow: 0 18px 45px rgba(31,38,34,.1); backdrop-filter: blur(14px); }
.track-switcher { display: flex; gap: 6px; margin-bottom: 10px; }
.track-button { padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.track-button.active { background: var(--green); border-color: var(--green); color: white; }
.track-button:disabled { opacity: .3; cursor: not-allowed; }
audio { width: 100%; height: 38px; display: block; accent-color: var(--orange); }
.lesson-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.nav-button { padding: 3px 0; border: 0; background: transparent; color: var(--green); cursor: pointer; font-size: 11px; font-weight: 700; }
.nav-button:disabled { color: #aaa; cursor: not-allowed; }
.mobile-backdrop { display: none; }

@media (max-width: 820px) {
  body { overflow: hidden; }
  .app-shell { display: block; }
  .library-resizer { display: none; }
  .library { position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(88vw, 360px); transform: translateX(-105%); transition: transform .22s ease; box-shadow: 24px 0 50px rgba(0,0,0,.24); }
  .library.open { transform: translateX(0); }
  .mobile-close { display: block; position: absolute; right: 18px; top: 18px; border: 0; background: transparent; color: #d6e1dc; font-size: 28px; cursor: pointer; }
  .study-area { height: 100vh; grid-template-rows: auto minmax(0,1fr) auto; }
  .study-header { min-height: 82px; padding: 12px 14px; gap: 10px; }
  .mobile-menu { display: inline-flex; flex: 0 0 auto; }
  .lesson-heading h2 { font-size: 22px; }
  .header-actions .icon-button { width: 36px; height: 36px; }
  .pdf-stage { margin: 0 8px; border-radius: 11px 11px 0 0; }
  .player-dock { margin: 0 8px 8px; padding: 10px; border-radius: 0 0 11px 11px; }
  .track-switcher { overflow-x: auto; }
  .mobile-backdrop { position: fixed; inset: 0; z-index: 15; background: rgba(13,22,19,.5); }
  .mobile-backdrop.open { display: block; }
}

@media (max-width: 520px) {
  .lesson-kicker { gap: 6px; font-size: 8px; }
  .level-pill { display: none; }
  .header-actions #favoriteButton { display: none; }
  .lesson-heading h2 { max-width: 54vw; }
  .lesson-nav span { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
