/* SageOx flasher — self-contained, no external fonts/assets (CSP: default-src 'none').
   Palette is the canonical SageOx dark theme (green-black rebrand), mirrored from
   packages/ui/styles/tokens.css. Values are inlined, NOT imported, because the
   flasher's CSP forbids external CSS — keep them in sync with the design tokens.

   Theme system: CSS custom properties on :root (dark default) + media-query light
   baseline + explicit [data-theme] overrides set by flash.js from localStorage.
   Order matters: :root → @media light → [data-theme="dark"] → [data-theme="light"]
   (later wins at equal specificity, letting explicit prefs beat system prefs). */
:root {
  --bg:            #0b0d0b; /* crater-900 — page base */
  --bg-top:        #161c16; /* gradient start (top of radial) */
  --surface-1:     #111411; /* crater-800 — app chrome */
  --surface-2:     #171b17; /* crater-700 — cards */
  --surface-3:     #212620; /* crater-600 — recessed wells (select) */
  --border:        #1d221d; /* crater-500 — hairline divider */
  --border-strong: #2b312a; /* mid-tone edge */
  --sage-300:      #adcfa3; /* links / accents on dark */
  --sage-400:      #99c693; /* primary CTA */
  --sage-500:      #7aaa77;
  --text:          #f2f0ec; /* dust-200 — primary text on dark */
  --text-muted:    #b7b6a3; /* silt-300 — WCAG AA on dark surfaces */
  --warn-text:     #fde8c8;
  --warn-bg:       rgba(245, 158, 11, 0.10);
  --warn-border:   rgba(245, 158, 11, 0.35);
  --info-text:     #e8f1e4;
  --info-bg:       rgba(153, 198, 147, 0.10);
  --info-border:   rgba(153, 198, 147, 0.35);
  --radius: 14px;
}

/* Light mode: system preference baseline */
@media (prefers-color-scheme: light) {
  :root {
    --bg:            #f5f7f4;
    --bg-top:        #e4ebe3;
    --surface-1:     #ffffff;
    --surface-2:     #edf0ec;
    --surface-3:     #e2e6e1;
    --border:        #d0d4ce;
    --border-strong: #bcc1ba;
    --sage-300:      #3d6b38; /* darker for WCAG AA on light backgrounds */
    --sage-400:      #5a9254; /* CTA button bg; dark text (#111411) gives 4.8:1 */
    --sage-500:      #2f5429;
    --text:          #1c201b;
    --text-muted:    #505851;
    --warn-text:     #7c3a00;
    --warn-bg:       rgba(245, 158, 11, 0.08);
    --warn-border:   rgba(245, 158, 11, 0.28);
    --info-text:     #1e4a1a;
    --info-bg:       rgba(61, 107, 56, 0.08);
    --info-border:   rgba(61, 107, 56, 0.25);
  }
}

/* Explicit dark — beats system-light when user pinned dark */
[data-theme="dark"] {
  --bg:            #0b0d0b;
  --bg-top:        #161c16;
  --surface-1:     #111411;
  --surface-2:     #171b17;
  --surface-3:     #212620;
  --border:        #1d221d;
  --border-strong: #2b312a;
  --sage-300:      #adcfa3;
  --sage-400:      #99c693;
  --sage-500:      #7aaa77;
  --text:          #f2f0ec;
  --text-muted:    #b7b6a3;
  --warn-text:     #fde8c8;
  --warn-bg:       rgba(245, 158, 11, 0.10);
  --warn-border:   rgba(245, 158, 11, 0.35);
  --info-text:     #e8f1e4;
  --info-bg:       rgba(153, 198, 147, 0.10);
  --info-border:   rgba(153, 198, 147, 0.35);
}

/* Explicit light — beats system-dark when user pinned light */
[data-theme="light"] {
  --bg:            #f5f7f4;
  --bg-top:        #e4ebe3;
  --surface-1:     #ffffff;
  --surface-2:     #edf0ec;
  --surface-3:     #e2e6e1;
  --border:        #d0d4ce;
  --border-strong: #bcc1ba;
  --sage-300:      #3d6b38;
  --sage-400:      #5a9254;
  --sage-500:      #2f5429;
  --text:          #1c201b;
  --text-muted:    #505851;
  --warn-text:     #7c3a00;
  --warn-bg:       rgba(245, 158, 11, 0.08);
  --warn-border:   rgba(245, 158, 11, 0.28);
  --info-text:     #1e4a1a;
  --info-bg:       rgba(61, 107, 56, 0.08);
  --info-border:   rgba(61, 107, 56, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% -10%, var(--bg-top) 0%, var(--bg) 60%);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 560px; margin: 0 auto; padding: 48px 20px 64px; }

