/* 시안 B "따뜻한 노트 느낌" */
:root {
  --bg: #F3EBDD;
  --side: #EADFCB;
  --text: #3B3026;
  --muted: #6F5F4E;
  --accent: #8F4524;
  --card: #FBF7EF;
  --card-border: #D8C9AE;
  --rule: #D2C3A6;
  --margin: #D9897A;
  --btn-border: #B9A78C;
  --hl: #F6DF8E;
  --hl-text: #8F4524;
  --postit-a: #F4DC6B;
  --postit-b: #F9E98E;
  --postit-text: #4A3A12;
  --pink-a: #F2B8C0;
  --pink-b: #F8D0D5;
  --ok: #4F7A3A;
  --ok-bg: #E3EDD3;
  --no: #A63D2F;
  --no-bg: #F6DCD3;
  --shadow: rgba(80, 55, 30, .14);
  --serif: 'Noto Serif KR', 'Batang', 'AppleMyungjo', serif;
  --sans: 'Noto Sans KR', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #443C34;
  --side: #4F463C;
  --text: #F1E8D9;
  --muted: #CDBFAA;
  --accent: #EDAE80;
  --card: #52483D;
  --card-border: #6C5D4D;
  --rule: #706252;
  --margin: #C97E70;
  --btn-border: #93836E;
  --hl: #72612F;
  --hl-text: #F9EDC2;
  --postit-a: #D4B650;
  --postit-b: #DEC468;
  --postit-text: #33270A;
  --pink-a: #C98A93;
  --pink-b: #D69CA4;
  --ok: #B5D69A;
  --ok-bg: #4A5A3C;
  --no: #F0A595;
  --no-bg: #6A4238;
  --shadow: rgba(0, 0, 0, .28);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  display: grid;
  grid-template-columns: 300px 1fr;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.serif { font-family: var(--serif); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 12px 16px; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ───── 버튼 ───── */
.btn {
  min-height: 44px;
  padding: 8px 16px;
  border: 1.5px solid var(--btn-border);
  border-radius: 10px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 15px;
}
.btn:hover { background: color-mix(in srgb, var(--btn-border) 18%, transparent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--card); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; }
.btn.danger { color: var(--no); }
.btn.primary.danger { background: var(--no); border-color: var(--no); color: var(--card); }
.btn.pink { background: linear-gradient(160deg, var(--pink-a), var(--pink-b)); border-color: transparent; color: #4A2129; font-weight: 500; }

/* ───── 사이드바 ───── */
#sidebar {
  background: var(--side);
  display: flex; flex-direction: column;
  height: 100dvh;
  border-right: 1px solid var(--card-border);
  padding-top: env(safe-area-inset-top);
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px; }
.logo { width: 34px; height: 34px; border-radius: 8px; }
.app-name { font-size: 22px; font-weight: 700; }
#tree { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.tree-row {
  display: flex; align-items: center;
  padding-left: calc(var(--depth) * 16px);
  border-radius: 10px;
}
.tree-row.active { background: color-mix(in srgb, var(--hl) 75%, transparent); }
.tree-row.active .name { color: var(--hl-text); font-weight: 700; }
.twisty, .more {
  width: 36px; min-height: 44px; border: 0; background: none; cursor: pointer; color: var(--muted); flex: none;
}
.twisty-space { width: 36px; flex: none; }
.more { opacity: .55; font-size: 18px; }
.tree-row:hover .more, .tree-row.active .more { opacity: 1; }
.tree-label {
  flex: 1; min-width: 0; min-height: 44px; border: 0; background: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px; text-align: left; padding: 0 4px;
}
.tree-label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ico { flex: none; }
.side-foot {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--card-border);
}
#btn-theme { grid-column: span 2; }

/* ───── 본문 ───── */
#content { display: flex; flex-direction: column; height: 100dvh; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 20px 8px;
  min-height: 60px;
}
#btn-menu { display: none; font-size: 20px; width: 44px; padding: 0; }
#topbar-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.crumb { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.progress { font-family: var(--serif); font-weight: 700; font-size: 18px; color: var(--accent); margin-left: auto; white-space: nowrap; }
#main { flex: 1; overflow-y: auto; padding: 18px 28px calc(48px + env(safe-area-inset-bottom)); }

