/* ===== 디자인 토큰 ===== */
:root {
  --bg-page: #F4F6FA;
  --bg-panel: #FFFFFF;
  --bg-stage: #F8FAFE;
  --fg: #1C2D3C;
  --fg-2: #526578;
  --fg-3: #687B8A;
  --line: #DCE4EF;
  --line-2: #C6D1DF;
  --blue: #315FD0;
  --blue-bg: #EDF3FF;
  --blue-soft: #C4D4F6;
  --green: #21836B;
  --green-bg: #E5F4EE;
  --focus: #F4A741;
  --sunk: #F3F6FA;
  --font-sans: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-title: 23px;
  --fs-body: 16px;
  --fs-step: 14px;
  --fs-label: 13.5px;
  --fs-small: 12.5px;
  --fs-code: 13px;
  --r-panel: 9px;
  --r-ctl: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg-page);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; }
button:disabled { cursor: default; opacity: .42; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code, .mono { font-family: var(--font-mono); }

/* ===== 앱 셸 ===== */
.app { height: 100dvh; display: grid; grid-template-rows: 56px auto minmax(0, 1fr); }

.topbar {
  height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px; background: var(--bg-panel); border-bottom: 1px solid var(--line); min-width: 0;
}
.top-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--fg); text-decoration: none; font-weight: 700; font-size: 15px; white-space: nowrap; border-radius: 4px; }
.brand-logo { display: grid; place-items: center; width: 24px; height: 24px; }
.brand-logo svg { width: 24px; height: 24px; display: block; }

.series { position: relative; min-width: 0; }
.series-btn {
  display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px 0 10px; max-width: min(46vw, 440px);
  border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--bg-panel); cursor: pointer; font-size: 14px; min-width: 0;
}
.series-btn:hover { border-color: var(--line-2); }
.series-num { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; color: var(--blue); white-space: nowrap; }
.series-ttl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.series-chev, .sum-chev { display: grid; place-items: center; width: 16px; height: 16px; flex: none; color: var(--fg-3); }
.series-chev svg, .sum-chev svg { width: 16px; height: 16px; display: block; }
.series-btn[aria-expanded="true"] .series-chev { transform: rotate(180deg); }
.series-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; margin: 0; padding: 6px; list-style: none;
  width: min(380px, calc(100vw - 24px)); background: var(--bg-panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 28px rgba(28, 45, 60, .13);
}
.series-menu a {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) 18px; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 6px; color: var(--fg); text-decoration: none; font-size: 14px; line-height: 1.4;
}
.series-menu a:hover { background: var(--sunk); }
.series-menu a[aria-current="page"] { background: var(--blue-bg); font-weight: 600; }
.sm-num { font-family: var(--font-mono); font-size: 12.5px; color: var(--fg-3); }
.series-menu a[aria-current="page"] .sm-num { color: var(--blue); }
.sm-cur { color: var(--blue); display: grid; place-items: center; }
.sm-cur svg { width: 16px; height: 16px; }
.sm-head { padding: 6px 10px 8px; margin-bottom: 2px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--fg-2); }
.sm-group { padding: 10px 10px 3px; font-size: 12px; font-weight: 600; color: var(--fg-3); }

.lang { display: flex; flex: none; border: 1px solid var(--line); border-radius: var(--r-ctl); overflow: hidden; }
.lang button { border: 0; background: var(--bg-panel); height: 32px; padding: 0 12px; font-size: 13px; color: var(--fg-2); cursor: pointer; }
.lang button + button { border-left: 1px solid var(--line); }
.lang button[aria-pressed="true"] { background: var(--blue-bg); color: var(--blue); font-weight: 600; }

.ep-head { padding: 14px 16px 12px; min-width: 0; }
.ep-title { margin: 0; font-size: var(--fs-title); line-height: 1.3; font-weight: 700; letter-spacing: -.01em; }
.ep-q { margin: 3px 0 0; font-size: 15px; color: var(--fg-2); }

.main { display: grid; grid-template-columns: 188px minmax(0, 1fr) 270px; gap: 12px; padding: 0 16px 16px; min-height: 0; }
.panel { background: var(--bg-panel); border: 1px solid var(--line); border-radius: var(--r-panel); min-height: 0; min-width: 0; }

