/* ============================================================
   전기맨 (Electroman) — 공통 스타일
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Jua&display=swap');
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css');

:root {
  --bg: #fffbef;
  --surface: #ffffff;
  --surface-2: #fff4d1;
  --surface-3: #f3f6ff;
  --text: #1d2330;
  --muted: #5a6275;
  --line: #ebe3c8;
  --accent: #ffb400;
  --accent-strong: #f59e0b;
  --accent-ink: #6b4300;
  --blue: #2f6fed;
  --blue-soft: #e4ecff;
  --green: #169a52;
  --green-soft: #dcf5e7;
  --red: #dc3b30;
  --red-soft: #fde4e1;
  --purple: #7555f0;
  --purple-soft: #ece7ff;
  --wire: #b8741a;
  --shadow: 0 2px 0 rgba(0,0,0,.04), 0 8px 24px rgba(80,60,0,.08);
  --radius: 18px;
  --radius-sm: 10px;
  --font-body: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --font-fun: 'Jua', 'Pretendard', sans-serif;
  --maxw: 1080px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141b; --surface: #1a1f2a; --surface-2: #2a2618; --surface-3: #1e2536;
    --text: #edf0f6; --muted: #a4acbd; --line: #2f3646;
    --accent-ink: #ffd166; --blue: #6f9bff; --blue-soft: #1d2a4a; --green: #3ecf7f; --green-soft: #173626;
    --red: #ff6f63; --red-soft: #3d1c1a; --purple: #a590ff; --purple-soft: #2a2350; --wire: #e0a049;
    --shadow: 0 2px 0 rgba(0,0,0,.2), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11141b; --surface: #1a1f2a; --surface-2: #2a2618; --surface-3: #1e2536;
  --text: #edf0f6; --muted: #a4acbd; --line: #2f3646;
  --accent-ink: #ffd166; --blue: #6f9bff; --blue-soft: #1d2a4a; --green: #3ecf7f; --green-soft: #173626;
  --red: #ff6f63; --red-soft: #3d1c1a; --purple: #a590ff; --purple-soft: #2a2350; --wire: #e0a049;
  --shadow: 0 2px 0 rgba(0,0,0,.2), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 17px; line-height: 1.75;
  word-break: keep-all; overflow-wrap: break-word;
}
img, svg { max-width: 100%; }
a { color: var(--blue); }
h1, h2, h3, .fun { font-family: var(--font-fun); font-weight: 400; line-height: 1.3; letter-spacing: -.01em; }
h1 { font-size: clamp(30px, 5vw, 46px); margin: .2em 0 .3em; }
h2 { font-size: clamp(24px, 3.4vw, 32px); margin: 2.2em 0 .6em; }
h3 { font-size: 22px; margin: 1.6em 0 .5em; }
p { margin: .6em 0; }
code, kbd { font-family: ui-monospace, Consolas, monospace; background: var(--surface-3); padding: .1em .35em; border-radius: 6px; font-size: .92em; }
hr { border: 0; border-top: 2px dashed var(--line); margin: 2.5em 0; }
table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: 15.5px; background: var(--surface); border-radius: var(--radius-sm); overflow: hidden; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; }
.table-wrap { overflow-x: auto; margin: 1em 0; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.table-wrap table { margin: 0; }

/* ---------- 레이아웃 ---------- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }
main.container { padding-bottom: 60px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- 헤더 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.site-header .bar { display: flex; align-items: center; gap: 10px; height: 60px; }
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-family: var(--font-fun); font-size: 22px; white-space: nowrap; }
.logo img { width: 34px; height: 34px; }
@media (max-width: 420px) { .logo { font-size: 0; gap: 0; } .site-header .bar { gap: 6px; } .site-header .mode-switch button { padding-left: 10px; padding-right: 10px; } }
.bar .spacer { flex: 1; }
.btn, button.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 2px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font: 600 15px var(--font-body);
  cursor: pointer; text-decoration: none; transition: transform .1s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #3a2600; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13.5px; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #3a2600; }

.mode-switch { display: inline-flex; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.mode-switch button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; font: 700 14px var(--font-body); cursor: pointer; white-space: nowrap; }
.mode-switch button.on { background: var(--accent); color: #3a2600; }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 18px; }

/* 네비 서랍 */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 90; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 90vw); background: var(--surface); z-index: 100; transform: translateX(100%); transition: transform .25s; overflow-y: auto; padding: 18px; box-shadow: var(--shadow); }
body.drawer-open .drawer { transform: none; }
body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
.drawer h4 { font-family: var(--font-fun); font-weight: 400; font-size: 18px; margin: 18px 0 6px; color: var(--muted); }
.drawer a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text); text-decoration: none; }
.drawer a:hover, .drawer a.current { background: var(--surface-2); }
.drawer a .done { margin-left: auto; color: var(--green); font-weight: 700; }

