:root {
  --bg: #0e0f13;
  --panel: #1a1c23;
  --panel-2: #23262f;
  --fg: #e7e9ee;
  --muted: #8a8f9c;
  --accent: #7ec8ff;
  --border: #2c2f3a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
}

header {
  padding: 0.2rem 0.3rem 0.2rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.math {
  font-family: 'Cambria Math', 'STIX Two Math', Georgia, serif;
  color: var(--accent);
}

main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.2rem;
  padding: 0.2rem 0.4rem;
  align-items: start;
  position: relative;
}
main.sidebar-collapsed {
  grid-template-columns: 1fr 0;
}
main.sidebar-collapsed .controls {
  display: none;
}
.sidebar-toggle {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  z-index: 50;
  width: 2.4rem;
  height: 2.4rem;
  flex: 0 0 auto;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.sidebar-toggle.active {
  background: var(--accent);
  color: #0a0c10;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
  }
}

.canvas-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

canvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  background: #000;
  border-radius: 4px;
  display: block;
}
.canvas-wrap {
  width: 100%;
}
.sweep-btn {
  margin-top: 0.3rem;
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  padding: 0.25rem;
  font-weight: 500;
}
.sweep-btn.active {
  background: var(--accent);
  color: #0a0c10;
}
.offset-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 0.3rem;
}
.offset-buttons button {
  padding: 0.35rem;
  font-size: 0.8rem;
}
/* --- Integer stepper (numerator-style control) --- */
.int-stepper {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
}
.int-stepper button {
  flex: 0 0 auto;
  width: 2rem;
  padding: 0.25rem 0;
  font-size: 1rem;
  line-height: 1;
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--border);
}
.int-stepper button:hover {
  filter: brightness(1.2);
}
.int-stepper input[type='number'] {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
/* --- Rational stepper (p / q control) --- */
.rational-stepper {
  margin-top: 0.4rem;
}
.rs-frac {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.rs-frac .int-stepper {
  flex: 1 1 0;
}
.rs-bar {
  color: var(--muted);
  font-size: 1.2rem;
  font-weight: 600;
  padding: 0 0.1rem;
}

.legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.gradient {
  width: 220px;
  height: 12px;
  border-radius: 2px;
  background: linear-gradient(to right, #440154, #3b528b, #21918c, #5ec962, #fde725);
}

.controls {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.control label {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.control output {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

select,
input[type='range'] {
  width: 100%;
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}

input[type='range'] {
  padding: 0;
  accent-color: var(--accent);
}

button {
  background: var(--accent);
  color: #0a0c10;
  border: none;
  border-radius: 4px;
  padding: 0.55rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

button:hover {
  filter: brightness(1.1);
}

.info {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.info h3 {
  margin: 0 0 0.4rem;
  color: var(--fg);
  font-size: 0.9rem;
}

.info p {
  margin: 0 0 0.5rem;
}

.stats {
  margin-top: 0.6rem;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.75rem;
  color: var(--fg);
  background: var(--panel-2);
  padding: 0.5rem;
  border-radius: 4px;
}

.stats div {
  display: flex;
  justify-content: space-between;
}
/* --- Floating draggable subwindow --- */
.floating-window {
  position: fixed;
  top: 90px;
  right: 40px;
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  z-index: 100;
  user-select: none;
}
.fw-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  cursor: move;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
}
.fw-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--fg);
}
.fw-buttons {
  display: flex;
  gap: 0.3rem;
}
.fw-btn {
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}
.fw-body {
  padding: 0.6rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.floating-window.collapsed .fw-body {
  display: none;
}
.floating-window.collapsed {
  width: 220px;
}
#fftCanvas {
  width: 100%;
  height: auto;
  background: #05060a;
  border-radius: 4px;
  image-rendering: auto;
  display: block;
}
.fw-controls {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.fw-controls label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.72rem;
  color: var(--muted);
}
.fw-controls input[type='range'] {
  flex: 1;
}
