/* ==========================================================================
   Study notes (/studies/…): pages generated by scripts/vault_export.py.
   Loaded only on note pages and the Studies hub (see _includes/head.html).
   ========================================================================== */

.note-header {
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--rule);
}

.note-crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.note-crumbs a {
  text-decoration: none;
}

.note-crumbs a:hover {
  color: var(--course, var(--accent));
}

.note-crumbs a + span + a,
.note-crumbs a:last-child {
  color: var(--course, inherit);
  font-weight: 600;
}

.note-title {
  max-width: none;
  margin-top: 0.75rem;
  font-size: clamp(1.9rem, 4.5vw, 2.9rem);
  line-height: 1.2;
  word-break: keep-all;
}

.note-header .article-meta dd {
  margin: 0;
}

.note-aliases {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

/* -- body ---------------------------------------------------------------- */

.note-body {
  max-width: 50rem;
  font-size: 1.08rem;
  line-height: 1.8;
  word-break: keep-all;
}

/* the drop cap belongs to essays, not to notes */
.note-body > p:first-of-type::first-letter {
  float: none;
  font: inherit;
  padding: 0;
  color: inherit;
}

.note-body h2 {
  font-size: 1.5rem;
  margin-top: 2.4em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--rule);
}

.note-body h2::before {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  margin-right: 0.5em;
  vertical-align: 0.12em;
  background: var(--course, var(--accent));
}

.note-body h2:nth-of-type(3n + 2)::before { border-radius: 50%; }
.note-body h2:nth-of-type(3n)::before { clip-path: polygon(50% 0, 100% 100%, 0 100%); }

.note-body h3 {
  font-size: 1.2rem;
  margin-top: 1.8em;
}

.note-body ul,
.note-body ol {
  padding-left: 1.5em;
}

.note-body ul {
  list-style: disc;
}

.note-body ol {
  list-style: decimal;
}

.note-body ul ul {
  list-style: circle;
}

.note-body li + li,
.note-body li > ul,
.note-body li > ol {
  margin-top: 0.35em;
}

.note-body li > p + p {
  margin-top: 0.6em;
}

.note-body blockquote {
  margin: 0;
  padding: 0.2rem 0 0.2rem 1.1rem;
  border-left: 3px solid var(--rule);
  font-size: 1rem;
  font-style: normal;
  color: var(--ink-muted);
}

.note-body a {
  color: var(--course, var(--accent));
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.note-body code {
  padding: 0.1em 0.3em;
  border-radius: var(--radius);
  background: var(--bg-alt);
}

.note-body pre code {
  padding: 0;
  background: none;
}

.note-body pre {
  font-size: 0.86rem;
  line-height: 1.55;
}

.note-body mark {
  background: color-mix(in srgb, var(--accent-ochre) 30%, transparent);
  color: inherit;
}

.note-body table {
  font-size: 0.88rem;
  line-height: 1.55;
}

.note-body th {
  white-space: normal;
}

/* -- math ---------------------------------------------------------------- */

.note-body mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.2rem 0;
}

.note-body mjx-container:not([display="true"]) {
  white-space: nowrap;
}

/* -- callouts ------------------------------------------------------------ */

.callout {
  --callout: var(--accent-inkblue);
  padding: 0.85rem 1.1rem;
  border-left: 3px solid var(--callout);
  border-radius: var(--radius);
  background: var(--card);
  background: color-mix(in srgb, var(--callout) 7%, var(--card));
  font-size: 1rem;
}

.callout > * + * {
  margin-top: 0.7em;
}

.callout-title {
  font-weight: 600;
}

/* a folded question shows the whole prompt; only its label (**C1**) is bold */
summary.callout-title:not(.callout-title--default) {
  font-weight: 400;
}

.callout-title--default {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--callout);
}