/* ---------- 페이지 히어로 ---------- */
.page-hero { padding: 36px 0 12px; display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; }
.page-hero .eyebrow { font-weight: 700; color: var(--accent-ink); letter-spacing: .02em; }
.page-hero .lead { font-size: 19px; color: var(--muted); max-width: 640px; }
.page-hero .hero-art { width: 150px; }
@media (max-width: 640px) { .page-hero { grid-template-columns: 1fr; } .page-hero .hero-art { width: 100px; order: -1; } }

.toc { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 8px; }
.toc a { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 14px; color: var(--text); text-decoration: none; }
.toc a:hover { border-color: var(--accent); }

/* ---------- 카드 & 박스 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h3:first-child, .card h4:first-child { margin-top: 0; }
.card.link { text-decoration: none; color: var(--text); transition: transform .15s, border-color .15s; display: block; }
.card.link:hover { transform: translateY(-3px); border-color: var(--accent); }

section.lesson { scroll-margin-top: 80px; }

.analogy, .tip, .warn, .danger, .pro-box, .note {
  border-radius: var(--radius); padding: 16px 18px 16px 58px; margin: 16px 0; position: relative; border: 2px solid;
}
.analogy::before, .tip::before, .warn::before, .danger::before, .pro-box::before, .note::before {
  position: absolute; left: 16px; top: 14px; font-size: 26px; line-height: 1;
}
.analogy { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.analogy::before { content: "💡"; }
.tip { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.tip::before { content: "👍"; }
.warn { background: #fff1d6; border-color: #f2b64c; }
:root[data-theme="dark"] .warn { background: #3a2c12; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .warn { background: #3a2c12; } }
.warn::before { content: "⚠️"; }
.danger { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.danger::before { content: "⛔"; }
.pro-box { background: var(--purple-soft); border-color: color-mix(in srgb, var(--purple) 40%, transparent); }
.pro-box::before { content: "🎓"; }
.note { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 35%, transparent); }
.note::before { content: "📌"; }
.analogy > strong:first-child, .tip > strong:first-child, .warn > strong:first-child,
.danger > strong:first-child, .pro-box > strong:first-child, .note > strong:first-child { display: block; font-family: var(--font-fun); font-weight: 400; font-size: 19px; margin-bottom: 4px; }

/* 마스코트 말풍선 */
.say { display: flex; gap: 12px; align-items: flex-start; margin: 18px 0; }
.say img { width: 54px; height: 54px; flex: none; }
.say .bubble { background: var(--surface); border: 2px solid var(--accent); border-radius: 4px 18px 18px 18px; padding: 12px 16px; box-shadow: var(--shadow); }