/* ===== 단계 목록 ===== */
.steps-panel { overflow: auto; padding: 8px 6px; }
.steps-head { font-size: 12px; font-weight: 600; color: var(--fg-3); padding: 2px 8px 6px; }
.steps-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.step-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-radius: 6px;
  background: transparent; text-align: left; cursor: pointer; font-size: var(--fs-step); line-height: 1.35; color: var(--fg-2);
}
.step-btn:hover { background: var(--sunk); }
.is-current .step-btn { background: var(--blue-bg); color: var(--fg); font-weight: 600; }
.step-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.step-name { min-width: 0; }
.step-term { font-family: var(--font-mono); font-size: 11px; font-weight: 500; line-height: 1.35; color: var(--fg-3); overflow-wrap: anywhere; }
.is-current .step-term { color: var(--blue); }
.ex-term {
  display: inline-block; margin: 0 0 10px; padding: 2px 8px; border-radius: 5px; border: 1px solid var(--blue-soft);
  background: var(--blue-bg); color: var(--blue); font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; line-height: 1.5;
}
.ex-term[hidden] { display: none; }
.step-ind {
  position: relative; flex: none; width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg-panel); display: grid; place-items: center; font-family: var(--font-mono); font-size: 11.5px; font-weight: 500; color: var(--fg-3);
}
.step-ind > span { grid-area: 1 / 1; display: grid; place-items: center; }
.ind-spin, .ind-check { visibility: hidden; }
.is-current .step-ind { border-color: var(--blue); color: var(--blue); }
.is-started .ind-num { visibility: hidden; }
.is-started .ind-spin { visibility: visible; }
.ind-spin::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--blue-soft); border-top-color: var(--blue);
  animation: ind-spin .85s linear infinite; animation-play-state: paused;
}
.is-running .ind-spin::before { animation-play-state: running; }
.is-done .step-ind { background: var(--green-bg); border-color: var(--green-bg); color: var(--green); }
.is-done .ind-num, .is-done .ind-spin { visibility: hidden; }
.is-done .ind-check { visibility: visible; color: var(--green); }
.ind-check svg { width: 14px; height: 14px; display: block; }
.pop .step-ind { animation: ind-pop 340ms cubic-bezier(.3, 1.4, .5, 1); }
.pop .ind-check path { stroke-dasharray: 1; animation: ind-draw 300ms ease-out both; }
@keyframes ind-spin { to { transform: rotate(360deg); } }
@keyframes ind-pop { 0% { transform: scale(1); } 45% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes ind-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }

/* ===== 중앙 ===== */
.center { display: grid; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; background: var(--bg-stage); }
.stage-scroll {
  overflow: auto; display: flex; min-height: 0; min-width: 0; container-type: inline-size;
  background-image: radial-gradient(circle, #E1E8F2 1px, transparent 1.3px); background-size: 22px 22px; background-attachment: local;
}
.stage { margin: auto; width: 100%; max-width: 1120px; padding: 20px; position: relative; }

.controls {
  position: relative; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px;
  padding: 9px 12px; background: var(--bg-panel); border-top: 1px solid var(--line);
}
.prog { position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: transparent; }
.prog-fill { position: absolute; inset: 0; background: var(--blue); transform-origin: left; transform: scaleX(0); }
.ctl-main { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.icon-btn {
  width: 36px; height: 36px; padding: 0; display: grid; place-items: center; flex: none;
  border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--bg-panel); color: var(--fg); cursor: pointer;
}
.icon-btn:not(:disabled):hover { border-color: var(--line-2); background: var(--sunk); }
.ico { display: grid; place-items: center; width: 18px; height: 18px; }
.ico svg { width: 18px; height: 18px; display: block; }
.play-btn {
  height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 14px 0 11px; min-width: 112px;
  border: 1px solid var(--blue); border-radius: var(--r-ctl); background: var(--blue); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.play-btn:hover { background: #2A53B8; }
.play-btn.is-playing { background: var(--bg-panel); color: var(--blue); }
.counter { font-family: var(--font-mono); font-size: 13px; color: var(--fg-2); padding: 0 6px; white-space: nowrap; }
.speed { display: flex; border: 1px solid var(--line); border-radius: var(--r-ctl); overflow: hidden; flex: none; }
.speed-btn { border: 0; background: var(--bg-panel); height: 34px; min-width: 44px; padding: 0 8px; font-family: var(--font-mono); font-size: 12.5px; color: var(--fg-2); cursor: pointer; }
.speed-btn + .speed-btn { border-left: 1px solid var(--line); }
.speed-btn[aria-pressed="true"] { background: var(--blue-bg); color: var(--blue); font-weight: 600; }

/* ===== 설명 패널 ===== */
.explain { overflow: auto; padding: 16px 16px 18px; }
.ex-eyebrow { font-family: var(--font-mono); font-size: 12px; color: var(--fg-3); }
.ex-title { margin: 4px 0 8px; font-size: 22px; line-height: 1.38; font-weight: 700; letter-spacing: -.01em; overflow-wrap: break-word; }
.ex-desc { margin: 0; font-size: var(--fs-body); line-height: 1.75; color: var(--fg); overflow-wrap: break-word; }
.ex-next { margin-top: 12px; }
.ex-next:empty { display: none; }
.ex-next.is-shown > * { animation: next-in 420ms cubic-bezier(.2, .8, .3, 1) both; }
.ex-next.is-shown > * + * { animation-delay: 80ms; }
.next-link { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--blue); text-decoration: none; line-height: 1.45; border-radius: 4px; }
.next-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.next-arrow { display: grid; place-items: center; width: 16px; height: 16px; flex: none; transition: transform .2s ease; }
.next-arrow svg { width: 16px; height: 16px; display: block; }
.next-link:hover .next-arrow { transform: translateX(3px); }
.next-arrow svg { animation: nudge 1.6s ease-in-out 600ms 2; }
.series-done { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--green); margin-bottom: 6px; }
.sd-check { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--green-bg); }
.sd-check svg { width: 14px; height: 14px; }
@keyframes next-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes nudge { 0%, 100% { transform: none; } 50% { transform: translateX(3px); } }

