:root {
  color-scheme: dark light;
  --bg: var(--tg-theme-bg-color, #0b1220);
  --card: var(--tg-theme-secondary-bg-color, #151f33);
  --text: var(--tg-theme-text-color, #f8fafc);
  --muted: var(--tg-theme-hint-color, #94a3b8);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(148, 163, 184, 0.2);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px calc(26px + env(safe-area-inset-bottom));
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1 {
  margin: 3px 0 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.icon-button {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:disabled {
  opacity: 0.5;
}

.card {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.card-head .muted {
  margin-top: 5px;
}

.status-pill {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.status-pill::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  content: "";
}

.status-pill.ok {
  background: rgba(34, 197, 94, 0.15);
}

.status-pill.ok::before {
  background: #22c55e;
}

.status-pill.off {
  background: rgba(239, 68, 68, 0.15);
}

.status-pill.off::before {
  background: #ef4444;
}

.status-pill.warn {
  background: rgba(245, 158, 11, 0.15);
}

.status-pill.warn::before {
  background: #f59e0b;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  min-height: 46px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s ease;
}

.button:active:not(:disabled) {
  transform: scale(0.98);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.button.secondary {
  background: rgba(148, 163, 184, 0.16);
  color: var(--text);
}

.button.danger {
  background: #dc2626;
  color: #ffffff;
}

.button.ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.button.small {
  min-height: 38px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0 4px;
}

.swatch {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.swatch:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.swatch.red {
  background: #ef4444;
}

.swatch.green {
  background: #22c55e;
}

.swatch.blue {
  background: #3b82f6;
}

.swatch.white {
  background: #f8fafc;
}

.swatch.violet {
  background: #a855f7;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.control-label {
  min-width: 64px;
  color: var(--muted);
  font-size: 13px;
}

input[type="color"] {
  width: 48px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

input[type="range"] {
  flex: 1 1 120px;
  min-width: 110px;
  accent-color: var(--accent);
}

#led-bright-value {
  min-width: 28px;
  text-align: right;
}

.notice {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 16px;
  background: rgba(245, 158, 11, 0.12);
  font-size: 14px;
  line-height: 1.45;
}

.toast {
  position: sticky;
  top: 8px;
  z-index: 10;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  box-shadow: var(--shadow);
}

.toast.ok {
  border-color: rgba(34, 197, 94, 0.45);
}

.toast.warn {
  border-color: rgba(245, 158, 11, 0.55);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.55);
}

.footer-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 480px) {
  .app {
    padding-top: 16px;
  }

  h1 {
    font-size: 25px;
  }

  .card {
    padding: 16px;
  }

  .button-row .button {
    flex: 1 1 130px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