/* 배지 */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.lv1 { background: var(--green-soft); color: var(--green); }
.lv2 { background: #fff0c2; color: #8a5a00; }
.lv3 { background: var(--red-soft); color: var(--red); }
.safe-ok { background: var(--green-soft); color: var(--green); }
.safe-adult { background: var(--blue-soft); color: var(--blue); }
.safe-no { background: var(--red-soft); color: var(--red); }
:root[data-theme="dark"] .lv2 { background: #3a3014; color: #ffd166; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lv2 { background: #3a3014; color: #ffd166; } }

/* 공식 */
.formula { font-family: ui-monospace, Consolas, monospace; font-size: 22px; font-weight: 700; text-align: center; background: var(--surface-3); border: 2px dashed var(--blue); border-radius: var(--radius); padding: 14px; margin: 14px 0; }
.formula small { display: block; font: 500 14px var(--font-body); color: var(--muted); margin-top: 4px; }

/* 스텝 */
ol.steps { list-style: none; counter-reset: s; padding: 0; margin: 16px 0; }
ol.steps > li { counter-increment: s; position: relative; padding: 12px 14px 12px 58px; margin: 10px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
ol.steps > li::before { content: counter(s); position: absolute; left: 14px; top: 12px; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #3a2600; font: 700 16px/32px var(--font-body); text-align: center; }

/* details 아코디언 */
details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 16px; margin: 10px 0; }
details > summary { cursor: pointer; padding: 12px 0; font-weight: 700; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; color: var(--accent-strong); }
details[open] > summary::before { content: "▾ "; }
details[open] { padding-bottom: 12px; }

/* 탭 */
.tabs { margin: 16px 0; }
.tab-list { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tab-list button { border: 2px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 14px; font: 700 14.5px var(--font-body); cursor: pointer; }
.tab-list button.on { background: var(--accent); border-color: var(--accent); color: #3a2600; }
.tab-panel { display: none; }
.tab-panel.on { display: block; }

/* 플립카드 */
.flip { perspective: 900px; min-height: 170px; cursor: pointer; }
.flip .inner { position: relative; width: 100%; height: 100%; min-height: inherit; transition: transform .5s; transform-style: preserve-3d; }
.flip.flipped .inner { transform: rotateY(180deg); }
.flip .front, .flip .back { position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; border: 2px solid var(--line); box-shadow: var(--shadow); }
.flip .front { background: var(--surface); }
.flip .back { background: var(--surface-2); transform: rotateY(180deg); }
.flip .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- 시뮬레이터 패널 ---------- */
.sim { background: var(--surface); border: 2px solid var(--blue); border-radius: var(--radius); padding: 18px; margin: 20px 0; box-shadow: var(--shadow); }
.sim-title { font-family: var(--font-fun); font-size: 21px; display: flex; align-items: center; gap: 8px; margin: 0 0 10px; color: var(--blue); }
.sim-title::before { content: "🕹️"; }
.sim .stage { background: var(--surface-3); border-radius: var(--radius-sm); padding: 10px; margin: 10px 0; overflow: hidden; }
.sim .readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 10px 0; }
.sim .readout > div { background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 12px; text-align: center; }
.sim .readout b { display: block; font-size: 22px; font-family: ui-monospace, Consolas, monospace; }
.sim .readout span { font-size: 13px; color: var(--muted); }
.control { display: grid; grid-template-columns: 110px 1fr 90px; gap: 10px; align-items: center; margin: 8px 0; }
.control label { font-weight: 700; font-size: 15px; }
.control output { font-family: ui-monospace, Consolas, monospace; font-weight: 700; text-align: right; }
@media (max-width: 520px) { .control { grid-template-columns: 1fr 70px; } .control label { grid-column: 1 / -1; } }
input[type="range"] { width: 100%; accent-color: var(--accent-strong); height: 28px; }
select, input[type="number"], input[type="text"], input[type="search"] {
  font: 500 16px var(--font-body); padding: 8px 10px; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); max-width: 100%;
}
select:focus, input:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }

/* 드래그 분류 게임 등에서 쓰는 칩 */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 2px solid var(--line); font-weight: 700; cursor: pointer; user-select: none; }
.chip.ok { border-color: var(--green); background: var(--green-soft); }
.chip.no { border-color: var(--red); background: var(--red-soft); }

/* ---------- 퀴즈 ---------- */
.quiz { background: var(--surface); border: 2px solid var(--purple); border-radius: var(--radius); padding: 20px; margin: 30px 0; }
.quiz-head { font-family: var(--font-fun); font-size: 24px; color: var(--purple); margin: 0 0 8px; }
.quiz-q { margin: 18px 0; padding-top: 14px; border-top: 1px dashed var(--line); }
.quiz-q:first-of-type { border-top: 0; }
.quiz-q .q { font-weight: 700; margin-bottom: 8px; }
.quiz-opts { display: grid; gap: 8px; }
.quiz-opts button { text-align: left; border: 2px solid var(--line); background: var(--surface); color: var(--text); border-radius: var(--radius-sm); padding: 10px 14px; font: 500 16px var(--font-body); cursor: pointer; }
.quiz-opts button:hover:not(:disabled) { border-color: var(--purple); }
.quiz-opts button.correct { border-color: var(--green); background: var(--green-soft); }
.quiz-opts button.wrong { border-color: var(--red); background: var(--red-soft); }
.quiz-opts button:disabled { cursor: default; }
.quiz-explain { margin-top: 8px; font-size: 15px; background: var(--surface-3); border-radius: var(--radius-sm); padding: 8px 12px; }
.quiz-result { margin-top: 16px; font-weight: 700; font-size: 18px; }

/* ---------- 푸터 / 단원 이동 ---------- */
.unit-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 40px 0 10px; }
.unit-nav a { display: block; padding: 14px 16px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; }
.unit-nav a:hover { border-color: var(--accent); }
.unit-nav a small { display: block; color: var(--muted); }
.unit-nav .next { text-align: right; grid-column: 2; }
.complete-box { text-align: center; margin: 30px 0; }
.site-footer { border-top: 1px solid var(--line); padding: 24px 0 40px; color: var(--muted); font-size: 14px; }

