:root {
  color-scheme: dark;
  --bg: #07080c;
  --surface: rgba(255, 255, 255, .045);
  --surface-hi: rgba(255, 255, 255, .08);
  --border: rgba(255, 255, 255, .09);
  --text: #f4f5fa;
  --muted: #8a8fa3;
  --ok: #3ddc84;
  --err: #ff5c6c;
  --warn: #ffb020;
  --radius: 24px;
  /* werden per JS auf die aktuelle Farbe gesetzt */
  --accent: #ffb46b;
  --accent-2: #ff6b9d;
  --level: .8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  /* Wie eine App: kein Doppeltipp-Zoom, kein Markieren, kein Lupen-/Kopiermenü */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}
input, textarea, select {
  -webkit-user-select: text;
  user-select: text;
}

button { font: inherit; cursor: pointer; }

/* ---------- Leuchtender Hintergrund ---------- */

.aurora {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: calc(.25 + var(--level) * .55);
  transition: opacity .6s;
}
.blob {
  position: absolute;
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .55;
  transition: background 1s;
}
.blob.a { background: var(--accent); top: -35vmax; left: -20vmax; animation: drift-a 18s ease-in-out infinite alternate; }
.blob.b { background: var(--accent-2); top: -25vmax; right: -35vmax; animation: drift-b 22s ease-in-out infinite alternate; }
.blob.c { background: var(--accent); bottom: -55vmax; left: 10vmax; opacity: .25; animation: drift-a 26s ease-in-out infinite alternate-reverse; }

@keyframes drift-a { to { transform: translate(12vmax, 8vmax) scale(1.1); } }
@keyframes drift-b { to { transform: translate(-10vmax, 12vmax) scale(.9); } }

body.off .aurora { opacity: .06; }

@media (prefers-reduced-motion: reduce) {
  .blob { animation: none !important; }
}

/* ---------- Layout ---------- */

main {
  position: relative;
  max-width: 460px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
h1 {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -.03em;
  margin: 0;
}
.summary { margin: 2px 0 0; color: var(--muted); font-size: 15px; }

h2 {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .12em;
  margin: 32px 4px 12px;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 32px 0 12px;
}
.section-head h2 { margin: 0 4px; }

.power {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .3);
  background: var(--accent);
  color: #0b0b0f;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 18%, transparent), 0 8px 40px var(--accent);
  transition: background .3s, box-shadow .3s, color .3s, transform .15s;
}
.power:active { transform: scale(.92); }
body.off .power {
  background: var(--surface-hi);
  border-color: var(--border);
  color: var(--muted);
  box-shadow: none;
}

.banner {
  background: rgba(255, 176, 32, .12);
  border: 1px solid rgba(255, 176, 32, .5);
  color: #ffe2b0;
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.45;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
}

/* ---------- Farbrad ---------- */

.hero {
  display: grid;
  place-items: center;
  padding: 24px 0 8px;
}
.wheel {
  position: relative;
  width: min(76vw, 300px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle closest-side, #fff, rgba(255, 255, 255, 0) 100%),
    conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  box-shadow:
    0 0 0 10px rgba(255, 255, 255, .04),
    0 0 0 11px var(--border),
    0 20px 80px -20px var(--accent);
  /* Senkrechtes Wischen scrollt die Seite – Farbe wird per Tippen oder am Griff gewählt */
  touch-action: pan-y;
  cursor: crosshair;
  transition: box-shadow .4s, filter .4s;
}
body.off .wheel { filter: saturate(.2) brightness(.5); }

.handle {
  position: absolute;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .45), 0 0 24px var(--accent);
  touch-action: none;
  cursor: grab;
  transition: transform .15s;
}
/* Größere unsichtbare Fläche, damit man den Griff sicher trifft */
.handle::before {
  content: "";
  position: absolute;
  inset: -16px;
  border-radius: 50%;
}
.wheel.dragging .handle { transform: scale(1.25); cursor: grabbing; }

/* ---------- Farbkreise ---------- */

.swatches {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin: 24px 0 16px;
}
.swatches button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15);
  transition: transform .15s, box-shadow .2s;
}
.swatches button:active { transform: scale(.88); }
.swatches button.active {
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px #fff, 0 0 18px var(--glow);
}

/* ---------- Helligkeit ---------- */

.brightness {
  position: relative;
  display: block;
  height: 60px;
  border-radius: 20px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  /* Waagerecht wischen = Helligkeit, senkrecht = Seite scrollen */
  touch-action: pan-y;
  cursor: pointer;
}
.brightness-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--level) * 100%);
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 35%, transparent), var(--accent));
  border-right: 3px solid rgba(255, 255, 255, .85);
  transition: width .08s linear;
}
.brightness.dragging .brightness-fill { transition: none; }
.brightness:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.brightness-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  pointer-events: none;
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .5);
}
body.off .brightness { opacity: .4; }

/* ---------- Szenen ---------- */

.scenes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.scenes button {
  position: relative;
  height: 76px;
  border: 0;
  border-radius: 20px;
  padding: 14px 16px;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-align: left;
  display: flex;
  align-items: flex-end;
  background: var(--scene);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12), inset 0 -40px 40px -20px rgba(0, 0, 0, .45);
  text-shadow: 0 1px 8px rgba(0, 0, 0, .45);
  transition: transform .15s, box-shadow .25s;
}
.scenes button:active { transform: scale(.96); }
.scenes button.active {
  box-shadow: inset 0 0 0 2px #fff, 0 10px 30px -8px var(--scene-glow);
}
.scenes button.wide { grid-column: span 2; }
.scenes button.animated { animation: hue 8s linear infinite; }
@keyframes hue { to { filter: hue-rotate(360deg); } }

