:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #0891b2;
  --accent-hover: #0e7490;
  --accent-weak: #ecfeff;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.08);
  --radius: 12px;
  --radius-lg: 20px;
}

[data-theme="dark"] {
  --bg: #0b0f14;
  --surface: #131920;
  --text: #e6edf3;
  --text-muted: #8b98a5;
  --border: #1f2933;
  --accent: #22d3ee;
  --accent-hover: #67e8f9;
  --accent-weak: #083344;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  transition: background-color .2s, color .2s;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ─── Header ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: grid;
  place-items: center;
  color: white;
  font-size: 16px;
}

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

/* ─── Segmented control (resolution toggle) ─── */
.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color .15s, color .15s;
  font-family: inherit;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ─── Icon buttons ─── */
.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color .15s, border-color .15s;
  font-family: inherit;
}

.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 18px; height: 18px; }

/* ─── Main content ─── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  gap: 16px;
}

/* ─── Video ─── */
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.video-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255,255,255,.8);
  font-size: 13px;
  pointer-events: none;
  transition: opacity .3s;
}

.video-overlay.hidden { opacity: 0; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: rgba(255,255,255,.9);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Status pill ─── */
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background-color .2s;
}

.status-dot.ready { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 20%, transparent); }
.status-dot.active { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 30%, transparent); animation: pulse 1s ease-in-out infinite; }
.status-dot.cooling { background: var(--text-muted); }
.status-dot.error { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ─── Spray button ─── */
.spray-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 0;
}

.spray-btn {
  --size: 180px;
  --ring: 6px;
  position: relative;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  border: 0;
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  color: white;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--shadow-lg), inset 0 2px 4px rgba(255,255,255,.2);
  transition: transform .08s ease-out, box-shadow .15s;
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.spray-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.spray-btn:disabled {
  cursor: not-allowed;
  background: linear-gradient(145deg, #9ca3af, #6b7280);
  box-shadow: var(--shadow);
}

.spray-btn .icon {
  display: block;
  font-size: 38px;
  margin-bottom: 4px;
}

.spray-btn .label {
  display: block;
}

/* Progress ring around button */
.spray-ring {
  position: absolute;
  inset: calc(var(--ring) * -1);
  border-radius: 50%;
  pointer-events: none;
}

.spray-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.spray-ring circle {
  fill: none;
  stroke-width: var(--ring);
  cx: 50%; cy: 50%;
}

.spray-ring .track { stroke: var(--border); }
.spray-ring .progress {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.1s linear;
}

.spray-meta {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* ─── Login ─── */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card .brand {
  justify-content: center;
  margin-bottom: 8px;
  font-size: 18px;
}

.login-card .brand-mark { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; }

.login-card p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-card input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  margin-bottom: 12px;
  transition: border-color .15s, box-shadow .15s;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.login-card button {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: background-color .15s;
  font-family: inherit;
}

.login-card button:hover:not(:disabled) { background: var(--accent-hover); }
.login-card button:disabled { opacity: .6; cursor: wait; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  min-height: 18px;
}

/* ─── Responsive ─── */
@media (max-width: 480px) {
  .header { padding: 12px 16px; }
  .main { padding: 12px; }
  .spray-btn { --size: 160px; font-size: 18px; }
  .spray-btn .icon { font-size: 34px; }
}

@media (min-height: 800px) and (min-width: 600px) {
  .spray-btn { --size: 200px; }
}
