:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-elevated: rgba(255, 255, 255, 0.78);
  --surface-muted: #ececf0;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.12);
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff3b30;
  --border: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.09);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-elevated: rgba(28, 28, 30, 0.78);
  --surface-muted: #2c2c2e;
  --text: #f5f5f7;
  --muted: #98989d;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-soft: rgba(10, 132, 255, 0.18);
  --green: #30d158;
  --border: rgba(255, 255, 255, 0.12);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
  body {
    padding-bottom: 48px;
  }
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Frosted Glass Navbar */
.top-nav-wrap {
  position: sticky;
  top: 12px;
  z-index: 40;
  padding: 0 16px;
}

.top-nav {
  max-width: 1180px;
  margin: 0 auto;
  height: 58px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--surface-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1d1d1f, #0071e3);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
}

.nav-links {
  display: none;
  align-items: center;
  gap: 4px;
}

@media (min-width: 768px) {
  .nav-links {
    display: flex;
  }
}

.nav-link {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
  background: transparent;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.nav-link.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-pill {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease;
}

.icon-pill:hover {
  transform: translateY(-1px);
}

.badge-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Mobile Frosted Bottom Tab Bar */
.mobile-tabbar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 45;
  height: 62px;
  border-radius: 22px;
  background: var(--surface-elevated);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 4px;
}

@media (min-width: 768px) {
  .mobile-tabbar {
    display: none;
  }
}

.tab-item {
  border: none;
  background: transparent;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}

.tab-item.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

/* Surfaces & Bento Grid */
.page-section {
  padding: 28px 0 24px;
  animation: fadeSlide 0.25s ease;
}

@keyframes fadeSlide {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.card-hover {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.bento-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .bento-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  .bento-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  .bento-grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Typography & Buttons */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.h1-hero {
  margin: 14px 0 12px;
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1.08;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.h2-section {
  margin: 0 0 8px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.15;
  letter-spacing: -0.025em;
  font-weight: 700;
}

.lead {
  color: var(--muted);
  font-size: 16px;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface-muted);
  color: var(--text);
}

.btn-secondary:hover {
  opacity: 0.88;
}

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

.btn-sm {
  padding: 7px 14px;
  font-size: 13px;
}

.pill-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-muted);
}

.pill-tab {
  border: none;
  background: transparent;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.pill-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Hero Robot & AI Glow */
.hero-card {
  position: relative;
  overflow: hidden;
  padding: 36px 28px;
  display: grid;
  gap: 28px;
  align-items: center;
}

@media (min-width: 900px) {
  .hero-card {
    grid-template-columns: 1.15fr 0.85fr;
    padding: 48px 44px;
  }
}

.robot-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
  border-radius: var(--radius-lg);
  background: radial-gradient(circle at 50% 45%, rgba(0, 113, 227, 0.14), rgba(129, 140, 248, 0.08) 45%, transparent 72%);
}

.robot-body {
  width: 220px;
  height: 162px;
  border-radius: 40px;
  background: linear-gradient(160deg, #ffffff, #e5e7eb);
  padding: 14px;
  box-shadow: 0 24px 48px rgba(0, 113, 227, 0.16), inset 0 2px 4px rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(0, 0, 0, 0.06);
  cursor: pointer;
  transition: transform 0.25s ease;
}

[data-theme="dark"] .robot-body {
  background: linear-gradient(160deg, #2c2c2e, #1c1c1e);
  border-color: rgba(255, 255, 255, 0.12);
}

.robot-body:hover {
  transform: scale(1.03);
}

.robot-screen {
  width: 100%;
  height: 100%;
  border-radius: 28px;
  background: #0d0e12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

.robot-eyes {
  display: flex;
  gap: 38px;
}

.robot-eye {
  width: 24px;
  height: 28px;
  border-radius: 999px;
  background: #38bdf8;
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.8);
  animation: blink 4.5s infinite;
}

@keyframes blink {
  0%, 94%, 100% { transform: scaleY(1); }
  97% { transform: scaleY(0.12); }
}

.robot-mouth {
  width: 44px;
  height: 10px;
  border-bottom: 4px solid #38bdf8;
  border-radius: 0 0 24px 24px;
}

.robot-bubble {
  margin-top: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

/* iOS Switch */
.ios-switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.ios-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.ios-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d1d1d6;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

[data-theme="dark"] .ios-slider {
  background: #39393d;
}

.ios-slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s ease;
}

.ios-switch input:checked + .ios-slider {
  background: var(--green);
}

.ios-switch input:checked + .ios-slider::before {
  transform: translateX(20px);
}

/* Flasher Stepper & AI Progress */
.stepper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 22px;
}

.step-chip {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.step-chip.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.step-chip.done {
  background: rgba(52, 199, 89, 0.14);
  color: var(--green);
}

.device-select-card {
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  background: var(--surface);
  transition: all 0.2s ease;
  text-align: left;
}

.device-select-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.ai-progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.ai-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0071e3, #38bdf8, #818cf8);
  box-shadow: 0 0 16px rgba(0, 113, 227, 0.55);
  transition: width 0.2s ease;
}

.serial-log {
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #111216;
  color: #d1d5db;
  font-family: var(--font-mono);
  font-size: 12px;
  max-height: 170px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Console Layout */
.console-shell {
  display: grid;
  gap: 16px;
}

@media (min-width: 960px) {
  .console-shell {
    grid-template-columns: 230px 1fr 340px;
    align-items: start;
  }
}

.console-sidebar {
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  gap: 6px;
  padding: 12px;
}

@media (min-width: 960px) {
  .console-sidebar {
    flex-direction: column;
    position: sticky;
    top: 84px;
  }
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.offline { background: var(--muted); }

/* Lab Table & Docs */
.pin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.pin-table th,
.pin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.pin-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
}

/* Drawer / Modal */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
}

.field {
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  outline: none;
}

.field:focus {
  border-color: var(--accent);
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.flex-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