.callout-summary { --callout: var(--course, var(--accent-inkblue)); }
.callout-info,
.callout-note { --callout: var(--accent-inkblue); }
.callout-definition,
.callout-theorem { --callout: var(--accent-ochre); }
.callout-proof { --callout: var(--accent-plum); }
.callout-example,
.callout-check,
.callout-tip { --callout: var(--accent-moss); }
.callout-question,
.callout-answer,
.callout-hint { --callout: var(--accent-inkblue); }
.callout-misconception,
.callout-warning,
.callout-important { --callout: var(--accent-rust); }

body[data-bg="midnight"] .callout {
  --accent-inkblue: #8fb3c7;
  --accent-ochre: #d8aa52;
  --accent-plum: #b892ba;
  --accent-moss: #9db57f;
  --accent-rust: #e0824f;
}

/* -- folds: callouts, answer lists, inline answers ----------------------- */

.note-body details > summary {
  cursor: pointer;
  list-style: none;
}

.note-body details > summary::-webkit-details-marker {
  display: none;
}

.note-body details > summary::before {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  margin-right: 0.6em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-0.15em) rotate(-45deg);
  transition: transform 0.15s ease;
  opacity: 0.6;
}

.note-body details[open] > summary::before {
  transform: translateY(-0.25em) rotate(45deg);
}

details.callout > summary {
  margin: -0.85rem -1.1rem;
  padding: 0.85rem 1.1rem;
}

details.callout[open] > summary {
  margin-bottom: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--callout) 20%, transparent);
}

details.callout[open] > summary + * {
  margin-top: 1.4em;
}

.answer-fold,
.inline-fold,
.note-body details:not([class]) {
  padding: 0.5rem 0.9rem;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  font-size: 1rem;
}

.inline-fold {
  margin-top: 0.4em;
}

.answer-fold > summary,
.inline-fold > summary,
.note-body details:not([class]) > summary {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.answer-fold[open] > summary,
.inline-fold[open] > summary,
.note-body details:not([class])[open] > summary {
  margin-bottom: 0.6em;
}

.answer-fold > * + *,
.note-body details:not([class]) > * + * {
  margin-top: 0.7em;
}

/* -- footnotes ------------------------------------------------------------ */

.note-body .footnotes {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink-muted);
}

.note-body .footnotes li + li {
  margin-top: 0.5em;
}

.note-body .footnote,
.note-body .reversefootnote {
  text-decoration: none;
}

/* "에이전트 보충." in the vault: something added beyond the course material */
.note-body .fn-tag {
  display: inline-block;
  margin-right: 0.3em;
  padding: 0 0.4em;
  border: 1px solid var(--rule);
  border-radius: 4px;
  font: 600 0.7rem/1.5 var(--font-sans);
  color: var(--ink-muted);
  vertical-align: 0.08em;
}

/* -- diagrams --------------------------------------------------------------- */

.note-body pre.mermaid {
  background: none;
  padding: 0;
  text-align: center;
}

