:root {
  --bg: #0f172a;
  --bg-light: #111827;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --card-bg: #020617;
  --card-border: #1f2937;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #1e293b 0, #020617 55%, #000 100%);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.page {
  width: 100%;
  max-width: 980px;
  padding: 2rem 1.25rem 3rem;
}

header {
  padding: 1.75rem 1.5rem 1.5rem;
  border-radius: 1.5rem;
  background: linear-gradient(135deg, rgba(56,189,248,0.16), rgba(129,140,248,0.1));
  border: 1px solid rgba(148,163,184,0.35);
  box-shadow:
    0 25px 50px -25px rgba(15,23,42,0.9),
    0 0 0 1px rgba(15,23,42,0.9) inset;
  backdrop-filter: blur(16px);
  margin-bottom: 2rem;
}

header h1 {
  font-size: clamp(2rem, 3vw, 2.3rem);
  margin-bottom: 0.25rem;
}

header p {
  max-width: 60rem;
  font-size: 0.98rem;
  color: #e5e7eb;
}

.tagline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding: 0.1rem 0.65rem;
  border-radius: 999px;
  background: rgba(15,23,42,0.68);
  border: 1px solid rgba(148,163,184,0.5);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}

.tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34,197,94,0.25);
}

.top-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1rem;
}

.header-status {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(148,163,184,0.2);
}

.header-status h2 {
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

.header-meta {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
}

.top-link {
  font-size: 0.8rem;
  text-decoration: none;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.55);
  background: rgba(15,23,42,0.72);
}

.top-link:hover {
  text-decoration: underline;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.3rem;
}

.card {
  border-radius: 1.25rem;
  padding: 1.3rem 1.4rem 1.4rem;
  background: radial-gradient(circle at top left, rgba(56,189,248,0.14), rgba(15,23,42,0.98));
  border: 1px solid rgba(31,41,55,0.9);
  box-shadow: 0 18px 35px -22px rgba(15,23,42,0.9);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(248,250,252,0.08), transparent 55%);
  opacity: 0.6;
  pointer-events: none;
}

.card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
  position: relative;
  color: #ffffff;
}

.card p {
  font-size: 0.92rem;
  color: var(--text-muted);
  position: relative;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  background: rgba(15,23,42,0.75);
  border: 1px solid rgba(148,163,184,0.45);
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  position: relative;
}

.pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.action-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(56,189,248,0.45);
  cursor: pointer;
  color: #ffffff;
  background: rgba(56,189,248,0.16);
  text-decoration: none;
  font: inherit;
  line-height: 1.2;
  box-shadow: none;
}

.action-btn:hover {
  border-color: rgba(56,189,248,0.7);
  background: rgba(56,189,248,0.22);
}

.action-btn:disabled {
  opacity: 0.65;
  cursor: default;
}

.lamp-action-btn {
  min-width: 210px;
  justify-content: flex-start;
  gap: 0.65rem;
}

.lamp-icon {
  width: 14px;
  height: 14px;
  border-radius: 50% 50% 40% 40%;
  position: relative;
  flex: 0 0 auto;
  background: rgba(148,163,184,0.16);
  border: 1px solid rgba(148,163,184,0.3);
  box-shadow: none;
}

.lamp-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 6px;
  height: 4px;
  transform: translateX(-50%);
  border-radius: 0 0 3px 3px;
  background: currentColor;
  opacity: 0.7;
}

.lamp-action-off {
  background: rgba(15,23,42,0.45);
  border-color: rgba(148,163,184,0.24);
}

.lamp-action-off .lamp-icon {
  color: rgba(148,163,184,0.8);
}

.lamp-action-on {
  background: rgba(56,189,248,0.22);
  border-color: rgba(250,204,21,0.45);
}

.lamp-action-on .lamp-icon {
  background: #facc15;
  border-color: rgba(250,204,21,0.75);
  color: #facc15;
  box-shadow: 0 0 0 4px rgba(250,204,21,0.12);
}

.lamp-action-dimmed {
  background: rgba(56,189,248,0.18);
  border-color: rgba(251,191,36,0.32);
}

.lamp-action-dimmed .lamp-icon {
  background: rgba(250,204,21,0.72);
  border-color: rgba(250,204,21,0.5);
  color: rgba(250,204,21,0.9);
  box-shadow: 0 0 0 4px rgba(250,204,21,0.08);
}

.status-name {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.meta-note {
  margin-top: 0.8rem;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.lamp-button-card {
  margin-top: 1rem;
  padding: 0.95rem;
  border-radius: 1rem;
  border: 1px solid rgba(148,163,184,0.18);
  background: rgba(15,23,42,0.42);
}

.lamp-button-grid {
  display: grid;
  gap: 0.8rem;
}

.lamp-dimmer-card {
  margin-top: 0.85rem;
  padding: 0.95rem;
  border-radius: 1rem;
  border: 1px solid rgba(148,163,184,0.14);
  background: rgba(15,23,42,0.28);
}

.lamp-dimmer-list {
  display: grid;
  gap: 0.85rem;
}

.dimmer-row {
  display: grid;
  gap: 0.45rem;
}

.dim-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.65rem;
}

.dim-label {
  font-size: 0.82rem;
  color: #ffffff;
}

.dim-range {
  width: 100%;
  accent-color: #38bdf8;
}

.dim-value {
  min-width: 32px;
  font-size: 0.78rem;
  color: #dbeafe;
  text-align: right;
}

.dim-btn {
  padding: 8px 11px;
  font-size: 0.78rem;
}

.sensor-grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  position: relative;
}