.explain details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 8px; }
.explain summary {
  list-style: none; display: flex; align-items: center; gap: 6px; min-height: 32px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--fg-2); border-radius: 4px;
}
.explain summary::-webkit-details-marker { display: none; }
.explain summary .sum-chev { transform: rotate(-90deg); transition: transform .15s; }
.explain details[open] > summary .sum-chev { transform: none; }
.more-body p { margin: 4px 0 8px; font-size: 14px; line-height: 1.7; color: var(--fg-2); }
.code {
  margin: 6px 0 0; padding: 7px 0; list-style: none; background: var(--sunk); border: 1px solid var(--line); border-radius: 7px;
  font-family: var(--font-mono); font-size: var(--fs-code); line-height: 1.6;
}
.code-line { display: flex; padding: 1px 10px 1px 0; }
.code-line .ln { flex: none; width: 30px; padding-right: 10px; text-align: right; color: #97A6B5; user-select: none; }
.code-line .lc { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; color: #2B3D4E; }
.code-line.is-hl { background: var(--blue-bg); }
.code-line.is-hl .ln { color: var(--blue); font-weight: 600; }
.code-line.is-hl .lc { color: var(--fg); }
.code-target { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; margin-top: 8px; font-size: 13px; color: var(--fg-2); }
.code-target b { color: var(--blue); font-weight: 600; }
.ct-dot { width: 10px; height: 10px; border-radius: 3px; border: 1.5px solid var(--blue); background: var(--blue-bg); }
.code-note { margin: 8px 0 0; font-size: 13px; line-height: 1.6; color: var(--fg-3); }

/* ===== 시각 어휘 ===== */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.fx-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ln { fill: none; stroke: var(--blue); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.ln.route { stroke-opacity: .5; stroke-width: 1.8; stroke-dasharray: 4 5; }
.ln.route-done { stroke-width: 2.6; stroke-opacity: .9; }
.ln.route.is-hidden { stroke-opacity: 0; }
.pulse { position: absolute; border: 2.5px solid var(--blue); border-radius: 10px; pointer-events: none; z-index: 1; }
.ln.tree { stroke: #A9B8CB; stroke-width: 1.2; }
.ln.ref { stroke: var(--blue); stroke-width: 1.8; }
.ln.gray { stroke: #9AAABD; }
.ln.green { stroke: var(--green); }
.ln.dashed { stroke-dasharray: 4 4; }
.ln.soft { stroke-opacity: .5; }
.arw-blue { fill: var(--blue); }
.arw-gray { fill: #9AAABD; }
.arw-green { fill: var(--green); }

.token {
  position: absolute; left: 0; top: 0; white-space: nowrap; z-index: 2;
  font-family: var(--font-sans); font-size: 13.5px; font-weight: 700; line-height: 1.3;
  padding: 6px 12px; border-radius: 6px; background: var(--blue); color: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .9), 0 4px 14px rgba(49, 95, 208, .35);
}
.token.k-ticket { border-left: 3px dotted rgba(255, 255, 255, .7); }
.token.k-packet { border-radius: 12px; padding: 4px 11px; }
.token.k-value { background: var(--green); box-shadow: 0 2px 8px rgba(33, 131, 107, .3); }
.token.k-signal { background: #fff; color: var(--blue); border: 1.5px solid var(--blue); }
.token.k-msg { border-radius: 4px 12px 12px 4px; }

.cursor { position: absolute; left: 0; top: 0; z-index: 3; width: 0; height: 0; }
.cursor-arrow { position: absolute; left: -1px; top: -1px; display: block; transition: transform .1s; }
.cursor-arrow svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .2)); }
.cursor.press .cursor-arrow { transform: scale(.86); }
.cursor-ring { position: absolute; left: 0; top: 0; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--blue); opacity: 0; }

.scene { position: relative; }
.region {
  position: relative; min-width: 0; background: var(--bg-panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px 12px;
  transition: background-color .25s ease, border-color .25s ease, box-shadow .25s ease, opacity .3s ease, transform .3s ease;
}
.region.is-active { border-color: var(--blue); box-shadow: inset 0 0 0 .5px var(--blue); background: var(--blue-bg); }
/* 지금 볼 곳 하나에 시선을 모은다: 나머지 영역은 흐리게 */
.stage.has-focus .region:not(.is-active):not(:has(.is-active)):not(.is-active .region) { opacity: .42; }
/* 아직 등장하지 않은 영역은 자리만 지킨다 */
.region.is-unborn, .is-unborn { opacity: 0 !important; transform: scale(.97); pointer-events: none; }
.region-term {
  font-size: 11.5px; font-weight: 600; color: var(--fg-2); padding: 1px 6px; border-radius: 4px;
  background: var(--sunk); border: 1px solid var(--line); white-space: nowrap;
}
.region-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; margin-bottom: 8px; }
.region-label { font-size: var(--fs-label); font-weight: 700; color: var(--fg); }
.region-sub { font-size: var(--fs-small); color: var(--fg-2); }
.group { border: 1px dashed var(--line-2); border-radius: 10px; padding: 8px 10px 10px; min-width: 0; }
.group-label { font-size: var(--fs-small); font-weight: 700; color: var(--fg-2); margin: 0 2px 8px; letter-spacing: .01em; }
/* 영역 이름 앞 아이콘. 글자 크기를 따라가고 줄 높이를 늘리지 않는다 */
.ico-i { display: inline-block; width: 1.15em; height: 1.15em; margin-right: .38em; vertical-align: -.2em; color: var(--blue); flex: none; }
.ico-i svg { display: block; width: 100%; height: 100%; }
.group-label .ico-i, .net-label .ico-i, .seg-btn .ico-i { color: inherit; }
.stack-cap b .ico-i { margin-right: .3em; }
.group-body { min-width: 0; }
.tag-note {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; line-height: 1.35; color: var(--fg-2);
  padding: 3px 8px; border-radius: 5px; background: var(--sunk); border: 1px solid var(--line);
}
.model-note { margin-top: 10px; font-size: 12px; color: var(--fg-3); text-align: right; }

/* 브라우저 창 */
.bw { border: 1px solid #C9D3E1; border-radius: 9px; background: #fff; overflow: hidden; min-width: 0; }
.bw-bar { display: flex; align-items: center; gap: 8px; padding: 7px 9px; background: #EFF3F8; border-bottom: 1px solid var(--line); }
.bw-dots { display: flex; gap: 4px; flex: none; }
.bw-dots i { width: 8px; height: 8px; border-radius: 50%; background: #CDD6E2; }
.bw-addr {
  flex: 1; min-width: 0; height: 27px; display: flex; align-items: center; gap: 6px; padding: 0 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 14px; font-family: var(--font-mono); font-size: 13px; color: var(--fg); white-space: nowrap; overflow: hidden;
}
.bw-lock { display: grid; place-items: center; color: var(--fg-3); flex: none; }
.bw-addr-text { overflow: hidden; text-overflow: clip; }
.caret { width: 1.5px; height: 15px; background: var(--blue); flex: none; margin-left: -4px; visibility: hidden; }
.caret.on { visibility: visible; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.bw-body { padding: 12px; min-height: 120px; }

/* 시뮬레이션 버튼(조작 불가 모형) */
.sim-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 14px;
  border-radius: 6px; border: 1px solid var(--blue); background: var(--blue); color: #fff; font-size: 13.5px; font-weight: 600; line-height: 1; user-select: none;
  transition: transform .12s, background-color .2s;
}
.sim-btn.is-pressed { transform: scale(.95); background: #2A53B8; }
button.sim-btn { cursor: pointer; }
button.sim-btn:disabled { cursor: not-allowed; background: #9BB0DE; border-color: #9BB0DE; opacity: 1; }

/* 콜 스택 */
.stack {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-height: 128px; padding: 6px 6px 6px;
  border: 1.5px solid var(--line-2); border-top: 0; border-radius: 0 0 8px 8px; background: var(--sunk);
}
.stack-list { display: flex; flex-direction: column-reverse; gap: 5px; }
.stack-empty { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; font-size: 12px; color: var(--fg-3); }
.frame {
  font-family: var(--font-mono); font-size: 13px; font-weight: 500; line-height: 1.3; padding: 6px 9px;
  background: #fff; border: 1px solid var(--line-2); border-radius: 5px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.frame.is-top { border-color: var(--blue); color: var(--blue); font-weight: 600; }
.frame.is-wait { border-style: dashed; }

/* 대기열 */
.queue {
  position: relative; display: flex; align-items: center; min-height: 42px; padding: 6px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--sunk);
}
.queue-list { display: flex; flex-wrap: wrap; gap: 6px; }
.queue-empty { font-size: 12px; color: var(--fg-3); padding-left: 4px; }
.ticket {
  display: inline-flex; align-items: stretch; font-family: var(--font-mono); font-size: 12.5px; font-weight: 500; line-height: 1.3;
  background: #fff; border: 1px solid var(--line-2); border-radius: 5px; white-space: nowrap; overflow: hidden;
}
.tk-no { padding: 4px 6px; color: var(--fg-3); border-right: 1.5px dotted var(--line-2); background: var(--sunk); }
.tk-label { padding: 4px 8px; color: var(--fg); }

/* 실행 흐름(메인 스레드) */
.lane { min-width: 0; }
.lane-track { position: relative; height: 8px; border-radius: 4px; background: #E6ECF4; overflow: visible; margin: 6px 0 8px; }
.lane-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--blue-soft); }
.lane-dot { position: absolute; top: -1px; left: -4px; width: 10px; height: 10px; border-radius: 50%; background: #B6C3D3; }
.lane.is-busy .lane-dot { background: var(--blue); }
.lane-status { font-family: var(--font-mono); font-size: 13px; color: var(--fg-2); line-height: 1.4; }
.lane.is-busy .lane-status { color: var(--blue); font-weight: 600; }

/* DOM 트리 */
.tree { display: flex; flex-direction: column; gap: 6px; }
.tnode { display: flex; min-width: 0; }
.node {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; font-family: var(--font-mono); font-size: 13px; line-height: 1.3;
  padding: 4px 8px; background: #fff; border: 1px solid var(--line-2); border-radius: 5px; flex-wrap: wrap; row-gap: 3px; transform-origin: left center;
}
.node > * { white-space: nowrap; }
.n-tag { color: var(--blue); font-weight: 600; }
.n-attr { color: var(--fg-2); }
.n-val { color: var(--fg); padding: 0 5px; border-radius: 4px; background: var(--sunk); font-weight: 600; }
.n-val.is-new, .val-new { background: var(--green-bg); color: var(--green); }
.node.is-changed { border-color: var(--green); }

/* 객체 */
.obj {
  display: inline-flex; flex-direction: column; font-family: var(--font-mono); font-size: 13px; line-height: 1.45;
  background: #fff; border: 1.5px solid var(--fg-2); border-radius: 7px; padding: 5px 10px; transform-origin: left center;
}
.obj-row { display: flex; gap: 6px; white-space: nowrap; }
.obj-key { color: var(--fg-2); }
.obj-val { color: var(--fg); font-weight: 600; }
.obj-brace { color: var(--fg-3); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; }
  .ind-spin::before { animation: none; border-color: var(--blue); }
  .pop .step-ind, .pop .ind-check path, .ex-next.is-shown > *, .next-arrow svg, .caret.on { animation: none !important; }
}

/* ===== 중간 너비 ===== */
@media (max-width: 1199px) and (min-width: 761px) {
  .main { grid-template-columns: 188px minmax(0, 1fr); grid-template-rows: max-content max-content; overflow: auto; align-content: start; }
  .center, .explain { min-height: auto; }
  .steps-panel { grid-row: 1 / span 2; align-self: start; position: sticky; top: 0; max-height: calc(100dvh - 160px); }
  .center { grid-column: 2; grid-template-rows: auto auto; overflow: visible; }
  .stage-scroll { overflow: auto; max-height: max(320px, calc(100dvh - 220px)); border-radius: var(--r-panel) var(--r-panel) 0 0; }
  .controls { border-radius: 0 0 var(--r-panel) var(--r-panel); }
  .explain { grid-column: 2; grid-row: 2; overflow: visible; }
}

/* ===== 모바일 ===== */
@media (max-width: 760px) {
  .app { height: auto; min-height: 100dvh; display: block; }
  .topbar { position: sticky; top: 0; z-index: 30; padding: 0 12px; gap: 8px; }
  .brand-text { display: none; }
  .top-left { gap: 8px; }
  .series-btn { max-width: calc(100vw - 200px); }
  .lang button { padding: 0 8px; height: 36px; }
  .series-btn { height: 36px; }
  /* 버튼 위치와 상관없이 화면 안에 들어오도록 화면 기준으로 띄운다 */
  .series-menu { position: fixed; top: 52px; left: 12px; right: 12px; width: auto; max-height: calc(100dvh - 64px); overflow-y: auto; }
  .ep-head { padding: 12px 12px 10px; }
  .ep-title { font-size: 21px; }
  .main { display: flex; flex-direction: column; gap: 10px; padding: 0 12px 20px; }
  .steps-panel { overflow-x: auto; overflow-y: hidden; padding: 6px; scroll-snap-type: x proximity; overscroll-behavior-x: contain; }
  .steps-head { display: none; }
  .steps-list { flex-direction: row; gap: 4px; width: max-content; }
  .step-item { scroll-snap-align: center; }
  .step-btn { white-space: nowrap; width: auto; min-height: 40px; padding: 7px 10px 7px 8px; }
  .center { display: block; overflow: hidden; }
  .stage-scroll { overflow-x: auto; overflow-y: visible; }
  .stage { padding: 14px 12px; }
  .controls { padding: 8px 10px; }
  .icon-btn, .play-btn { height: 40px; }
  .icon-btn { width: 40px; }
  .play-btn { min-width: 0; }
  .speed-btn { height: 38px; }
  .explain { overflow: visible; }
}
@media (max-width: 400px) {
  .counter { display: none; }
  .play-btn .play-txt { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
}

/* ===== JavaScript 실행 장면 공통 배치(2·4·5·6편) =====
   [사용자 화면] | 브라우저 내부: [DOM][보조 영역] / [대기열][메인 스레드] */
.jsl { display: grid; grid-template-columns: minmax(210px, .85fr) minmax(0, 2fr); gap: 28px; align-items: start; }
.jsl > .group > .group-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 18px 20px; align-items: stretch; }
.jsl .span2 { grid-column: 1 / -1; }
.jsl .col-q { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.jsl .col-q > .region { flex: 1; }
.thread-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(150px, 1fr); gap: 14px; align-items: end; }
.thread-left { min-width: 0; align-self: stretch; display: flex; flex-direction: column; justify-content: flex-end; gap: 8px; }
.thread-extra:empty { display: none; }
.stack-cap { margin-top: 6px; font-size: 12px; line-height: 1.35; color: var(--fg-2); text-align: center; }
.stack-cap b { display: block; font-size: 13px; color: var(--fg); margin-bottom: 3px; }
.rule-note { display: flex; align-items: flex-start; gap: 6px; margin-top: 8px; font-size: 12.5px; line-height: 1.45; color: var(--fg-2); }
.rule-note::before { content: ""; flex: none; width: 8px; height: 8px; margin-top: 5px; border-radius: 2px; border: 1.5px solid var(--line-2); }
.rule-note.is-on { color: var(--blue); font-weight: 600; }
.rule-note.is-on::before { border-color: var(--blue); background: var(--blue); }
.clock { margin-left: auto; font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; color: var(--fg-2); padding: 2px 8px; border-radius: 5px; background: var(--bg-panel); border: 1px solid var(--line); }
.group-label.has-clock { display: flex; align-items: center; gap: 8px; }
.ring-box { display: flex; align-items: center; gap: 10px; }
.ring { flex: none; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #E3E9F2; stroke-width: 5; }
.ring-arc { fill: none; stroke: var(--blue); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.ring-box.is-done .ring-arc { stroke: var(--green); }
.ring-label { font-family: var(--font-mono); font-size: 13px; color: var(--fg-2); line-height: 1.4; }
.ring-box.is-done .ring-label { color: var(--green); font-weight: 600; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.35;
  padding: 3px 8px; border-radius: 5px; background: #fff; border: 1px solid var(--line-2); color: var(--fg); white-space: nowrap; transform-origin: left center;
}
.chip .st { padding: 0 5px; border-radius: 4px; font-family: var(--font-sans); font-size: 12px; font-weight: 600; background: var(--sunk); color: var(--fg-2); }
.chip .st.ok { background: var(--green-bg); color: var(--green); }
.chip .st.wait { background: #FFF4E2; color: #8A5A12; }
.screen-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
@container (max-width: 620px) {
  .jsl { grid-template-columns: 1fr; gap: 18px; }
  .jsl > .group > .group-body { grid-template-columns: 1fr; }
  .thread-body { grid-template-columns: 1fr; }
}

/* ===== 보기 도구 줄, 다음 버튼, 용어 풀이, 참고 자료 ===== */
.center.has-toolbar { grid-template-rows: auto minmax(0, 1fr) auto; }
.center-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; background: var(--bg-panel); border-bottom: 1px solid var(--line); }
.next-btn { width: auto; padding: 0 8px 0 12px; gap: 2px; display: inline-flex; align-items: center; font-size: 14px; font-weight: 600; }
.next-txt { white-space: nowrap; }
.ex-tip { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--sunk); border: 1px solid var(--line); }
.ex-tip[hidden] { display: none; }
.tip-head { font-size: 12.5px; font-weight: 700; color: var(--fg-2); margin-bottom: 3px; }
.tip-text { margin: 0; font-size: 14.5px; line-height: 1.7; color: var(--fg); }
.ex-refs[hidden] { display: none; }
.ref-list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 6px; }
.ref-list a { font-size: 13.5px; color: var(--blue); text-decoration: none; }
.ref-list a:hover { text-decoration: underline; text-underline-offset: 3px; }
.ext { color: var(--fg-3); }
.thread-code { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.thread-code[hidden] { display: none; }
.thread-code span { font-size: 11.5px; font-weight: 600; color: var(--fg-3); }
.thread-code code { font-size: 12.5px; line-height: 1.45; padding: 4px 7px; border-radius: 5px; background: var(--blue-bg); color: var(--fg); border: 1px solid var(--blue-soft); overflow-wrap: anywhere; white-space: pre-wrap; }
@media (max-width: 1199px) and (min-width: 761px) {
  .center.has-toolbar { grid-template-rows: auto auto auto; }
  .center.has-toolbar .stage-scroll { max-height: max(300px, calc(100dvh - 274px)); }
}
@media (max-width: 760px) { .center.has-toolbar { grid-template-rows: auto auto auto; } }
@media (max-width: 760px) { .center-toolbar { padding: 8px 10px; } .next-txt { display: none; } .next-btn { width: 40px; padding: 0; justify-content: center; } }

/* ===== 중국어·일본어 ===== */
:root:lang(zh-CN) { --font-sans: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif; }
:root:lang(ja) { --font-sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", "Meiryo", system-ui, sans-serif; }
.lang-short { display: none; }
@media (max-width: 760px) {
  .lang-full { display: none; }
  .lang-short { display: inline; }
  .lang button { min-width: 34px; padding: 0 6px; }
}
