/* Paper reader — tokens
   paper / ink-blue / highlighter. Korean pane is white paper, English pane is
   a slightly cooler sheet so the eye always knows which side it is on. */
:root {
  --bg: #e9edf1;
  --pane-ko: #ffffff;
  --pane-en: #f5f7f9;
  --ink: #1d2430;
  --muted: #687284;
  --rule: #d5dbe3;
  --pen: #284a96;            /* blue-black fountain-pen ink: links, refs, focus */
  --mark: #fff0a0;           /* highlighter */
  --mark-edge: #e9c93a;
  --warn: #a8442b;
  --fs: 17px;
  --split: 50%;
  --font-ko: "Source Serif 4", "Noto Serif KR", "AppleMyungjo", serif;
  --font-en: "Source Serif 4", "Noto Serif", Georgia, serif;
  --font-ui: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a; --pane-ko: #1a1e25; --pane-en: #161a20; --ink: #dde3ec; --muted: #8d97a8;
    --rule: #2b313b; --pen: #8fb0ff; --mark: rgba(255, 214, 70, .22); --mark-edge: #d9b43a; --warn: #f08d72;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151a; --pane-ko: #1a1e25; --pane-en: #161a20; --ink: #dde3ec; --muted: #8d97a8;
  --rule: #2b313b; --pen: #8fb0ff; --mark: rgba(255, 214, 70, .22); --mark-edge: #d9b43a; --warn: #f08d72;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-ui); -webkit-font-smoothing: antialiased; }
a { color: var(--pen); }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; border-radius: 2px; }
button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- toolbar */
.bar {
  height: 48px; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  border-bottom: 1px solid var(--rule); background: var(--bg); font-size: 13.5px;
}
.bar .home { text-decoration: none; color: var(--muted); white-space: nowrap; }
.bar .home:hover { color: var(--ink); }
.bar .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .progress { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar .tools { display: flex; gap: 4px; align-items: center; }
.tbtn {
  border: 1px solid transparent; background: none; padding: 5px 9px; border-radius: 6px; cursor: pointer;
  color: var(--muted); white-space: nowrap;
}
.tbtn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.tbtn[aria-pressed="true"] { color: var(--pen); border-color: color-mix(in srgb, var(--pen) 35%, transparent); }

/* ---------------------------------------------------------------- panes */
.reader {
  position: relative; height: calc(100% - 48px);
  display: grid; grid-template-columns: var(--split) 8px 1fr;
}
.reader.swapped .pane.ko { order: 3; }
.reader.swapped .divider { order: 2; }
.reader.swapped .pane.en { order: 1; }
.pane { overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; position: relative; }
.pane.ko { background: var(--pane-ko); }
.pane.en { background: var(--pane-en); }
.divider { background: var(--bg); cursor: col-resize; border-left: 1px solid var(--rule); border-right: 1px solid var(--rule); }
.divider:hover, .divider.drag { background: color-mix(in srgb, var(--pen) 25%, var(--bg)); }
.lang-tag {
  position: sticky; top: 0; z-index: 2; font-size: 12px; color: var(--muted); padding: 8px 20px;
  background: inherit; border-bottom: 1px solid color-mix(in srgb, var(--rule) 60%, transparent);
}
.pane.ko .lang-tag { background: var(--pane-ko); }
.pane.en .lang-tag { background: var(--pane-en); }

.doc { position: relative; max-width: 42em; margin: 0 auto; padding: 28px 32px 40vh; font-size: var(--fs); }
.pane.ko .doc { font-family: var(--font-ko); line-height: 1.85; word-break: keep-all; overflow-wrap: anywhere; }
.pane.en .doc { font-family: var(--font-en); line-height: 1.7; hyphens: auto; }

/* ---------------------------------------------------------------- blocks */
.doc > * { margin: 0 0 1em; }
.doc h1, .doc h2, .doc h3, .doc h4, .doc h5, .doc h6 { font-family: var(--font-ui); line-height: 1.35; font-weight: 700; }
.doc h1 { font-size: 1.55em; margin: .2em 0 1.1em; letter-spacing: -.01em; }
.doc h2 { font-size: 1.22em; margin: 2.1em 0 .8em; }
.doc h3 { font-size: 1.06em; margin: 1.7em 0 .6em; }
.doc h4, .doc h5, .doc h6 { font-size: 1em; margin: 1.4em 0 .5em; }
.doc p { text-align: left; }
.doc .note { font-size: .86em; color: var(--muted); padding-left: 1em; border-left: 2px solid var(--rule); }
.doc blockquote, .doc .quote { margin-left: 0; padding-left: 1em; border-left: 3px solid var(--rule); }
.doc ul, .doc ol { padding-left: 1.4em; }
.doc li { margin: .3em 0; }
.doc pre { font-size: .82em; overflow-x: auto; padding: .8em 1em; background: color-mix(in srgb, var(--ink) 5%, transparent); border-radius: 4px; }
.doc code { font-size: .88em; }

/* sentences */
.s { border-radius: 2px; transition: background-color .12s; cursor: default; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.s.hl { background: var(--mark); box-shadow: 0 0 0 2px var(--mark); }
.s.pin { background: var(--mark); box-shadow: inset 0 -2px 0 var(--mark-edge), 0 0 0 2px var(--mark); }
.s.untranslated { color: var(--muted); }
.s.untranslated::before { content: "원문"; font: 600 10px/1 var(--font-ui); color: var(--warn); border: 1px solid currentColor;
  border-radius: 3px; padding: 1px 3px; margin-right: 4px; vertical-align: 2px; }

/* equations */
.eq { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; margin: 1.1em 0 1.3em; cursor: copy; border-radius: 4px; }
.eq .body { overflow-x: auto; overflow-y: hidden; padding: 4px 0; text-align: center; }
.eq .label { font-family: var(--font-en); color: var(--muted); font-size: .92em; }
.eq:hover { background: color-mix(in srgb, var(--pen) 5%, transparent); }
.eq.flash { background: var(--mark); }
.katex-display { margin: 0; }
.katex { font-size: 1.06em; }

/* figures and tables */
figure.fig { margin: 1.6em 0 1.8em; }
figure.fig .imgs { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
figure.fig img { max-width: 100%; max-height: 70vh; cursor: zoom-in; background: #fff; border-radius: 2px; }
figure.fig .svg svg { max-width: 100%; height: auto; }
figure.fig figcaption, .tbl figcaption { font-size: .88em; line-height: 1.6; margin-top: .7em; color: var(--ink); }
.cap-label { font-family: var(--font-ui); font-weight: 700; margin-right: .4em; }
.tbl { margin: 1.6em 0; }
.tbl .scroll { overflow-x: auto; cursor: zoom-in; }
.tbl table { border-collapse: collapse; font-size: .84em; margin: 0 auto; font-family: var(--font-en); }
.tbl th, .tbl td { padding: 4px 10px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.tbl thead th { border-bottom: 1.5px solid var(--ink); }
.tbl figcaption { margin: 0 0 .5em; }

.bib { font-size: .84em; line-height: 1.55; padding-left: 1.6em; }
.bib li { margin: .35em 0; }
.bib li.flash { background: var(--mark); }

/* refs */
a.ref { text-decoration: none; color: var(--pen); border-bottom: 1px dotted color-mix(in srgb, var(--pen) 50%, transparent); cursor: pointer; }
a.ref:hover { border-bottom-style: solid; }

/* bridge between highlighted sentences across panes */
.bridge { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: visible; }
.bridge path { fill: none; stroke: var(--mark-edge); stroke-width: 1.5; }
.bridge circle { fill: var(--mark-edge); }

/* popover */
.pop {
  position: fixed; z-index: 30; max-width: min(560px, 90vw); max-height: 60vh; overflow: auto;
  background: var(--pane-ko); color: var(--ink); border: 1px solid var(--rule); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 25, 45, .18); padding: 12px 16px; font-size: 15px; font-family: var(--font-en);
}
.pop img { max-width: 100%; display: block; }
.pop .eq { cursor: default; margin: 0; }
.pop .pop-cap { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* re-translate one sentence */
.retry {
  position: fixed; z-index: 31; width: 22px; height: 22px; padding: 0; line-height: 1;
  border: 1px solid var(--rule); border-radius: 50%; cursor: pointer;
  background: var(--pane-ko); color: var(--muted); font: 13px/1 var(--font-ui);
  box-shadow: 0 2px 8px rgba(15, 25, 45, .16); opacity: .75; transition: opacity .12s, color .12s;
}
.retry:hover, .retry:focus-visible { opacity: 1; color: var(--pen); border-color: var(--pen); }
.retry[hidden] { display: none; }
.retry.busy { pointer-events: none; color: var(--pen); animation: retry-spin .9s linear infinite; }
@keyframes retry-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .retry.busy { animation: none; opacity: .5; } }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(10, 14, 20, .95); display: none; }
.lightbox.open { display: block; }
.lightbox .stage { position: absolute; inset: 0; overflow: hidden; cursor: grab; }
.lightbox .stage.grabbing { cursor: grabbing; }
.lightbox .stage > * { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.lightbox img { background: #fff; }
.lightbox .tablewrap { background: var(--pane-ko); padding: 16px; font-size: 16px; }
.lightbox .hint { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); color: #cfd6e2; font-size: 12.5px; }
.lightbox .close { position: absolute; top: 12px; right: 14px; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.lightbox .caption { position: absolute; left: 50%; transform: translateX(-50%); bottom: 40px; max-width: min(880px, 92vw);
  color: #e8edf5; font-size: 14px; line-height: 1.6; text-align: center; font-family: var(--font-ko); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--pane-ko);
  padding: 8px 14px; border-radius: 6px; font-size: 13px; opacity: 0; transition: opacity .2s; z-index: 50; pointer-events: none; }
.toast.show { opacity: 1; }

/* ---------------------------------------------------------------- library */
.lib { max-width: 860px; margin: 0 auto; padding: 56px 24px 80px; }
.lib h1 { font-size: 28px; margin: 0 0 6px; letter-spacing: -.01em; }
.lib .sub { color: var(--muted); margin: 0 0 32px; font-size: 14.5px; }
.lib .item { display: block; padding: 18px 0; border-top: 1px solid var(--rule); text-decoration: none; color: inherit; }
.lib .item:hover .t { color: var(--pen); }
.lib .t { font-family: var(--font-en); font-size: 19px; font-weight: 600; line-height: 1.4; }
.lib .tko { font-family: var(--font-ko); font-size: 15px; color: var(--muted); margin-top: 3px; }
.lib .m { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 8px; align-items: center; flex-wrap: wrap; }
.lib .meter { width: 90px; height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; }
.lib .meter i { display: block; height: 100%; background: var(--pen); }
.lib .empty { border: 1px dashed var(--rule); border-radius: 8px; padding: 24px; color: var(--muted); line-height: 1.7; }
.lib .empty code, .lib .sub code { background: color-mix(in srgb, var(--ink) 7%, transparent); padding: 2px 6px; border-radius: 4px; color: var(--ink); font-size: 13px; }

@media (max-width: 760px) {
  .reader { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .divider { display: none; }
  .pane.en { border-top: 1px solid var(--rule); }
  .doc { padding: 16px 16px 30vh; }
  .bar .progress, .tbtn .opt { display: none; }
  .bridge { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print { .bar, .divider, .pane.en { display: none; } .reader { display: block; height: auto; } .pane { overflow: visible; } }
