﻿/**
 * DS4K 학습지 공통 스타일
 * ─────────────────────────────────────────────
 * 모든 워크북(연산·코딩 등)이 공유하는 레이아웃·컴포넌트·인쇄 규칙입니다.
 * 과목별 색상과 그림(visual) 스타일은 각 워크북의 styles.css 에서 정의합니다.
 * 이 파일을 먼저 불러오고, 과목 CSS 를 뒤에 불러오세요.
 */

:root {
  /* 테마 슬롯 — 과목 CSS 에서 덮어쓸 수 있습니다. */
  --bg: #dff3ec;
  --bg-glow-1: #cdeee0;
  --bg-glow-2: #d8f0fa;
  --hero-grad: linear-gradient(135deg, #bdeadb 0%, #d8f2e9 60%, #e3f4fb 100%);

  --surface: #ffffff;
  --surface-soft: #eef9f4;
  --surface-problem: #fdfffe;

  --accent: #14b8a0;
  --accent-deep: #0c7f6f;
  --accent-light: #8fdcc8;
  --accent-glow: rgba(14, 143, 125, 0.35);

  --ink: #102b27;
  --heading: #0d3a33;
  --muted: #44615c;
  --line: #cde9df;
  --rule-line: #eaf5f0;

  --yellow: #ffd66b;
  --coral: #ff8a7a;

  /* 난이도 색상 */
  --basic: #3fbf77;
  --basic-soft: #e3f7ec;
  --standard: #4d9de0;
  --standard-soft: #e6f1fb;
  --advanced: #f58a3c;
  --advanced-soft: #fdeede;

  --tip: #fff9e6;
  --tip-border: #ffe4a1;

  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow-card: 0 12px 32px rgba(20, 90, 80, 0.12);

  --font-display: "Jua", "BM Jua", "Noto Sans KR", sans-serif;
  --font-body: "Noto Sans KR", "Pretendard", "Malgun Gothic", sans-serif;
  --font-mono: "JetBrains Mono", "D2Coding", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 50% -8%, rgba(255, 214, 120, 0.35), transparent 55%),
    radial-gradient(circle at 8% 18%, rgba(255, 160, 122, 0.18), transparent 36%),
    radial-gradient(circle at 92% 14%, rgba(125, 211, 252, 0.22), transparent 38%),
    radial-gradient(ellipse 70% 45% at 15% -5%, var(--bg-glow-1) 0%, transparent 60%),
    radial-gradient(ellipse 55% 40% at 95% 5%, var(--bg-glow-2) 0%, transparent 55%),
    var(--bg);
  min-height: 100%;
  overflow-x: clip;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  line-height: 1.6;
  font-size: 16.5px;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 24px max(20px, env(safe-area-inset-right)) 90px max(20px, env(safe-area-inset-left));
}

/* —— Site nav (DS4K home link) —— */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--surface);
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  flex-wrap: wrap;
}

.site-nav-brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--ink);
  line-height: 1.15;
}

.site-nav-mark {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--accent-deep);
}

.site-nav-sub {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.site-nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.site-nav-links a {
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--accent-deep);
  background: var(--surface-soft);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  transition: transform 0.15s ease, background 0.15s ease;
}

.site-nav-links a:hover {
  background: #fff;
  transform: translateY(-1px);
}

/* —— Hero —— */
.hero {
  position: relative;
  background: var(--hero-grad);
  border-radius: var(--radius-lg);
  padding: 30px 32px 24px;
  margin-bottom: 22px;
  overflow: hidden;
  border: 2px solid #ffffff;
  box-shadow: var(--shadow-card);
}

.hero-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.hero-text {
  flex: 1 1 280px;
  min-width: 0;
}

.hero-kicker {
  display: inline-block;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4.5vw, 2.6rem);
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
  line-height: 1.2;
  color: var(--heading);
}

.hero h1 .accent {
  color: var(--accent-deep);
}

.hero-desc {
  margin: 0;
  color: var(--heading);
  font-size: 1rem;
  font-weight: 700;
  max-width: 30em;
}

