/* 파이썬 실행·편집기(pyrun.js) 공용 스타일. 교재와 탐구 학습지의 색 토큰을 모두 받아 쓴다. */
/* 코드 폰트(JetBrains Mono 등)의 합자 끄기: `->`가 `→`로, `!=`가 `≠`로 보이면 소스와 화면이 달라진다.
   font 단축 속성이 font-variant-ligatures를 초기화하므로 !important로 고정한다. */
*, *::before, *::after { font-variant-ligatures: none !important; font-feature-settings: "liga" 0, "calt" 0 !important; }
.pr, .pr-modal {
  --pr-mono: var(--font-code, var(--mono, ui-monospace, Menlo, Consolas, monospace));
  --pr-bad: var(--bad, #b3352b); --pr-ok: var(--ok, #2f6b3c);
  --pr-bg: var(--code-bg, var(--surface-2, #f3f1ec)); --pr-fg: var(--code-text, var(--text, #1d1d1d));
  --pr-on-accent: var(--accent-text, #fff);
  --pr-lh: 22px;   /* 편집기 줄 높이. 글자·행 번호·점선이 같은 격자에 놓이도록 정수 px 로 고정 */
}
.pr { margin: 12px 0; border: 1px solid var(--border); border-radius: var(--radius, 10px); overflow: hidden; background: var(--pr-bg); }
.pr-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.pr-btn {
  font-family: inherit; font-size: 13px; line-height: 1.4; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 6px; padding: 3px 10px; cursor: pointer;
}
.pr-btn:hover:not(:disabled) { border-color: var(--accent); }
.pr-btn:disabled { opacity: .5; cursor: default; }
.pr-btn.run { border-color: var(--pr-ok); color: var(--pr-ok); font-weight: 700; }
.pr-btn.stop { border-color: var(--pr-bad); color: var(--pr-bad); font-weight: 700; }
.pr-btn.ex { border-color: var(--accent); color: var(--accent); }
.pr-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--pr-on-accent); font-weight: 700; }
.pr-btn.small { padding: 0 8px; font-size: 12px; }
.pr-status { font-size: 12.5px; color: var(--muted); margin-left: 4px; }
textarea.pr-ta {
  display: block; width: 100%; border: 0; border-radius: 0; resize: vertical; min-height: 120px; max-height: 560px;
  background: var(--pr-bg); color: var(--pr-fg); padding: 14px 16px; margin: 0;
  font: 13.5px/var(--pr-lh) var(--pr-mono); tab-size: 4; white-space: pre; overflow: auto; outline: none;
}
textarea.pr-ta:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.pr-out { border-top: 1px solid var(--border); background: var(--surface); }
.pr-outhead { display: flex; justify-content: space-between; align-items: center; padding: 4px 10px; font-size: 12.5px; color: var(--muted); border-bottom: 1px dashed var(--border); }
.pr-pre { margin: 0; padding: 10px 16px; max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 13px/1.55 var(--pr-mono); color: var(--text); background: none; border: 0; border-radius: 0; }
.pr-err { color: var(--pr-bad); }
.pr-note, .pr-dim { color: var(--muted); }

/* 문법 강조 층: 투명 글자의 textarea 아래에 같은 글꼴·여백의 색칠된 pre 를 겹친다. 두 칸의 글꼴·여백·줄 높이는 반드시 같아야 한다. */
.pr-stack { position: relative; background: var(--pr-bg); }
.pr-stack pre.pr-hl, .pr-stack textarea.pr-ta {
  font: 13.5px/var(--pr-lh) var(--pr-mono); tab-size: 4; padding: 14px 16px; margin: 0; border: 0; border-radius: 0; letter-spacing: 0;
  white-space: pre; word-spacing: 0; text-indent: 0;
}
.pr-stack pre.pr-hl { position: absolute; inset: 0; overflow: hidden; pointer-events: none; color: var(--pr-fg); background: none; }
.pr-stack pre.pr-hl code { font: inherit; background: none; padding: 0; color: inherit; }
.pr-stack textarea.pr-ta { position: relative; background: transparent; color: transparent; caret-color: var(--pr-fg); }
.pr-stack textarea.pr-ta::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: transparent; }

/* 행 번호 칸 + 줄 사이 점선. 행 번호 칸(.pr-gutter)과 강조 층(.pr-hl)은 textarea 와 같은 글꼴·줄 높이·위쪽 여백을 써야 한다. */
.pr-edit { display: flex; align-items: stretch; }
.pr-edit > .pr-stack { flex: 1; min-width: 0; }
.pr-gutter {
  position: relative; flex: none; background: var(--surface-2); border-right: 1px solid var(--border);
  font: 13.5px/var(--pr-lh) var(--pr-mono); color: var(--muted); user-select: none; -webkit-user-select: none;
}
.pr-gutter pre.pr-gutter-pre {
  position: absolute; inset: 0; margin: 0; padding: 14px 10px 40px 0; overflow: hidden; text-align: right;
  font: inherit; color: inherit; background: none; border: 0; border-radius: 0; white-space: pre; tab-size: 4;
}
.pr-gutter code, .pr-stack pre.pr-hl code, .pr-static > pre code { position: relative; display: block; isolation: isolate; }
.pr-stack pre.pr-hl code, .pr-static > pre code { min-width: max-content; }
.pr-gutter code::before, .pr-stack pre.pr-hl code::before, .pr-static > pre code::before {
  content: ""; position: absolute; top: 0; z-index: -1; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--pr-lh) - 1px), var(--pr-rule, color-mix(in srgb, var(--muted, #888) 55%, transparent)) calc(var(--pr-lh) - 1px), var(--pr-rule, color-mix(in srgb, var(--muted, #888) 55%, transparent)) var(--pr-lh));
  -webkit-mask-image: repeating-linear-gradient(to right, #000 0, #000 2px, transparent 2px, transparent 5px);
          mask-image: repeating-linear-gradient(to right, #000 0, #000 2px, transparent 2px, transparent 5px);
}
.pr-gutter code::before { left: 0; right: -10px; bottom: 0; }
.pr-static > pre code::before { left: -16px; right: -16px; bottom: 0; }   /* 읽기 전용 코드: 끝에 덧붙은 줄이 없다 */
.pr-stack pre.pr-hl code::before { left: -16px; right: -16px; bottom: var(--pr-lh); }   /* 강조 층은 끝에 "\n" 한 줄이 더 붙어 있으니 그 줄은 제외 */

/* 읽기 전용 예제 코드 블록: 편집기와 같은 글꼴·줄 높이·여백이라야 행 번호와 점선이 글자와 맞는다. */
figure.code { --pr-mono: var(--font-code, ui-monospace, Menlo, Consolas, monospace); --pr-lh: 22px; }
.pr-static > pre { flex: 1; min-width: 0; padding: 14px 16px; font: 13.5px/var(--pr-lh) var(--pr-mono); }

/* 문법 강조 토큰 (pyhl.js 가 만든다). 색은 --tok-* 변수로만 정한다 → 라이트/다크 자동. 변수가 없으면 var() 의 두 번째 값(라이트 기본색)을 쓴다. */
.token.comment { color: var(--tok-comment, #6a737d); font-style: italic; }
.token.string { color: var(--tok-string, #1f6b3a); }
.token.triple-quoted-string { color: var(--tok-comment, #6a737d); }
.token.string-interpolation { color: var(--pr-fg, inherit); }
.token.keyword { color: var(--tok-keyword, #a3195b); }
.token.function, .token.builtin { color: var(--tok-func, #6639ba); }
.token.class-name { color: var(--tok-class, #8a4b08); }
.token.number, .token.boolean { color: var(--tok-number, #0b5c99); }
.token.decorator { color: var(--tok-deco, #b3561d); }
.token.operator, .token.punctuation { color: var(--muted, #656d76); }

/* 예시 코드 팝업 */
body.pr-lock { overflow: hidden; }
.pr-modal { position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, .5); display: flex; align-items: center; justify-content: center; padding: 20px; }
.pr-modal-panel {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  width: min(820px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.pr-modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.pr-modal-head h3 { margin: 0; font-size: 16px; }
.pr-grow { flex: 1; }
.pr-modal-note { margin: 0; padding: 8px 16px 0; font-size: 13px; color: var(--muted); }
pre.pr-modal-code {
  margin: 10px 16px 16px; padding: 14px 16px; overflow: auto; flex: 1; user-select: text; -webkit-user-select: text;
  background: var(--pr-bg); color: var(--pr-fg); border: 1px solid var(--border); border-radius: 8px;
  font: 13.5px/1.6 var(--pr-mono); white-space: pre; tab-size: 4;
}
pre.pr-modal-code code { background: none; padding: 0; font: inherit; color: inherit; }
@media print { .pr-bar, .pr-out, .pr-modal { display: none; } }

/* ---- 교재 전용: 예제 코드 블록의 실행 버튼, 연습문제 편집기 ---- */
/* 예제 코드 블록: 캡션 줄 오른쪽에 [▶ 실행] [■ 중지] 상태 [복사], 코드 아래에 출력 칸 */
figure.code figcaption .pr-btn.run { margin-left: auto; font-family: inherit; }
figure.code figcaption .pr-btn.run ~ .copy { margin-left: 0; }
figure.code figcaption .pr-status { font-family: var(--font-body, inherit); margin-left: 0; }
figure.code > .pr-out { border-top: 1px solid var(--border); }
.exercise .pr { margin: 18px 0; }

/* 교재: 본문 예제 코드는 편집기로 보인다(주석을 달 수 있고 자동 저장). 상자 테두리는 figure.code 가 이미 두르므로 편집기의 것은 없앤다. */
figure.code > .pr { margin: 0; border: 0; border-radius: 0; }
figure.code textarea.pr-ta, .code-pin textarea.pr-ta { max-height: none; }
.pr-saved { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
