:root {
  --bg-primary: #000000;
  --bg-secondary: #1c1e21;
  --bg-tertiary: #2a2c2f;
  --bg-card: #1a1c1f;
  --text-primary: #ffffff;
  --text-secondary: #e4e6eb;
  --text-muted: #b0b3b8;
  --accent-primary: #00d4ff;
  --accent-secondary: #00ff88;
  --accent-warm: #ff9f43;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.5);
  --success: #00ff88;
  --warning: #ffaa00;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

button {
  font-family: inherit;
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

/* ============================================================
   LANDING (desktop / phone)
   ============================================================ */
.landing-view {
  min-height: 100vh;
  background: linear-gradient(180deg, #0a0a0f 0%, #1c1e21 100%);
  color: var(--text-primary);
  padding: 32px 16px 80px;
}

.landing-container {
  max-width: 720px;
  margin: 0 auto;
}

.landing-header { text-align: center; margin-bottom: 40px; }
.landing-logo { font-size: 32px; font-weight: 700; letter-spacing: 0.5px; }
.landing-tagline { font-size: 16px; color: var(--text-muted); margin-top: 12px; line-height: 1.6; }
.landing-badges { margin-top: 16px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.badge {
  padding: 4px 12px; border: 1px solid var(--accent-primary);
  border-radius: 999px; font-size: 12px; color: var(--accent-primary);
}

.landing-section {
  margin: 32px 0;
  padding: 24px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
}
.landing-section h2 {
  font-size: 18px; font-weight: 600; margin-bottom: 16px;
  color: var(--accent-primary);
}

.steps { list-style: none; counter-reset: step; }
.steps li {
  padding: 16px 0; padding-left: 48px; position: relative;
  border-bottom: 1px solid var(--bg-tertiary);
  font-size: 14px; line-height: 1.6;
}
.steps li:last-child { border-bottom: none; }
.steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute; left: 0; top: 16px;
  width: 32px; height: 32px;
  background: var(--accent-primary); color: #000;
  border-radius: 50%; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.step-detail { color: var(--text-muted); font-size: 13px; display: block; margin-top: 4px; }
.step-url {
  margin-top: 8px; padding: 8px 12px; background: var(--bg-tertiary);
  border-radius: var(--radius-sm); font-family: monospace; font-size: 13px;
  color: var(--accent-secondary); white-space: pre-wrap; word-break: break-all;
}

.device-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.device-icon {
  text-align: center; padding: 16px 8px;
  background: var(--bg-tertiary); border-radius: var(--radius-md);
  font-size: 28px; line-height: 1.4;
}
.device-icon span { font-size: 12px; color: var(--text-muted); }

.privacy { list-style: none; padding: 0; }
.privacy li {
  padding: 8px 0 8px 24px; position: relative; font-size: 14px; line-height: 1.6;
}
.privacy li::before {
  content: '✓'; position: absolute; left: 0; top: 8px;
  color: var(--accent-secondary); font-weight: 700;
}

.landing-footer {
  text-align: center; margin-top: 40px; color: var(--text-muted);
  font-size: 13px;
}
.footer-link {
  color: var(--accent-primary); text-decoration: none; margin: 0 8px;
}
.footer-link:hover { text-decoration: underline; }

/* ============================================================
   GLASSES APP (600x600 fixed viewport)
   ============================================================ */
#glasses-app {
  width: 600px; height: 600px;
  position: relative; overflow: hidden;
  background: var(--bg-primary);
}

.screen {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  position: absolute; top: 0; left: 0;
}

/* --- Header --- */
.header {
  display: flex; align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
  min-height: 64px;
}
.header h1 {
  font-size: 24px; font-weight: 600; flex: 1; line-height: 1.2;
}
.header-meta {
  font-size: 14px; font-weight: 500; color: var(--text-muted);
}
.home-picker-btn {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 15px; font-weight: 600;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  max-width: 60%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: border-color .15s, box-shadow .15s;
}
.home-picker-btn .home-picker-chevron {
  font-size: 18px; line-height: 1; color: var(--text-muted);
}
.home-picker-btn:focus,
.home-picker-btn:hover {
  border-color: var(--accent-primary);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.35);
  outline: none;
}
.home-row {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 16px 20px;
  background: var(--bg-secondary);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  color: var(--text-primary);
  text-align: left;
}
.home-row:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 18px rgba(0,212,255,.4);
  outline: none;
}
.home-row.active { border-color: var(--accent-primary); }
.home-row-name { font-size: 17px; font-weight: 600; }
.home-row-meta { font-size: 13px; color: var(--text-muted); }
.home-row-check { color: var(--accent-primary); font-size: 20px; font-weight: 700; }
.back-btn {
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: var(--bg-tertiary);
}

/* --- Content area --- */
.content {
  flex: 1; min-height: 0;
  padding: 12px 16px;
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* IE / old Edge */
}
.content::-webkit-scrollbar { width: 0; height: 0; display: none; }

.content-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  align-content: start;
  width: 100%; box-sizing: border-box;
}

