:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #fff;
  --soft: #e9edf2;
  --text: #20272e;
  --muted: #626d79;
  --line: #dde2e8;
  --brand: #155eef;
  --accent: #087d70;
  --danger: #b42318;
}

* { box-sizing: border-box; letter-spacing: 0; }
[hidden] { display: none !important; }

html, body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", Roboto, Arial, sans-serif;
}

body {
  overflow-x: clip;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

button, select { font: inherit; }
button { border: 0; cursor: pointer; touch-action: manipulation; }
button:disabled, select:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible, select:focus-visible, input[type="range"]:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 3px;
}
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { display: block; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-solid { fill: currentColor; stroke-width: 1; }
.seek-symbol { position: relative; display: grid; place-items: center; width: 32px; height: 32px; }
.seek-symbol .icon { width: 32px; height: 32px; stroke-width: 1.5; }
.seek-symbol span { position: absolute; inset: 0; display: grid; place-items: center; padding-top: 2px; font-size: 10px; font-weight: 700; }

.app {
  width: min(840px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
}

.topbar, .track-row, .section-heading, .notice-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.topbar { padding: 4px 0 24px; }
.brand { margin: 0; color: var(--brand); font-size: 12px; font-weight: 700; }
h1 { margin: 8px 0 0; font-size: 26px; line-height: 1.4; word-break: keep-all; overflow-wrap: anywhere; }

.player {
  position: sticky;
  top: max(10px, env(safe-area-inset-top));
  z-index: 5;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 4px 18px rgb(20 32 51 / 4%);
}
.player-body { padding: 24px; }
.track-copy { min-width: 0; }
.track-round { margin: 0 0 6px; color: var(--accent); font-size: 13px; font-weight: 700; }
.track-copy h2 { margin: 0; font-size: 32px; line-height: 1.3; word-break: keep-all; overflow-wrap: anywhere; }
select { width: 88px; flex-shrink: 0; height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); font-weight: 600; font-size: 14px; }

.timeline {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 10px;
  margin: 16px 0 20px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.progress { --progress: 0%; appearance: none; -webkit-appearance: none; width: 100%; min-width: 0; height: 44px; margin: 0; background: transparent; cursor: pointer; touch-action: pan-y; }
.progress:disabled { cursor: default; opacity: .55; }
.progress::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: linear-gradient(to right, var(--brand) var(--progress), var(--soft) var(--progress)); }
.progress::-moz-range-track { height: 8px; border-radius: 4px; background: var(--soft); }
.progress::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--brand); }
.progress::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -6px; border: 2px solid #fff; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.progress::-moz-range-thumb { width: 16px; height: 16px; border: 2px solid #fff; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 1px var(--brand); }