.note-body pre.mermaid svg {
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

/* too wide to shrink without losing the text: scroll sideways (notes-mermaid.js) */
.note-body pre.mermaid.is-wide {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  text-align: left;
  padding-bottom: 0.4rem;
  margin-bottom: 0.3rem;
}

.note-body pre.mermaid.is-wide svg {
  display: block;
  margin: 0;
}

.note-body .mermaid-hint {
  margin: 0 0 1.4rem;
  font: 500 0.75rem var(--font-sans);
  color: var(--ink-muted);
  text-align: right;
}

/* edge labels: the page colour instead of white boxes */
.note-body pre.mermaid .edgeLabel,
.note-body pre.mermaid .edgeLabel p,
.note-body pre.mermaid .labelBkg {
  background-color: var(--bg) !important;
}

.note-body pre.mermaid .edgeLabel rect {
  fill: var(--bg) !important;
}

/* -- syntax highlighting (rouge) -------------------------------------------- */

.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: var(--ink-muted); font-style: italic; }
.highlight .k, .highlight .kn, .highlight .kd, .highlight .kc, .highlight .ow { color: var(--accent-plum); font-weight: 600; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sd, .highlight .si, .highlight .sa { color: var(--accent-moss); }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .il { color: var(--accent-rust); }
.highlight .nf, .highlight .fm, .highlight .nc { color: var(--accent-inkblue); font-weight: 600; }
.highlight .nb, .highlight .bp { color: var(--accent-ochre); }

body[data-bg="midnight"] .highlight {
  --accent-plum: #c9a3cb;
  --accent-moss: #a9c28a;
  --accent-inkblue: #9cc0d4;
}

/* -- Studies hub -------------------------------------------------------------- */

.study-track + .study-track {
  margin-top: 3.5rem;
}

.study-track__title {
  margin: 0 0 1rem;
  font-size: 1.5rem;
}

.course-row__counts {
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

@media (max-width: 560px) {
  .course-row__counts {
    order: 1;
    flex-direction: row;
    gap: 0.9em;
  }
}

.course-row:hover .index-list__title {
  color: var(--accent);
}

/* -- course roadmap --------------------------------------------------------- */

.note--course .note-body {
  max-width: 60rem;
}

.course-header {
  padding-top: clamp(3rem, 8vw, 6rem);
  padding-bottom: clamp(2rem, 5vw, 3rem);
}

.course-header .note-title {
  font-size: clamp(2.4rem, 6vw, 4.2rem);
}

.course-header .note-title::after {
  content: "";
  display: block;
  width: 3.5rem;
  height: 6px;
  margin-top: 1rem;
  background: var(--course);
}

.note--course .note-body table td:first-child {
  white-space: nowrap;
  color: var(--ink-muted);
}

/* -- Note sidebar: the course roadmap as contents (_layouts/note.html) ------
   Wide screens: flush against the left edge with no box, like the Studies
   contents; the note column moves right by the same width.
   Narrow screens: a drawer opened from the 목차 button. */
.note-toc {
  --toc-w: clamp(15rem, 19vw, 19.5rem);
  position: fixed;
  /* --toc-top: how much of the site header is still on screen (note-toc.js),
     so a long, scrolled list never slides under the logo */
  top: var(--toc-top, 0px);
  left: 0;
  z-index: 30;
  width: var(--toc-w);
  height: calc(100vh - var(--toc-top, 0px));
  padding: 1.5rem 1rem 2rem clamp(1rem, 1.8vw, 2rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  isolation: isolate;
  font-family: var(--font-sans);
}

.note-toc::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: var(--toc-w);
  height: 100vh;
  z-index: -1;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--bg) 88%, transparent) 0%,
    color-mix(in srgb, var(--bg) 75%, transparent) 70%,
    transparent 100%);
  pointer-events: none;
}

.note-toc ol,
.note-toc li {
  margin: 0;
  padding: 0;
  list-style: none;
}

.note-toc a {
  background-image: none !important;
  text-decoration: none;
}

.note-toc__top {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0 0 1rem;
}

/* folds the whole sidebar away (wide screens) or closes the drawer (narrow) */
.note-toc__hide {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0 0 0.1rem;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  border-radius: 6px;
  background: transparent;
  color: var(--ink-muted);
  font: 600 0.95rem/1 var(--font-sans);
  cursor: pointer;
}

.note-toc__hide:hover,
.note-toc__hide:focus-visible {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}

.note-toc__course {
  display: block;
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
}

.note-toc__course::after {
  content: "";
  display: block;
  width: 2rem;
  height: 2px;
  margin-top: 0.55rem;
  background: var(--course, var(--ink));
}

.note-toc__part summary {
  display: flex;
  gap: 0.4rem;
  padding: 0.3rem 0;
  cursor: pointer;
  list-style: none;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink-muted);
}

.note-toc__part summary::-webkit-details-marker {
  display: none;
}

