:root {
  --bg: #081538;
  --bg-deep: #06102a;
  --grid: rgba(130, 175, 235, 0.28);
  --axis: rgba(230, 240, 255, 0.92);
  --label: rgba(190, 215, 250, 0.78);
  --neon: #f4f8ff;
  --neon-soft: #c5dcff;
  --glow: rgba(190, 225, 255, 0.95);
  --input-bg: rgba(8, 22, 52, 0.55);
  --danger: #ff8fa3;
  --font-display: "Cormorant Garamond", "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-deep);
  color: var(--neon);
  font-family: var(--font-mono);
}

body {
  min-height: 100vh;
  display: grid;
  place-items: stretch;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

.formula-bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.75rem 1rem 0.15rem;
}

.formula-label {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 600;
  color: var(--neon);
  text-shadow:
    0 0 8px var(--glow),
    0 0 18px rgba(140, 190, 255, 0.55);
  user-select: none;
}

.formula-input {
  width: min(28rem, calc(100vw - 7rem));
  border: 1px solid rgba(170, 205, 255, 0.28);
  border-radius: 0.55rem;
  background: var(--input-bg);
  color: var(--neon);
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.55rem, 3.6vw, 2.35rem);
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 0.35rem 0.85rem 0.45rem;
  outline: none;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 0 24px rgba(90, 150, 255, 0.18);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.formula-input:focus {
  border-color: rgba(190, 220, 255, 0.7);
  box-shadow:
    0 0 0 1px rgba(190, 220, 255, 0.18) inset,
    0 0 28px rgba(120, 180, 255, 0.35);
}

.formula-input.is-invalid {
  border-color: rgba(255, 120, 150, 0.7);
  color: #ffd5de;
}

.formula-error {
  position: absolute;
  top: calc(100% - 0.1rem);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0 0.75rem;
  color: var(--danger);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-shadow: 0 0 10px rgba(255, 100, 130, 0.35);
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.bg {
  fill: var(--bg);
}

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

.axes line {
  stroke: var(--axis);
  stroke-width: 0.035;
}

.axis-labels text {
  fill: var(--label);
  font-family: var(--font-mono);
  font-size: 0.28px;
  user-select: none;
}

.formula-display {
  fill: var(--neon);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.72px;
  font-weight: 600;
  letter-spacing: 0.02em;
  paint-order: stroke fill;
}

.stickman .arms,
.stickman .limb,
.stickman .head {
  stroke: var(--neon);
  stroke-width: 0.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stickman .arms {
  stroke-width: 0.115;
}

.stickman .foot,
.stickman .eye {
  fill: var(--neon);
  stroke: none;
}

.stickman .head {
  fill: transparent;
}

.hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem 0.9rem;
  background: var(--bg-deep);
}

.hints button {
  appearance: none;
  border: 1px solid rgba(150, 190, 255, 0.22);
  border-radius: 999px;
  background: rgba(10, 28, 62, 0.65);
  color: var(--neon-soft);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.hints button:hover,
.hints button:focus-visible,
.hints button.is-active {
  border-color: rgba(190, 220, 255, 0.55);
  color: var(--neon);
  background: rgba(24, 52, 104, 0.85);
  outline: none;
}

.hints button.is-active {
  box-shadow: 0 0 16px rgba(120, 180, 255, 0.35);
}

.hints button.demo-btn {
  border-color: rgba(255, 210, 140, 0.45);
  color: #ffe6b8;
  background: rgba(72, 42, 12, 0.55);
  font-weight: 500;
}

.hints button.demo-btn:hover,
.hints button.demo-btn:focus-visible,
.hints button.demo-btn.is-running {
  border-color: rgba(255, 220, 160, 0.75);
  color: #fff3d6;
  background: rgba(98, 58, 16, 0.85);
  box-shadow: 0 0 16px rgba(255, 180, 80, 0.3);
  outline: none;
}

@media (max-width: 640px) {
  .formula-bar {
    padding-top: 0.7rem;
  }

  .formula-error {
    white-space: normal;
    text-align: center;
    max-width: 90vw;
  }
}