.mascots {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.mascots svg {
  display: block;
}

.speech {
  position: relative;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 8px 14px;
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 14px;
  align-self: flex-start;
  white-space: normal;
  max-width: 100%;
}

.speech::after {
  content: "";
  position: absolute;
  bottom: -9px;
  left: 24px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: rotate(45deg);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.chip strong {
  color: var(--accent-deep);
  font-weight: 800;
}

/* —— Catalog (전체 카테고리) —— */
.catalog {
  background: var(--surface);
  border: 2px solid #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.catalog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.catalog-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--accent-deep);
  margin: 0;
}

.catalog-desc {
  margin: 4px 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.btn-ghost {
  background: var(--surface-soft);
  border: 1.5px solid var(--line);
  font-size: 13px;
  padding: 8px 16px;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.catalog.collapsed .catalog-grid {
  display: none;
}

.cat-card {
  background: var(--surface-soft);
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cat-card.current {
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(20, 184, 160, 0.18);
}

.cat-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.cat-grade {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--ink);
}

.cat-days {
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--muted);
  background: #fff;
  border-radius: 999px;
  padding: 3px 8px;
}

.cat-focus {
  margin: 8px 0 12px;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--muted);
}

.cat-levels {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.cat-level {
  display: grid;
  grid-template-columns: 46px 1fr 14px;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.cat-level:hover {
  transform: translateX(2px);
  border-color: var(--accent);
}

.cat-level-name {
  font-family: var(--font-display);
  font-size: 0.86rem;
  text-align: center;
  border-radius: 999px;
  padding: 3px 0;
  color: #fff;
}

.cat-level.level-basic .cat-level-name {
  background: var(--basic);
}
.cat-level.level-standard .cat-level-name {
  background: var(--standard);
}
.cat-level.level-advanced .cat-level-name {
  background: var(--advanced);
}

.cat-level-detail {
  font-size: 0.71rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--muted);
}

.cat-level-go {
  font-size: 0.6rem;
  color: var(--accent-deep);
}

.cat-level.active {
  border-color: var(--accent-deep);
  background: #fffdf2;
  box-shadow: inset 0 0 0 1.5px var(--yellow);
}

.cat-level.level-basic.active {
  background: var(--basic-soft);
}
.cat-level.level-standard.active {
  background: var(--standard-soft);
}
.cat-level.level-advanced.active {
  background: var(--advanced-soft);
}

/* —— Filters —— */
.filters {
  position: sticky;
  top: 10px;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  border: 2px solid #fff;
  box-shadow: var(--shadow-card);
  padding: 16px 20px;
  margin-bottom: 24px;
  transition: padding 0.2s ease, box-shadow 0.2s ease;
}

.filters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.filters-head-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-deep);
  letter-spacing: 0.03em;
}

.btn-filters-toggle {
  flex-shrink: 0;
  font-size: 13px !important;
  padding: 6px 12px !important;
}

.filters.is-collapsed {
  padding: 8px 14px;
  top: 6px;
}

.filters.is-collapsed .filters-head {
  margin-bottom: 0;
}

.filters.is-collapsed .filters-body {
  display: none;
}

.filters.is-collapsed .filters-head-title {
  font-size: 12px;
  opacity: 0.85;
}

.filter-group {
  margin-bottom: 12px;
}

.filter-group:last-of-type {
  margin-bottom: 0;
}

.filter-label {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--accent-deep);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  appearance: none;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 18px;
  font-size: 15px;
  font-family: var(--font-display);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, border-color 0.15s, color 0.15s;
}

.tab:hover {
  transform: translateY(-2px);
  border-color: var(--accent-light);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 3px 0 var(--accent-glow);
}

.tab.level-basic.active {
  background: var(--basic);
  border-color: var(--basic);
  box-shadow: 0 3px 0 rgba(47, 143, 89, 0.35);
}

.tab.level-standard.active {
  background: var(--standard);
  border-color: var(--standard);
  box-shadow: 0 3px 0 rgba(50, 105, 152, 0.35);
}

.tab.level-advanced.active {
  background: var(--advanced);
  border-color: var(--advanced);
  box-shadow: 0 3px 0 rgba(184, 100, 38, 0.35);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 2px dashed var(--line);
}

.btn {
  appearance: none;
  border: none;
  background: #f1f6f4;
  color: var(--ink);
  padding: 10px 20px;
  font-size: 14px;
  font-family: var(--font-display);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s, filter 0.15s;
}

.btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.03);
}

.btn-primary {
  background: var(--yellow);
  color: #5c4300;
  box-shadow: 0 3px 0 rgba(190, 150, 40, 0.4);
}

.btn.is-active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 0 var(--accent-glow);
}

/* —— 펜 도구 —— */
.pen-tools {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: #f1f6f4;
  border-radius: 999px;
}

.pen-tool {
  appearance: none;
  border: none;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
}

.pen-tool:hover {
  color: var(--ink);
}

.pen-tool.is-active {
  color: #fff;
  background: var(--accent);
}

.answer-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-left: auto;
  cursor: pointer;
}

.answer-toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

/* —— Summary —— */
.summary {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 2px solid #fff;
  box-shadow: var(--shadow-card);
  padding: 22px 26px;
  margin-bottom: 24px;
}

