/* ── Theme: Dark (default) ── */
:root {
  --bg:          #09090b;
  --surface:     #18181b;
  --surface2:    #27272a;
  --border:      rgba(255, 255, 255, 0.08);
  --accent:      #2dd4bf;
  --accent-dim:  #0d9488;
  --danger:      #fb7185;
  --warning:     #fbbf24;
  --green:       #4ade80;
  --text:        #fafafa;
  --text-muted:  #a1a1aa;
  --shadow:      rgba(0, 0, 0, 0.6);
  --radius:      14px;
  --transition:  0.18s ease;
}

/* ── Theme: Light ── */
@media (prefers-color-scheme: light) {
  :root {
    --bg:         #f4f4f5;
    --surface:    #ffffff;
    --surface2:   #f4f4f5;
    --border:     rgba(0, 0, 0, 0.08);
    --accent:     #0d9488;
    --accent-dim: #0f766e;
    --danger:     #e11d48;
    --warning:    #d97706;
    --green:      #16a34a;
    --text:       #09090b;
    --text-muted: #71717a;
    --shadow:     rgba(0, 0, 0, 0.1);
  }
}

/* ── Manual overrides (set by toggle) ── */
html.dark {
  --bg:          #09090b;
  --surface:     #18181b;
  --surface2:    #27272a;
  --border:      rgba(255, 255, 255, 0.08);
  --accent:      #2dd4bf;
  --accent-dim:  #0d9488;
  --danger:      #fb7185;
  --warning:     #fbbf24;
  --green:       #4ade80;
  --text:        #fafafa;
  --text-muted:  #a1a1aa;
  --shadow:      rgba(0, 0, 0, 0.6);
}

html.light {
  --bg:         #f4f4f5;
  --surface:    #ffffff;
  --surface2:   #f4f4f5;
  --border:     rgba(0, 0, 0, 0.08);
  --accent:     #0d9488;
  --accent-dim: #0f766e;
  --danger:     #e11d48;
  --warning:    #d97706;
  --green:      #16a34a;
  --text:       #09090b;
  --text-muted: #71717a;
  --shadow:     rgba(0, 0, 0, 0.1);
}

/* ── Global Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Base Body ── */
html, body {
  min-height: 100%;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.5rem, 5vw, 2.5rem) clamp(1.25rem, 4vw, 2.5rem);
  width: 100%;
  max-width: 480px;
  box-shadow: 0 4px 24px var(--shadow);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.625rem 1.25rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) / 1.4);
  font-family: inherit;
  font-size: clamp(0.9375rem, 2.5vw, 1rem);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--transition), box-shadow var(--transition),
              background var(--transition), border-color var(--transition),
              color var(--transition);
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.01em;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

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

.btn-primary {
  background: var(--accent);
  color: #09090b;
  border-color: var(--accent);
  font-weight: 700;
}

.btn-primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(45, 212, 191, 0.25);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface2);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

html.light .btn-secondary:hover {
  border-color: rgba(0, 0, 0, 0.15);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  font-weight: 700;
  width: 100%;
}

.btn-danger:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(251, 113, 133, 0.3);
}

/* ── Error Banner ── */
.error-banner {
  display: none;
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  border-radius: calc(var(--radius) / 2);
  padding: 0.875rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9375rem;
  color: var(--text);
  text-align: left;
}

.error-banner.visible {
  display: block;
}

.error-banner .error-title {
  font-weight: 700;
  color: var(--danger);
  margin-bottom: 0.25rem;
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 0.4rem;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 1.25rem 0;
}

/* ── Mobile-first layout: single column by default ── */
.actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.indicators-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  width: 100%;
}

/* ── Responsive: multi-column at 600px+ ── */
@media (min-width: 600px) {
  .actions {
    flex-direction: row;
  }

  .actions .btn {
    flex: 1;
  }

  .indicators-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

@media (min-width: 1024px) {
  .card {
    padding: 2.5rem 3rem;
  }
}

/* ── Theme toggle ── */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: color var(--transition), background var(--transition),
              border-color var(--transition);
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--surface2);
  border-color: color-mix(in srgb, var(--border) 200%, transparent);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Default: follow system preference */
@media (prefers-color-scheme: dark) {
  .theme-toggle .icon-sun  { display: block; }
  .theme-toggle .icon-moon { display: none; }
}
@media (prefers-color-scheme: light) {
  .theme-toggle .icon-sun  { display: none; }
  .theme-toggle .icon-moon { display: block; }
}

/* Manual overrides */
html.dark .theme-toggle .icon-sun  { display: block; }
html.dark .theme-toggle .icon-moon { display: none; }
html.light .theme-toggle .icon-sun  { display: none; }
html.light .theme-toggle .icon-moon { display: block; }

/* ── QR code container (always white bg so QR is scannable) ── */
.qr-wrap {
  display: inline-flex;
  background: #fff;
  padding: 8px;
  border-radius: 10px;
}

/* ── Keyframe Animations ── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes confetti-fall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(80px) rotate(720deg); opacity: 0; }
}

@keyframes level-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
  50%       { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0); }
}

@keyframes level-text-fade {
  0%   { opacity: 0; transform: scale(0.8); }
  20%  { opacity: 1; transform: scale(1.05); }
  80%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

@keyframes confetti-burst {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx, 40px), var(--dy, -60px)) rotate(var(--dr, 360deg)); opacity: 0; }
}
