/* ============ Design tokens ============ */
:root {
  --bg: #0e1013;
  --bg-elev: #14171c;
  --card: #1b1f26;
  --card-2: #232833;
  --line: #2b313d;
  --text: #edeff4;
  --muted: #8f96a6;
  --accent: #ffb46b;
  --accent-ink: #2a1c08;
  --green: #59d98c;
  --danger: #ff6b6b;
  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

#view {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
  min-height: 100%;
  animation: view-in 0.22s var(--ease);
}
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }

/* ============ Header ============ */
.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0 18px;
}
.page-head h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-head .sub { color: var(--muted); font-size: 0.85rem; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--card);
  color: var(--muted);
  flex-shrink: 0;
  transition: background 0.15s var(--ease), transform 0.1s;
}
.icon-btn:active { transform: scale(0.92); background: var(--card-2); }
.icon-btn svg { width: 20px; height: 20px; }

/* ============ Sections ============ */
.section-title {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 22px 4px 10px;
}

/* ============ Thèmes (rangée) ============ */
.themes-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scrollbar-width: none;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
}
.themes-row::-webkit-scrollbar { display: none; }
.theme-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: 999px;
  padding: 8px 16px 8px 8px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: transform 0.1s, background 0.15s;
  user-select: none;
  -webkit-user-select: none;
}
.theme-chip:active { transform: scale(0.95); }
.theme-chip.applying { opacity: 0.55; pointer-events: none; }
.theme-chip .swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}
.theme-chip.add { color: var(--muted); padding: 8px 16px; }
.theme-chip.add .swatch {
  display: grid;
  place-items: center;
  background: var(--card-2);
  box-shadow: none;
}
.theme-chip.add svg { width: 14px; height: 14px; }