.note-toc__part summary::before {
  content: "›";
  flex: none;
  width: 0.8rem;
  transition: transform 0.2s ease;
}

.note-toc__part[open] > summary::before {
  transform: rotate(90deg);
}

.note-toc__part.is-current > summary {
  color: var(--ink);
}

.note-toc__part > ol {
  margin: 0.2rem 0 0.6rem 0.35rem;
  padding-left: 0.75rem;
  border-left: 1px solid color-mix(in srgb, var(--ink) 16%, transparent);
}

.note-toc__link {
  position: relative;
  display: flex;
  gap: 0.45rem;
  padding: 0.24rem 0;
  font-size: 0.86rem;
  line-height: 1.35;
  color: var(--ink-muted);
}

.note-toc__link:hover {
  color: var(--ink);
}

.note-toc__no {
  flex: none;
  min-width: 1.4rem;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--course, var(--accent));
}

.note-toc__name {
  word-break: keep-all;
}

.note-toc__link.is-practice .note-toc__name::before {
  content: "연습 · ";
  color: var(--ink-muted);
}

.note-toc__link.is-current {
  color: var(--ink);
  font-weight: 600;
}

.note-toc__link.is-current::before {
  content: "";
  position: absolute;
  top: 0.25rem;
  bottom: 0.25rem;
  left: calc(-0.75rem - 2px);
  width: 3px;
  border-radius: 2px;
  background: var(--course, var(--accent));
}

/* this note's own headings, under its entry: one indent deeper, on their
   own thin rail, folded and unfolded by the small arrow beside the entry */
.note-toc__entry {
  display: flex;
  align-items: flex-start;
}

.note-toc__entry .note-toc__link {
  flex: 0 1 auto;
  min-width: 0;
}

.note-toc__fold {
  flex: none;
  width: 1.35rem;
  height: 1.35rem;
  margin: 0.15rem 0 0 0.35rem;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  border-radius: 5px;
  background: transparent;
  color: var(--course, var(--accent));
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.2s ease, color 0.2s ease;
}

.note-toc__fold:hover,
.note-toc__fold:focus-visible {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}

.note-toc__fold[aria-expanded="false"] {
  transform: rotate(-90deg);
}

.note-toc .note-toc__here {
  margin: 0.15rem 0 0.45rem 2.15rem;
  padding-left: 0.7rem;
  border-left: 1px dashed color-mix(in srgb, var(--ink) 22%, transparent);
}

.note-toc__here a {
  display: block;
  padding: 0.16rem 0;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--ink-muted);
}

.note-toc__here a.is-sub {
  padding-left: 0.85rem;
  font-size: 0.76rem;
}

.note-toc__here a.is-active {
  color: var(--course, var(--accent));
}

/* The 목차 pill: opens the drawer on narrow screens, and brings a folded
   sidebar back on wide ones. */