.summary-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.summary h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.45rem;
  color: var(--heading);
}

.summary .focus {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.level-badge {
  display: inline-block;
  padding: 8px 18px;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.04em;
  color: #fff;
  border-radius: 999px;
}

.level-badge.basic {
  background: var(--basic);
  box-shadow: 0 3px 0 rgba(47, 143, 89, 0.35);
}
.level-badge.standard {
  background: var(--standard);
  box-shadow: 0 3px 0 rgba(50, 105, 152, 0.35);
}
.level-badge.advanced {
  background: var(--advanced);
  box-shadow: 0 3px 0 rgba(184, 100, 38, 0.35);
}

.day-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 2px dashed var(--line);
}

.day-nav a {
  text-decoration: none;
  color: var(--accent-deep);
  font-size: 13px;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1.5px solid var(--line);
  transition: transform 0.12s;
}

.day-nav a:hover {
  transform: translateY(-2px);
  filter: brightness(0.97);
}

/* —— Worksheet —— */
.sheet {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 2px solid #fff;
  box-shadow: var(--shadow-card);
  margin-bottom: 30px;
  padding: 30px 34px 24px;
  break-inside: avoid;
  page-break-after: always;
}

.sheet-head {
  border-bottom: 3px solid var(--accent-light);
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.sheet-head-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.day-label {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 13px;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  padding: 4px 14px;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.sheet-title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.45rem;
  color: var(--heading);
}

.star-tracker {
  font-size: 15px;
  font-weight: 800;
  color: #b8860b;
  background: #fff8e1;
  border: 2px solid var(--tip-border);
  border-radius: 999px;
  padding: 6px 14px;
  white-space: nowrap;
}

.meta-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.meta-fields .field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meta-input {
  width: 130px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--accent-light);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.meta-input:focus {
  border-bottom-color: var(--accent);
  background: var(--surface-soft);
  border-radius: 6px 6px 0 0;
}

.meta-input-sm {
  width: 46px;
  text-align: center;
}

.progress-wrap {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1.5px solid var(--line);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  transition: width 0.35s ease;
}

.progress-text {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-deep);
  white-space: nowrap;
}

/* 지도 팁 — 마스코트 말풍선 */
.tip-box {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--tip);
  border: 2px solid var(--tip-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 22px;
  font-size: 13.5px;
}

.tip-mascot {
  flex: 0 0 auto;
}

.tip-box .tip-label {
  font-family: var(--font-display);
  color: #a4740f;
  margin-bottom: 4px;
  font-size: 13px;
}

.tip-box p {
  margin: 0;
  color: #59470f;
  font-size: 14px;
  font-weight: 700;
}

/* —— 문제 —— */
.problem-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.problem {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  padding: 16px 18px;
  border: 2px solid var(--surface-soft);
  background: var(--surface-problem);
  border-radius: var(--radius-md);
  transition: border-color 0.2s, background 0.2s;
}

.problem.correct {
  border-color: var(--basic);
  background: var(--basic-soft);
}

.problem.wrong {
  border-color: var(--coral);
  background: #fff2f0;
}