/* Room paging — sliding the grid when the user steps across the row edge */
@keyframes roomSlideOutLeft   { from { transform: translateX(0);    opacity: 1; } to { transform: translateX(-22%); opacity: 0; } }
@keyframes roomSlideOutRight  { from { transform: translateX(0);    opacity: 1; } to { transform: translateX( 22%); opacity: 0; } }
@keyframes roomSlideInRight   { from { transform: translateX(22%);  opacity: 0; } to { transform: translateX(0);    opacity: 1; } }
@keyframes roomSlideInLeft    { from { transform: translateX(-22%); opacity: 0; } to { transform: translateX(0);    opacity: 1; } }
.content-grid.slide-out-left  { animation: roomSlideOutLeft  .16s ease forwards; }
.content-grid.slide-out-right { animation: roomSlideOutRight .16s ease forwards; }
.content-grid.slide-in-right  { animation: roomSlideInRight  .18s ease forwards; }
.content-grid.slide-in-left   { animation: roomSlideInLeft   .18s ease forwards; }

.room-tab.active-pulse { box-shadow: 0 0 0 2px var(--accent-primary) inset; }

/* --- Focusable / focus ring --- */
.focusable {
  outline: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease,
              border-color 0.12s ease, background-color 0.12s ease;
  opacity: 0.82;
}
.focusable:focus {
  opacity: 1;
  box-shadow: 0 0 0 3px var(--focus-ring), 0 0 20px var(--focus-glow);
}

