:root {
  color-scheme: dark;
  --bg: #17120f;
  --panel: #211a17;
  --panel-soft: #2b221e;
  --ink: #fff8ed;
  --muted: #c9b7a3;
  --line: rgba(255, 248, 237, 0.12);
  --accent: #ffbc66;
  --accent-2: #6fe7d0;
  --danger: #ff5c7a;
  --ok: #52e6a3;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(255, 188, 102, 0.035) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(0deg, rgba(111, 231, 208, 0.025) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.28;
  background:
    radial-gradient(circle at 18px 22px, rgba(255, 188, 102, 0.16) 0 3px, transparent 4px),
    radial-gradient(circle at 10px 14px, rgba(255, 188, 102, 0.1) 0 2px, transparent 3px),
    radial-gradient(circle at 26px 14px, rgba(255, 188, 102, 0.1) 0 2px, transparent 3px);
  background-size: 82px 82px;
  pointer-events: none;
}

button,
input,
a {
  font: inherit;
}

button,
a {
  touch-action: manipulation;
}

button:disabled,
input:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.dotol-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(100px, env(safe-area-inset-bottom));
}

.dotol-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin: -16px -14px 12px;
  padding: max(16px, env(safe-area-inset-top)) 14px 12px;
  background: rgba(23, 18, 15, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.dotol-header p,
.dotol-header h1,
h2,
.compact-panel p {
  margin: 0;
  letter-spacing: 0;
}

.dotol-header p {
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
}

.dotol-header h1 {
  margin-top: 2px;
  font-size: 19px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 248, 237, 0.07);
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}

.hero-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, #000 8%);
  box-shadow: var(--shadow);
}

.hero-panel {
  position: relative;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 124px;
  padding: 14px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 188, 102, 0.16), transparent 42%),
    linear-gradient(315deg, rgba(111, 231, 208, 0.12), transparent 48%),
    var(--panel);
}

.hero-panel::before,
.hero-panel::after {
  content: "";
  position: absolute;
  top: -18px;
  width: 74px;
  height: 74px;
  border: 1px solid var(--line);
  background: rgba(255, 188, 102, 0.12);
  transform: rotate(45deg);
}

.hero-panel::before {
  left: 26px;
}

.hero-panel::after {
  right: 36px;
}

.hero-panel > * {
  position: relative;
  z-index: 1;
}

.lamp-preview {
  position: relative;
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  isolation: isolate;
}

.lamp-preview::before {
  content: "";
  position: absolute;
  inset: 14px 18px 7px;
  border: 2px solid rgba(255, 248, 237, 0.18);
  border-top: 0;
  border-radius: 0 0 999px 999px;
  transform: translateY(8px);
}

.lamp-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, var(--lamp-color, #3b4aff) 0%, rgba(255,255,255,.1) 42%, transparent 70%);
  opacity: var(--lamp-opacity, 0.3);
  filter: blur(6px);
  transition: background 180ms ease, opacity 180ms ease;
}

.lamp-core {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--lamp-color, #3b4aff);
  box-shadow: 0 0 34px var(--lamp-color, #3b4aff);
  opacity: var(--lamp-core-opacity, 0.45);
  transition: background 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.lamp-core::before,
.lamp-core::after {
  content: "";
  position: absolute;
  top: -8px;
  width: 16px;
  height: 16px;
  background: inherit;
  border-radius: 4px 80% 4px 80%;
}

.lamp-core::before {
  left: 5px;
  transform: rotate(-28deg);
}

.lamp-core::after {
  right: 5px;
  transform: rotate(118deg);
}

.hero-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.state-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.status-pill.online {
  color: var(--ok);
}

.status-pill.offline {
  color: var(--danger);
}

.hero-copy h2,
.panel h2 {
  font-size: 17px;
}

#powerText {
  color: var(--accent);
  font-size: 38px;
  line-height: 1;
}

.power-switch,
.mini-switch {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
}

.power-switch {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 58px;
  height: 32px;
}

.mini-switch {
  width: 54px;
  height: 32px;
}

.power-switch input,
.mini-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.power-switch span,
.mini-switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 248, 237, 0.14);
  transition: background 160ms ease;
}