.note-toc-toggle {
  display: none;
  align-items: center;
  gap: 0.35rem;
  position: fixed;
  left: 1rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: 600 0.9rem var(--font-sans);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.note-toc-scrim {
  display: none;
}

/* The note column: header, text and prev/next share one left edge. */
.note-shell {
  --note-w: 50rem;
  --note-pad-r: 0px;
}

.note-shell .note-header {
  width: auto;
  max-width: none;
  /* the rule under the header runs on to the right edge of the page */
  margin-right: calc(-1 * var(--note-pad-r));
  padding-left: max(var(--gutter), calc((100% - var(--note-w)) / 2 + var(--gutter)));
  padding-right: calc(var(--gutter) + var(--note-pad-r));
}

.note-shell .note-title {
  max-width: calc(var(--note-w) - 2 * var(--gutter));
}

.note-shell .note-nav {
  max-width: var(--note-w);
}

@media (min-width: 1100px) {
  /* The sidebar's width is mirrored on the right while there is room, so the
     text column sits on the page's centre line (where the background is
     cleared for it) instead of being pushed right by the sidebar. */
  .note-shell.has-toc {
    --note-toc-w: clamp(15rem, 19vw, 19.5rem);
    --note-pad-r: clamp(0px, calc(100vw - var(--note-toc-w) - var(--note-w) - 2rem), var(--note-toc-w));
    padding-left: var(--note-toc-w);
    padding-right: var(--note-pad-r);
  }

  .note-toc {
    transition: opacity 0.2s ease, visibility 0s;
  }

  .note-toc-collapsed .note-toc {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0s 0.2s;
  }

  .note-toc-collapsed .note-shell.has-toc {
    --note-pad-r: 0px;
    padding-left: 0;
  }

  .note-toc-collapsed .note-toc-toggle {
    display: inline-flex;
    top: calc(var(--toc-top, 0px) + 1rem);
    z-index: 30;
  }
}

@media (max-width: 1099.98px) {
  .note-toc {
    top: 0;
    height: 100vh;
    width: min(20rem, 86vw);
    padding-top: 1.5rem;
    background: var(--bg);
    border-right: 1px solid var(--rule);
    box-shadow: 0 0 2rem rgba(0, 0, 0, 0.18);
    transform: translateX(-102%);
    transition: transform 0.25s ease;
    z-index: 960;
  }

  .note-toc::before {
    display: none;
  }

  body.note-toc-open .note-toc {
    transform: none;
  }

  .note-toc-toggle {
    display: inline-flex;
    bottom: 1rem;
    z-index: 940;
  }

  .note-toc-scrim {
    position: fixed;
    inset: 0;
    z-index: 955;
    background: rgba(0, 0, 0, 0.35);
  }

  body.note-toc-open .note-toc-scrim {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .note-toc {
    transition: none;
  }
}

/* -- Code panel (assets/js/code-panel.js) -------------------------------------
   A code link opens its code here instead of leaving the page.
   Wide screens: the page narrows by --code-panel-w and the panel sits beside
   it. Narrow screens: a sheet over the page. */

.note-code {
  margin-top: 1.1rem;
}

.note-code[hidden],
.note-code ul {
  display: none;
}

.note-code__btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.35rem 0.85rem;
  border: 1px solid color-mix(in srgb, var(--course, var(--accent)) 55%, transparent);
  border-radius: 999px;
  background: transparent;
  color: var(--course, var(--accent));
  font: 600 0.85rem var(--font-sans);
  cursor: pointer;
  transition: background 0.15s ease;
}

.note-code__btn:hover,
html.code-panel-open .note-code__btn {
  background: color-mix(in srgb, var(--course, var(--accent)) 12%, transparent);
}

.note-code__icon {
  font: 600 0.8em "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* the links that point at the code in view */
.note-body a.is-code-open {
  border-radius: 2px;
  background: color-mix(in srgb, var(--course, var(--accent)) 14%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--course, var(--accent)) 14%, transparent);
}

.code-panel {
  --code-bg: var(--bg-alt);
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 45; /* above the site header (40) */
  display: flex;
  flex-direction: column;
  width: var(--code-panel-w, 40vw);
  background: var(--bg);
  border-left: 1px solid var(--rule);
  box-shadow: -0.5rem 0 1.5rem rgba(0, 0, 0, 0.06);
  color: var(--ink);
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.code-panel[hidden] {
  display: none;
}

html.code-panel-open .code-panel {
  transform: none;
}

.code-panel:focus {
  outline: none;
}

html.code-panel-split body {
  padding-right: var(--code-panel-w);
}

/* 홍철 would sit on the text column; he steps out while the panel is open */
html.code-panel-split .robot {
  right: calc(var(--code-panel-w) + 16px);
  transition: opacity 0.2s ease;
}

html.code-panel-split .robot:not(.is-open) {
  opacity: 0;
  pointer-events: none;
}

/* the text column is no longer in the middle of the window, so the
   background keeps to the header band */
html.code-panel-split .geo-canvas--masked {
  --geo-clear: 200vw !important;
}

@media (min-width: 1100px) {
  html.code-panel-split .note-shell.has-toc {
    --note-pad-r: clamp(0px, calc(100vw - var(--code-panel-w) - var(--note-toc-w) - var(--note-w) - 2rem), var(--note-toc-w));
  }
}

html.code-panel-dragging,
html.code-panel-dragging * {
  cursor: col-resize !important;
  user-select: none !important;
}

/* the left edge: drag to resize */
.code-panel__grip {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -5px;
  z-index: 2;
  width: 10px;
  cursor: col-resize;
  touch-action: none;
}

.code-panel__grip::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 3px;
  width: 4px;
  height: 2.75rem;
  margin-top: -1.375rem;
  border-radius: 2px;
  background: var(--rule);
  transition: background 0.15s ease, height 0.15s ease;
}

.code-panel__grip:hover::after,
.code-panel__grip:focus-visible::after,
html.code-panel-dragging .code-panel__grip::after {
  background: var(--course, var(--accent));
}

.code-panel__grip:focus {
  outline: none;
}

/* tab strip */
.code-panel__bar {
  display: flex;
  align-items: stretch;
  flex: none;
  min-height: 2.75rem;
  border-bottom: 1px solid var(--rule);
  background: var(--code-bg);
}

.code-panel__tabs {
  position: relative; /* offsetParent for the tabs (code-panel.js revealTab) */
  display: flex;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.code-panel__tabs::-webkit-scrollbar {
  display: none;
}

.code-tab {
  display: flex;
  align-items: center;
  flex: none;
  max-width: 15rem;
  border-right: 1px solid var(--rule);
  color: var(--ink-muted);
}

.code-tab.is-active {
  position: relative;
  background: var(--bg);
  color: var(--ink);
}

.code-tab.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  background: var(--course, var(--accent));
}

.code-tab.is-active::after {
  /* covers the strip's bottom rule under the tab in view */
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 1px;
  background: var(--bg);
}

.code-tab__btn {
  min-width: 0;
  overflow: hidden;
  padding: 0 0.35rem 0 0.85rem;
  border: 0;
  background: none;
  color: inherit;
  font: 500 0.8rem/2.75rem "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}

.code-tab--list .code-tab__btn {
  padding-right: 0.85rem;
  font-family: var(--font-sans);
  font-weight: 600;
}

.code-tab__icon {
  margin-right: 0.35em;
}

.code-tab__x,
.code-panel__close {
  display: grid;
  place-items: center;
  flex: none;
  border: 0;
  background: none;
  color: var(--ink-muted);
  cursor: pointer;
}

.code-tab__x {
  width: 1.5rem;
  height: 1.5rem;
  margin-right: 0.35rem;
  border-radius: 3px;
  font-size: 1rem;
  line-height: 1;
}

.code-panel__close {
  width: 2.75rem;
  border-left: 1px solid var(--rule);
  font-size: 1.35rem;
}

.code-tab__x:hover,
.code-panel__close:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
}

.code-tab__btn:focus-visible,
.code-tab__x:focus-visible,
.code-panel__close:focus-visible {
  outline: 2px solid var(--course, var(--accent));
  outline-offset: -2px;
}

/* one view per tab */
.code-panel__views {
  position: relative;
  flex: 1;
  min-height: 0;
}

.code-panel__view {
  display: flex;
  flex-direction: column;
  position: absolute;
  inset: 0;
}

.code-panel__view[hidden] {
  display: none;
}

.code-panel__head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 1rem;
  align-items: start;
  flex: none;
  padding: 0.95rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--rule);
}

