:root {
  --bg: #ffffff;
  --text: #0f172a;
  --text-sub: #64748b;
  --border: rgba(15, 23, 42, 0.09);
  --panel-bg: rgba(255, 255, 255, 0.94);
  --pill-bg: #f1f5f9;
  --accent: #0f172a;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --shadow-lg: 0 18px 42px rgba(15, 23, 42, 0.11), 0 2px 8px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.09), 0 1px 4px rgba(15, 23, 42, 0.04);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #ffffff;
  color: var(--text);
  font-family: "Inter", "Overpass", -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}

/* Minimal Top Bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 40;
  pointer-events: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  pointer-events: auto;
}

.brand-badge {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #0f172a;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.16);
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

.settings-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: var(--shadow-md);
  transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease;
}

.settings-btn:hover {
  background: #f8fafc;
  transform: scale(1.04);
}

.settings-btn:active {
  transform: scale(0.97);
}

.settings-btn[aria-expanded="true"] {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
}

/* Top-Right Settings Panel */
.settings-panel {
  position: fixed;
  top: 66px;
  right: 24px;
  width: 300px;
  max-width: calc(100vw - 32px);
  background: var(--panel-bg);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 1;
  transform: translateY(0) scale(1);
  transform-origin: top right;
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-panel[hidden] {
  display: none !important;
}

.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: #334155;
  border: 1px solid var(--border);
}

.status-pill.connected {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border-color: rgba(16, 185, 129, 0.28);
}

.status-pill.sim {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
  border-color: rgba(245, 158, 11, 0.28);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
}

.status-pill.connected .status-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.status-pill.sim .status-dot {
  background: var(--amber);
}

.sd-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.panel-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

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

.btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  text-align: center;
}

.btn:hover {
  background: #f1f5f9;
}

.btn-primary {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
}

.btn-primary:hover {
  background: #1e293b;
}

.btn[hidden] {
  display: none !important;
}

.ble-error {
  font-size: 11.5px;
  line-height: 1.45;
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.22);
  border-radius: 10px;
  padding: 8px 10px;
}

.ble-error[hidden] {
  display: none !important;
}

/* Segmented Language Control */
.seg-group {
  display: inline-flex;
  background: #f1f5f9;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.seg-btn.active {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

/* Switch Toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

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

.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background-color 0.18s ease;
}

.switch-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s ease;
}

.switch input:checked + .switch-slider {
  background: #0f172a;
}

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

/* 3D Stage */
#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: #ffffff;
  overflow: hidden;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

/* Display Mode Controls (BOOT & PWR round buttons + Back to 3D) */
.display-controls {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 35;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.display-controls[hidden] {
  display: none !important;
}

.hw-buttons {
  display: flex;
  align-items: center;
  gap: 20px;
}

.round-hw-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1.5px solid rgba(15, 23, 42, 0.14);
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.12s ease, background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  touch-action: manipulation;
}

.round-hw-btn:hover {
  border-color: #0f172a;
  transform: translateY(-1px);
}

.round-hw-btn:active,
.round-hw-btn.pressed {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
  transform: scale(0.94);
}

.back-3d-btn {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-sub);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.back-3d-btn:hover {
  color: var(--text);
  border-color: rgba(15, 23, 42, 0.22);
  background: #ffffff;
}

@media (max-width: 600px) {
  .topbar {
    padding: 0 16px;
    height: 54px;
  }

  .settings-panel {
    top: 60px;
    right: 16px;
    width: calc(100vw - 32px);
  }

  .display-controls {
    bottom: 20px;
  }

  .round-hw-btn {
    width: 50px;
    height: 50px;
  }
}

/* Puck battery: tiny indicator left of the settings button */
.topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}
.battery {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
}
.battery[hidden] { display: none; }
.battery-body {
  position: relative;
  width: 16px;
  height: 8px;
  border: 1px solid #9ca3af;
  border-radius: 2px;
  padding: 1px;
  box-sizing: border-box;
}
.battery-body::after {
  content: '';
  position: absolute;
  right: -3px;
  top: 2px;
  width: 1.5px;
  height: 3px;
  background: #9ca3af;
  border-radius: 0 1px 1px 0;
}
.battery-fill {
  display: block;
  height: 100%;
  width: 0;
  background: #111827;
  border-radius: 1px;
}
.battery.low .battery-fill { background: #dc2626; }

/* "Your Element" controls */
.panel-title { font-size: 13px; font-weight: 600; margin: 0 0 8px; }
.element-controls { display: flex; flex-direction: column; gap: 8px; }
.element-controls.off > :not(.panel-title):not(.ctl-hint) { opacity: 0.4; pointer-events: none; }
.ctl-hint { font-size: 12px; opacity: 0.65; margin: 0; }
.ctl-input, .ctl-select { width: 100%; box-sizing: border-box; padding: 8px 10px; border-radius: 10px; border: 1px solid rgba(0,0,0,0.15); font: inherit; font-size: 13px; background: #fff; color: #111; }
.ctl-select { width: auto; }
.ctl-range { width: 140px; }
.ctl-sounds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ctl-sounds .btn { padding: 6px 4px; font-size: 12px; }

/* Talk to Element 0 (Gemini): ask bar at the bottom, above the BOOT/PWR buttons in display mode */
.ask-bar { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 16px; background: rgba(255,255,255,0.92); box-shadow: 0 8px 30px rgba(0,0,0,0.12); backdrop-filter: blur(10px); z-index: 20; box-sizing: border-box; }
.ask-bar[hidden] { display: none; }
body.display-mode .ask-bar { bottom: 120px; }
.ask-input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(0,0,0,0.15); font: inherit; font-size: 14px; background: #fff; color: #111; }
.ask-send { width: auto; flex: none; padding: 10px 18px; }
.ask-mic { width: 38px; height: 38px; flex: none; border-radius: 10px; border: 1px solid rgba(0,0,0,0.15); background: #fff; color: #111; cursor: pointer; display: grid; place-items: center; }
.ask-mic.on { background: #0F172A; color: #fff; }
.ask-bar.busy .ask-send { opacity: 0.5; pointer-events: none; }
#talk-settings a { color: inherit; }
.brand-logo { width: 30px; height: 30px; display: block; }
