: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(540px, 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); }
