:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --paper: #fffdf8;
  --panel: rgba(255, 253, 248, 0.92);
  --panel-strong: #fffaf0;
  --ink: #18211f;
  --muted: #66736f;
  --soft: #36433f;
  --line: rgba(39, 53, 49, 0.14);
  --line-strong: rgba(39, 53, 49, 0.26);
  --accent: #0f8f75;
  --accent-soft: rgba(15, 143, 117, 0.1);
  --accent-2: #a66b12;
  --danger: #c4493f;
  --blue: #286fa8;
  --shadow: 0 18px 45px rgba(43, 35, 20, 0.08);
  --radius: 8px;
  font-family: "Avenir Next", "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(rgba(24, 33, 31, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 33, 31, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 15% 7%, rgba(15, 143, 117, 0.12), transparent 24rem),
    radial-gradient(circle at 90% 4%, rgba(166, 107, 18, 0.10), transparent 22rem),
    var(--bg);
  background-size: 42px 42px, 42px 42px, auto, auto, auto;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(255,253,248,0.15), rgba(255,253,248,0.72));
}

header {
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  padding: 40px 32px 20px;
}

header::before {
  content: "ALGORITHM VISUALS";
  display: inline-flex;
  margin-bottom: 14px;
  padding: 5px 8px;
  border: 1px solid rgba(15, 143, 117, 0.24);
  border-radius: 999px;
  color: var(--accent);
  background: rgba(255, 253, 248, 0.7);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  max-width: 940px;
  margin-bottom: 12px;
  color: var(--ink);
  font-size: clamp(30px, 4.2vw, 58px);
  line-height: 1.02;
  font-weight: 780;
  letter-spacing: 0;
}

h2 {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

p {
  max-width: 940px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.72;
}

main {
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 32px 54px;
  display: grid;
  gap: 18px;
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.76), rgba(255,250,240,0.9)), var(--panel);
  box-shadow: var(--shadow);
  animation: rise-in 420ms cubic-bezier(.2,.8,.2,1) both;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-top: 1px solid rgba(255,255,255,0.82);
}

.panel:nth-of-type(2) { animation-delay: 55ms; }
.panel:nth-of-type(3) { animation-delay: 110ms; }
.panel:nth-of-type(4) { animation-delay: 165ms; }

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  min-height: 38px;
  border: 1px solid rgba(15, 143, 117, 0.28);
  border-radius: 999px;
  padding: 8px 14px;
  color: #0c4f43;
  background: linear-gradient(180deg, #ffffff, #f5fbf8);
  box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 8px 18px rgba(28, 72, 62, 0.07);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(15, 143, 117, 0.6);
  background: linear-gradient(180deg, #ffffff, #ecf8f4);
  box-shadow: 0 10px 24px rgba(15, 143, 117, 0.13);
}

button:active { transform: translateY(0); }

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

.metric {
  color: var(--soft);
  font-variant-numeric: tabular-nums;
}

.explain {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.explain-item {
  position: relative;
  min-height: 122px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255, 255, 255, 0.56);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.explain-item:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.86);
}

.explain-item b {
  display: block;
  margin-bottom: 8px;
  color: var(--accent-2);
  font-size: 14px;
}

.explain-item span {
  color: var(--muted);
  line-height: 1.62;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 800;
}

.back-link::before {
  content: "←";
  transition: transform 160ms ease;
}

.back-link:hover::before { transform: translateX(-3px); }

code {
  border: 1px solid rgba(15, 143, 117, 0.18);
  border-radius: 6px;
  padding: 2px 6px;
  color: #0a5d4d;
  background: rgba(15, 143, 117, 0.08);
  font-family: "SFMono-Regular", Consolas, monospace;
}

.plot-container, .js-plotly-plot { border-radius: var(--radius); }

@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 720px) {
  header { padding: 30px 18px 14px; }
  main { padding: 10px 18px 34px; }
  .panel { padding: 16px; }
  .controls { align-items: stretch; }
  button { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