/* ---------- 모드 (어린이/심화) ---------- */
html[data-mode="kid"] .only-pro { display: none !important; }
html[data-mode="pro"] .only-kid { display: none !important; }

/* 토스트 */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px); background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 999px; font-weight: 700; z-index: 200; transition: transform .3s; box-shadow: var(--shadow); max-width: 90vw; text-align: center; }
.toast.show { transform: translateX(-50%) translateY(0); }

/* 유틸 애니메이션 */
@keyframes flow { to { stroke-dashoffset: -40; } }
.flowing { stroke-dasharray: 6 14; animation: flow 1s linear infinite; }
@keyframes glow { 0%,100% { filter: drop-shadow(0 0 4px #ffd54a); } 50% { filter: drop-shadow(0 0 16px #ffd54a); } }
@keyframes wobble { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.wobble { animation: wobble 2.4s ease-in-out infinite; transform-origin: 50% 80%; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition: none !important; } }

/* 홈 */
.home-hero { padding: 48px 0 20px; display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: center; }
.home-hero h1 { font-size: clamp(34px, 6vw, 58px); }
.home-hero h1 .hl { background: linear-gradient(transparent 60%, var(--accent) 60%); padding: 0 4px; }
@media (max-width: 760px) { .home-hero { grid-template-columns: 1fr; } }
.unit-card { position: relative; }
.unit-card .num { font-family: var(--font-fun); font-size: 15px; color: var(--accent-ink); }
.unit-card .emoji { font-size: 38px; line-height: 1; }
.unit-card h3 { margin: 6px 0 4px; font-size: 21px; }
.unit-card p { margin: 0; color: var(--muted); font-size: 15px; }
.unit-card .status { position: absolute; top: 14px; right: 14px; font-size: 13px; font-weight: 700; }
.progress-bar { height: 14px; background: var(--surface-3); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-strong)); width: 0; transition: width .6s; }
.badge-shelf { display: flex; flex-wrap: wrap; gap: 10px; }
.badge-shelf .medal { width: 74px; text-align: center; font-size: 12px; color: var(--muted); }
.badge-shelf .medal .m { font-size: 36px; display: block; filter: grayscale(1) opacity(.35); }
.badge-shelf .medal.got .m { filter: none; }

@media print {
  .site-header, .site-footer, .unit-nav, .drawer, .drawer-backdrop, .complete-box, .quiz, .sim { display: none !important; }
  body { background: #fff; color: #000; font-size: 13px; }
}
