/* ── 색 · 글꼴 ─────────────────────────────────── */
:root {
  --bg: #f4f2ed;
  --panel: #ffffff;
  --panel-2: #f9f8f5;
  --hover: #f1efea;
  --line: #e4e0d7;
  --line-2: #cfc9bc;
  --text: #1d1b18;
  --muted: #69645b;
  --faint: #9a958b;
  --accent: #2b5a8c;
  --accent-hover: #234c78;
  --accent-weak: #e9f0f8;
  --accent-line: #b9cde3;
  --on-accent: #ffffff;
  --ok: #2d7a4b;
  --ok-weak: #e7f4ec;
  --warn: #9a6a12;
  --warn-weak: #fbf2df;
  --danger: #b4412d;
  --danger-weak: #fbebe7;
  --mark: #ffe58f;
  --mark-text: #1d1b18;
  --paper: #fffefb;
  --shadow: 0 1px 2px rgba(30, 25, 15, .06), 0 4px 16px rgba(30, 25, 15, .06);
  --shadow-lg: 0 10px 40px rgba(30, 25, 15, .18);
  --ui: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  --serif: "AppleMyungjo", "Nanum Myeongjo", "NanumMyeongjo", "Batang", "Noto Serif KR", serif;
  --r: 10px;
  --top: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --panel: #1c1d20;
    --panel-2: #222327;
    --hover: #26282c;
    --line: #2f3136;
    --line-2: #43464d;
    --text: #ecebe7;
    --muted: #a9a69f;
    --faint: #77756f;
    --accent: #7fb0e6;
    --accent-hover: #9cc3ee;
    --accent-weak: #1e2b3b;
    --accent-line: #35506f;
    --on-accent: #0c1724;
    --ok: #6cc893;
    --ok-weak: #18291f;
    --warn: #e2b45c;
    --warn-weak: #2c2416;
    --danger: #ee8a76;
    --danger-weak: #33201c;
    --mark: #6d5a17;
    --mark-text: #fff6d6;
    --paper: #1f2023;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--ui);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
mark { background: var(--mark); color: var(--mark-text); border-radius: 2px; padding: 0 1px; }
[hidden] { display: none !important; }
::selection { background: var(--accent-line); }

/* ── 상단 막대 ─────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top);
  display: flex; align-items: center; gap: 28px; padding: 0 20px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
.brand svg { width: 24px; height: 24px; }
.brand svg rect { fill: var(--accent); }
.brand svg rect.l { fill: var(--panel); }
.tabs { display: flex; gap: 2px; height: 100%; }
.tabs a {
  display: flex; align-items: center; gap: 6px; padding: 0 14px; color: var(--muted);
  font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: 12px; font-weight: 700;
  background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center;
}
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.top-right .btn.on { background: var(--accent-weak); color: var(--accent); }
.status { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

#main { height: calc(100vh - var(--top)); }
.view { height: 100%; }
.view.page-scroll, .view:has(> .page) { overflow-y: auto; }

/* ── 공통 부품 ─────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer;
  font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.danger:hover { background: var(--danger-weak); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 42px; padding: 0 20px; font-size: 15px; }
.btn.on { background: var(--accent-weak); border-color: var(--accent-line); color: var(--accent); }
.btn svg { width: 16px; height: 16px; flex: none; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 7px; border: 0; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--panel); outline: none; transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; padding: 9px 11px; line-height: 1.65; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.select { padding-right: 28px; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label.field > span { padding-left: 1px; }

.seg { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--hover); gap: 2px; }
.seg button {
  border: 0; background: transparent; height: 28px; padding: 0 12px; border-radius: 7px; cursor: pointer;
  color: var(--muted); font-weight: 500; font-size: 13px;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 12px;
  font-size: 12px; background: var(--hover); color: var(--muted); white-space: nowrap; border: 1px solid transparent;
}
.chip.accent { background: var(--accent-weak); color: var(--accent); }
.chip.btn-chip { cursor: pointer; border-color: var(--line); background: var(--panel); height: 28px; font-size: 12.5px; }
.chip.btn-chip:hover { border-color: var(--line-2); }
.chip.btn-chip.on { background: var(--accent-weak); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }
.chip .x { border: 0; background: none; padding: 0; margin-left: 1px; cursor: pointer; color: inherit; opacity: .6; font-size: 14px; line-height: 1; }
.chip .x:hover { opacity: 1; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.sm { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty h3 { margin: 10px 0 6px; color: var(--text); font-size: 16px; }
.empty .big { font-size: 34px; opacity: .5; }
kbd {
  font-family: var(--ui); font-size: 11px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-2);
  border-bottom-width: 2px; background: var(--panel); color: var(--muted);
}
.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 알림 · 대화상자 */
#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1f2328; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: 13.5px; animation: up .18s ease-out; max-width: 560px;
}
.toast.error { background: #8c2f20; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }
.modal-back { position: fixed; inset: 0; background: rgba(10, 10, 12, .38); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(520px, 100%); max-height: 86vh; display: flex; flex-direction: column; }
.modal.wide { width: min(760px, 100%); }
.modal h3 { margin: 0; padding: 18px 20px 4px; font-size: 16px; }
.modal .m-body { padding: 10px 20px; overflow-y: auto; }
.modal .m-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }

/* ── 검색 화면 ─────────────────────────────────── */
.search-layout { display: grid; grid-template-columns: 248px minmax(360px, 430px) 1fr; height: 100%; }
.filters { border-right: 1px solid var(--line); padding: 18px 14px 40px 18px; background: var(--panel-2); }
.f-sec { margin-bottom: 22px; }
.f-title { display: flex; align-items: center; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; margin-bottom: 8px; }
.f-title .reset { margin-left: auto; font-weight: 500; color: var(--accent); cursor: pointer; border: 0; background: none; font-size: 12px; }
.tree { display: flex; flex-direction: column; }
.f-more > summary { cursor: pointer; list-style: none; }
.f-more > summary::before { content: "▸"; margin-right: 5px; font-size: 10px; }
.f-more[open] > summary::before { content: "▾"; }
.tnode { display: flex; align-items: center; gap: 4px; height: 29px; border-radius: 6px; padding-right: 6px; cursor: pointer; user-select: none; }
.tnode:hover { background: var(--hover); }
.tnode .tw { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; color: var(--faint); flex: none; border-radius: 4px; }
.tnode .tw svg { width: 13px; height: 13px; transition: transform .12s; }
.tnode.open .tw svg { transform: rotate(90deg); }
.tnode .cb {
  width: 15px; height: 15px; border-radius: 4px; border: 1.5px solid var(--line-2); flex: none; display: inline-flex;
  align-items: center; justify-content: center; background: var(--panel);
}
.tnode.on .cb, .tnode.implied .cb { background: var(--accent); border-color: var(--accent); }
.tnode.implied .cb { opacity: .45; }
.tnode .cb svg { width: 11px; height: 11px; color: var(--on-accent); display: none; }
.tnode.on .cb svg, .tnode.implied .cb svg { display: block; }
.tnode .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 4px; }
.tnode.top .nm { font-weight: 600; }
.tnode .ct { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.tchildren { padding-left: 16px; }
.years { display: flex; align-items: center; gap: 6px; }
.years .select { height: 32px; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.quick { display: flex; gap: 5px; margin-top: 7px; }

.results { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; background: var(--panel-2); }
.searchbar { padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 9px; border-bottom: 1px solid var(--line); background: var(--panel); }
.qbox { position: relative; }
.qbox svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--faint); }
.qbox input { height: 42px; padding-left: 38px; font-size: 15px; border-radius: 10px; }
.qbox .clear { position: absolute; right: 6px; top: 6px; }
.sb-row { display: flex; align-items: center; gap: 8px; }
.sb-row .hint { font-size: 12px; color: var(--faint); margin-left: auto; }
.active { display: flex; flex-wrap: wrap; gap: 5px; }
.rhead { padding: 9px 16px; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.rhead b { color: var(--text); }
.note { margin: 10px 12px 0; padding: 8px 12px; border-radius: 8px; background: var(--warn-weak); color: var(--warn); font-size: 12.5px; }
.hits { flex: 1; min-height: 0; padding: 8px 8px 30px; }
.hit {
  position: relative; padding: 11px 44px 11px 12px; border-radius: 9px; cursor: pointer; border: 1px solid transparent;
  margin-bottom: 2px;
}
.hit:hover { background: var(--hover); }
.hit.sel { background: var(--panel); border-color: var(--accent-line); box-shadow: var(--shadow); }
.hit .meta { font-size: 11.5px; color: var(--faint); display: flex; gap: 6px; align-items: center; }
.hit .meta .rank { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.hit .ttl { font-weight: 600; font-size: 14px; margin: 2px 0 3px; line-height: 1.4; }
.hit .wk { font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.hit .snip { font-size: 12.5px; color: var(--muted); line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hit .snip .in-q { font-size: 11px; font-weight: 700; color: var(--accent); }
.hit .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.hit .tags .chip { height: 20px; font-size: 11px; padding: 0 7px; }
.addbtn {
  position: absolute; right: 9px; top: 10px; width: 28px; height: 28px; border-radius: 50%;
  border: 1.5px solid var(--line-2); background: var(--panel); color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .12s;
}
.addbtn svg { width: 15px; height: 15px; }
.addbtn:hover { border-color: var(--accent); color: var(--accent); }
.addbtn.in { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.more { display: block; margin: 8px auto; }

.preview { min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.pv-head {
  display: flex; gap: 16px; align-items: flex-start; padding: 16px 28px 14px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.pv-exam { font-size: 12.5px; color: var(--muted); }
.pv-head h2 { margin: 3px 0 2px; font-size: 19px; letter-spacing: -.3px; line-height: 1.35; }
.pv-works { font-size: 13px; color: var(--muted); }
.pv-actions { display: flex; gap: 6px; margin-left: auto; flex: none; padding-top: 4px; }
.pv-scroll { flex: 1; min-height: 0; padding: 20px 28px 60px; }
.pv-info { max-width: 760px; margin: 0 auto 16px; display: grid; grid-template-columns: 56px 1fr; gap: 6px 10px; font-size: 13px; }
.pv-info dt { color: var(--faint); font-weight: 600; font-size: 12px; padding-top: 2px; }
.pv-info dd { margin: 0; line-height: 1.6; }
.pv-info .chips .chip { height: 22px; }

/* ── 시험지 모양 ───────────────────────────────── */
.paper {
  max-width: 760px; margin: 0 auto; background: var(--paper); border: 1px solid var(--line); border-radius: 6px;
  padding: 30px 38px 36px; box-shadow: var(--shadow); font-family: var(--serif); font-size: 15.5px; line-height: 1.85;
}
.paper .p-body { border: 1px solid var(--line-2); padding: 18px 22px; margin-bottom: 8px; }
.paper .p-instr { font-family: var(--ui); font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.paper .q-lead { margin-top: 24px; line-height: 1.7; }
.paper .rng { position: relative; border-left: 1.5px solid var(--text); margin: 4px 0 4px 2.6em; padding-left: 8px; }
.paper .rng .rl { position: absolute; left: -2.6em; top: 50%; transform: translateY(-50%); font-family: var(--ui); font-size: 12px; font-weight: 700; color: var(--muted); }
img.gl { height: 1.05em; vertical-align: -0.16em; display: inline !important; margin: 0 !important; padding: 0 !important; background: none !important; }
@media (prefers-color-scheme: dark) { img.gl { filter: invert(1) brightness(.92); } }
.paper p { margin: 0; }
.paper .pr { text-indent: 1em; text-align: justify; word-break: keep-all; }
.paper .vs { padding-left: .6em; }
.paper .fn { font-size: .86em; color: var(--muted); padding-left: 1em; text-indent: -1em; line-height: 1.6; }
.paper .src { text-align: right; font-size: .9em; color: var(--muted); }
.paper .gap { height: .7em; }
.paper figure { margin: 10px 0; text-align: center; }
.paper figure img { max-width: min(100%, 440px); height: auto; }
@media (prefers-color-scheme: dark) { .paper figure img { background: #fff; border-radius: 4px; padding: 4px; } }
.paper .q { margin-top: 24px; }
.paper .q-stem { line-height: 1.7; }
.paper .q-no { font-family: var(--ui); font-weight: 800; margin-right: 2px; }
.paper .pts { font-family: var(--ui); font-size: .82em; color: var(--muted); }
.paper .bogi { border: 1px solid var(--line-2); padding: 12px 18px; margin: 10px 0 6px; font-size: .95em; }
.paper .bogi-h { text-align: center; font-family: var(--ui); font-size: .85em; font-weight: 600; letter-spacing: .3em; margin-bottom: 6px; color: var(--muted); }
.paper .choices { list-style: none; margin: 8px 0 0; padding: 0 0 0 4px; }
.paper .choices li { display: flex; gap: .45em; line-height: 1.7; padding: 1px 4px; border-radius: 4px; }
.paper .choices li .cn { flex: none; }
.paper .choices li .ct { flex: 1; min-width: 0; }
.paper .choices li.ok { background: var(--ok-weak); color: var(--ok); font-weight: 700; }
.paper .q-ans { font-family: var(--ui); font-size: 12.5px; color: var(--muted); margin-top: 8px; padding: 6px 10px; background: var(--panel-2); border-radius: 6px; }
.paper .q-ans .sep { margin: 0 8px; color: var(--line-2); }
.paper .q-expl { font-family: var(--ui); font-size: 13px; line-height: 1.7; color: var(--muted); margin-top: 4px; padding: 8px 10px; border-left: 3px solid var(--line-2); }
.paper .attach img { max-width: 100%; }
.paper figure.crop { margin: 8px 0 0; text-align: left; }
.paper figure.crop img { max-width: 100%; width: 100%; }

/* ── 수업자료 화면 ─────────────────────────────── */
.cart-layout { display: grid; grid-template-columns: minmax(380px, 460px) 1fr; height: 100%; }
.cart-side { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel-2); min-height: 0; }
.cart-head { padding: 18px 18px 12px; }
.cart-head h2 { margin: 0; font-size: 18px; }
.cart-list { flex: 1; min-height: 0; padding: 0 12px 12px; }
.citem {
  display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 4px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 9px; margin-bottom: 6px;
}
.citem.drag { opacity: .4; }
.citem.over { border-color: var(--accent); box-shadow: 0 -2px 0 var(--accent); }
.citem .handle { cursor: grab; color: var(--faint); padding: 4px 2px; display: flex; }
.citem .handle svg { width: 16px; height: 16px; }
.citem .num { width: 22px; height: 22px; border-radius: 6px; background: var(--hover); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; color: var(--muted); }
.citem .ttl { font-weight: 600; font-size: 13.5px; line-height: 1.4; }
.citem .meta { font-size: 12px; color: var(--faint); }
.opts { padding: 14px 18px 18px; border-top: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 12px; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.switch input { display: none; }
.switch .sw { width: 30px; height: 18px; border-radius: 9px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch .sw::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .sw { background: var(--accent); }
.switch input:checked + .sw::after { transform: translateX(12px); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: 8px; height: 32px; }
.stepper button { width: 30px; height: 100%; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; }
.stepper span { min-width: 54px; text-align: center; font-variant-numeric: tabular-nums; font-size: 13px; }
.dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pdf-pane { position: relative; background: #525659; min-height: 0; }
.pdf-pane iframe { width: 100%; height: 100%; border: 0; display: block; }
.pdf-pane .loading { position: absolute; top: 14px; right: 18px; background: rgba(0,0,0,.65); color: #fff; padding: 6px 12px; border-radius: 16px; font-size: 12.5px; display: flex; gap: 8px; align-items: center; }
.pdf-pane .loading .spinner { border-color: rgba(255,255,255,.3); border-top-color: #fff; width: 13px; height: 13px; }
.pdf-pane .empty { color: #ddd; }

/* ── 편집 화면 ─────────────────────────────────── */
.edit-layout { display: grid; grid-template-columns: minmax(520px, 1fr) minmax(420px, 1fr); height: 100%; }
.edit-form { padding: 22px 28px 120px; border-right: 1px solid var(--line); }
.edit-form h2 { margin: 0 0 4px; font-size: 20px; }
.esec { margin-top: 26px; }
.esec > h3 { font-size: 13px; color: var(--muted); font-weight: 700; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; letter-spacing: .02em; }
.esec > h3 .spacer { flex: 1; }
.grid { display: grid; gap: 10px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: 2fr 1fr 1fr; }
.g5 { grid-template-columns: repeat(5, 1fr); }
.toolbar { display: flex; gap: 4px; padding: 5px; border: 1px solid var(--line-2); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--panel-2); }
.toolbar + .textarea { border-radius: 0 0 8px 8px; }
.body-ta { min-height: 340px; font-size: 14px; }
.works-row { display: grid; grid-template-columns: 64px 1.6fr 1fr 1fr .8fr 30px; gap: 6px; margin-bottom: 6px; }
.works-row .input { height: 32px; font-size: 13px; }
.qcard { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); margin-bottom: 12px; }
.qcard-h { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.qcard-h b { font-size: 15px; }
.qcard-b { padding: 12px; display: flex; flex-direction: column; gap: 9px; }
.ans-pick { display: inline-flex; gap: 3px; }
.ans-pick button { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; font-size: 14px; }
.ans-pick button.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.choice-row { display: flex; align-items: center; gap: 8px; }
.choice-row .cn { width: 18px; text-align: center; color: var(--muted); }
.choice-row .input { height: 32px; }
.savebar {
  position: fixed; bottom: 0; left: 0; width: 50%; min-width: 520px; padding: 12px 28px; display: flex; gap: 8px; align-items: center;
  background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line); z-index: 10;
}
.savebar .dirty { font-size: 12.5px; color: var(--warn); }
.edit-preview { padding: 22px 26px 60px; background: var(--bg); }
.edit-preview .paper { font-size: 14.5px; padding: 24px 28px; }
.picker { position: relative; }
.picker-list { position: absolute; z-index: 30; top: 38px; left: 0; right: 0; max-height: 300px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 9px; box-shadow: var(--shadow-lg); padding: 4px; }
.picker-list div { padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.picker-list div:hover, .picker-list div.hi { background: var(--hover); }
.picker-list div .lv { color: var(--faint); }

/* ── 가져오기 · 관리 ───────────────────────────── */
.page { max-width: 1120px; margin: 0 auto; padding: 26px 28px 80px; }
.page > h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.3px; }
.page > .sub { color: var(--muted); margin-bottom: 20px; }
.stats { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; min-width: 130px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }
table.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 12px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--panel-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; height: 22px; align-items: center; padding: 0 8px; border-radius: 11px; font-size: 11.5px; font-weight: 600; }
.pill.ok { background: var(--ok-weak); color: var(--ok); }
.pill.todo { background: var(--warn-weak); color: var(--warn); }
.pill.no { background: var(--danger-weak); color: var(--danger); }
.mgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mcard { padding: 18px 20px; }
.mcard h3 { margin: 0 0 4px; font-size: 15px; }
.mcard p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.mcard.full { grid-column: 1 / -1; }
.joblog { margin-top: 12px; background: #16181b; color: #cfd3d8; border-radius: 8px; padding: 10px 12px; font: 12px/1.6 ui-monospace, Menlo, monospace; max-height: 220px; white-space: pre-wrap; }
.jobres { margin-top: 10px; font-size: 13px; font-weight: 600; }
.jobres.ok { color: var(--ok); }
.jobres.error { color: var(--danger); }
.steps { margin: 6px 0 0; padding-left: 20px; line-height: 2; color: var(--text); font-size: 13.5px; }
.adv { margin-top: 22px; }
.adv > summary { cursor: pointer; font-weight: 600; padding: 10px 2px; color: var(--muted); }
.adv > summary:hover { color: var(--text); }
.adv-list { padding: 4px 2px 20px; }
.adv-list h4 { margin: 22px 0 8px; font-size: 13px; color: var(--muted); }
.adv-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ctree .crow { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 6px; border-radius: 6px; font-size: 13px; }
.ctree .crow:hover { background: var(--panel-2); }
.ctree .crow .n { margin-left: auto; color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12px; }
.ctree .crow .icon-btn { width: 24px; height: 24px; opacity: 0; }
.ctree .crow:hover .icon-btn { opacity: 1; }
.review { margin-top: 18px; }
.rv-item { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); margin-bottom: 8px; }
.rv-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.rv-head input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.rv-body { border-top: 1px solid var(--line); padding: 16px; background: var(--bg); }
.warns { background: var(--warn-weak); color: var(--warn); border-radius: 8px; padding: 10px 14px; font-size: 12.5px; margin-bottom: 12px; }
.warns summary { cursor: pointer; font-weight: 600; }

/* 바깥(학원) 접속에서는 이 컴퓨터에서만 되는 기능을 숨긴다 */
body.remote [data-local] { display: none !important; }
.alert { background: var(--danger-weak); color: var(--danger); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; font-size: 13.5px; }
.evlist { font-size: 12.5px; max-height: 260px; }
.evlist div { display: grid; grid-template-columns: 120px 110px 120px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.evlist .k-bad { color: var(--danger); font-weight: 600; }

/* 좁은 화면에서만 보이는 부품(필터 버튼, 휴대폰 전용 버튼) */
.filter-toggle, .f-foot, .f-shade, .ph-only { display: none !important; }

@media (max-width: 1180px) {
  .search-layout { grid-template-columns: 0 minmax(320px, 400px) 1fr; }
  .filters { position: fixed; z-index: 40; top: var(--top); bottom: 0; left: 0; width: 280px; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-lg); padding-bottom: 0; }
  .filters.open { transform: none; }
  .filters { display: flex; flex-direction: column; }
  .filters > * { flex: none; }
  .f-foot { margin-top: auto !important; }
  .filter-toggle { display: inline-flex !important; }
  .f-foot { display: block !important; position: sticky; bottom: 0; margin: 0 -14px 0 -18px; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)) 18px; background: var(--panel-2); border-top: 1px solid var(--line); }
  .f-foot .btn { width: 100%; }
  .filters.open ~ .f-shade { display: block !important; position: fixed; inset: var(--top) 0 0 0; z-index: 39; background: rgba(10, 10, 12, .32); }
}

/* ── 휴대폰 ────────────────────────────────────── */
@media (max-width: 760px) {
  :root { --top: 52px; }
  #main { height: calc(100vh - var(--top)); height: calc(100dvh - var(--top)); }
  .view { overflow-y: auto; }
  .ph-only { display: inline-flex !important; }
  .pc-only { display: none !important; }

  /* 상단 막대: 로고만 남기고 탭을 짧게 */
  .topbar { gap: 2px; padding: 0 6px 0 14px; padding-top: env(safe-area-inset-top); height: calc(var(--top) + env(safe-area-inset-top)); }
  .brand span, .tabs .n, .top-right .lbl, .status { display: none !important; }
  .tabs { flex: 1; justify-content: center; }
  .tabs a { padding: 0 12px; font-size: 15px; white-space: nowrap; }
  .top-right { margin-left: 0; gap: 0; }
  .top-right .btn { width: 42px; height: 42px; padding: 0; }
  .top-right .btn svg { width: 20px; height: 20px; }

  /* 손가락으로 누르기 좋은 크기 · 입력할 때 화면이 확대되지 않게 16px */
  .input, .select, .textarea { font-size: 16px; }
  .input, .select { height: 42px; }
  .btn { height: 40px; }
  .btn.sm { height: 36px; padding: 0 12px; }
  .btn.lg { height: 48px; }
  .icon-btn { width: 40px; height: 40px; }
  .seg button { height: 32px; }
  .chip.btn-chip { height: 34px; padding: 0 12px; font-size: 13.5px; }
  .row { flex-wrap: wrap; }
  .toast { max-width: calc(100vw - 24px); }
  .modal-back { padding: 12px; align-items: flex-end; }
  .modal .m-foot .btn { flex: 1; }

  /* 검색: 결과 목록 한 줄, 지문을 누르면 시험지가 화면 전체로 열림 */
  .search-layout { grid-template-columns: 1fr; }
  .results { border-right: 0; }
  .searchbar { padding: 10px 12px 8px; }
  .qbox input { height: 46px; }
  .qbox .clear { top: 3px; right: 3px; }
  .sb-row { flex-wrap: wrap; }
  .sb-row .hint { display: none; }
  .filter-toggle { margin-left: auto; }
  .filters { width: min(330px, 88vw); }
  .tnode { height: 40px; }
  .tnode .cb { width: 19px; height: 19px; }
  .rhead { padding: 8px 14px; }
  .rhead .faint { display: none; }
  .hits { padding: 6px 6px 40px; }
  .hit { padding: 12px 54px 12px 12px; border-color: var(--line); background: var(--panel); margin-bottom: 6px; }
  .hit.sel { box-shadow: none; }
  .addbtn { width: 40px; height: 40px; right: 8px; top: 50%; transform: translateY(-50%); }
  .addbtn svg { width: 18px; height: 18px; }
  .preview { position: fixed; inset: 0; z-index: 60; transform: translateX(100%); visibility: hidden; transition: transform .2s, visibility .2s; }
  .preview.open { transform: none; visibility: visible; }
  .pv-head { flex-wrap: wrap; gap: 6px 8px; padding: 8px 10px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .pv-head .grow { flex-basis: 100%; order: 2; padding: 0 4px; }
  .pv-head h2 { font-size: 17px; }
  .pv-actions { order: 1; margin-left: auto; padding-top: 0; gap: 4px; }
  .pv-actions .btn { padding: 0 10px; }
  .pv-back { order: 0; }
  .pv-scroll { padding: 12px 8px calc(40px + env(safe-area-inset-bottom)); }
  .pv-info { grid-template-columns: 46px 1fr; padding: 0 6px; }
  .paper { padding: 18px 14px 22px; font-size: 15px; line-height: 1.8; border-radius: 4px; }
  .paper .p-body { padding: 12px 12px; }
  .paper .bogi { padding: 10px 12px; }
  .paper .rng { margin-left: 2.1em; padding-left: 6px; }
  .paper .rng .rl { left: -2.1em; }

  /* 수업자료: 한 줄로 쌓고, PDF는 버튼으로 새 창에서 */
  .cart-layout { display: block; height: auto; }
  .cart-side { border-right: 0; }
  .cart-head { padding: 16px 14px 10px; }
  .cart-list { padding: 0 10px 12px; }
  .citem { padding: 8px 4px 8px 10px; gap: 8px; }
  .citem .handle { display: none; }
  .citem .icon-btn { width: 36px; height: 36px; }
  .citem .mv { display: flex; flex-direction: column; }
  .citem .mv .icon-btn { height: 26px; }
  .citem .mv .icon-btn:disabled { opacity: .25; }
  .pdf-pane { display: none; }
  .opts { padding: 16px 14px calc(28px + env(safe-area-inset-bottom)); gap: 14px; }
  .toggles { gap: 14px 10px; }
  .toggles > .row { grid-column: 1 / -1; }
  .switch { font-size: 14px; min-height: 28px; }
  .switch .sw { width: 38px; height: 22px; border-radius: 11px; }
  .switch .sw::after { width: 18px; height: 18px; }
  .switch input:checked + .sw::after { transform: translateX(16px); }
  .stepper { height: 40px; }
  .stepper button { width: 42px; }
  .dl .ph-only { grid-column: 1 / -1; }

  /* 편집: 입력란 → 미리보기 순서로 한 줄 */
  .edit-layout { display: block; height: auto; }
  .edit-form { padding: 16px 14px 24px; border-right: 0; overflow: visible; }
  .edit-preview { padding: 16px 8px calc(96px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); overflow: visible; }
  .edit-preview .paper { padding: 18px 14px; }
  .g3 { grid-template-columns: 1fr 1fr; }
  .g3 > :first-child { grid-column: 1 / -1; }
  .g5 { grid-template-columns: 1fr 1fr; }
  .esec > h3 { flex-wrap: wrap; }
  .works-row { grid-template-columns: 1fr 1fr 40px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
  .works-row.faint { display: none; }
  .works-row .input { height: 40px; font-size: 16px; }
  .works-row .input:nth-child(2) { grid-column: 2 / 4; grid-row: 1; }
  .works-row .icon-btn { grid-column: 3; grid-row: 3; }
  .toolbar { flex-wrap: wrap; }
  .body-ta { min-height: 260px; }
  .qcard-h { flex-wrap: wrap; }
  .qcard-h > .grow { flex-basis: 60%; }
  .ans-pick button { width: 36px; height: 36px; }
  .choice-row .input { height: 40px; }
  .savebar { width: 100%; min-width: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .savebar .dirty { order: 5; flex-basis: 100%; }

  /* 설정 */
  .page { padding: 18px 14px calc(60px + env(safe-area-inset-bottom)); }
  .page > h1 { font-size: 20px; }
  .mgrid { grid-template-columns: 1fr; }
  .mcard { padding: 16px 14px; }
  .mcard .input { max-width: none !important; flex: 1 1 140px; }
  .mcard .row > .btn.primary { flex: 1 1 100%; }
  .mcard .spacer { display: none; }
  .steps { padding-left: 18px; }
  .adv-row { flex-wrap: wrap; gap: 8px; }
  .adv-row > div:first-child { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
  .stat { flex: 1 1 40%; min-width: 0; }
  table.tbl { display: block; overflow-x: auto; white-space: nowrap; }
  .evlist div { grid-template-columns: auto 1fr; gap: 2px 10px; padding: 6px 0; }
  .evlist div > :nth-child(4) { grid-column: 1 / -1; overflow-wrap: anywhere; }
  .ctree .crow .icon-btn { opacity: 1; }
}