.sensor-card {
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  border: 1px solid rgba(148,163,184,0.2);
  background: rgba(15,23,42,0.38);
}

.sensor-name {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sensor-value {
  display: block;
  margin-top: 0.25rem;
  font-size: 1.1rem;
  color: #ffffff;
}

.sensor-humidity {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: #dbeafe;
}

.sensor-updated {
  display: block;
  margin-top: 0.45rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.guest-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 1.5rem;
}

.guest-shell {
  width: 100%;
  max-width: 520px;
}

.guest-card {
  border-radius: 1.35rem;
  padding: 1.35rem 1.1rem 1.1rem;
  background: radial-gradient(circle at top left, rgba(56,189,248,0.16), rgba(15,23,42,0.98));
  border: 1px solid rgba(31,41,55,0.92);
  box-shadow: 0 18px 35px -22px rgba(15,23,42,0.9);
}

.guest-tagline {
  margin-bottom: 0.9rem;
}

.guest-card h1 {
  font-size: clamp(1.6rem, 6vw, 2rem);
  margin-bottom: 0.35rem;
}

.guest-description {
  font-size: 0.94rem;
  color: var(--text-muted);
}

.guest-button-card {
  margin-top: 1rem;
  padding: 0.95rem;
  border-radius: 1rem;
  border: 1px solid rgba(148,163,184,0.18);
  background: rgba(15,23,42,0.42);
}

.guest-button-grid {
  display: grid;
  gap: 0.8rem;
}

.guest-action-btn {
  width: 100%;
  min-height: 48px;
  font-size: 1rem;
}

.guest-empty {
  margin-top: 1rem;
  padding: 0.95rem;
  border-radius: 1rem;
  border: 1px solid rgba(148,163,184,0.18);
  background: rgba(15,23,42,0.38);
  color: var(--text-muted);
}

.device-directory {
  margin-top: 1rem;
  display: grid;
  gap: 0.7rem;
}

.directory-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 0.9rem;
  border-radius: 1rem;
  border: 1px solid rgba(148,163,184,0.16);
  background: rgba(15,23,42,0.32);
}

.directory-name {
  display: block;
  color: #ffffff;
}

.directory-kind {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.directory-copy {
  min-width: 0;
}

.directory-id {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
}

.guest-meta {
  margin-top: 1rem;
  text-align: center;
}

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

.manage-form {
  margin-top: 1rem;
  display: grid;
  gap: 1rem;
  position: relative;
}

.form-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.92rem;
  color: #ffffff;
}

.field-grid {
  display: grid;
  gap: 0.85rem;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: end;
}

.form-field {
  display: grid;
  gap: 0.4rem;
}

.form-field span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-field input {
  width: 100%;
  padding: 0.75rem 0.8rem;
  border-radius: 0.9rem;
  border: 1px solid rgba(148,163,184,0.22);
  background: rgba(15,23,42,0.58);
  color: #ffffff;
  font: inherit;
}

.form-field input:focus {
  outline: 1px solid rgba(56,189,248,0.45);
  border-color: rgba(56,189,248,0.45);
}

.secondary-btn {
  background: rgba(15,23,42,0.38);
  border-color: rgba(148,163,184,0.24);
}

.secondary-btn:hover {
  background: rgba(15,23,42,0.56);
  border-color: rgba(148,163,184,0.36);
}

.share-box {
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem;
  border-radius: 1rem;
  border: 1px solid rgba(148,163,184,0.16);
  background: rgba(15,23,42,0.32);
}

.share-line {
  display: grid;
  gap: 0.35rem;
}

.share-link {
  color: #dbeafe;
  word-break: break-all;
  text-decoration: none;
}

.share-link:hover {
  text-decoration: underline;
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.lamp-picker {
  display: grid;
  gap: 0.8rem;
}

.lamp-picker-head {
  display: grid;
  gap: 0.2rem;
}

.checkbox-list {
  display: grid;
  gap: 0.65rem;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.8rem 0.9rem;
  border-radius: 1rem;
  border: 1px solid rgba(148,163,184,0.16);
  background: rgba(15,23,42,0.32);
}

.checkbox-copy {
  display: grid;
  gap: 0.15rem;
}

.checkbox-copy strong {
  color: #ffffff;
}

.checkbox-copy span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.manage-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.manage-actions-top {
  justify-content: flex-start;
  margin-bottom: 0.1rem;
}

footer {
  margin-top: 2.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  opacity: 0.85;
}

@media (max-width: 640px) {
  header {
    padding: 1.3rem 1.1rem 1.3rem;
  }

  .dim-controls {
    width: 100%;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .dim-range {
    width: 100%;
  }

  .guest-page {
    padding-top: 1rem;
  }

  .guest-card {
    padding: 1.15rem 0.95rem 1rem;
  }

  .header-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.5rem;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .share-actions,
  .manage-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .lamp-action-btn {
    width: 100%;
    min-width: 0;
  }
}