/* ---------- Geräte ---------- */

.devices {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.device {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
}
.device > div { min-width: 0; }
.device.unavailable { opacity: .55; }

.lamp {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--surface-hi);
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background .3s, box-shadow .3s, color .3s;
}
.lamp.lit {
  background: var(--lamp);
  color: rgba(0, 0, 0, .55);
  box-shadow: 0 0 24px -2px var(--lamp);
}

.device .name { font-weight: 700; font-size: 16px; }
.device .state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.device .state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: .8;
}
.device .state.ok { color: var(--ok); }
.device .state.busy { color: var(--warn); }
.device .state.busy::before { animation: pulse 1s ease-in-out infinite; }
.device .state.err { color: var(--err); }
@keyframes pulse { 50% { opacity: .2; } }

.device .connect {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  background: var(--surface-hi);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.device .connect:disabled { opacity: .4; cursor: default; }

/* ---------- Schalter ---------- */

.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, .14);
  cursor: pointer;
  transition: background .25s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  transition: transform .25s cubic-bezier(.3, 1.4, .6, 1);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

/* ---------- Knöpfe ---------- */

.primary, .secondary {
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
}
.primary {
  border: 0;
  background: var(--accent);
  color: #0b0b0f;
  box-shadow: 0 6px 24px -6px var(--accent);
}
.secondary {
  border: 1px solid var(--border);
  background: var(--surface-hi);
  color: var(--text);
}

/* ---------- Einrichtungsfenster ---------- */

.sheet {
  width: min(100% - 24px, 440px);
  max-height: calc(100% - 24px);
  margin: auto auto calc(12px + env(safe-area-inset-bottom));
  padding: 22px 18px 18px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: #13151c;
  color: var(--text);
  box-shadow: 0 -10px 60px rgba(0, 0, 0, .6);
}
.sheet[open] { animation: sheet-in .28s cubic-bezier(.2, .9, .3, 1.1); }
.sheet::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }

.sheet h3 { margin: 0 0 6px; font-size: 21px; letter-spacing: -.01em; }
.sheet .hint { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.sheet .field { display: block; margin-bottom: 14px; font-size: 14px; font-weight: 600; color: var(--muted); }
.sheet input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-hi);
  color: var(--text);
  font: 16px ui-monospace, "SF Mono", Menlo, Consolas, monospace; /* ≥16px verhindert Zoom auf dem iPhone */
}
.sheet input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.sheet .log {
  display: block;
  width: 100%;
  height: 46vh;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #0b0c10;
  color: #b9bdcc;
  font: 12px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre;
  resize: none;
}

.test-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: 18px;
  background: var(--surface-hi);
  border: 1px solid var(--border);
}
.test-swatch {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--test-color, #444);
  box-shadow: 0 0 24px var(--test-color, transparent);
  transition: background .2s, box-shadow .2s;
}
.test-step { font-weight: 700; font-size: 16px; }
.test-label { margin-top: 2px; color: var(--muted); font-size: 13px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.test-question { margin: 18px 0 14px; font-size: 17px; font-weight: 700; text-align: center; }

.text-muted {
  display: block;
  margin: 14px auto 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.advanced { margin: 4px 0 14px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 4px 0 10px; }
.dp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.form-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 92, 108, .12);
  color: #ffb3bb;
  font-size: 14px;
}

.guide-link { display: inline-block; margin-bottom: 18px; color: var(--accent); font-weight: 600; text-decoration: none; }

.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.text-danger {
  display: block;
  margin: 14px auto 0;
  border: 0;
  background: none;
  color: var(--err);
  font-size: 14px;
  font-weight: 600;
}

/* ---------- Einstellungen ---------- */

.settings { margin-top: 32px; padding: 4px 18px; }
.settings summary {
  padding: 14px 0;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
}
.settings summary::-webkit-details-marker { display: none; }
.settings summary::after { content: "›"; color: var(--muted); font-size: 22px; line-height: 1; transition: transform .2s; }
.settings[open] summary::after { transform: rotate(90deg); }
.settings label { display: block; margin: 0 0 16px; font-size: 15px; }

.manage {
  margin: 6px 0 18px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(0, 0, 0, .2);
  border: 1px solid var(--border);
}
.manage-title { font-weight: 700; margin-bottom: 10px; }
.manage-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.manage-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name actions" "type actions";
  align-items: center;
  gap: 2px 10px;
}
.manage-item .rename {
  grid-area: name;
  min-width: 0;
  padding: 6px 0;
  border: 0;
  border-bottom: 1px dashed var(--border);
  background: none;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
}
.manage-item .rename:focus { outline: none; border-bottom-color: var(--accent); }
.manage-type { grid-area: type; font-size: 12px; color: var(--muted); }
.manage-actions { grid-area: actions; display: flex; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  background: var(--surface-hi);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.chip.remove { color: var(--muted); }
.chip.remove.confirm { color: #fff; background: var(--err); border-color: var(--err); }
.add-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.add-row select {
  min-width: 0;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-hi);
  color: var(--text);
  font-size: 15px;
}
.settings > button { width: 100%; margin-bottom: 16px; }
.settings .check { display: flex; gap: 12px; align-items: center; }
.settings .field select {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-hi);
  color: var(--text);
  font-size: 15px;
}