.power-switch span::after,
.mini-switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  transition: transform 160ms ease;
}

.power-switch span::after {
  width: 24px;
  height: 24px;
}

.mini-switch span::after {
  width: 24px;
  height: 24px;
}

.power-switch input:checked + span,
.mini-switch input:checked + span {
  background: var(--accent);
}

.power-switch input:checked + span::after {
  transform: translateX(26px);
}

.mini-switch input:checked + span::after {
  transform: translateX(22px);
}

.panel {
  display: grid;
  gap: 14px;
  margin-top: 12px;
  padding: 16px;
}

.panel-head,
.compact-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel output {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.segmented button,
.scene-grid button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.segmented button {
  position: relative;
  overflow: hidden;
}

.segmented button.active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: -8px -1px 0 currentColor, 8px -1px 0 currentColor;
  transform: translateX(-50%);
  opacity: 0.7;
}

.segmented button.active,
.scene-grid button.active {
  border-color: rgba(255, 183, 3, 0.7);
  background: rgba(255, 183, 3, 0.16);
  color: var(--accent);
}

.range-input {
  width: 100%;
  accent-color: var(--accent);
}

.warm-range {
  accent-color: #ffd166;
}

.color-layout {
  display: grid;
  grid-template-columns: 152px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.color-wheel {
  position: relative;
  width: 152px;
  height: 152px;
  touch-action: none;
}

.color-wheel canvas {
  width: 152px;
  height: 152px;
  border-radius: 50%;
  display: block;
  box-shadow: inset 0 0 0 1px rgba(255, 248, 237, 0.2), 0 14px 26px rgba(0, 0, 0, 0.24);
}

#colorPointer {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--lamp-color, #3b4aff);
  box-shadow: 0 0 0 1px rgba(0,0,0,.38), 0 4px 12px rgba(0,0,0,.34);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.color-sliders {
  display: grid;
  gap: 12px;
}

.color-sliders label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.preset-grid,
.scene-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.preset-grid button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--preset);
  cursor: pointer;
}

.scene-info {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.scene-info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.scene-units {
  display: grid;
  gap: 8px;
}

.scene-unit {
  display: grid;
  grid-template-columns: 32px 24px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 52px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 248, 237, 0.045);
}

.scene-swatch {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 248, 237, 0.22);
  border-radius: 50%;
  background: var(--scene-color);
  box-shadow: 0 0 18px color-mix(in srgb, var(--scene-color) 70%, transparent);
}

.scene-unit strong,
.scene-unit span,
.scene-unit small,
.scene-empty {
  letter-spacing: 0;
}

.scene-unit strong {
  color: var(--accent);
  font-size: 13px;
}

.scene-unit span,
.scene-unit small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.scene-unit span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.scene-unit small {
  grid-column: 3;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.scene-empty {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.compact-panel {
  grid-template-columns: minmax(0, 1fr) auto;
}

.compact-panel p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

#toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 60;
  max-width: 532px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff8ed;
  color: #17120f;
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 430px) {
  .dotol-header {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 9px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .header-actions {
    gap: 6px;
  }

  .header-actions .status-pill {
    min-height: 28px;
    padding: 0 8px;
    font-size: 11px;
  }

  .hero-panel {
    grid-template-columns: 74px minmax(0, 1fr);
    min-height: 112px;
    padding: 12px;
  }

  .lamp-preview {
    width: 74px;
    height: 74px;
  }

  #powerText {
    font-size: 34px;
  }

  .power-switch {
    right: 12px;
    bottom: 12px;
  }

  .color-layout {
    grid-template-columns: 1fr;
  }

  .color-wheel {
    margin: 0 auto;
  }

  .preset-grid,
  .scene-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