/* --- Nav bar --- */
.nav-bar {
  display: flex; gap: 8px;
  padding: 8px 12px 12px;
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  padding: 14px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  font-size: 15px; font-weight: 500;
  min-height: 48px;
  text-align: center;
}
.nav-item.primary { background: var(--accent-primary); color: #000; font-weight: 600; }
.nav-item.danger { background: var(--bg-tertiary); color: var(--danger); }

/* ============================================================
   PAIR SCREEN
   ============================================================ */
.content-pair {
  align-items: center; justify-content: center; text-align: center;
  gap: 18px; padding: 24px 16px;
}
.pair-instruction { font-size: 16px; color: var(--text-secondary); }
.pair-url {
  font-size: 20px; font-weight: 600; color: var(--accent-primary);
  letter-spacing: 0.5px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  font-family: monospace;
}
.pair-code-box {
  display: flex; gap: 12px; margin-top: 6px;
}
.pair-digit {
  width: 72px; height: 96px;
  display: flex; align-items: center; justify-content: center;
  font-size: 56px; font-weight: 700;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'SF Mono', monospace;
}
.pair-meta {
  font-size: 14px; color: var(--text-muted); margin-top: 4px;
}
.pair-meta-sep { margin: 0 8px; }

/* ============================================================
   SCENES + ROOMS
   ============================================================ */
.scene-strip {
  display: flex; gap: 8px; padding: 8px 16px 0;
  overflow-x: auto;
  flex-shrink: 0;
}
.scene-strip::-webkit-scrollbar { display: none; }

.scene-btn {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 92px; height: 76px;
  padding: 8px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  gap: 4px;
}
.scene-btn .scene-icon { font-size: 26px; line-height: 1; }
.scene-btn .scene-name { font-size: 13px; }

.room-tabs {
  display: flex; gap: 6px; padding: 8px 16px 4px;
  overflow-x: auto;
  flex-shrink: 0;
}
.room-tabs::-webkit-scrollbar { display: none; }
.room-tab {
  flex: 0 0 auto;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--bg-tertiary);
  font-size: 14px; color: var(--text-secondary);
  white-space: nowrap;
  min-height: 36px;
}
.room-tab.active { background: var(--accent-primary); color: #000; font-weight: 600; }

/* ============================================================
   DEVICE CARDS
   ============================================================ */
.device-card {
  padding: 14px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  display: flex; flex-direction: column; gap: 8px;
  min-height: 96px;
  min-width: 0;            /* allow grid column to shrink below content size */
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
  border: 2px solid transparent;
  text-align: left;
}
.device-card.on { border-color: rgba(0, 212, 255, 0.4); }
.device-card.offline { opacity: 0.4; }
.device-card-header {
  display: flex; align-items: center; gap: 10px;
  min-width: 0;
}
.device-card-icon { font-size: 28px; line-height: 1; flex-shrink: 0; }
.device-card-name {
  font-size: 15px; font-weight: 600; color: var(--text-primary);
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.device-card-state {
  font-size: 13px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.device-card.on .device-card-state { color: var(--accent-primary); }
.device-card-state .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.device-card.on .device-card-state .dot { background: var(--accent-secondary); }

/* ============================================================
   DEVICE DETAIL
   ============================================================ */
.content-device {
  gap: 8px; padding: 10px 14px 12px;
}
.dev-hero {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: var(--bg-card); border-radius: var(--radius-lg);
}
.dev-hero-icon { font-size: 40px; line-height: 1; }
.dev-hero-info { flex: 1; }
.dev-hero-state { font-size: 18px; font-weight: 600; color: var(--accent-primary); }
.dev-hero-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.dev-row {
  padding: 8px 14px 10px;
  background: var(--bg-card); border-radius: var(--radius-md);
  display: flex; flex-direction: column; gap: 6px;
}
.dev-row-header {
  display: flex; align-items: center; gap: 8px;
  min-height: 20px;
}
.dev-row-label { font-size: 13px; color: var(--text-muted); flex: 1; }
.dev-row-value { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.dev-row-controls {
  display: flex; gap: 10px; align-items: center;
}
.dev-step-btn {
  width: 56px; height: 48px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  font-size: 22px; font-weight: 700;
}
.dev-bar {
  flex: 1; height: 24px;
  background: var(--bg-tertiary); border-radius: 12px;
  position: relative; overflow: hidden;
}
.dev-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 12px;
  transition: width 0.25s ease;
}

/* Slider: D-pad ←/→ adjustable, takes the place of the old -/+ buttons */
.dev-slider {
  position: relative;
  width: 100%;
  padding: 6px 12px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dev-slider:focus,
.dev-slider:focus-visible {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
}
.dev-slider.adjusting { background: rgba(0, 212, 255, 0.08); }
.dev-slider-track {
  position: relative;
  height: 10px;
  background: var(--bg-secondary);
  border-radius: 5px;
  overflow: visible;
}
.dev-slider-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 7px;
  transition: width 0.12s ease;
}
.dev-slider-handle {
  position: absolute; top: 50%;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--accent-primary);
  transform: translate(-50%, -50%);
  transition: left 0.12s ease, transform 0.12s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.dev-slider:focus .dev-slider-handle,
.dev-slider.adjusting .dev-slider-handle {
  transform: translate(-50%, -50%) scale(1.18);
}
.dev-slider-hint {
  position: absolute; left: 0; right: 0; bottom: 2px;
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.dev-slider:focus .dev-slider-hint { opacity: 1; }

/* Centered grid spinner used while the device list is being fetched */
.grid-loading {
  grid-column: 1 / -1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  padding: 72px 16px;
  color: var(--text-muted);
  font-size: 14px;
}
.grid-loading-spinner {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.10);
  border-top-color: var(--accent-primary);
  animation: dev-spin 0.8s linear infinite;
}

/* Inline spinner shown on the hero (right after a control command) */
.dev-hero-spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent-primary);
  animation: dev-spin 0.8s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}
@keyframes dev-spin { to { transform: rotate(360deg); } }
.dev-hero-state.pending { color: var(--text-secondary); }

.dev-pill-row {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.dev-pill {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-tertiary);
  font-size: 13px; min-height: 32px;
}
.dev-pill.active { background: var(--accent-primary); color: #000; font-weight: 600; }

.dev-action-row {
  display: flex; gap: 10px;
}
.dev-action-btn {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  font-size: 15px; font-weight: 500;
  min-height: 44px;
}
.dev-action-btn.primary { background: var(--accent-primary); color: #000; font-weight: 600; }
.dev-action-btn.danger { background: var(--bg-tertiary); color: var(--danger); }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-row {
  display: flex; align-items: center; padding: 14px 16px;
  background: var(--bg-card); border-radius: var(--radius-md);
  gap: 12px;
}
.settings-label { font-size: 14px; color: var(--text-muted); flex: 1; }
.settings-value { font-size: 15px; color: var(--text-primary); }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: absolute; bottom: 88px; left: 50%; transform: translateX(-50%);
  padding: 12px 20px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid var(--accent-primary);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  font-size: 14px;
  z-index: 100;
  max-width: 84%;
  text-align: center;
  pointer-events: none;
}
.toast.success { border-color: var(--accent-secondary); }
.toast.error { border-color: var(--danger); }

/* ============================================================
   PAIR PAGE (mobile)
   ============================================================ */
.pair-page {
  min-height: 100vh;
  background: linear-gradient(180deg, #0a0a0f 0%, #1c1e21 100%);
  color: var(--text-primary);
  padding: 24px 16px 80px;
  display: flex; flex-direction: column;
  align-items: center;
}
.pair-page-container { max-width: 480px; width: 100%; }
.pair-page-title {
  font-size: 24px; font-weight: 700; text-align: center; margin-bottom: 8px;
}
.pair-page-sub {
  font-size: 14px; color: var(--text-muted); text-align: center; margin-bottom: 32px;
}

.pair-page-step {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}
.pair-page-step-title {
  font-size: 16px; font-weight: 600; margin-bottom: 16px;
  color: var(--accent-primary);
}

.pair-input-row {
  display: flex; gap: 10px; justify-content: center;
}
.pair-input {
  width: 56px; height: 72px;
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 32px; font-weight: 700;
  text-align: center;
  font-family: 'SF Mono', monospace;
  outline: none;
}
.pair-input:focus { border-color: var(--accent-primary); }

.pair-input-text {
  width: 100%; margin-top: 12px;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 16px; font-family: inherit;
  outline: none;
}
.pair-input-text:focus { border-color: var(--accent-primary); }

.pair-page-button {
  width: 100%;
  margin-top: 20px;
  padding: 16px;
  background: var(--accent-primary);
  color: #000;
  border-radius: var(--radius-md);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  min-height: 56px;
}
.pair-page-button:disabled { opacity: 0.5; cursor: not-allowed; }

.qr-box {
  display: flex; align-items: center; justify-content: center;
  width: 240px; height: 240px;
  margin: 16px auto;
  background: #fff;
  border-radius: var(--radius-md);
  padding: 16px;
}
.qr-box img { width: 100%; height: 100%; object-fit: contain; }
.qr-mock-text {
  text-align: center; color: #000; font-family: monospace;
  font-size: 11px; word-break: break-all;
}

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-radius: 999px;
  font-size: 13px; color: var(--text-secondary);
  margin: 12px auto 0;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warning);
  animation: pulse 1.4s ease infinite;
}
.status-pill.success .status-dot { background: var(--success); animation: none; }
.status-pill.error .status-dot { background: var(--danger); animation: none; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.pair-success-icon {
  width: 80px; height: 80px;
  background: var(--success); color: #000;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 44px; font-weight: 900;
  margin: 0 auto 16px;
}

.error-banner {
  margin-top: 12px;
  padding: 12px 16px;
  background: rgba(255, 68, 102, 0.15);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}