.controls {
  display: grid;
  grid-template-columns: 48px 72px 48px;
  align-items: center;
  justify-items: center;
  justify-content: center;
  gap: 28px;
}
.icon-button, .play-button { display: grid; place-items: center; }
.icon-button { width: 48px; height: 48px; border-radius: 50%; background: transparent; color: var(--text); }
.play-button { width: 72px; height: 72px; border-radius: 50%; background: var(--brand); color: #fff; }
.play-button .icon { width: 27px; height: 27px; }
.notice-row { align-items: center; min-height: 40px; padding: 9px 24px; border-top: 1px solid var(--line); background: #fcfcfd; }
.notice-row { flex-wrap: wrap; gap: 8px; }
.notice-row p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.notice-row.is-error p { color: var(--danger); }
#retryCatalog, #retryMedia { min-height: 44px; padding: 0 12px; border-radius: 6px; background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; }

.category-tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 20px; margin-top: 26px; border-bottom: 1px solid var(--line); }
.category-tab { min-height: 48px; padding: 10px 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-weight: 600; font-size: 15px; }
.category-tab.is-active { border-bottom-color: var(--brand); color: var(--brand); }
.lessons { padding-bottom: 20px; }
.section-heading { align-items: center; margin: 26px 0 12px; }
.section-heading h2 { margin: 0; font-size: 16px; }
.section-heading span { color: var(--muted); font-size: 12px; font-weight: 500; }
.lesson-list { display: grid; border-top: 1px solid var(--line); }
.lesson {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 72px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  scroll-margin-block-start: 360px;
}
.lesson.is-active { background: #edf3ff; box-shadow: inset 3px 0 var(--brand); }
.lesson-title { display: block; font-size: 16px; font-weight: 600; line-height: 1.5; word-break: keep-all; overflow-wrap: anywhere; }
.lesson-trailing { display: flex; align-items: center; gap: 18px; }
.lesson-action { min-width: 66px; color: var(--muted); font-size: 12px; font-weight: 500; text-align: right; }
.lesson-icon { width: 19px; height: 19px; color: var(--muted); }
.lesson.is-active .lesson-title, .lesson.is-active .lesson-icon { color: var(--brand); }
.lesson.is-playing .lesson-action { color: var(--accent); }
.lesson:focus-visible { position: relative; z-index: 6; outline-offset: -3px; }
.empty-state { min-height: 74px; margin: 0; padding: 25px; border: 1px dashed var(--line); border-radius: 8px; background: #fff; color: var(--muted); text-align: center; }
audio { display: none; }
.mobile-dock { display: none; }

@media (hover: hover) {
  .lesson:not(.is-active):hover { background: #eef1f5; }
  .category-tab:hover { color: var(--brand); }
  .icon-button:not(:disabled):hover, .mobile-dock-button:not(:disabled):hover { background: var(--soft); }
  .play-button:not(:disabled):hover, .mobile-dock-play:not(:disabled):hover { background: #124ec7; }
}

@media (max-width: 820px), (max-height: 700px) {
  .player { position: static; }
  .lesson { scroll-margin-block-start: 16px; }
}

@media (max-width: 820px) {
  body.has-mobile-media .app {
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }
  .mobile-dock {
    position: fixed;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    z-index: 20;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px 52px 44px;
    align-items: center;
    gap: 7px;
    min-height: 64px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgb(255 255 255 / 96%);
    box-shadow: 0 4px 20px rgb(20 32 51 / 10%);
  }
  .mobile-dock-copy { min-width: 0; padding-left: 4px; }
  .mobile-dock-copy span,
  .mobile-dock-copy strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-dock-copy span { margin-bottom: 3px; color: var(--accent); font-size: 11px; font-weight: 600; }
  .mobile-dock.is-error .mobile-dock-copy span { color: var(--danger); }
  .mobile-dock-copy strong { font-size: 12px; line-height: 1.25; }
  .mobile-dock-button,
  .mobile-dock-play { display: grid; place-items: center; padding: 0; touch-action: manipulation; }
  .mobile-dock-button { width: 44px; height: 44px; border-radius: 50%; background: transparent; color: var(--text); }
  .mobile-dock-button .seek-symbol, .mobile-dock-button .seek-symbol .icon { width: 28px; height: 28px; }
  .mobile-dock-play { width: 52px; height: 52px; border-radius: 50%; background: var(--brand); color: #fff; }
  .mobile-dock-play .icon { width: 21px; height: 21px; }
}

@media (max-width: 520px) {
  h1 { font-size: 22px; }
  .track-copy h2 { font-size: 28px; }
  .app { padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
  .topbar { padding-bottom: 20px; }
  .player-body { padding: 20px; }
  .notice-row { padding-left: 20px; padding-right: 20px; }
  .timeline { grid-template-columns: 42px 1fr 42px; gap: 8px; }
  .controls { grid-template-columns: 44px 66px 44px; gap: 24px; }
  .play-button { width: 66px; height: 66px; }
  .icon-button { width: 44px; height: 44px; }
  .lesson { padding-left: 14px; padding-right: 14px; }
  .lesson-trailing { gap: 12px; }
}
