:root {
  --ink: #1d2733;
  --muted: #52606d;
  --paper: #f6f4ee;
  --white: #ffffff;
  --line: #d5d9cf;
  --brand: #17624f;
  --brand-dark: #0f4a3b;
  --brand-soft: #e1f0ea;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --bad: #a4261c;
  --good: #17624f;
  --mono: "D2Coding", "Cascadia Mono", Consolas, "Courier New", monospace;
  --sans: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans CJK KR", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-dark); }
a:hover { color: var(--brand); }
:focus-visible { outline: 3px solid #1b6ef3; outline-offset: 2px; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .6rem; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1rem; overflow-wrap: anywhere; }

.shell { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* ---------- 헤더·푸터 ---------- */
.site-header { background: var(--white); border-bottom: 1px solid var(--line); }
.site-header .shell { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1.5rem; padding-top: .6rem; padding-bottom: .6rem; }
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--brand-dark); }
.site-nav { display: flex; flex-wrap: wrap; gap: .1rem .3rem; }
.site-nav a { display: inline-block; padding: .4rem .65rem; border-radius: 8px; text-decoration: none; color: var(--ink); font-size: .98rem; }
.site-nav a:hover { background: var(--brand-soft); }
.site-nav a[aria-current="page"] { background: var(--brand); color: #fff; }
.site-footer { margin-top: 3rem; padding: 1.5rem 0 2.5rem; border-top: 1px solid var(--line); background: var(--white); color: var(--muted); font-size: .92rem; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; margin-bottom: .5rem; }
.site-footer a { color: var(--ink); }

main { padding-top: 1.5rem; }
.hero { padding: 1rem 0 .5rem; }
.hero p { max-width: 46rem; }
.section { margin-top: 2.2rem; }
.lede { font-size: 1.05rem; }

/* ---------- 카드·버튼 ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .9rem; padding: 0; margin: 0; list-style: none; }
.card { display: block; height: 100%; padding: 1rem 1.1rem; background: var(--white); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--ink); }
.card:hover { border-color: var(--brand); }
.card strong { display: block; font-size: 1.05rem; color: var(--brand-dark); margin-bottom: .2rem; }
.card span { color: var(--muted); font-size: .94rem; }

.btn { display: inline-block; font: inherit; font-weight: 700; padding: .6rem 1.1rem; border-radius: 10px; border: 2px solid var(--brand); background: var(--white); color: var(--brand-dark); cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { background: var(--brand-soft); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; margin: .8rem 0; }
.status { min-height: 1.5rem; color: var(--muted); font-size: .95rem; margin: 0; }
.notice { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: .7rem 1rem; }

.article { background: var(--white); border: 1px dashed var(--line); border-radius: 12px; padding: 1rem 1.2rem; margin: 1.5rem 0; }
.steps { padding-left: 1.3rem; }
.steps li { margin-bottom: .4rem; }

/* ---------- 설정 패널 ---------- */
.layout-2 { display: grid; grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.settings { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.settings fieldset { border: 0; padding: 0; margin: 0 0 .9rem; min-width: 0; }
.settings legend { font-weight: 700; padding: 0; margin-bottom: .3rem; }
.field { margin-bottom: .8rem; }
.field label { display: block; font-weight: 700; font-size: .95rem; margin-bottom: .2rem; }
.field small { display: block; color: var(--muted); font-size: .85rem; }
.field input[type="text"], .field select { width: 100%; font: inherit; padding: .5rem .6rem; border: 1px solid #8a94a0; border-radius: 8px; background: #fff; color: var(--ink); min-height: 44px; }
.check { display: flex; align-items: center; gap: .5rem; min-height: 36px; font-weight: 400 !important; }
.check input { width: 1.15rem; height: 1.15rem; flex: none; }
.check-row { display: flex; flex-wrap: wrap; gap: .1rem 1rem; }
.settings .btn-row .btn { flex: 1 1 auto; }

/* ---------- 학습지 (화면) ---------- */
.sheet { background: var(--white); border: 1px solid var(--line); border-radius: 6px; padding: 1.4rem 1.4rem 1.8rem; margin-bottom: 1.2rem; box-shadow: 0 1px 4px rgba(0, 0, 0, .06); }
.sheet-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .4rem 1.5rem; border-bottom: 2px solid var(--ink); padding-bottom: .5rem; margin-bottom: 1.1rem; }
.sheet-title { margin: 0; font-size: 1.35rem; overflow-wrap: anywhere; }
.sheet-meta { display: flex; gap: 1.2rem; font-size: .95rem; }
.sheet-meta .line { display: inline-block; min-width: 6rem; border-bottom: 1px solid var(--ink); height: 1.2em; vertical-align: bottom; }
.grid { display: grid; gap: 1.1rem .9rem; }
.grid.v { grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); }
.grid.h { grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); }
.prob { break-inside: avoid; page-break-inside: avoid; position: relative; font-family: var(--mono); font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.prob .no { font-family: var(--sans); font-size: .8rem; color: var(--muted); display: block; margin-bottom: .1rem; }
.prob.vert .calc { display: inline-block; min-width: 4.5ch; }
.prob .r { display: flex; justify-content: space-between; gap: .6ch; white-space: pre; line-height: 1.45; }
.prob .r.last { border-bottom: 2px solid var(--ink); }
.prob .space { height: 1.9em; }
.prob .space.tall { height: 3.6em; }
.prob .space.t3 { height: 5.1em; }
.prob .space.t4 { height: 6.6em; }
.print-only { display: none; }
.prob.horiz { display: flex; flex-wrap: wrap; align-items: baseline; gap: .3rem .6rem; padding: .35rem 0; }
.prob.horiz .no { display: inline; margin: 0; min-width: 1.6rem; }
.prob.wide { grid-column: span 2; }
.grid.h .prob.wide { grid-column: 1 / -1; }
.blank { display: inline-block; min-width: 4.2ch; border-bottom: 1.5px solid var(--ink); height: 1.3em; vertical-align: bottom; }
.prob .lbl { font-family: var(--sans); font-size: .95rem; }
.answer-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: .3rem 1rem; padding: 0; margin: 0; list-style: none; font-family: var(--mono); font-size: 1.02rem; }
.answer-list li { break-inside: avoid; }
.answer-list .no { font-family: var(--sans); color: var(--muted); display: inline-block; min-width: 2.3rem; }
details.answers { margin: 1rem 0; }
details.answers summary { cursor: pointer; font-weight: 700; padding: .5rem 0; }

/* ---------- 온라인 연습 ---------- */
.practice-box { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 1.2rem; max-width: 30rem; margin: 0 auto; }
.practice-top { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 1rem; margin-bottom: .8rem; }
.practice-top .time { font-family: var(--mono); font-size: 1.25rem; color: var(--ink); }
.question { text-align: center; font-family: var(--mono); font-size: 2.2rem; margin: .8rem 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.answer-fields { display: flex; justify-content: center; gap: .8rem; margin-bottom: .6rem; }
.answer-field { min-width: 7rem; min-height: 3.4rem; padding: .2rem .8rem; border: 2px solid #8a94a0; border-radius: 10px; background: #fff; font: inherit; font-family: var(--mono); font-size: 1.8rem; text-align: right; color: var(--ink); cursor: pointer; }
.answer-field[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.answer-field .cap { display: block; font-family: var(--sans); font-size: .75rem; color: var(--muted); text-align: left; }
.feedback { min-height: 1.6rem; text-align: center; margin: 0 0 .6rem; font-weight: 700; }
.feedback.ok { color: var(--good); }
.feedback.ng { color: var(--bad); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.key { font: inherit; font-family: var(--mono); font-size: 1.5rem; min-height: 3.6rem; border: 2px solid #6f7a86; border-radius: 10px; background: #fff; color: var(--ink); cursor: pointer; }
.key:hover { background: var(--brand-soft); }
.key.enter { background: var(--brand); color: #fff; border-color: var(--brand); font-family: var(--sans); font-size: 1.1rem; font-weight: 700; }
.key.enter:hover { background: var(--brand-dark); }
.result-big { font-size: 1.8rem; font-weight: 800; color: var(--brand-dark); }
.records { width: 100%; border-collapse: collapse; font-size: .95rem; }
.records th, .records td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.wrong-list { padding-left: 1.2rem; font-family: var(--mono); }

/* ---------- 모바일 ---------- */
@media (max-width: 760px) {
  .layout-2 { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.55rem; }
  .sheet { padding: 1rem .8rem 1.2rem; }
  .grid.h { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- 인쇄 (A4 세로) ---------- */
@page { size: A4 portrait; margin: 14mm; }
/* 홈: 학년·학기로 찾기 표, 근거 표기 */
.grade-table { width: 100%; border-collapse: collapse; margin: .75rem 0; background: var(--white); font-size: .95rem; }
.grade-table caption { text-align: left; color: var(--muted); font-size: .9rem; padding-bottom: .35rem; }
.grade-table th, .grade-table td { border: 1px solid var(--line); padding: .55rem .65rem; text-align: left; vertical-align: top; }
.grade-table thead th { background: #eef2ea; }
.grade-table tbody th { white-space: nowrap; }
.source-note { color: var(--muted); font-size: .88rem; margin-top: 1rem; }
@media (max-width: 480px) { .grade-table th, .grade-table td { padding: .45rem .4rem; font-size: .9rem; } }

@media print {
  body { background: #fff; font-size: 12pt; line-height: 1.4; }
  .site-header, .site-footer, .settings, .no-print, .article, .hero,
  ins.adsbygoogle, .google-auto-placed, iframe, .adsbygoogle, [id^="aswift"], [id^="google_ads"] { display: none !important; }
  .shell { max-width: none; padding: 0; }
  main { padding-top: 0; }
  .layout-2 { display: block; }
  .section { margin-top: 0; }
  .sheet { border: 0; box-shadow: none; padding: 0; margin: 0; border-radius: 0; }
  .sheet + .sheet { margin-top: 0; }
  .answer-sheet { break-before: page; page-break-before: always; }
  .sheet-title { font-size: 18pt; }
  .grid.v { grid-template-columns: repeat(5, 1fr); gap: 7mm 5mm; }
  .grid.h { grid-template-columns: repeat(2, 1fr); gap: 5mm 8mm; }
  .prob.horiz { flex-wrap: nowrap; white-space: nowrap; }
  .grid.v .prob.horiz { grid-column: span 2; }
  .grid.v .prob.horiz.wide { grid-column: 1 / -1; }
  .grid.h .prob.wide { grid-column: 1 / -1; }
  body.print-one .preset.print-target .print-only { display: block; }
  .prob { font-size: 16pt; }
  .prob .no { font-size: 9pt; color: #333; }
  .answer-list { grid-template-columns: repeat(3, 1fr); font-size: 12pt; }
  body.print-one .preset:not(.print-target) { display: none !important; }
  a { color: inherit; text-decoration: none; }
  .doc-page .article, .doc-page .hero { display: block !important; }
  .doc-page .article { border: 0; padding: 0; box-shadow: none; }
}