.problem-no {
  font-family: var(--font-display);
  font-size: 17px;
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.problem.correct .problem-no {
  background: var(--basic);
}

.problem.wrong .problem-no {
  background: var(--coral);
}

.problem-q {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.5;
}
.problem-hint {
  font-size: 13px;
  color: #92400e;
  margin: 0 0 10px;
  padding: 8px 10px;
  background: #fffbeb;
  border-radius: 8px;
  border: 1px solid #fde68a;
  line-height: 1.45;
}

.problem-body {
  min-width: 0;
}

/* 그림이 있는 문제는 계산식·보기를 그림 아래에 따로 표시합니다. */
.problem-expr {
  display: inline-block;
  margin: 10px 0 2px;
  padding: 8px 16px;
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 0.03em;
  color: var(--accent-deep);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
}

/* —— 손으로 푸는 공간 (모눈종이) —— */
.work-space {
  position: relative;
  margin: 12px 0 4px;
  min-height: 56px;
  border: 1.5px solid #c5d8ef;
  border-radius: var(--radius-sm);
  background-color: #fbfcff;
  /* 세로·가로 모눈 + 5칸마다 조금 더 진한 선 */
  background-image:
    linear-gradient(to right, rgba(90, 140, 200, 0.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(90, 140, 200, 0.28) 1px, transparent 1px),
    linear-gradient(to right, rgba(70, 120, 180, 0.45) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(70, 120, 180, 0.45) 1px, transparent 1px);
  background-size: 12px 12px, 12px 12px, 60px 60px, 60px 60px;
  background-position: -1px -1px;
}

.work-space.sm {
  min-height: 42px;
}

.work-space.mid {
  min-height: 84px;
}

.work-space.tall {
  min-height: 126px;
}

/* —— 펜 필기용 캔버스 —— */
.work-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  pointer-events: none;
  touch-action: none;
}

body.pen-on .work-canvas {
  pointer-events: auto;
  cursor: crosshair;
}

body.pen-on.pen-eraser .work-canvas {
  cursor: cell;
}

body.pen-on .work-space {
  border-style: solid;
  border-color: var(--accent-light);
}

.work-clear {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: none;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.work-clear:hover {
  color: var(--ink);
  border-color: var(--accent);
}

body.pen-on .work-clear {
  display: block;
}

/* —— 문장제 식 쓰는 칸 —— */
.expr-line {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.expr-label {
  flex: none;
  font-weight: 800;
}

.expr-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: none;
  border-bottom: 2px solid var(--line);
  border-radius: 0;
  outline: none;
  transition: border-color 0.15s;
}

.expr-input:focus {
  border-bottom-color: var(--accent);
}

.work-label {
  position: absolute;
  top: -9px;
  left: 12px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  background: var(--surface-problem);
  border-radius: 999px;
}

.problem.correct .work-label {
  background: var(--basic-soft);
}

.problem.wrong .work-label {
  background: #fff2f0;
}

/* —— 그림(비주얼) 공통 컨테이너 —— */
.visual {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 10px;
  margin: 10px 0 4px;
  padding: 12px 14px;
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--accent-light);
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* 이모지·막대 등 넓은 그림은 줄바꿈 허용 */
.visual:has(.vgroup),
.visual:has(.vbox),
.visual:has(.tape-wrap),
.visual:has(.ratio-bar),
.visual:has(.dot-array),
.visual:has(.gg-array),
.visual:has(.gg-strip) {
  flex-wrap: wrap;
  overflow-x: visible;
  align-items: flex-start;
}

.visual:has(.tape-wrap),
.visual:has(.ratio-bar) {
  flex-direction: column;
  align-items: stretch;
}

@media (min-width: 720px) {
  .visual:not(:has(.vgroup)):not(:has(.tape-wrap)):not(:has(.ratio-bar)) {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

.visual svg,
.visual img {
  max-width: 100%;
  height: auto;
  flex-shrink: 0;
}

.visual .vop,
.visual .pie-group,
.visual .split-arrow {
  flex-shrink: 0;
}

/* —— 답 입력 —— */
.mc-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
  width: 100%;
  max-width: 420px;
}
.mc-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  padding: 10px 12px;
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  color: var(--ink);
  min-width: 0;
}
.mc-txt {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
}
.mc-btn:hover { border-color: var(--accent); }
.mc-btn.is-correct { border-color: #047857; background: #ecfdf5; }
.mc-btn.is-wrong { border-color: #be123c; background: #fff1f2; }
.mc-let {
  width: 1.4em;
  height: 1.4em;
  border-radius: 999px;
  background: var(--accent-light);
  color: var(--accent-deep);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}
.problem.correct .mc-btn:not(.is-correct) { opacity: 0.55; }

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.unit-card {
  display: block;
  padding: 16px 18px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-card);
}
.unit-card h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}
.unit-card p {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.5;
}
.unit-card.active {
  border-color: var(--accent);
  background: var(--accent-light);
}

.answer-line {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}

.ans-input {
  width: 150px;
  padding: 9px 14px;
  font-size: 16px;
  font-weight: 800;
  font-family: inherit;
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}

.ans-input:focus {
  border-color: var(--accent);
}

.btn-check {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 14px;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--accent-glow);
  transition: transform 0.12s;
}

.btn-check:hover {
  transform: translateY(-2px);
}

.feedback {
  font-family: var(--font-display);
  font-size: 15px;
  min-width: 90px;
}

.feedback.ok {
  color: var(--accent-deep);
}

.feedback.no {
  color: #e0472f;
}

.answer-box {
  display: none;
}

.answer-reveal {
  margin-top: 8px;
  font-size: 13px;
  color: var(--accent-deep);
  font-weight: 800;
  display: none;
}

body.show-answers .answer-reveal {
  display: block;
}

.sheet-foot {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 2px dashed var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

/* —— 정답지 —— */
.answer-key {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 2px solid #fff;
  box-shadow: var(--shadow-card);
  padding: 26px 30px;
  margin-top: 8px;
}

.answer-key h3 {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.2rem;
  color: var(--heading);
}

.answer-day {
  margin-bottom: 18px;
}

.answer-day h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--accent-deep);
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 6px 16px;
  font-size: 14px;
}