.bar { height: 4px; background: var(--rule); border-radius: 2px; margin: 0 auto 18px; max-width: 860px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ───── 종이 카드 ───── */
.paper {
  position: relative;
  max-width: 860px;
  margin: 14px auto 24px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 4px 20px 20px 4px;
  padding: 36px 40px 36px 92px;
  box-shadow:
    5px 5px 0 -1px var(--card), 5px 5px 0 0 var(--card-border),
    10px 10px 0 -1px var(--card), 10px 10px 0 0 var(--card-border),
    0 14px 28px var(--shadow);
}
/* 왼쪽 빨간 여백선 */
.paper::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 64px;
  border-left: 2px solid var(--margin); opacity: .8;
}
/* 바인더 펀칭 구멍 3개 */
.holes { position: absolute; left: 20px; top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: space-around; padding: 40px 0; }
.holes i {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg);
  box-shadow: inset 1px 2px 3px var(--shadow);
  border: 1px solid var(--card-border);
}
/* 노란 포스트잇 (과목) */
.postit {
  position: absolute; top: -12px; right: 28px;
  transform: rotate(3deg);
  background: linear-gradient(170deg, var(--postit-a), var(--postit-b));
  color: var(--postit-text);
  font-family: var(--serif); font-weight: 700; font-size: 14px;
  padding: 10px 16px 12px;
  max-width: 220px;
  box-shadow: 2px 4px 8px var(--shadow);
  border-radius: 1px 1px 2px 10px;
}
.paper h1 { font-size: 26px; margin: 4px 0 8px; padding-right: 200px; line-height: 1.35; }
.paper h2.sub { font-size: 19px; margin: 28px 0 6px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 18px 0; }
.node-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  min-height: 92px; padding: 14px 16px;
  border: 1px solid var(--card-border); border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 40%, var(--card));
  cursor: pointer; text-align: left;
}
.node-card:hover { border-color: var(--accent); }
.node-card .ico { font-size: 22px; }
.node-title { font-family: var(--serif); font-weight: 700; }

.row-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { border-bottom: 1px solid var(--rule); padding: 8px 2px; }
.stat .v { font-family: var(--serif); font-weight: 700; font-size: 26px; color: var(--accent); }
.stat .l { color: var(--muted); font-size: 13px; }

.q-list { list-style: none; padding: 0; margin: 0; }
.q-item button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  min-height: 46px; padding: 6px 4px;
  border: 0; border-bottom: 1px solid var(--rule); background: none; cursor: pointer; text-align: left;
}
.q-item .mark { width: 20px; text-align: center; color: var(--muted); font-weight: 700; flex: none; }
.q-item.ok .mark { color: var(--ok); }
.q-item.no .mark { color: var(--no); }
.q-item .qt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--rule); border-radius: 20px; padding: 1px 9px; white-space: nowrap; flex: none; }

/* ───── 문제 ───── */
.q-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.q-no { font-size: 15px; font-weight: 700; color: var(--accent); }
.q-text { font-family: var(--serif); font-size: 20px; line-height: 1.75; font-weight: 500; white-space: pre-wrap; margin: 4px 0 18px; padding-right: 150px; }
.hint { color: var(--muted); font-size: 14px; margin: -10px 0 8px; }

