:root {
  --paper: rgba(255, 252, 247, 0.94);
  --ink: #182026;
  --muted: #5d686e;
  --accent: #b55d2d;
  --accent-2: #0d6b73;
  --accent-3: #e2a33a;
  --accent-4: #7b6cf0;
  --line: rgba(24, 32, 38, 0.1);
  --shadow: 0 24px 70px rgba(67, 44, 20, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  background:
    radial-gradient(circle at 10% 10%, rgba(226, 163, 58, 0.24), transparent 26%),
    radial-gradient(circle at 90% 15%, rgba(13, 107, 115, 0.18), transparent 28%),
    linear-gradient(180deg, #fdf6ea 0%, #efe5d6 100%);
}

.page {
  max-width: var(--page-max-width, 430px);
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.page-width-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-bottom: 14px;
}

.page-width-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.page-width-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid rgba(212, 198, 173, 0.95);
  box-shadow: var(--shadow);
}

.width-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: #efe3d0;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.width-button:hover {
  background: var(--accent);
  color: #fff8ee;
}

.width-value {
  min-width: 62px;
  text-align: center;
  font-size: 0.9rem;
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  margin-bottom: 22px;
}

.hero-copy,
.hero-card,
.controls,
.visual-panel,
.lesson-card {
  background: var(--paper);
  border: 1px solid rgba(212, 198, 173, 0.95);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: 34px;
}

.hero-card,
.controls,
.lesson-card {
  padding: 24px 26px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.84rem;
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 4.6rem);
  line-height: 1.03;
  letter-spacing: -0.045em;
}

h2,
h3 {
  margin: 0;
}

.hero-text,
.scene-description,
.lesson-points,
.process-list,
.explanation-box {
  color: var(--muted);
  line-height: 1.75;
}

.hero-text {
  margin: 18px 0 0;
  font-size: 1.05rem;
}

.scene-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.scene-step {
  display: inline-block;
  width: fit-content;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(181, 93, 45, 0.13);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.84rem;
}

.scene-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  width: 100%;
}

.scene-button {
  border: 0;
  border-radius: 999px;
  padding: 10px 15px;
  width: 100%;
  background: #efe3d0;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
  text-align: left;
}

.scene-button:hover,
.scene-button.active {
  background: var(--accent);
  color: #fff8ee;
  transform: translateY(-1px);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "visual"
    "controls"
    "lesson";
  gap: 22px;
  align-items: start;
}

.controls,
.lesson-panel {
  position: sticky;
  top: 18px;
}

.controls {
  position: static;
  grid-area: controls;
}

.control-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.readout-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.readout {
  padding: 14px;
  border-radius: 20px;
  background: #f8f0e4;
  border: 1px solid #eadbc6;
}

.readout-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.readout-detail {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-line;
}

.visual-panel {
  grid-area: visual;
  padding: 16px;
  overflow: hidden;
}

#graph {
  display: block;
  width: 100%;
  height: auto;
}

.lesson-panel {
  display: grid;
  grid-area: lesson;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  position: static;
}

.lesson-card {
  min-width: 0;
}

.lesson-card h3 {
  line-height: 1.3;
}

.lesson-points,
.process-list,
.explanation-box,
.formula-box {
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.lesson-points {
  padding-left: 18px;
  margin: 12px 0 0;
}

.formula-box {
  margin-top: 14px;
  min-height: 136px;
  padding: 18px;
  border-radius: 22px;
  background: linear-gradient(135deg, #192229 0%, #22343b 100%);
  color: #eff7fb;
  font-family: "JetBrains Mono", "Consolas", monospace;
  line-height: 1.85;
  white-space: pre-line;
}

.process-list {
  margin: 0;
  padding-left: 22px;
}

.process-list li + li {
  margin-top: 8px;
}

.explanation-box {
  margin: 0;
}

.grid-line {
  stroke: var(--line);
  stroke-width: 1;
}

.axis {
  stroke: rgba(24, 32, 38, 0.45);
  stroke-width: 2.2;
}

.curve {
  fill: none;
  stroke: var(--accent-2);
  stroke-width: 4;
}

.family-curve {
  fill: none;
  stroke: rgba(123, 108, 240, 0.35);
  stroke-width: 3;
}

.secant {
  fill: none;
  stroke: var(--accent-3);
  stroke-width: 3;
  stroke-dasharray: 10 10;
}

.tangent {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3.5;
}

.area-fill {
  fill: rgba(181, 93, 45, 0.22);
  stroke: rgba(181, 93, 45, 0.48);
  stroke-width: 2;
}

.rect-fill {
  fill: rgba(226, 163, 58, 0.2);
  stroke: rgba(226, 163, 58, 0.6);
  stroke-width: 2;
  stroke-dasharray: 8 6;
}

.ball-shadow {
  fill: rgba(24, 32, 38, 0.14);
}

.ball-halo {
  fill: rgba(226, 163, 58, 0.18);
}

.rolling-ball {
  fill: #d96f3c;
  stroke: #8e4421;
  stroke-width: 4;
}

.ball-stripe {
  fill: none;
  stroke: rgba(255, 244, 224, 0.78);
  stroke-width: 4;
  stroke-linecap: round;
}

.ball-highlight {
  fill: rgba(255, 247, 236, 0.7);
}

.point-main {
  fill: var(--accent);
}

.point-helper {
  fill: var(--accent-3);
}

.point-accent {
  fill: var(--accent-4);
}

.helper-line {
  stroke: rgba(24, 32, 38, 0.24);
  stroke-width: 2;
  stroke-dasharray: 6 8;
}

.label {
  fill: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.label-soft {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.fade {
  opacity: 0;
  transform: translateY(6px);
  animation: fadeUp 0.45s ease forwards;
}

@keyframes fadeUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .controls,
  .lesson-panel {
    position: static;
  }
}

@media (max-width: 860px) {
  .page {
    padding: 16px 12px 28px;
  }

  .page-width-bar {
    gap: 8px;
    margin-bottom: 12px;
  }

  .hero {
    grid-template-columns: 1fr;
  }
}
