:root {
  --glass: rgba(10, 12, 24, 0.72);
  --edge: rgba(255, 255, 255, 0.09);
  --text: #e9ecf5;
  --muted: #9aa3bd;
  --accent: #ffb547;
  --field: rgba(255, 255, 255, 0.06);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#view {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  cursor: grab;
  touch-action: none;
}
#view.dragging { cursor: grabbing; }

.chrome { transition: opacity 0.25s ease, transform 0.25s ease; }
body:not(.ui-on) .chrome { opacity: 0; pointer-events: none; }

#hud {
  position: fixed;
  left: 16px;
  bottom: 16px;
  padding: 10px 14px 12px;
  min-width: 200px;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
#hudZoom { font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }
#hudInfo { color: var(--muted); font-size: 12px; margin-top: 2px; }
#hudBusy {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 0;
  opacity: 0;
  overflow: hidden;
  font-size: 12px;
  transition: height 0.2s ease, opacity 0.2s ease, margin 0.2s ease;
}
#hud.busy #hudBusy { height: 18px; margin-top: 6px; opacity: 1; }
.spin {
  flex: none;
  width: 11px;
  height: 11px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#progress {
  height: 3px;
  margin-top: 8px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
#progressBar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #5ab0ff, var(--accent));
  transition: width 0.12s linear;
}

#outFab { right: 64px; }
body.panel-open #outFab { right: 348px; }
#outFab.busy::after {
  content: '';
  position: absolute;
  inset: -4px;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.fab {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--glass);
  border: 1px solid var(--edge);
  color: var(--text);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  cursor: pointer;
}
body.panel-open #panelBtn { opacity: 0; pointer-events: none; }

#panel {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 320px;
  max-width: calc(100vw - 24px);
  overflow-y: auto;
  padding: 14px 16px 12px;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 16px;
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
body:not(.panel-open) #panel { transform: translateX(calc(100% + 24px)); pointer-events: none; }

#panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: 0.01em; }
h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 8px;
}
section { padding: 12px 0; border-top: 1px solid var(--edge); }
section:first-of-type { border-top: 0; }

button {
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}
button:hover { background: rgba(255, 255, 255, 0.11); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#closeBtn { background: none; border: 0; padding: 4px; color: var(--muted); display: grid; }
#closeBtn:hover { color: var(--text); }
button.wide { width: 100%; margin-bottom: 10px; }
button.on { background: rgba(255, 181, 71, 0.18); border-color: rgba(255, 181, 71, 0.5); }
.buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.buttons.two { grid-template-columns: 1fr 1fr; margin: 0 0 10px; }
.buttons button { padding: 7px 4px; }

#presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.preset {
  position: relative;
  padding: 0;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  border-radius: 9px;
  background: #05060c;
}
.preset canvas { width: 100%; height: 100%; display: block; }
.preset canvas.loading {
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.07) 50%, transparent 70%) #05060c;
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
@media (prefers-reduced-motion: reduce) {
  .spin, #outFab.busy::after { animation-duration: 2.4s; }
  .preset canvas.loading { animation: none; }
}
.preset span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 7px 5px;
  font-size: 11.5px;
  font-weight: 600;
  text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.preset:hover { border-color: rgba(255, 255, 255, 0.35); }
.preset.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

#palettes {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.swatch {
  height: 22px;
  padding: 0;
  border-radius: 6px;
}
.swatch.active { box-shadow: 0 0 0 2px var(--accent); border-color: transparent; }

label { display: block; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0;
}
.row > span { color: var(--muted); }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row.two label span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0 6px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
#juliaBox.off { opacity: 0.4; pointer-events: none; }

select, input[type="number"] {
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: 5px 8px;
  min-width: 0;
}
select { max-width: 190px; }
select option { background: #11131f; }
input[type="number"] { width: 100%; font-variant-numeric: tabular-nums; }

.slider { margin: 8px 0 4px; }
.slider span { display: flex; justify-content: space-between; color: var(--muted); }
.slider b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; margin: 6px 0 0; accent-color: var(--accent); }

.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.keys dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 12px;
}
.keys dt { color: var(--text); white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }

footer { color: var(--muted); font-size: 11px; padding-top: 10px; border-top: 1px solid var(--edge); }

#toast {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translate(-50%, -8px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--edge);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#hint {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--edge);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text);
  text-align: center;
  pointer-events: none;
}
#hint[hidden] { display: none; }
body.panel-open #hint { left: calc((100vw - 344px) / 2); }

#fatal[hidden] { display: none; }
#fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
}

@media (max-width: 600px) {
  #panel { top: auto; height: 60vh; width: auto; left: 12px; }
  body:not(.panel-open) #panel { transform: translateY(calc(100% + 24px)); }
  #hud { min-width: 0; }
  body.panel-open #outFab { right: 64px; }
}
