:root {
    --bg: #05060A;
    --ink: #EAF4FF;
    --soft: #7D8796;
    --dim: #3A404C;
    --done: #8FD3FF;
    --open: #FF9A4D;
    --lock: #262A33;
    --panel: #0C0E14;
    --line: #1C2030;
  }
  *, *::before, *::after { box-sizing: border-box; }
  html, body {
    height: 100%; margin: 0; overflow: hidden;
    background: var(--bg); color: var(--ink);
    font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
                 "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.011em;
  }

  /* 무대 */
  #stage { position: fixed; inset: 0; touch-action: none; cursor: grab; }
  #stage.dragging { cursor: grabbing; }
  #svg { width: 100%; height: 100%; display: block; }
  #svg text { font-family: inherit; user-select: none; -webkit-user-select: none; }

  /* 상단 */
  .top {
    position: fixed; top: 0; left: 0; right: 0; z-index: 5; pointer-events: none;
    display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
    padding: calc(env(safe-area-inset-top, 0px) + 22px) 24px 0;
  }
  .top > * { pointer-events: auto; }
  .mark { font-weight: 800; font-size: 14px; letter-spacing: 0.24em; }
  .mark span { color: var(--done); }
  .tagline { margin-top: 6px; font-size: 13px; color: var(--soft); }
  .progress { text-align: right; font-size: 13px; color: var(--soft); }
  .progress b { color: var(--ink); font-weight: 700; }
  .reset {
    background: none; border: 0; padding: 4px 0; margin-top: 2px; cursor: pointer;
    font: inherit; font-size: 12px; color: var(--dim); text-decoration: underline;
  }
  .reset:hover { color: var(--soft); }
  .hint {
    position: fixed; left: 0; right: 0; text-align: center; pointer-events: none;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    font-size: 12px; color: #4A5160;
  }

  /* 연결선 */
  .edge { fill: none; stroke-width: 2.5; stroke-linecap: round; transition: stroke .7s ease, opacity .7s ease; }
  .edge.locked { stroke: #1E222B; stroke-dasharray: 3 7; }
  .edge.open   { stroke: var(--open); opacity: .9; filter: url(#glowOrange); }
  .edge.done   { stroke: var(--done); filter: url(#glowBlue); }

  /* 노드 */
  .node { cursor: pointer; outline: none; }
  .node .box { stroke-width: 2; transition: fill .7s ease, stroke .7s ease; }
  .node.done   .box { fill: #CFEBFF; stroke: var(--done); filter: url(#glowBlue); }
  .node.open   .box { fill: #FFD2AE; stroke: var(--open); filter: url(#glowOrange); }
  .node.locked .box { fill: #0E1016; stroke: var(--lock); }
  .node .num { font-size: 14px; font-weight: 800; text-anchor: middle; dominant-baseline: central; }
  .node.done .num, .node.open .num { fill: #0A1A2A; }
  .node.locked .num { fill: var(--dim); }
  .node .label { font-size: 13px; font-weight: 600; text-anchor: middle; fill: var(--ink); transition: fill .7s ease; }
  .node.locked .label { fill: var(--dim); }
  .node:focus-visible .box { stroke: #fff; }

  .node .pulse { fill: none; stroke: var(--open); stroke-width: 2; opacity: 0;
                 transform-box: fill-box; transform-origin: center; }
  @media (prefers-reduced-motion: no-preference) {
    .node.open .pulse { animation: pulse 2.2s ease-out infinite; }
    .node.flash .box { animation: flash 1.4s ease-out; }
  }
  .seed { fill: var(--open); filter: url(#glowOrange); }
  @media (prefers-reduced-motion: no-preference) { .seed { animation: seed 2.4s ease-in-out infinite; } }
  @keyframes seed { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
  @keyframes pulse { 0% { opacity: .75; transform: scale(1); } 100% { opacity: 0; transform: scale(1.9); } }
  @keyframes flash { 0% { stroke: #fff; stroke-width: 6; } 100% { stroke-width: 2; } }

  /* 학습 패널 */
  #scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none;
           transition: opacity .3s ease; z-index: 9; }
  #scrim.show { opacity: 1; pointer-events: auto; }
  #panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 10;
    width: min(620px, 100%); display: flex; flex-direction: column;
    background: var(--panel); border-left: 1px solid var(--line);
    transform: translateX(100%); transition: transform .38s cubic-bezier(.2,.7,.2,1);
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #panel.show { transform: none; }
  .p-head { display: flex; justify-content: space-between; align-items: center; padding: 22px 28px 0; }
  .p-meta { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--open); }
  .p-close { background: none; border: 0; color: var(--soft); font-size: 26px; line-height: 1; cursor: pointer; padding: 4px; }
  .p-close:hover { color: var(--ink); }
  .p-scroll { flex: 1; overflow-y: auto; padding: 10px 28px 32px; font-size: 16.5px; line-height: 1.85; }
  .p-title { font-size: clamp(24px, 4.4vw, 32px); font-weight: 800; letter-spacing: -0.035em; line-height: 1.35; margin: 6px 0 28px; }
  .md h1, .md h2, .md h3 { font-size: 20px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.45; margin: 44px 0 12px; }
  .p-scroll p { margin: 0 0 16px; color: #C3C7CE; }
  .p-scroll strong { color: var(--ink); font-weight: 600; }
  .p-scroll .stanza { color: var(--ink); font-size: 19px; font-weight: 600; line-height: 2; margin: 20px 0; }
  .p-scroll a { color: var(--ink); text-decoration-color: var(--done); text-underline-offset: 4px; }
  .p-foot { padding: 16px 28px 20px; border-top: 1px solid var(--line); }
  .btn {
    width: 100%; padding: 15px; border: 0; border-radius: 12px; cursor: pointer;
    font: inherit; font-size: 15px; font-weight: 700;
    background: var(--done); color: #05121F; transition: filter .15s;
  }
  .btn:hover { filter: brightness(1.08); }
  .btn:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
  .btn.ghost { background: transparent; color: var(--soft); border: 1px solid var(--line); cursor: default; filter: none; }

  @media (max-width: 640px) {
    #panel {
      top: auto; height: 88%; width: 100%;
      border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
      transform: translateY(100%);
    }
    .tagline { display: none; }
  }

  /* 토스트 */
  #toast {
    position: fixed; left: 50%; z-index: 20; pointer-events: none;
    top: calc(env(safe-area-inset-top, 0px) + 76px);
    transform: translate(-50%, -8px); opacity: 0; transition: opacity .3s, transform .3s;
    background: #10131B; border: 1px solid var(--line); border-radius: 999px;
    padding: 10px 18px; font-size: 14px; max-width: calc(100% - 40px); text-align: center;
  }
  #toast.show { opacity: 1; transform: translate(-50%, 0); }

  .md img { max-width: 100%; height: auto; border-radius: 10px; margin: 8px 0 16px; }
  .md ul, .md ol { padding-left: 1.3em; margin: 0 0 16px; color: #C3C7CE; }
  .md blockquote { margin: 20px 0; padding: 4px 0 4px 18px; border-left: 2px solid var(--done); }
  .md blockquote p { color: var(--ink); }
  .md hr { border: 0; border-top: 1px solid var(--line); margin: 36px 0; }
  .loading { color: var(--soft); }

/* ---- 인터랙티브 레슨 ---- */
.lesson .beat { animation: beatIn .25s ease; }
.lesson .beat-heading h1, .lesson .beat-heading h2, .lesson .beat-heading h3 { margin-top: 36px; }
@keyframes beatIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.beat.typing > :last-child::after, .q.typing > :last-child::after, .feedback.typing > :last-child::after {
  content: ""; display: inline-block; width: .45em; height: 1.05em; margin-left: 3px;
  vertical-align: -.15em; background: var(--done); animation: blink .9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.beat-choice, .beat-think { margin: 26px 0; padding: 18px 18px 16px; border: 1px solid var(--line); border-radius: 14px; background: #0F1218; }
.beat-choice .q p, .beat-think .q p { color: var(--ink); font-weight: 600; margin: 0; }
.opts { display: grid; gap: 8px; margin-top: 14px; }
.opt {
  text-align: left; padding: 13px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: #141821; color: var(--ink);
  font: inherit; font-size: 15.5px; transition: border-color .2s, background .2s, opacity .2s;
}
.opt:hover:not(:disabled) { border-color: var(--done); }
.opt:focus-visible { outline: 2px solid var(--done); outline-offset: 2px; }
.opt.picked { border-color: var(--done); background: rgba(143, 211, 255, .12); }
.opt:disabled:not(.picked) { opacity: .4; cursor: default; }
.opt:disabled.picked { cursor: default; }
.feedback { margin-top: 12px; padding: 10px 14px; border-left: 2px solid var(--done); }
.feedback p { margin: 0; color: var(--ink); }
.beat-think textarea {
  width: 100%; min-height: 88px; margin-top: 14px; padding: 12px 14px; resize: vertical;
  border-radius: 12px; border: 1px solid var(--line); background: #141821; color: var(--ink);
  font: inherit; font-size: 15.5px; line-height: 1.7;
}
.beat-think textarea:focus { outline: none; border-color: var(--done); }
.beat-think .row { display: flex; justify-content: flex-end; margin-top: 8px; }
.answer { margin-top: 12px; padding: 10px 14px; border-left: 2px solid var(--open); color: var(--ink); white-space: pre-wrap; }
.btn.small { width: auto; padding: 9px 18px; font-size: 14px; }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
.btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.foot-row { display: flex; gap: 8px; }
.foot-row .btn { flex: 1; }
.tap {
  display: block; width: 100%; padding: 12px; background: none; border: 0; cursor: pointer;
  font: inherit; font-size: 13.5px; color: var(--soft); text-align: center;
}
.tap:hover { color: var(--ink); }
.tap span { display: inline-block; margin-left: 4px; }
@media (prefers-reduced-motion: no-preference) { .tap span { animation: bob 1.4s ease-in-out infinite; } }
@keyframes bob { 50% { transform: translateY(3px); } }

/* ---- 상단 통계 ---- */
.stats { display: flex; gap: 18px; text-align: right; font-size: 13px; color: var(--soft); }
.stats > div { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.stats .k { font-size: 11.5px; letter-spacing: .04em; }
.stats b { font-size: 17px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---- 몰입형 전체 화면 학습 ---- */
#panel {
  top: 0; right: 0; bottom: 0; left: 0; width: auto; height: auto;
  border: 0; border-radius: 0; background: var(--bg);
  transform: none; opacity: 0; visibility: hidden;
  transition: opacity .35s ease, visibility .35s ease;
}
#panel.show { opacity: 1; visibility: visible; transform: none; }
#scrim { display: none; }
.p-progress { height: 2px; background: var(--line); flex-shrink: 0; }
.p-progress i { display: block; height: 100%; width: 0; background: var(--done); box-shadow: 0 0 10px var(--done); transition: width .4s ease; }
.p-head { padding: 18px 24px 0; }
.p-back { background: none; border: 0; padding: 6px 0; cursor: pointer; font: inherit; font-size: 14px; color: var(--soft); }
.p-back:hover { color: var(--ink); }
.p-back:focus-visible { outline: 2px solid var(--done); outline-offset: 3px; border-radius: 4px; }
.p-scroll {
  padding: 40px max(24px, calc((100% - 680px) / 2)) 64px;
  font-size: 18px; line-height: 1.9;
}
.p-title { font-size: clamp(28px, 5vw, 40px); margin: 0 0 40px; }
.lesson .beat-text p { color: #D2D6DC; }
.p-foot {
  padding: 14px max(24px, calc((100% - 680px) / 2)) 22px;
  border-top: 0; background: linear-gradient(transparent, var(--bg) 40%);
}
@media (max-width: 640px) {
  .p-scroll { font-size: 17px; padding-top: 28px; }
  .stats { gap: 14px; }
}

/* ---- 시선 고정 + 현재 문장 강조 ---- */
.lesson.playing { padding-bottom: 55vh; }
.lesson.playing .beat { opacity: .38; transition: opacity .5s ease; }
.lesson.playing .beat.current,
.lesson.ended .beat { opacity: 1; }

/* ---- 별자리 스타일 ---- */
.sky-star { fill: #CFE3FF; pointer-events: none; }
@media (prefers-reduced-motion: no-preference) {
  .sky-star { animation-name: skyTwinkle; animation-timing-function: ease-in-out; animation-iteration-count: infinite; }
}
@keyframes skyTwinkle { 50% { opacity: .05; } }

.edge { stroke-width: 1.2; }
.edge.locked { stroke: #1A1E27; stroke-dasharray: none; }
.edge.open { stroke-width: 1.5; }
.edge.done { stroke-width: 1.5; opacity: .75; }

.node .hit { fill: transparent; }
.node .core { transform-box: fill-box; transform-origin: center; transition: transform .25s ease, fill .6s ease; }
.node.done   .core { fill: #DDF1FF; filter: url(#glowBlue); }
.node.open   .core { fill: #FFE0C4; filter: url(#glowOrange); }
.node.locked .core { fill: #2F3440; }
.node:hover .core, .node:focus-visible .core { transform: scale(1.6); }
.node.locked:hover .core { fill: #4A5160; }
@media (prefers-reduced-motion: no-preference) {
  .node.done .core { animation: starTwinkle 5s ease-in-out infinite; }
  .node.flash .core { animation: starBurst 1.4s ease-out; }
}
@keyframes starTwinkle { 50% { opacity: .55; } }
@keyframes starBurst { 0% { transform: scale(3.2); } 100% { transform: scale(1); } }

.node .pulse { stroke-width: 1.5; }
.node .tip { opacity: 0; transform: translateY(-4px); transition: opacity .25s ease, transform .25s ease; pointer-events: none; }
.node:hover .tip, .node:focus-visible .tip { opacity: 1; transform: none; }
.node .tip .label { font-size: 14px; font-weight: 700; fill: var(--ink); }
.node .tip .status { font-size: 11.5px; text-anchor: middle; fill: var(--soft); }
.node.open .tip .status { fill: var(--open); }
.node.locked .tip .label { fill: var(--soft); }
.node .label, .node .status { paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }

/* ---- 진행 대시바 ---- */
.p-progress {
  display: flex; gap: 6px; height: auto; background: none;
  padding: 14px max(24px, calc((100% - 680px) / 2)) 0;
}
.p-progress span { flex: 1; height: 4px; border-radius: 2px; background: #1C2030; overflow: hidden; }
.p-progress i {
  display: block; height: 100%; width: 0; border-radius: 2px;
  background: var(--done); box-shadow: 0 0 8px rgba(143, 211, 255, .6);
  transition: width .45s ease;
}
.p-head { padding-left: max(24px, calc((100% - 680px) / 2)); padding-right: max(24px, calc((100% - 680px) / 2)); }
