:root {
  color-scheme: dark;
  --bg: #090b0f;
  --panel: #111821;
  --panel-2: #17212c;
  --text: #f4f7fb;
  --muted: #94a3b8;
  --line: #273445;
  --line-soft: rgba(255,255,255,0.07);
  --on: #7dd3fc;
  --on-bg: #122b3a;
  --on-line: rgba(125, 211, 252, 0.82);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  overflow: hidden;
  user-select: none;
}

.panel {
  width: 100vw;
  height: 100vh;
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  min-height: 46px;
  gap: 8px;
}

.mode-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
  font-weight: 760;
}

p {
  margin: 0;
  color: var(--muted);
  font-size: 20px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #17212c, #101720);
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(0,0,0,0.16), inset 0 1px 0 var(--line-soft);
}

.mode-button {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #17212c, #101720);
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(0,0,0,0.16), inset 0 1px 0 var(--line-soft);
}

.bedtime-mode {
  width: 100%;
  padding: 0 16px;
  background: linear-gradient(180deg, #202232, #141824);
  border-color: rgba(180, 80, 255, 0.52);
  color: #d8c7ff;
  font-size: 16px;
}

.morning-mode {
  width: 100%;
  padding: 0 16px;
  background: linear-gradient(180deg, #243422, #152315);
  border-color: rgba(134, 239, 172, 0.48);
  color: #b7f7c8;
  font-size: 16px;
}

.mode-button:active,
.icon-button:active {
  transform: scale(0.96);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(78px, 1fr);
  gap: 10px;
  min-height: 0;
}

.tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #151e29, #101720);
  color: var(--text);
  padding: 12px;
  display: grid;
  align-content: space-between;
  min-width: 0;
  min-height: 78px;
  text-align: left;
  touch-action: manipulation;
  box-shadow: 0 10px 22px rgba(0,0,0,0.18), inset 0 1px 0 var(--line-soft);
}

.tile:active { transform: scale(0.98); }

.tile.on {
  border-color: var(--on-line);
  background: linear-gradient(180deg, #18384a, var(--on-bg));
  box-shadow: 0 10px 24px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.10);
}

.tile.unavailable { opacity: 0.46; }

.tile-label {
  font-size: 18px;
  font-weight: 730;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.tile-state {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.tile.on .tile-state,
.tile.on .tile-label { color: var(--on); }

.tv-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #182231, #121a24);
  padding: 10px;
  box-shadow: inset 0 1px 0 var(--line-soft);
}

.section-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.swatch {
  height: 42px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.18), inset 0 0 0 1px rgba(0,0,0,0.24);
}

.swatch:active { transform: scale(0.96); }
.warm { background: #ff9c4a; }
.red { background: #ff2828; }
.blue { background: #4678ff; }
.purple { background: #b450ff; }
.white { background: linear-gradient(180deg, #ffffff, #d7e1ea); }

@media (max-width: 390px), (max-height: 430px) {
  .panel { padding: 10px; gap: 9px; }
  .mode-row { gap: 8px; }
  .bedtime-mode,
  .morning-mode { font-size: 15px; padding: 0 10px; }
  p { font-size: 18px; }
  .grid { gap: 8px; grid-auto-rows: minmax(66px, 1fr); }
  .tile { min-height: 66px; padding: 10px; }
  .tile-label { font-size: 16px; }
  .tv-card { padding: 8px; }
  .swatch { height: 34px; }
}
