:root {
  color-scheme: dark;
  --bg: #07090f;
  --panel: rgba(16, 20, 27, 0.86);
  --panel-strong: rgba(20, 26, 36, 0.94);
  --border: rgba(132, 148, 166, 0.28);
  --border-strong: rgba(93, 214, 196, 0.55);
  --text: #f6f7fb;
  --muted: #aeb8c8;
  --quiet: #7d8aa0;
  --accent: #5dd6c4;
  --accent-2: #ffb454;
  --accent-3: #ff6b7a;
  --focus: #8fd8ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

#app-shell,
#canvas-container,
#math-canvas {
  width: 100%;
  height: 100%;
}

#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#math-canvas {
  display: block;
  cursor: grab;
  touch-action: none;
}

#math-canvas.is-dragging {
  cursor: grabbing;
}

.panel {
  position: fixed;
  z-index: 10;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow: hidden;
}

.art-toolbar {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 11;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  touch-action: manipulation;
  user-select: none;
}

.art-toolbar.is-dragging {
  cursor: grabbing;
}

.toolbar-drag-handle {
  width: 18px;
  min-height: 36px;
  align-self: stretch;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background:
    radial-gradient(circle, rgba(174, 184, 200, 0.85) 1.2px, transparent 1.4px) 50% 50% / 6px 6px,
    rgba(255, 255, 255, 0.035);
  cursor: grab;
  touch-action: none;
}

.toolbar-drag-handle:active {
  cursor: grabbing;
}

.art-tool-button {
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--text);
  cursor: pointer;
  font-weight: 850;
  line-height: 1;
  user-select: none;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.art-tool-button:hover {
  border-color: var(--border-strong);
  background: rgba(93, 214, 196, 0.12);
}

.art-tool-button:active {
  transform: translateY(1px);
}

.reset-tool-button {
  min-width: 58px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.control-panel {
  top: 18px;
  left: 18px;
  width: min(330px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
}

.panel-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.panel-header:active {
  cursor: grabbing;
}

.panel-title-group {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
.info-header {
  margin: 0;
  color: var(--text);
  font-size: 1.18rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.info-header {
  font-weight: 750;
}

.panel-content {
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 142px);
}

.panel-content::-webkit-scrollbar {
  width: 7px;
}

.panel-content::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(174, 184, 200, 0.35);
}

.panel.minimized .panel-content {
  display: none;
}

.panel.minimized .panel-header {
  border-bottom: 0;
}

.panel.minimized .panel-tabs {
  display: none;
}

.panel-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 12px 0;
}

.tab-button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  cursor: pointer;
  font-weight: 750;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.tab-button.active {
  border-color: var(--border-strong);
  background: rgba(93, 214, 196, 0.12);
  color: var(--text);
}

.tab-panel:not(.active) {
  display: none;
}

.control-group {
  margin-bottom: 14px;
}

label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

output {
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

select,
.primary-button {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--text);
}

select {
  padding: 8px 10px;
  cursor: pointer;
}

select.native-select {
  display: none;
}

.viz-picker {
  position: relative;
}

.viz-picker-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.035));
  color: var(--text);
  cursor: pointer;
  font-weight: 760;
  line-height: 1.2;
  text-align: left;
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.viz-picker-button:hover,
.viz-picker-button[aria-expanded="true"] {
  border-color: var(--border-strong);
  background: rgba(93, 214, 196, 0.12);
  box-shadow: 0 0 0 1px rgba(93, 214, 196, 0.08) inset;
}

.viz-picker-chevron {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 160ms ease, border-color 160ms ease;
}

.viz-picker-button[aria-expanded="true"] .viz-picker-chevron {
  border-color: var(--text);
  transform: rotate(225deg) translateY(-2px);
}

.viz-picker-menu {
  position: fixed;
  z-index: 40;
  min-width: 240px;
  max-height: min(56vh, 430px);
  padding: 8px 0;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: rgba(12, 16, 27, 0.98);
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.viz-picker-menu[hidden] {
  display: none;
}

.viz-picker-menu::-webkit-scrollbar {
  width: 8px;
}

.viz-picker-menu::-webkit-scrollbar-track {
  background: transparent;
}

.viz-picker-menu::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(174, 184, 200, 0.35);
}

