:root {
  --bg: #f5f7f2;
  --ink: #17201c;
  --muted: #66736d;
  --panel: #ffffff;
  --line: #d8ded5;
  --accent: #0c7f83;
  --accent-2: #e2553f;
  --shadow: 0 18px 45px rgba(29, 46, 41, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    linear-gradient(120deg, rgba(12, 127, 131, 0.09), transparent 42%),
    linear-gradient(230deg, rgba(226, 85, 63, 0.1), transparent 38%),
    var(--bg);
}

button,
input {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.75fr);
  align-items: start;
  gap: 18px;
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.stage-panel,
.controls {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(216, 222, 213, 0.95);
  box-shadow: var(--shadow);
}

.stage-panel {
  display: flex;
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  min-height: calc(100vh - 36px);
  flex-direction: column;
  overflow: hidden;
}

.topbar,
.chart-head,
.group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  padding: 18px 20px 10px;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.5vw, 2.5rem);
}

h2 {
  font-size: 1rem;
}

.readout {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.readout span {
  min-width: 132px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(245, 247, 242, 0.78);
  text-align: center;
}

#pendulumCanvas,
#phaseCanvas,
#angleGridCanvas,
#heatmapCanvas {
  display: block;
  width: 100%;
}

#pendulumCanvas {
  flex: 1;
  min-height: 460px;
  cursor: grab;
  touch-action: none;
}

#pendulumCanvas:active {
  cursor: grabbing;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: calc(100vh - 36px);
  min-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 16px;
}

.control-group,
.chart-panel {
  border: 1px solid var(--line);
  background: rgba(250, 251, 248, 0.9);
  padding: 14px;
}

.control-group label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

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

button {
  height: 40px;
  border: 1px solid #bfc9c2;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.grid-actions span {
  min-width: 72px;
  padding: 8px 10px;
  border: 1px solid rgba(155, 142, 98, 0.55);
  background: rgba(17, 17, 15, 0.88);
  color: #f7dd8b;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.chart-panel {
  display: flex;
  flex: 0 0 auto;
  min-height: 420px;
  flex-direction: column;
}

.angle-template-panel {
  min-height: 460px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 750;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-2);
}

#phaseCanvas {
  flex: 1;
  min-height: 320px;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: #fbfcf8;
}

#angleGridCanvas {
  flex: 1;
  min-height: 360px;
  margin-top: 12px;
  border: 1px solid #9b8e62;
  background: #11110f;
}

#heatmapCanvas {
  flex: 1;
  min-height: 360px;
  margin-top: 12px;
  border: 1px solid #4f6d78;
  background: #0f1215;
}

.axis-note {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

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

  .stage-panel,
  .controls {
    min-height: auto;
  }

  #pendulumCanvas {
    min-height: 420px;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 10px;
  }

  .topbar,
  .chart-head,
  .group-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .readout {
    justify-content: flex-start;
  }

  .control-row {
    grid-template-columns: 1fr;
  }
}
