:root {
  --bg: #f4f5f8;
  --card: #fff;
  --text: #1c2230;
  --muted: #6b7385;
  --line: #e3e6ee;
  --primary: #2d5bd7;
  --primary-soft: #e8eefc;
  --ok: #1a8f4a;
  --mid: #c98a00;
  --bad: #d12f2f;
  --c: #2d5bd7; --p: #8a3fd1; --i: #0f8f8a; --l: #d1652f;
  --paper: #fffdf6;
  --paper-line: #e4e8f2;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --card: #1b2029; --text: #e8ebf2; --muted: #9aa3b5; --line: #2c3340;
    --primary: #6d93ff; --primary-soft: #222d47;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pre { white-space: pre-wrap; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
#app { max-width: 820px; margin: 0 auto; padding: 0 16px calc(90px + var(--safe-b)); }
body[data-route="solve"] #app { max-width: none; padding: 0; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 2px 12px; padding-top: max(18px, env(safe-area-inset-top)); }
.top p { margin: 2px 0 0; font-size: 13px; }
.pad-x { padding: 0 2px; margin-top: 0; font-size: 14px; }
.dday { background: var(--primary); color: #fff; font-weight: 700; padding: 6px 12px; border-radius: 999px; font-size: 15px; white-space: nowrap; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.04); border: 1px solid var(--line); }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-h h2 { margin: 0; }
.card.hint { border-style: dashed; }
.card.hint p { margin: 6px 0 10px; font-size: 14px; }
.card.cont { display: flex; justify-content: space-between; align-items: center; background: var(--primary-soft); }
.card.cont small, .task small { display: block; color: var(--muted); font-size: 13px; }

.btn { border: 1px solid var(--line); background: var(--card); padding: 10px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; min-height: 44px; }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; margin: 8px 0; }
.btn:disabled { opacity: .4; cursor: default; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip.ghost { background: var(--primary-soft); border: 0; color: var(--primary); font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.actions.sticky { position: sticky; bottom: calc(76px + var(--safe-b)); background: var(--card); padding: 8px 0; margin-bottom: 0; }
.quick { display: flex; gap: 8px; margin-top: 12px; }
.quick .btn { flex: 1; }

.task { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.task:first-of-type { border-top: 0; }
.tip { background: #fff7e0; color: #6b4f00; border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 8px 0 0; }
@media (prefers-color-scheme: dark) { .tip { background: #3a3220; color: #f0d68a; } }

.bar-row { display: grid; grid-template-columns: 82px 1fr auto; align-items: center; gap: 10px; padding: 5px 0; font-size: 14px; }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar-num { color: var(--muted); font-size: 13px; min-width: 90px; text-align: right; }

.nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); z-index: 20; }
.nav-it { flex: 1; max-width: 150px; background: none; border: 0; padding: 8px 0 6px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer; }
.nav-it span { font-size: 21px; position: relative; }
.nav-it.on { color: var(--primary); font-weight: 700; }
.dot { position: absolute; top: -4px; right: -14px; background: var(--bad); color: #fff; font-style: normal; font-size: 11px; border-radius: 99px; padding: 0 5px; line-height: 16px; }

.filters { display: flex; flex-direction: column; gap: 8px; }
.filters .row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; align-items: center; }
.filters select, .search, textarea, .form input, .form select { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px 10px; }
.search { width: 100%; padding: 10px 12px; }
textarea { width: 100%; margin: 6px 0; }

.qlist { list-style: none; margin: 0; padding: 0; }
.qlist li { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 64px 12px 14px; margin-bottom: 8px; cursor: pointer; }
.qlist li:active { background: var(--primary-soft); }
.qmeta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }
.qline { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 15px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; color: #fff; font-weight: 600; white-space: nowrap; }
.tag.s-c { background: var(--c); } .tag.s-p { background: var(--p); } .tag.s-i { background: var(--i); } .tag.s-l { background: var(--l); }
.tag.ghost { background: var(--bg); color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
.tag.hot { background: #fff0e5; color: #c2410c; }
.st { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; }
.st.n { color: var(--muted); background: var(--bg); }
.st.o { color: var(--ok); background: #e6f6ec; }
.st.x { color: var(--bad); background: #fdeaea; }
.rrow { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.boxdots { display: inline-flex; gap: 3px; }
.boxdots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.boxdots i.on { background: var(--ok); }
.due { color: var(--bad); font-size: 13px; }

.tabs { display: flex; background: var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--text); }

.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.restdays { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-weight: 600; font-size: 14px; }
.restdays span { margin-right: 4px; }
.phasebar { display: flex; border-radius: 10px; overflow: hidden; font-size: 12px; font-weight: 700; color: #fff; text-align: center; margin: 4px 0 10px; }
.phasebar div { padding: 6px 4px; white-space: nowrap; overflow: hidden; }
.ph1 { --ph: #4c7cf0; } .ph2 { --ph: #9b5de5; } .ph3 { --ph: #e76f51; }
.phasebar .ph1, .phasebar .ph2, .phasebar .ph3 { background: var(--ph); }
.explain { padding-left: 18px; margin: 0 0 12px; font-size: 14px; }
.explain li { margin-bottom: 4px; }
.cal-head, .cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head span { text-align: center; font-size: 12px; color: var(--muted); }
.cd { min-height: 54px; border-radius: 8px; padding: 4px; font-size: 11px; display: flex; flex-direction: column; background: var(--bg); border-left: 3px solid var(--ph, transparent); }
.cd.empty { background: none; border: 0; }
.cd .dn { font-weight: 700; font-size: 12px; }
.cd .dl { color: var(--muted); line-height: 1.25; }
.cd.mock { background: #fdece6; } .cd.mock .dl { color: #c2410c; font-weight: 700; }
.cd.today { outline: 2px solid var(--primary); }
.cd.exam { background: var(--primary); color: #fff; } .cd.exam .dl { color: #fff; font-weight: 700; }
.cd.ph0 .dl { color: var(--muted); opacity: .6; }
@media (prefers-color-scheme: dark) { .cd.mock { background: #3d2a22; } }

.exams { list-style: none; padding: 0; margin: 0 0 10px; }
.exams li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.exams li span:first-child { font-weight: 600; flex: 1; }
.switch { display: flex; gap: 8px; align-items: center; font-size: 14px; }
details.more { margin-top: 12px; }
details summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.pvlist { list-style: none; padding: 0; margin: 0; }
.pvlist li { display: flex; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.pvlist li.off { opacity: .45; }
.pvlist select { font-size: 13px; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); }
.pvchk input { width: 20px; height: 20px; margin-top: 2px; }
.pvbody { flex: 1; min-width: 0; }
.pvbody ol { margin: 6px 0; padding-left: 20px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); background: #222a; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); background: rgba(28,34,48,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: 90vw; text-align: center; }

/* ── 풀이 화면 ── */
.solve { display: grid; height: 100vh; height: 100dvh; grid-template-rows: minmax(0, auto) minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
.qpanel { display: flex; flex-direction: column; min-width: 0; background: var(--card); border-bottom: 1px solid var(--line); max-height: 38vh; max-height: 38dvh; min-height: 0; }
.sbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.stitle { flex: 1; min-width: 0; line-height: 1.25; }
.stitle b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stitle small { color: var(--muted); }
.icon { border: 0; background: var(--bg); width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer; flex: none; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; background: var(--primary-soft); color: var(--primary); padding: 4px 10px; border-radius: 8px; }
.timer.warn { background: #fdeaea; color: var(--bad); }
.qscroll { overflow-y: auto; padding: 12px 16px; -webkit-overflow-scrolling: touch; flex: 1; min-height: 0; }
.qtext { font-size: 17px; font-weight: 600; margin: 6px 0 8px; line-height: 1.6; white-space: pre-wrap; }
.answer { border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 6px; }
.answer h3 small { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.points { list-style: none; padding: 0; margin: 0; }
.points li { border-radius: 8px; }
.points label { display: flex; gap: 10px; align-items: flex-start; padding: 7px 4px; cursor: pointer; }
.points input { width: 20px; height: 20px; flex: none; margin-top: 2px; accent-color: var(--ok); }
.points input:checked + span { color: var(--ok); }
.ex { margin: 8px 0; background: var(--bg); border-radius: 10px; padding: 8px 12px; }
.ex p { margin: 6px 0 0; font-size: 14px; }
.grade { display: flex; gap: 8px; margin: 12px 0 4px; }
.g { flex: 1; border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 0; font-weight: 700; cursor: pointer; min-height: 48px; }
.g.sug { border-style: dashed; }
.g-o.sug, .g-o.on { border-color: var(--ok); } .g-o.on { background: var(--ok); color: #fff; }
.g-p.sug, .g-p.on { border-color: var(--mid); } .g-p.on { background: var(--mid); color: #fff; }
.g-x.sug, .g-x.on { border-color: var(--bad); } .g-x.on { background: var(--bad); color: #fff; }
.snav { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 12px; border-top: 1px solid var(--line); }
.snav .btn { min-width: 96px; }
.star.on { background: #fdeaea; }

.padwrap { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.toolbar { display: flex; gap: 6px; padding: 6px 8px; align-items: center; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
.tg { display: flex; gap: 3px; align-items: center; padding-right: 6px; border-right: 1px solid var(--line); }
.tg.right { margin-left: auto; border: 0; padding: 0; }
.tb { border: 0; background: none; min-width: 44px; height: 44px; border-radius: 10px; cursor: pointer; font-size: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; padding: 0 4px; }
.tb small { font-size: 10px; color: var(--muted); }
.tb.on { background: var(--primary-soft); }
.tb.on small { color: var(--primary); font-weight: 700; }
.tb:disabled { opacity: .3; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--card); background: var(--c); box-shadow: 0 0 0 1px var(--line); cursor: pointer; margin: 0 2px; }
.sw.on { box-shadow: 0 0 0 2px var(--primary); }
.wd { width: 36px; height: 36px; border: 0; border-radius: 8px; background: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.wd i { width: var(--w); height: var(--w); border-radius: 50%; background: var(--text); }
.wd.on { background: var(--primary-soft); }
/* 풀이창(왼쪽, 늘 새 종이) | 필기창(오른쪽, 문제에 저장) */
.pads { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 8px calc(8px + var(--safe-b)); }
.padtabs { display: none; }
.padcol { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.padcol[data-pad="note"] { border-top: 3px solid #e0a800; }
.padcol[data-pad="scratch"] { border-top: 3px solid var(--primary); }
.padhead { display: flex; align-items: center; gap: 6px; padding: 2px 4px 2px 10px; border-bottom: 1px solid var(--line); min-height: 40px; }
.padhead b { font-size: 14px; white-space: nowrap; }
.padhead small { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ph-btns { margin-left: auto; display: flex; gap: 0; flex: none; }
.pb { border: 0; background: none; width: 36px; height: 36px; border-radius: 8px; font-size: 17px; cursor: pointer; }
.pb:disabled { opacity: .3; cursor: default; }
.padhost { flex: 1; min-height: 0; position: relative; }
.pad-scroll { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 8px 8px 12px; background: var(--bg); }
.padcol[data-pad="note"] .pad-paper { background-color: #fff8e6; }
@media (max-width: 700px) {
  .pads { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .padtabs { display: flex; background: var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
  .padtabs button { flex: 1; border: 0; background: none; padding: 6px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
  .pads[data-show="scratch"] .padtabs [data-v="scratch"], .pads[data-show="note"] .padtabs [data-v="note"] { background: var(--card); color: var(--text); }
  .pads[data-show="scratch"] .padcol[data-pad="note"], .pads[data-show="note"] .padcol[data-pad="scratch"] { display: none; }
}
.pad-paper {
  position: relative; background-color: var(--paper); border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.12);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line, 40px) - 1px), var(--paper-line) calc(var(--line, 40px) - 1px), var(--paper-line) var(--line, 40px));
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.pad-paper canvas { position: absolute; left: 0; top: 0; touch-action: none; }
.pad-live { pointer-events: none; }
.pad-more { display: block; margin: 12px auto 0; border: 1px dashed var(--line); background: none; border-radius: 10px; padding: 8px 16px; color: var(--muted); cursor: pointer; }

/* 태블릿 가로: 문제 왼쪽, 필기 오른쪽 */
@media (min-width: 900px) and (orientation: landscape), (min-width: 1100px) {
  .solve { grid-template-rows: none; grid-template-columns: minmax(250px, 26%) minmax(0, 1fr); }
  .qpanel { max-height: none; border-bottom: 0; border-right: 1px solid var(--line); }
}

/* 관심문제 별표 */
.starbtn { font-size: 22px; color: var(--muted); }
.starbtn.on { color: #f5a400; background: #fff4d6; }
.starmark { color: #f5a400; font-size: 15px; line-height: 1; }
@media (prefers-color-scheme: dark) { .starbtn.on { background: #3a3220; } }

/* 홈 과목별 풀기 */
button.bar-row { width: 100%; border: 0; background: none; text-align: left; cursor: pointer; border-radius: 10px; padding: 7px 6px; grid-template-columns: 82px 1fr auto 14px; font: inherit; color: inherit; }
button.bar-row:hover, button.bar-row.open { background: var(--primary-soft); }
button.bar-row:disabled { cursor: default; opacity: .5; }
.chev { color: var(--muted); font-size: 12px; text-align: right; }
.subj-menu { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 6px 10px 6px; }

/* 모의고사 안내 */
.mock-hint { background: var(--primary-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.6; margin: 8px 0; }
.mockbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.mockbar .btn { margin-left: auto; }