.answer-grid span {
  color: var(--muted);
}

.answer-grid strong {
  color: var(--ink);
  font-weight: 800;
}

.answer-expr {
  font-style: normal;
  color: var(--muted);
  font-weight: 600;
}

.hidden {
  display: none !important;
}

/* —— 인쇄: PDF 워크북 형태로 —— */
@page {
  size: A4;
  margin: 10mm 12mm;
}

@media print {
  body {
    background: #fff;
  }

  /* 모눈종이 배경과 펜으로 쓴 글씨가 종이에도 나오도록 */
  .work-space,
  .work-canvas {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .filters,
  .hero,
  .catalog,
  .site-nav,
  .toolbar,
  .day-nav,
  .no-print,
  .btn-check,
  .ans-input,
  .work-clear,
  .pen-tools,
  .feedback,
  .star-tracker,
  .progress-wrap {
    display: none !important;
  }

  .app {
    max-width: none;
    padding: 0;
  }

  .summary,
  .sheet,
  .answer-key {
    border: none;
    box-shadow: none;
    border-radius: 0;
  }

  .summary {
    padding: 0 0 12px;
  }

  .sheet {
    padding: 4mm 2mm;
    margin: 0;
  }

  .sheet-head,
  .tip-box,
  .problem {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .problem {
    border: none;
    border-bottom: 1px dashed #c9d4cf;
    border-radius: 0;
    background: #fff !important;
    padding: 10px 0;
  }

  .problem-no {
    background: none;
    color: #333;
    width: auto;
    height: auto;
    justify-content: flex-start;
  }

  .visual {
    background: #fff;
    border-color: #bbb;
  }

  .meta-input {
    border-bottom-color: #999;
  }

  .problem-expr {
    border-color: #999;
    color: #000;
  }

  .work-space {
    background-color: #fff;
    background-image:
      linear-gradient(to right, #d5d5d5 1px, transparent 1px),
      linear-gradient(to bottom, #d5d5d5 1px, transparent 1px),
      linear-gradient(to right, #bdbdbd 1px, transparent 1px),
      linear-gradient(to bottom, #bdbdbd 1px, transparent 1px);
    background-size: 12px 12px, 12px 12px, 60px 60px, 60px 60px;
    border-color: #bbb;
  }

  .work-label {
    background: #fff;
    color: #666;
  }

  .expr-line {
    color: #333;
  }

  .expr-input {
    background: transparent;
    border-bottom-color: #999;
    color: #000;
  }

  .answer-box {
    display: inline-block;
    width: 220px;
    min-height: 30px;
    border: 1.5px solid #999;
    border-radius: 6px;
    background: transparent;
  }

  body.show-answers .answer-reveal {
    display: none;
  }

  .answer-key {
    page-break-before: always;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 12px max(12px, env(safe-area-inset-right)) 56px max(12px, env(safe-area-inset-left));
  }

  .site-nav {
    border-radius: 18px;
  }

  .site-nav-sub {
    display: none;
  }

  .hero {
    padding: 18px 16px 16px;
  }

  .sheet {
    padding: 16px 12px 14px;
  }

  .filters {
    top: 6px;
    padding: 12px 14px;
  }

  .answer-toggle {
    margin-left: 0;
    width: 100%;
  }

  .meta-input {
    width: 90px;
  }

  .mascots {
    margin: 0 auto;
  }

  .problem {
    grid-template-columns: 32px 1fr;
    gap: 8px;
    padding: 12px 12px;
  }

  .problem-no {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .problem-q {
    font-size: 16px;
  }

  .problem-expr {
    font-size: 1.05rem;
    overflow-wrap: anywhere;
    max-width: 100%;
  }

  .visual {
    padding: 10px 12px;
    gap: 8px;
  }

  .ans-input {
    width: min(150px, 100%);
  }

  .mc-choices {
    max-width: 100%;
  }

  .expr-line {
    flex-direction: column;
    align-items: stretch;
  }

  .expr-line .expr-input {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .answer-line {
    align-items: flex-start;
  }

  .toolbar {
    gap: 8px;
  }

  .toolbar .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 4px);
    justify-content: center;
    text-align: center;
  }

  .toolbar .answer-toggle,
  .toolbar .pen-tools {
    flex: 1 1 100%;
    min-width: 100%;
  }
}

@media (max-width: 380px) {
  .mc-choices {
    grid-template-columns: 1fr;
  }

  .tab {
    padding: 8px 14px;
    font-size: 14px;
  }
}
