* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  color: #1f2430;
  background: #fff;
  font-size: 14px;
}

/* ---------- 사이드바 ---------- */
.sidebar {
  width: 360px;
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  border-right: 1px solid #e6e8ee;
  background: #fafbfc;
  padding: 18px 16px 28px;
}
.brand h1 { font-size: 19px; margin: 0 0 12px; letter-spacing: -0.3px; }
.tabs { display: flex; gap: 4px; background: #eef0f4; padding: 3px; border-radius: 9px; }
.tab {
  flex: 1; border: 0; background: transparent; padding: 6px 0; border-radius: 7px;
  font: inherit; font-size: 13px; color: #6b7280; cursor: pointer;
}
.tab.active { background: #fff; color: #1f2430; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.tab:disabled { cursor: default; opacity: .55; }

section { margin-top: 22px; }
h2 { font-size: 13px; font-weight: 700; color: #4b5263; margin: 0 0 6px; }
.hint { margin: 0 0 10px; color: #8a90a0; font-size: 12px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

.preset-group { margin-bottom: 10px; }
.grade { font-size: 11px; color: #8a90a0; margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip, .btn {
  border: 1px solid #d9dce4; background: #fff; border-radius: 999px;
  padding: 5px 11px; font: inherit; font-size: 13px; cursor: pointer; color: #1f2430;
}
.chip:hover, .btn:hover { border-color: #3e63dd; color: #3e63dd; }
.btn { border-radius: 8px; padding: 5px 10px; }

/* ---------- 함수 카드 ---------- */
.card {
  background: #fff; border: 1px solid #e3e6ec; border-radius: 12px;
  padding: 10px 10px 8px; margin-bottom: 10px;
}
.card.selected { border-color: #3e63dd; box-shadow: 0 0 0 3px rgba(62, 99, 221, .12); }
.card-head { display: flex; align-items: center; gap: 6px; }
.dot {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--c);
  background: var(--c); cursor: pointer; padding: 0; flex-shrink: 0;
}
.dot.off { background: transparent; }
.ylabel { font-family: "Times New Roman", serif; font-style: italic; font-size: 15px; color: #4b5263; }
.expr {
  flex: 1; min-width: 0; border: 1px solid transparent; background: #f4f5f8; border-radius: 7px;
  padding: 6px 8px; font: 15px ui-monospace, "SF Mono", Menlo, monospace;
}
.expr:focus { outline: none; border-color: #3e63dd; background: #fff; }
.expr.bad { border-color: #e5484d; }
.error { color: #e5484d; font-size: 12px; margin: 4px 0 0 22px; }
.error:empty { display: none; }
.icon-btn {
  border: 0; background: transparent; color: #8a90a0; font-size: 18px; line-height: 1;
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: #f0f1f4; color: #1f2430; }

.param { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding-left: 2px; }
.pname { font-family: "Times New Roman", serif; font-style: italic; font-size: 16px; width: 14px; text-align: center; }
.param input[type="range"] { flex: 1; accent-color: #3e63dd; }
.pval {
  width: 58px; border: 1px solid #e3e6ec; border-radius: 6px; padding: 3px 5px;
  font: 13px ui-monospace, Menlo, monospace; text-align: right;
}
.play { font-size: 11px; }
.play.on { color: #3e63dd; background: #edf1fd; }

.info {
  margin-top: 10px; background: #f6f8fc; border-radius: 9px; padding: 9px 11px; font-size: 13px; line-height: 1.6;
}
.info .formula { font-family: "Times New Roman", serif; font-style: italic; font-size: 17px; margin-bottom: 4px; }
.info ul { margin: 0; padding-left: 17px; }
.info b { color: #2a3fa8; }
code { background: #eef0f4; border-radius: 4px; padding: 0 4px; font-size: 12px; }

.help { margin-top: 6px; color: #4b5263; font-size: 12.5px; }
.help summary { cursor: pointer; color: #6b7280; }
.help ul { padding-left: 18px; line-height: 1.8; }

.opts label { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; cursor: pointer; }

/* ---------- 그래프 영역 ---------- */
.stage { position: relative; flex: 1; height: 100%; overflow: hidden; }
#graph { display: block; cursor: crosshair; touch-action: none; }
#graph.dragging { cursor: grabbing; }
.zoom {
  position: absolute; top: 14px; right: 14px; display: flex; flex-direction: column;
  background: #fff; border: 1px solid #e3e6ec; border-radius: 10px; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.zoom button {
  width: 36px; height: 34px; border: 0; background: #fff; font-size: 18px; cursor: pointer; color: #4b5263;
}
.zoom button + button { border-top: 1px solid #eef0f4; }
.zoom button:hover { background: #f4f5f8; }
#readout, .readout {
  position: absolute; left: 14px; bottom: 14px; background: rgba(255,255,255,.95);
  border: 1px solid #e3e6ec; border-radius: 9px; padding: 7px 11px; font-size: 13px; line-height: 1.6;
  font-variant-numeric: tabular-nums; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
#readout .sw, .readout .sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.stage-hint { position: absolute; right: 14px; bottom: 12px; color: #a0a6b4; font-size: 12px; pointer-events: none; }

@media (max-width: 760px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: 48%; border-right: 0; border-bottom: 1px solid #e6e8ee; }
  .stage { height: 52%; }
}

/* ---------- 모듈 탭 ---------- */
[hidden] { display: none !important; }
.tab:not(:disabled):not(.active):hover { color: #1f2430; }

/* ---------- 도형 ---------- */
#geo { display: block; touch-action: none; cursor: default; }
#geo.can-drag { cursor: grab; }
#geo.dragging { cursor: grabbing; }
.chip.active { background: #3e63dd; border-color: #3e63dd; color: #fff; }
.ctrl-range { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ctrl-range span:first-child { min-width: 64px; font-size: 13px; color: #4b5263; }
.ctrl-range input[type="range"] { flex: 1; accent-color: #3e63dd; }
.ctrl-range .v { width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
#geo-info table { border-collapse: collapse; margin: 4px 0 6px; font-variant-numeric: tabular-nums; }
#geo-info td { padding: 1px 10px 1px 0; }
#geo-info .big { font-size: 15px; margin: 4px 0; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- 방정식 ---------- */
#eq-graph { display: block; cursor: crosshair; touch-action: none; }
#eq-graph.dragging { cursor: grabbing; }
.equation {
  font-family: "Times New Roman", serif; font-style: italic; font-size: 21px; text-align: center;
  background: #fff; border: 1px solid #e3e6ec; border-radius: 10px; padding: 10px 8px; margin: 6px 0 10px;
}
.equation .lhs { color: #3e63dd; } .equation .rhs { color: #e5484d; }
.select-row { display: flex; gap: 6px; margin: 8px 0; }
.select-row button { flex: 1; font-size: 16px; }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 4px 0; }
.steps li { counter-increment: step; position: relative; padding-left: 26px; margin-bottom: 5px; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #3e63dd; color: #fff; font-size: 11px; display: flex; align-items: center; justify-content: center;
}
.answer { margin-top: 8px; padding: 7px 10px; background: #fff; border-left: 3px solid #30a46c; border-radius: 6px; font-size: 14px; }
.m { font-family: "Times New Roman", serif; font-style: italic; font-size: 15px; }

/* ---------- 미적분 ---------- */
#calc-graph { display: block; cursor: crosshair; touch-action: none; }
#calc-graph.dragging { cursor: grabbing; }
.calc-fn { background: #fff; border: 1px solid #e3e6ec; border-radius: 10px; padding: 6px 8px; margin: 6px 0 4px; }
.fn-presets { margin: 8px 0 6px; }
.chip.small { padding: 3px 9px; font-size: 12.5px; }
.chip.small .m { font-size: 14px; }
.chip .note { color: #8a90a0; font-size: 11px; }
.toggle { display: flex; align-items: center; gap: 7px; margin: 10px 0 2px; cursor: pointer; }
#calc-info table { border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 4px 0 8px; }
#calc-info td { padding: 1px 8px 1px 0; }
#calc-controls .select-row button { font-size: 12.5px; white-space: nowrap; padding: 5px 4px; }