.choices { list-style: none; padding: 0; margin: 0; }
.choice {
  display: flex; gap: 12px; align-items: baseline;
  min-height: 52px; padding: 12px 6px 8px;
  border-bottom: 1.5px solid var(--rule);
  cursor: pointer; font-size: 17px;
}
.choice .num { color: var(--muted); flex: none; }
.choice .hl { padding: 0 3px; border-radius: 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.choice.selected .hl {
  background: linear-gradient(transparent 38%, var(--hl) 38%, var(--hl) 92%, transparent 92%);
  color: var(--hl-text); font-weight: 500;
}
.answered .choice { cursor: default; }
.choice.correct .hl { background: linear-gradient(transparent 38%, var(--ok-bg) 38%, var(--ok-bg) 92%, transparent 92%); color: var(--ok); font-weight: 700; }
.choice.correct .num::after { content: ' ✓'; color: var(--ok); }
.statements .choice { flex-wrap: wrap; }
.choice .why { flex-basis: 100%; padding-left: 32px; font-size: 14px; color: var(--muted); }
.choice.wrong .hl { text-decoration: line-through; text-decoration-color: var(--no); text-decoration-thickness: 2px; }

.ox-row { display: flex; gap: 18px; }
.ox-btn {
  width: 120px; height: 100px; font-family: var(--serif); font-size: 44px; font-weight: 700;
  border: 2px solid var(--btn-border); border-radius: 16px; background: none; cursor: pointer;
}
.ox-btn[aria-pressed="true"] { background: var(--hl); color: var(--hl-text); border-color: var(--hl); }
.ox-btn.correct { border-color: var(--ok); color: var(--ok); background: var(--ok-bg); }
.ox-btn.wrong { border-color: var(--no); color: var(--no); background: var(--no-bg); }

.field {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1.5px solid var(--btn-border); border-radius: 10px;
  background: color-mix(in srgb, var(--card) 70%, var(--bg)); color: var(--text);
  font: inherit; font-size: 17px;
}
textarea.field { resize: vertical; line-height: 1.7; }
.blank-input {
  font: inherit; font-family: var(--sans); font-size: 17px; color: var(--hl-text);
  width: 8em; min-height: 38px; margin: 0 4px; padding: 2px 6px;
  border: 0; border-bottom: 2px solid var(--accent); background: color-mix(in srgb, var(--hl) 35%, transparent);
  text-align: center; border-radius: 4px 4px 0 0;
}
.blank-extra { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.blank-extra .blank-input { width: 12em; }
.correct.blank-input, .correct.field { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.wrong.blank-input, .wrong.field { border-color: var(--no); background: var(--no-bg); color: var(--no); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 8px 16px;
  border: 1.5px solid var(--btn-border); border-radius: 22px; background: none; cursor: pointer; font-size: 16px;
}
.chip[aria-pressed="true"] { background: var(--hl); color: var(--hl-text); border-color: var(--hl); font-weight: 500; }
.chip.correct { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.chip.wrong { border-color: var(--no); background: var(--no-bg); color: var(--no); text-decoration: line-through; }
.pick-list { display: flex; flex-direction: column; gap: 4px; }
.pick-row { padding: 10px 0; border-bottom: 1.5px solid var(--rule); }
.pick-text { margin-bottom: 8px; font-size: 17px; }

.seq-answer { margin: 0 0 16px; padding-left: 28px; min-height: 52px; }
.seq-answer li { padding: 4px 0; border-bottom: 1.5px solid var(--rule); }
.seq-answer li.empty { list-style: none; margin-left: -28px; padding: 12px 0; }
.seq-item {
  min-height: 44px; width: 100%; text-align: left; border: 0; background: none; cursor: pointer; font-size: 17px; padding: 6px 4px;
}
.seq-item.correct { color: var(--ok); font-weight: 700; }
.seq-item.wrong { color: var(--no); text-decoration: line-through; }
.seq-pool { display: flex; flex-wrap: wrap; gap: 8px; }

.essay-input { min-height: 180px; }
.essay-reveal { margin-top: 18px; }
.label { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.model { border-left: 4px solid var(--postit-a); padding: 10px 14px; background: color-mix(in srgb, var(--postit-b) 22%, transparent); border-radius: 0 8px 8px 0; }
.model-text { white-space: pre-wrap; font-family: var(--serif); line-height: 1.8; }
.kw-box { margin-top: 16px; }
.kw-list { display: flex; flex-wrap: wrap; gap: 8px; }
.kw { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px; border: 1.5px solid var(--btn-border); border-radius: 22px; cursor: pointer; }
.kw input { width: 20px; height: 20px; accent-color: var(--accent); }
.score { color: var(--accent); margin-left: 6px; }

.q-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.feedback:empty { display: none; }
.feedback { margin-top: 20px; padding: 14px 18px; border-radius: 10px; }
.feedback.ok { background: var(--ok-bg); }
.feedback.ok strong { color: var(--ok); }
.feedback.no { background: var(--no-bg); }
.feedback.no strong { color: var(--no); }
.feedback .answer-line { margin-top: 4px; font-weight: 500; }
.feedback .explain { margin-top: 8px; white-space: pre-wrap; color: var(--text); }

/* ───── 노트 ───── */
.note-wrap { max-width: 900px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; }
.note-frame { flex: 1; min-height: 70vh; width: 100%; border: 1px solid var(--card-border); border-radius: 12px; background: #fff; margin-top: 10px; }

/* ───── 모달 · 토스트 ───── */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(40, 28, 18, .45);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: min(440px, 100%);
  background: var(--card); color: var(--text);
  border: 1px solid var(--card-border); border-radius: 16px;
  padding: 20px; box-shadow: 0 20px 40px var(--shadow);
  max-height: 90dvh; overflow-y: auto;
}
.modal h3 { font-family: var(--serif); margin: 0 0 12px; }
.modal p { margin: 0 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.menu-item {
  display: block; width: 100%; min-height: 48px; text-align: left; padding: 10px 12px;
  border: 0; border-bottom: 1px solid var(--rule); background: none; cursor: pointer; font-size: 16px;
}
.menu-item:last-child { border-bottom: 0; }
.menu-item.danger { color: var(--no); }
.menu-item:hover { background: color-mix(in srgb, var(--hl) 40%, transparent); }
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 12px 20px; border-radius: 12px; transition: .25s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#scrim { display: none; }

/* ───── 좁은 화면 (탭 세로, 폰) ───── */
@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; z-index: 40; left: 0; top: 0; width: min(320px, 86vw);
    transform: translateX(-100%); transition: transform .25s; box-shadow: 4px 0 20px var(--shadow);
  }
  body.drawer-open #sidebar { transform: none; }
  body.drawer-open #scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(40, 28, 18, .35); }
  #btn-menu { display: inline-flex; }
  #main { padding: 10px 16px 40px; }
  .paper { padding: 32px 18px 24px 52px; border-radius: 4px 14px 14px 4px; }
  .paper::before { left: 40px; }
  .holes { left: 10px; }
  .holes i { width: 16px; height: 16px; }
  .paper h1 { padding-right: 0; margin-top: 24px; font-size: 22px; }
  .q-text { padding-right: 0; font-size: 18px; margin-top: 24px; }
  .postit { right: 14px; font-size: 13px; padding: 8px 12px; max-width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