/* ============ Tuiles appareils ============ */
.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.tile {
  position: relative;
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 16px;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: transform 0.12s var(--ease), background 0.2s;
  user-select: none;
  -webkit-user-select: none;
}
.tile:active { transform: scale(0.97); }
.tile .glow {
  position: absolute;
  inset: -30%;
  opacity: 0;
  transition: opacity 0.35s var(--ease);
  pointer-events: none;
}
.tile.on .glow { opacity: 0.22; }
.tile-top { display: flex; justify-content: space-between; align-items: flex-start; }
.tile .dev-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--card-2);
  color: var(--muted);
  transition: background 0.25s, color 0.25s, box-shadow 0.35s;
  position: relative;
}
.tile.on .dev-icon { color: #fff; }
.tile .dev-icon svg { width: 22px; height: 22px; }
.tile-open {
  width: 34px;
  height: 34px;
  margin: -6px -6px 0 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  position: relative;
  z-index: 1;
}
.tile-open svg { width: 16px; height: 16px; }
.tile-name {
  font-weight: 600;
  font-size: 0.95rem;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; position: relative; }
.tile.offline { opacity: 0.55; }

/* skeleton */
.skeleton { pointer-events: none; }
.skeleton .sk {
  background: linear-gradient(90deg, var(--card-2) 25%, #2c3340 50%, var(--card-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
  color: transparent;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 24px;
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ============ Page appareil ============ */
.segmented {
  display: flex;
  background: var(--card);
  border-radius: 999px;
  padding: 4px;
  margin: 4px auto 22px;
  width: fit-content;
}
.segmented button {
  padding: 8px 26px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.2s var(--ease), color 0.2s;
}
.segmented button.active { background: var(--card-2); color: var(--text); }

.wheel-wrap { display: grid; place-items: center; padding: 8px 0 4px; }
.wheel {
  position: relative;
  width: min(74vw, 300px);
  aspect-ratio: 1;
  touch-action: none;
}
.wheel .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  -webkit-mask: radial-gradient(circle, transparent 57%, #000 58.5%);
  mask: radial-gradient(circle, transparent 57%, #000 58.5%);
}
.wheel .center {
  position: absolute;
  inset: 15.5%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.25s;
}
.wheel .center svg { width: 34%; height: 34%; color: #fff; filter: drop-shadow(0 2px 10px rgba(0,0,0,0.25)); position: relative; }
.wheel .stem {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  transform-origin: top center;
  background: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}
.wheel .thumb {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: transform 0.08s;
}
.wheel.dragging .thumb { transform: translate(-50%, -50%) scale(1.15); }
.wheel.disabled { opacity: 0.35; pointer-events: none; filter: saturate(0.4); }

/* slider luminosité */
.control-card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 18px;
  margin-top: 22px;
}
.control-card .label-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 12px;
}
.control-card .label-row b { color: var(--text); font-size: 0.95rem; }
input[type="range"].fancy {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  border-radius: 999px;
  background: var(--card-2);
  overflow: hidden;
  cursor: pointer;
}
input[type="range"].fancy::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: -412px 0 0 400px var(--accent);
}
input[type="range"].fancy:disabled { opacity: 0.4; }

/* power bar */
.power-bar {
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  margin-top: 28px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.power-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--card-2);
  color: var(--muted);
  transition: background 0.25s, color 0.25s, box-shadow 0.35s, transform 0.1s;
}
.power-btn:active { transform: scale(0.93); }
.power-btn svg { width: 30px; height: 30px; }
.power-btn.on {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 34px color-mix(in srgb, var(--accent) 55%, transparent);
}
.power-label { color: var(--muted); font-size: 0.8rem; margin-top: 8px; }

/* ============ Réglages / formulaires ============ */
.form-card {
  background: var(--card);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: 18px;
}
.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.form-row:last-child { border-bottom: none; }
.form-row .grow { flex: 1; color: var(--muted); }
.form-row input[type="text"] {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  text-align: right;
  outline: none;
  min-width: 0;
}
.form-row .value { color: var(--muted); }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0; }
.chip {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.chip:active { transform: scale(0.95); }
.chip.active { background: var(--accent); color: var(--accent-ink); }
.chip.ghost { border: 1px dashed var(--line); background: none; }

.icon-grid { display: flex; gap: 10px; flex-wrap: wrap; padding: 4px 0; }
.icon-choice {
  width: 48px;
  height: 48px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: var(--card);
  color: var(--muted);
}
.icon-choice.active { background: var(--accent); color: var(--accent-ink); }
.icon-choice svg { width: 22px; height: 22px; }

.btn {
  display: block;
  width: 100%;
  padding: 15px;
  border-radius: var(--r-md);
  background: var(--card);
  font-weight: 600;
  text-align: center;
  transition: transform 0.1s, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn + .btn { margin-top: 10px; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* éditeur de thème : mini contrôles par lampe */
.theme-dev {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.theme-dev .head { display: flex; align-items: center; gap: 12px; }
.theme-dev .head .dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.15);
  flex-shrink: 0;
}
.theme-dev .head .name { flex: 1; font-weight: 600; }
.theme-dev .controls { margin-top: 14px; display: flex; flex-direction: column; gap: 14px; }
.theme-dev .mini-seg { margin: 0; }
.theme-dev .mini-seg button { padding: 6px 18px; font-size: 0.82rem; }
input[type="range"].hue {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
input[type="range"].ct-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(to right, #ff9540, #fff2e0, #ffffff, #dbe9ff, #cfe2ff);
}
input[type="range"].hue::-webkit-slider-thumb,
input[type="range"].ct-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--bg);
  box-shadow: 0 1px 6px rgba(0,0,0,0.4);
}
input[type="text"].field {
  width: 100%;
  background: var(--card);
  border: none;
  border-radius: var(--r-md);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 15px 18px;
  outline: none;
  margin-bottom: 18px;
}
input[type="text"].field::placeholder { color: var(--muted); font-weight: 400; }

/* action sheet (long press thème) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 30;
  display: grid;
  align-items: end;
  animation: fade 0.15s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--bg-elev);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: slide-up 0.2s var(--ease);
}
@keyframes slide-up { from { transform: translateY(30%); } }
.sheet h3 { font-size: 1rem; margin-bottom: 14px; text-align: center; }

/* ============ Login ============ */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 30px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}
.login-logo {
  width: 60px;
  height: 60px;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, var(--accent), #d17f2f);
  box-shadow: 0 0 34px color-mix(in srgb, var(--accent) 45%, transparent);
}
.login-card h1 { font-size: 1.3rem; }
.login-card p { color: var(--muted); font-size: 0.9rem; }
.login-card input {
  padding: 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  text-align: center;
  outline: none;
}
.login-card button {
  padding: 14px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.error { color: var(--danger) !important; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-size: 0.9rem;
  max-width: 90vw;
  z-index: 50;
  box-shadow: var(--shadow);
  animation: slide-up 0.2s var(--ease);
}