.code-panel__tag {
  grid-column: 1;
}

.code-panel__name {
  grid-column: 1;
  margin: 0;
  overflow-wrap: anywhere;
  font: 600 0.95rem/1.4 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.code-panel__parent {
  grid-column: 1;
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.code-panel__parent a {
  color: var(--course, var(--accent));
}

.code-panel__tools {
  display: flex;
  gap: 0.4rem;
  grid-column: 2;
  grid-row: 1 / span 3;
  align-self: center;
}

.code-panel__tool {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font: 500 0.8rem var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.code-panel__tool:hover {
  border-color: var(--course, var(--accent));
  color: var(--course, var(--accent));
}

.code-panel__tool.is-done {
  border-color: var(--course, var(--accent));
  background: color-mix(in srgb, var(--course, var(--accent)) 12%, var(--bg));
  color: var(--course, var(--accent));
}

.code-panel__status {
  margin: 1.25rem 1.1rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.code-panel__status a {
  color: var(--course, var(--accent));
}

.code-panel__retry {
  margin-left: 0.6rem;
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

/* the code: one scroller, the line numbers stay put when it moves sideways */
.code-view {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--code-bg);
}

.code-view:focus {
  outline: none;
}

.code-view:focus-visible {
  outline: 2px solid var(--course, var(--accent));
  outline-offset: -2px;
}

.code-view__inner {
  display: flex;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
}

.code-view__ln,
.code-view__src pre {
  margin: 0;
  padding: 0.9rem 0;
  border: 0;
  border-radius: 0;
  background: none;
  overflow: visible;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre;
  tab-size: 4;
}

.code-view__ln {
  position: sticky;
  left: 0;
  z-index: 1;
  flex: none;
  padding-right: 0.8rem;
  padding-left: 0.8rem;
  border-right: 1px solid var(--rule);
  background: var(--code-bg);
  color: color-mix(in srgb, var(--ink-muted) 70%, transparent);
  text-align: right;
  user-select: none;
}

.code-view__src {
  flex: 1 0 auto;
  padding: 0 1.1rem 0 0.9rem;
}

.code-view__src div,
.code-view__src code {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
}

/* 목록: the note's own code files */
.code-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.1rem;
}

.code-list__title {
  margin: 0 0 0.7rem;
  font: 600 0.85rem var(--font-sans);
  color: var(--ink-muted);
}

.code-list__items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.code-list__items li + li {
  margin-top: 0.45rem;
}

.code-list__item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.code-list__item:hover,
.code-list__item:focus-visible {
  border-color: var(--course, var(--accent));
  outline: none;
}

.code-list__item.is-open {
  border-left: 3px solid var(--course, var(--accent));
}

.code-list__role {
  font: 600 0.72rem var(--font-sans);
  letter-spacing: 0.04em;
  color: var(--course, var(--accent));
}

.code-list__name {
  overflow-wrap: anywhere;
  font: 500 0.88rem/1.4 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.code-panel-scrim {
  display: none;
}

/* narrow screens: a sheet that comes up over the page */
@media (max-width: 959.98px) {
  .code-panel {
    top: max(1.25rem, env(safe-area-inset-top));
    left: 0;
    z-index: 970; /* above the 목차 drawer (960) and the robot (950) */
    width: auto;
    border-top: 1px solid var(--rule);
    border-left: 0;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -0.5rem 2rem rgba(0, 0, 0, 0.18);
    transform: translateY(100%);
    overflow: hidden;
  }

  .code-panel__grip {
    display: none;
  }

  html.code-panel-sheet {
    overflow: hidden;
  }

  .code-panel-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 965;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .code-panel-scrim[hidden] {
    display: none;
  }

  html.code-panel-open .code-panel-scrim {
    opacity: 1;
  }

  .code-panel__head {
    padding: 0.8rem 0.9rem 0.75rem;
  }

  .code-view {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (prefers-reduced-motion: reduce) {
  .code-panel,
  .code-panel-scrim {
    transition: none;
  }
}

@media print {
  .code-panel,
  .code-panel-scrim,
  .note-code {
    display: none;
  }

  html.code-panel-split body {
    padding-right: 0;
  }
}