.viz-picker-group {
  padding: 10px 12px 5px;
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.viz-picker-option {
  width: calc(100% - 12px);
  min-height: 36px;
  display: block;
  margin: 2px 6px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.84rem;
  line-height: 1.25;
  text-align: left;
}

.viz-picker-option:hover,
.viz-picker-option:focus-visible {
  border-color: rgba(93, 214, 196, 0.25);
  background: rgba(93, 214, 196, 0.11);
  color: var(--text);
}

.viz-picker-option[aria-current="true"] {
  border-color: rgba(93, 214, 196, 0.42);
  background: rgba(93, 214, 196, 0.16);
  color: var(--text);
  font-weight: 760;
}

.primary-button {
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 700;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.primary-button:hover {
  border-color: var(--border-strong);
  background: rgba(93, 214, 196, 0.12);
}

.primary-button:active {
  transform: translateY(1px);
}

.icon-button {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.icon-button:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(93, 214, 196, 0.1);
}

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

select:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button-row {
  margin-top: 4px;
}

.stats {
  margin-top: 12px;
  color: var(--quiet);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.info-section + .info-section {
  margin-top: 16px;
}

.info-content .info-header {
  margin-bottom: 14px;
}

.info-label {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.info-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

@media (max-width: 760px) {
  body {
    min-height: 100dvh;
  }

  .control-panel {
    top: auto;
    left: 10px;
    right: auto;
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: min(350px, calc(100vw - 20px));
    max-height: min(43vh, 360px);
    border-radius: 8px;
  }

  .art-toolbar {
    top: calc(10px + env(safe-area-inset-top));
    right: 8px;
    bottom: auto;
    padding: 5px;
    gap: 5px;
  }

  .art-tool-button {
    min-width: 34px;
    height: 34px;
    font-size: 0.92rem;
  }

  .toolbar-drag-handle {
    width: 20px;
    min-height: 34px;
  }

  .reset-tool-button {
    min-width: 52px;
    font-size: 0.72rem;
  }

  .panel-header {
    min-height: 46px;
    padding: 9px 12px;
    cursor: default;
  }

  .eyebrow {
    display: none;
  }

  h1,
  .info-header {
    font-size: 1rem;
    line-height: 1.2;
  }

  .icon-button {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
  }

  .panel-tabs {
    gap: 6px;
    padding: 8px 10px 0;
  }

  .tab-button {
    min-height: 32px;
    font-size: 0.82rem;
  }

  .panel-content {
    padding: 10px;
    max-height: min(calc(43vh - 88px), 272px);
  }

  .control-group {
    margin-bottom: 10px;
  }

  label {
    margin-bottom: 5px;
    font-size: 0.78rem;
  }

  select,
  .primary-button,
  .viz-picker-button {
    min-height: 36px;
    font-size: 0.88rem;
  }

  .viz-picker-menu {
    max-height: min(62vh, 520px);
    padding: 9px 0;
    border-radius: 8px;
  }

  .viz-picker-option {
    min-height: 39px;
    font-size: 0.88rem;
  }

  .primary-button {
    padding: 7px 10px;
  }

  .stats {
    margin-top: 8px;
    font-size: 0.68rem;
  }

  .info-section + .info-section {
    margin-top: 11px;
  }

  .info-content .info-header {
    margin-bottom: 10px;
  }

  .info-label {
    margin-bottom: 3px;
    font-size: 0.62rem;
  }

  .info-text {
    font-size: 0.78rem;
    line-height: 1.42;
  }
}

@media (max-width: 420px) {
  .control-panel {
    left: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    width: min(340px, calc(100vw - 16px));
    max-height: min(40vh, 330px);
  }

  .art-toolbar {
    right: 8px;
  }

  .panel-content {
    max-height: min(calc(40vh - 86px), 244px);
  }
}