.hd { text-align: center; margin-bottom: 28px; }

/* SageOx wordmark — light-on-dark PNG, self-hosted (CSP img-src 'self').
   In light mode: invert(1) flips the white wordmark to black on transparent. */
.brand { display: inline-block; margin: 0 auto 18px; line-height: 0; }
.brand img { width: 150px; height: auto; } /* intrinsic 512×133 */
.brand:focus-visible { outline: 2px solid var(--sage-500); outline-offset: 4px; border-radius: 4px; }

@media (prefers-color-scheme: light) {
  .brand img { filter: invert(1); }
}
[data-theme="light"] .brand img { filter: invert(1); }
[data-theme="dark"]  .brand img { filter: none; }

h1 { margin: 0 0 8px; font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }
.sub { margin: 0; color: var(--text-muted); }

.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 28px;
}

.picker { margin-bottom: 18px; }
.picker label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.picker select {
  width: 100%; padding: 11px 36px 11px 12px; font-size: 15px;
  color: var(--text); background: var(--surface-3);
  border: 1px solid var(--border-strong); border-radius: 10px;
  appearance: none; -webkit-appearance: none;
  /* Custom chevron via inline SVG data-URI — color-matched to --text-muted */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23b7b6a3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}
/* Light mode chevron — swap stroke color to match --text-muted in light */
@media (prefers-color-scheme: light) {
  .picker select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23505851' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  }
}
[data-theme="light"] .picker select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23505851' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
[data-theme="dark"] .picker select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23b7b6a3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
.picker select:focus { outline: 2px solid var(--sage-500); outline-offset: 1px; }

.action { display: flex; justify-content: center; margin: 8px 0 4px; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 13px 26px; border-radius: 999px; border: 0;
}
/* Primary CTA = sage fill, near-black text for AA contrast in both modes.
   --sage-400 in dark is #99c693 (light), in light is #5a9254 (medium) — both
   pass AA with #111411 text (dark: ~12:1, light: ~4.8:1). */
.btn.primary {
  color: #111411; background: linear-gradient(180deg, var(--sage-300), var(--sage-400));
  box-shadow: 0 6px 18px -8px var(--sage-400);
}
.btn.primary:hover { filter: brightness(1.04); }
.btn.primary:active { transform: translateY(1px); }

.note { font-size: 13px; color: var(--text-muted); margin: 6px 0 0; }

.banner {
  border-radius: 10px; padding: 12px 14px; font-size: 14px; margin-bottom: 16px;
}
.banner.warn {
  color: var(--warn-text); background: var(--warn-bg);
  border: 1px solid var(--warn-border);
}
/* Info callout — sage accent (brand), for the one action the user MUST take
   (pick the serial port). Distinct from .warn (amber) so it doesn't read as an error. */
.banner.info {
  color: var(--info-text); background: var(--info-bg);
  border: 1px solid var(--info-border);
}
.banner strong { display: block; margin-bottom: 2px; }
.banner p { margin: 8px 0 0; }

.erase-note { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.erase-note summary { cursor: pointer; color: var(--sage-300); font-size: 14px; }
.erase-note p { color: var(--text-muted); font-size: 14px; margin: 10px 0 0; }

.steps h2 { font-size: 17px; margin: 0 0 12px; }
.steps ol { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 10px; color: var(--text); }
.steps li b { font-weight: 600; }

.ft {
  margin-top: 36px; text-align: center; font-size: 13px; color: var(--text-muted);
}
.ft a { color: var(--sage-300); text-decoration: none; }
.ft a:hover { text-decoration: underline; }
.ft span { margin: 0 8px; opacity: 0.5; }

/* esp-web-tools renders its own dialog; just make sure the host element doesn't
   add layout when hidden. */
esp-web-install-button[hidden] { display: none; }

/* Theme toggle — fixed top-right pill button */
.theme-toggle {
  position: fixed; top: 14px; right: 14px; z-index: 100;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface-1); color: var(--text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }
.theme-toggle:focus-visible { outline: 2px solid var(--sage-500); outline-offset: 2px; }

/* Show sun (→ switch to light) in dark mode; moon (→ switch to dark) in light mode */
.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; }
}
[data-theme="dark"]  .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"]  .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun  { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }
