:root {
  color-scheme: dark;
  --ink: #f5f4e8;
  --muted: #94ab9f;
  --line: rgba(169, 196, 180, .19);
  --red: #ff4d5e;
  --gold: #f5c04a;
  --green: #3fd08a;
  --mint: #8fe3b5;
  --ice: #ddf3ff;
  --serif: "DM Serif Display", Georgia, serif;
  --sans: Inter, system-ui, sans-serif;
  --mono: "DM Mono", monospace;
}

html, body { min-width: 320px; min-height: 100%; margin: 0; }
body {
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(circle at 70% 42%, rgba(139, 28, 40, .2), transparent 28%),
    linear-gradient(rgba(71, 113, 87, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(71, 113, 87, .05) 1px, transparent 1px),
    linear-gradient(145deg, #102c22, #061811 66%);
  background-size: auto, 56px 56px, 56px 56px, auto;
}
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.flake { position: absolute; top: -12px; width: var(--size); height: var(--size); border-radius: 50%; background: var(--ice); opacity: var(--opacity); animation: snowfall var(--duration) linear infinite; animation-delay: var(--delay); }
@keyframes snowfall { to { transform: translate3d(var(--drift), 108vh, 0); } }

.topbar {
  height: 78px;
  padding: 0 clamp(22px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 22;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 20, 15, .65);
  backdrop-filter: blur(18px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand img { filter: saturate(.75) drop-shadow(0 0 10px rgba(63,208,138,.25)); }
.close { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); font-size: 25px; font-weight: 300; text-decoration: none; }
.garland { position: absolute; left: 28%; right: 28%; top: 9px; height: 54px; display: flex; justify-content: space-around; align-items: flex-end; border-top: 1px solid rgba(143,227,181,.32); border-radius: 50%; }
.garland span { width: 7px; height: 11px; border-radius: 50% 50% 45% 45%; background: var(--red); box-shadow: 0 0 11px currentColor; }
.garland span:nth-child(2n) { color: var(--gold); background: currentColor; }
.garland span:nth-child(3n) { color: var(--green); background: currentColor; }
.garland span:nth-child(4n) { color: var(--ice); background: currentColor; }
body.playing .garland span:nth-child(odd) { animation: twinkle .4s ease-in-out infinite alternate; }
@keyframes twinkle { to { opacity: .34; filter: brightness(.65); } }

.christmas-app { min-height: calc(100vh - 78px); display: grid; grid-template-columns: 330px minmax(0, 1fr); }
.selector-panel { padding: 42px 28px 30px; border-right: 1px solid var(--line); background: rgba(5, 20, 15, .46); }
.eyebrow { margin: 0 0 9px; color: var(--gold); font: 500 10px/1 var(--mono); letter-spacing: .16em; }
h1 { margin: 0; max-width: 250px; font: 400 42px/.98 var(--serif); }
h1 em { color: var(--red); font-weight: 400; }
.intro { margin: 15px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.function-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 14px; padding: 4px; border: 1px solid var(--line); border-radius: 4px; background: rgba(3,14,10,.45); }
.function-tab { min-height: 38px; border: 0; border-radius: 2px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; }
.function-tab.active { background: rgba(245,192,74,.12); color: var(--gold); }
.function-tab span { display: inline-grid; min-width: 18px; height: 18px; margin-left: 4px; place-items: center; border-radius: 999px; background: rgba(143,227,181,.1); color: var(--mint); font: 9px/1 var(--mono); }
.function-panel[hidden] { display: none; }
.auto-mode {
  width: 100%; min-height: 66px; padding: 10px 13px; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 3px; background: rgba(143,227,181,.035);
}
.auto-mode.active { border-color: rgba(245,192,74,.52); background: linear-gradient(100deg, rgba(245,192,74,.11), rgba(255,77,94,.05)); }
.auto-icon { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid rgba(245,192,74,.35); border-radius: 50%; color: var(--gold); font: 22px/1 var(--serif); }
.auto-mode strong, .auto-mode small { display: block; }
.auto-mode strong { font-size: 12px; }
.auto-mode small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.function-list { display: grid; gap: 7px; margin-top: 18px; }
.function-choice {
  min-height: 51px; padding: 8px 11px; display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 9px;
  border: 1px solid transparent; border-radius: 3px; background: rgba(8,29,21,.68); text-align: left;
}
.function-choice:hover, .function-choice.active { border-color: color-mix(in srgb, var(--item-color) 50%, transparent); background: color-mix(in srgb, var(--item-color) 7%, #081d15); }
.function-number { color: #637c70; font: 500 9px/1 var(--mono); }
.function-name { font-size: 12px; font-weight: 600; }
.function-choice code { color: var(--item-color); font: 500 10px/1 var(--mono); }
.source-note { margin: 20px 0 0; color: #6e877b; font-size: 9px; line-height: 1.55; }
.custom-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.custom-heading .eyebrow { margin-bottom: 5px; font-size: 8px; }
.custom-heading h2 { margin: 0; font: 400 20px/1 var(--serif); }
.add-custom { width: 31px; height: 31px; border: 1px solid rgba(245,192,74,.35); border-radius: 50%; background: rgba(245,192,74,.06); color: var(--gold); font-size: 21px; font-weight: 300; }
.random-function { width: 100%; min-height: 42px; margin-top: 13px; border: 1px solid rgba(143,227,181,.25); border-radius: 3px; background: rgba(143,227,181,.065); color: var(--mint); font-size: 11px; font-weight: 700; }
.random-function span { margin-right: 7px; color: var(--gold); }
.random-function:hover { border-color: rgba(143,227,181,.48); background: rgba(143,227,181,.11); }
.empty-custom { margin: 20px 2px 0; color: #6e877b; font-size: 11px; line-height: 1.55; text-align: center; }
.custom-form { margin-top: 13px; padding: 13px; border: 1px solid var(--line); border-radius: 3px; background: rgba(3,14,10,.55); }
.custom-form label { display: block; margin-bottom: 10px; color: #8ca397; font: 500 9px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.custom-form input { width: 100%; height: 37px; margin-top: 6px; padding: 0 10px; border: 1px solid var(--line); border-radius: 2px; outline: 0; background: rgba(143,227,181,.04); color: var(--ice); font: 500 11px/1 var(--mono); text-transform: none; }
.custom-form input:focus { border-color: rgba(245,192,74,.5); }
.formula-preview { min-height: 35px; padding: 9px 10px; border-left: 2px solid rgba(245,192,74,.42); background: rgba(245,192,74,.035); color: var(--gold); font: 400 17px/1.2 var(--serif); }
.formula-preview math { color: inherit; }
.formula-preview.bad { border-left-color: rgba(255,77,94,.6); color: var(--red); font: 10px/1.4 var(--mono); }
.custom-form small { display: block; color: #667f73; font-size: 9px; line-height: 1.5; }
.custom-error { min-height: 13px; margin: 7px 0; color: var(--red); font-size: 10px; }
.save-custom { width: 100%; height: 36px; border: 0; border-radius: 2px; background: var(--gold); color: #102118; font-size: 11px; font-weight: 700; }
.custom-function-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.function-choice.custom { width: 100%; grid-template-columns: 28px minmax(0, 1fr); }
.delete-function { width: 24px; height: 24px; display: grid; place-items: center; border: 1px solid rgba(255,77,94,.22); border-radius: 50%; background: rgba(255,77,94,.04); color: #bd6e75; font-size: 14px; }
.delete-function:hover { color: var(--red); border-color: rgba(255,77,94,.55); }

.stage-panel { min-width: 0; padding: 36px clamp(24px, 5vw, 76px) 28px; display: flex; flex-direction: column; }
.stage-copy { text-align: center; }
.stage-copy h2 { margin: 0; font: 400 clamp(30px, 4vw, 48px)/1 var(--serif); }
.stage-copy code { display: inline-block; margin-top: 10px; color: var(--mint); font: 500 13px/1.3 var(--mono); }
.canvas-wrap {
  position: relative; min-height: 460px; flex: 1; margin: 24px auto 18px; width: 100%; max-width: 860px;
  overflow: hidden; border: 1px solid var(--line); border-radius: 3px;
  background: radial-gradient(circle at 50% 55%, rgba(255,77,94,.1), transparent 40%), rgba(4,17,12,.46);
}
#christmas-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.axis-label { position: absolute; color: rgba(169,196,180,.58); font: italic 14px var(--serif); pointer-events: none; }
.axis-x { right: 13px; top: calc(50% + 4px); }
.axis-y { left: calc(50% + 7px); top: 9px; }
.parameter-readout { position: absolute; right: 15px; bottom: 14px; display: flex; flex-direction: column; gap: 5px; text-align: right; }
.parameter-readout span { color: #6d877a; font: 500 8px/1 var(--mono); letter-spacing: .13em; }
.parameter-readout strong { color: var(--gold); font: 500 12px/1 var(--mono); }
.music-player { min-height: 76px; padding: 12px 16px; display: flex; align-items: center; gap: 15px; border: 1px solid var(--line); border-radius: 3px; background: rgba(4,17,12,.78); }
.play { width: 49px; height: 49px; flex: none; display: grid; place-items: center; border: 0; border-radius: 50%; color: #092017; background: linear-gradient(135deg, var(--gold), #ff8c60); box-shadow: 0 7px 22px rgba(245,192,74,.14); }
.play svg { grid-area: 1/1; width: 21px; height: 21px; fill: currentColor; stroke: currentColor; stroke-width: 2; }
.pause-icon, body.playing .play-icon { display: none; }
body.playing .pause-icon { display: block; }
.track { min-width: 0; flex: 1; }
.track-meta { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 9px; }
.track select {
  min-width: 0;
  max-width: 300px;
  border: 0;
  outline: 0;
  background: transparent;
  color: #dce3de;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.track select option { color: #dce3de; background: #081d15; }
.track span { flex: none; color: #738c80; font: 10px/1 var(--mono); }
.track input { width: 100%; height: 3px; accent-color: var(--gold); cursor: pointer; }
.sound-toggle { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 50%; background: rgba(143,227,181,.06); color: var(--muted); }
.sound-toggle svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sound-toggle[aria-pressed="true"] { color: var(--red); opacity: .7; }

@media (max-width: 920px) {
  .christmas-app { grid-template-columns: 280px minmax(0, 1fr); }
  .selector-panel { padding: 34px 20px; }
  .stage-panel { padding: 32px 22px 24px; }
  .canvas-wrap { min-height: 420px; }
}
@media (max-width: 680px) {
  .topbar { height: 68px; padding: 0 18px; }
  .garland { left: 36%; right: 25%; opacity: .55; }
  .christmas-app { grid-template-columns: 1fr; }
  .selector-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  h1 { max-width: none; font-size: 38px; }
  .function-list { grid-template-columns: repeat(2, 1fr); }
  .function-choice { grid-template-columns: 20px minmax(0, 1fr); }
  .function-choice code { display: none; }
  .stage-panel { padding: 30px 16px 20px; }
  .canvas-wrap { min-height: 430px; }
  .track-meta { align-items: flex-start; flex-direction: column; gap: 4px; }
}
@media (max-width: 390px) {
  .function-list { grid-template-columns: 1fr; }
  .garland { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .flake, .garland span { animation: none !important; }
}
