/* Copyright 2026 John "topjohnwu" Wu */
/* samloader-rs Odin Web Flasher — Material Design 3 Styles */

/* Self-hosted fonts (SIL Open Font License, see fonts/OFL-*.txt). Variable WOFF2
   files from Google Fonts, split into latin and latin-ext subsets so browsers only
   download the subsets a page uses. */
/* DM Sans (latin-ext) */
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/dm-sans-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* DM Sans (latin) */
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/dm-sans-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Roboto (latin-ext) */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/roboto-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Roboto (latin) */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/roboto-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Roboto Mono (latin-ext) */
@font-face {
  font-family: 'Roboto Mono';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('fonts/roboto-mono-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Roboto Mono (latin) */
@font-face {
  font-family: 'Roboto Mono';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('fonts/roboto-mono-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Color tokens use light-dark(), which resolves against the root's color-scheme.
   It follows the OS by default; data-theme on <html> (set by ui/theme.js) forces
   light or dark. */
:root {
  color-scheme: light dark;

  /* Material Design 3 (M3) Color Tokens — Baseline Google Blue (light, dark) */
  --md-sys-color-primary: light-dark(#0b57d0, #a8c7fa);
  --md-sys-color-on-primary: light-dark(#ffffff, #062e6f);
  --md-sys-color-primary-container: light-dark(#d3e3fd, #0842a0);
  --md-sys-color-on-primary-container: light-dark(#041e49, #d3e3fd);
  --md-sys-color-primary-hover: light-dark(#0842a0, #d3e3fd);
  --md-sys-color-primary-container-hover: light-dark(#c1d8fb, #0b57d0);

  --md-sys-color-secondary-container: light-dark(#e8f0fe, #004a77);
  --md-sys-color-on-secondary-container: light-dark(#001d35, #c2e7ff);

  --md-sys-color-surface: light-dark(#ffffff, #1b1c1d);
  --md-sys-color-surface-dim: light-dark(#f0f4f9, #131314);
  --md-sys-color-surface-container-low: light-dark(#f8fafd, #202124);
  --md-sys-color-surface-container: light-dark(#f0f4f9, #26282a);
  --md-sys-color-surface-container-high: light-dark(#e9eef6, #303235);
  --md-sys-color-on-surface: light-dark(#1f1f1f, #e3e3e3);
  --md-sys-color-on-surface-variant: light-dark(#444746, #c4c7c5);

  --md-sys-color-outline: light-dark(#747775, #8e918f);
  --md-sys-color-outline-variant: light-dark(#c4c7c5, #444746);
  --md-sys-color-outline-subtle: light-dark(#e1e3e1, #303235);

  /* Semantic Status Tokens (M3 Tonal Containers) */
  --status-success: light-dark(#146c2e, #6dd58c);
  --status-success-bg: light-dark(#c4eed0, #0f5223);
  --status-warning: light-dark(#8f4c00, #ffb95c);
  --status-warning-bg: light-dark(#ffefc3, #5c3a00);
  --status-error: light-dark(#b3261e, #f2b8b5);
  --status-error-bg: light-dark(#f9dedc, #8c1d18);

  /* Terminal Surface */
  --terminal-bg: light-dark(#111318, #0b0c0f);
  --terminal-text: #e2e8f0;

  /* M3 Shape Tokens */
  --md-shape-xs: 4px;
  --md-shape-sm: 8px;
  --md-shape-md: 12px;
  --md-shape-lg: 16px;
  --md-shape-full: 9999px;

  /* M3 Elevation Shadows */
  --md-elevation-1:
    0 1px 2px 0 light-dark(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.3)),
    0 1px 3px 1px light-dark(rgba(0, 0, 0, 0.04), rgba(0, 0, 0, 0.15));
  --md-elevation-2:
    0 1px 2px 0 light-dark(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.3)),
    0 2px 6px 2px light-dark(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.15));
}

/* Explicit theme selection; native controls and scrollbars follow too */
:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

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

[hidden] {
  display: none !important;
}

/* Hidden visually but still read by screen readers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Keyboard focus for custom interactive elements */
.dropzone:focus-visible,
.partition-file-trigger:focus-visible,
.partition-item:focus-visible,
.log-terminal:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--md-sys-color-surface-dim);
  color: var(--md-sys-color-on-surface);
  font-size: 0.875rem;
  line-height: 1.5;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
}

button,
select,
input,
textarea {
  font-family: inherit;
}

/* M3 Top App Bar */
.app-header {
  background-color: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-subtle);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  padding: 12px 24px;
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo-wrap {
  width: 36px;
  height: 36px;
  border-radius: var(--md-shape-md);
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-logo {
  width: 20px;
  height: 20px;
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-pill {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--md-sys-color-on-primary-container);
  background-color: var(--md-sys-color-primary-container);
  padding: 4px 10px;
  border-radius: var(--md-shape-full);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand-version {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.backend-selector-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.backend-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

/* M3 Outlined Select */
.select-input {
  appearance: none;
  -webkit-appearance: none;
  height: 36px;
  padding: 0 30px 0 12px;
  border-radius: var(--md-shape-sm);
  border: 1px solid var(--md-sys-color-outline-variant);
  background-color: var(--md-sys-color-surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='%23444746'%3E%3Cpath d='M7 10l5 5 5-5H7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 18px;
  color: var(--md-sys-color-on-surface);
  font-size: 0.8125rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}

.select-input:hover:not(:disabled) {
  border-color: var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface-container-low);
}

.select-input:focus-visible,
.select-input:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.select-input:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* Select matching the height of the buttons next to it */
.select-input-action {
  height: 40px;
  font-size: 0.875rem;
}

/* M3 Assist / Status Chip */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--md-shape-sm);
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.chip-disconnected {
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.chip-connected {
  background-color: var(--status-success-bg);
  color: var(--status-success);
  border: 1px solid transparent;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
}

/* M3 Segmented Button (theme toggle), backed by native radios for keyboard support */
.segmented-group {
  display: inline-flex;
  height: 36px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-full);
  overflow: hidden;
}

.segmented-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.segmented-option + .segmented-option {
  border-left: 1px solid var(--md-sys-color-outline-variant);
}

.segmented-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.segmented-option svg {
  width: 18px;
  height: 18px;
}

.segmented-option:hover {
  background-color: var(--md-sys-color-surface-container);
}

.segmented-option:has(input:checked) {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.segmented-option:has(input:focus-visible) {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: -2px;
}

/* Main Container */
.app-container {
  max-width: 980px;
  margin: 24px auto 64px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* M3 Elevated / Outlined Cards */
.card {
  background-color: var(--md-sys-color-surface);
  border-radius: var(--md-shape-lg);
  border: 1px solid var(--md-sys-color-outline-subtle);
  box-shadow: var(--md-elevation-1);
  overflow: hidden;
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--md-sys-color-outline-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.step-number {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.875rem;
  font-weight: 700;
  flex-shrink: 0;
}

.card-title {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  line-height: 1.35;
}

.card-subtitle {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 2px;
}

.card-body {
  padding: 24px;
}

/* M3 Pill Buttons (Filled, Tonal, Outlined) */
.btn {
  height: 40px;
  padding: 0 20px;
  border-radius: var(--md-shape-full);
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  user-select: none;
}

.btn-sm {
  height: 36px;
  padding: 0 16px;
  font-size: 0.8125rem;
}

.btn-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* M3 Filled Button */
.btn-primary,
.btn-flash {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.btn-primary:hover:not(:disabled),
.btn-flash:hover:not(:disabled) {
  background-color: var(--md-sys-color-primary-hover);
  box-shadow: var(--md-elevation-1);
}

/* M3 Filled Tonal Button */
.btn-primary-outline {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: transparent;
}

.btn-primary-outline:hover:not(:disabled) {
  background-color: var(--md-sys-color-primary-container-hover);
  box-shadow: var(--md-elevation-1);
}

/* M3 Outlined Button */
.btn-outline {
  background-color: transparent;
  border-color: var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
}

.btn-outline:hover:not(:disabled) {
  background-color: var(--md-sys-color-surface-container);
  border-color: var(--md-sys-color-outline);
}

.btn-flash {
  height: 44px;
  padding: 0 28px;
  font-size: 0.9375rem;
}

.btn:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}

/* Step 1: Device Empty State & Connected State */
.device-empty-state {
  padding: 20px 16px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.empty-icon-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.empty-icon-circle svg {
  width: 28px;
  height: 28px;
}

.empty-state-title {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 6px;
}

.empty-state-desc {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
  max-width: 520px;
  margin-bottom: 20px;
}

.device-pair-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Connected Device List */
.device-list-wrap {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.device-list {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-md);
  background-color: var(--md-sys-color-surface-container-low);
  overflow: hidden;
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}

.device-item-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.device-item-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.device-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--md-sys-color-primary);
  flex-shrink: 0;
}

.device-status-dot.dot-normal {
  background-color: var(--status-warning);
}

.device-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.device-name {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.device-sub {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.mode-badge {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: var(--md-shape-full);
}

.mode-badge-download {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.mode-badge-normal {
  background-color: var(--status-warning-bg);
  color: var(--status-warning);
}

/* Structured Hardware Telemetry Grid */
.device-info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

@media (max-width: 680px) {
  .device-info-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.info-stat-card {
  background-color: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-subtle);
  border-radius: var(--md-shape-md);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.info-stat-card.stat-wide {
  grid-column: span 2;
}

.info-stat-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.info-stat-value {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.info-box {
  padding: 14px 16px;
  border-radius: var(--md-shape-md);
  border: 1px solid var(--md-sys-color-outline-subtle);
  background-color: var(--md-sys-color-surface-container-low);
  font-family: 'Roboto Mono', monospace;
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface);
  white-space: pre-wrap;
}

/* Normal Mode Device Panel */
.device-normal-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-radius: var(--md-shape-md);
  background-color: var(--status-warning-bg);
  color: var(--md-sys-color-on-surface);
}

.device-normal-desc {
  flex: 1 1 320px;
  font-size: 0.875rem;
}

/* Device Actions Bar */
.device-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.device-actions-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Step 2: Unified Single-Layer Firmware Slots */
.slots-header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

/* M3 Switch Component */
.inline-check-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  user-select: none;
}

.inline-check-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.md-switch-track {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: var(--md-shape-full);
  background-color: var(--md-sys-color-surface-container-high);
  border: 2px solid var(--md-sys-color-outline);
  transition: background-color 0.2s, border-color 0.2s;
  display: inline-flex;
  align-items: center;
}

.md-switch-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--md-sys-color-outline);
  transform: translateX(3px);
  transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), background-color 0.2s, width 0.2s, height 0.2s;
}

.inline-check-toggle input[type="checkbox"]:checked + .md-switch-track {
  background-color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.inline-check-toggle input[type="checkbox"]:checked + .md-switch-track .md-switch-thumb {
  width: 18px;
  height: 18px;
  background-color: var(--md-sys-color-on-primary);
  transform: translateX(20px);
}

.inline-check-toggle input[type="checkbox"]:focus-visible + .md-switch-track {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.inline-check-toggle input[type="checkbox"]:disabled + .md-switch-track {
  opacity: 0.38;
  cursor: not-allowed;
}

.slots-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (max-width: 680px) {
  .slots-grid {
    grid-template-columns: 1fr;
  }
}

.slot-box {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-md);
  background-color: var(--md-sys-color-surface);
  overflow: hidden;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}

.slot-box:hover {
  border-color: var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface-container-low);
}

.slot-box.dragover {
  border-color: var(--md-sys-color-primary);
  background-color: var(--md-sys-color-secondary-container);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.slot-box.slot-populated {
  border-color: var(--md-sys-color-primary);
  background-color: var(--md-sys-color-surface-container-low);
}

.dropzone {
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.slot-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.slot-badge {
  width: 46px;
  height: 36px;
  border-radius: var(--md-shape-sm);
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-family: 'Roboto Mono', monospace;
  font-weight: 600;
  font-size: 0.76rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s, color 0.15s;
}

.slot-box.slot-populated .slot-badge {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.slot-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.3;
}

.file-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.slot-box:not(.slot-populated) .file-name {
  color: var(--md-sys-color-primary);
  font-weight: 400;
  font-size: 0.8125rem;
}

.slot-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.file-size {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.badge {
  padding: 3px 10px;
  border-radius: var(--md-shape-full);
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-idle {
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
}

.badge-hashing {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.badge-valid {
  background-color: var(--status-success-bg);
  color: var(--status-success);
}

.badge-invalid {
  background-color: var(--status-error-bg);
  color: var(--status-error);
}

.btn-clear-slot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: none;
  font-size: 1.15rem;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background-color 0.15s, color 0.15s;
}

.btn-clear-slot:hover:not(:disabled) {
  background-color: var(--status-error-bg);
  color: var(--status-error);
}

.btn-clear-slot:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.slot-progress-track {
  height: 4px;
  background-color: transparent;
  overflow: hidden;
}

.slot-box.slot-populated .slot-progress-track {
  background-color: var(--md-sys-color-primary-container);
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--md-sys-color-primary);
  border-radius: var(--md-shape-full);
  transition: width 0.2s;
}

.progress-bar-fill.progress-bar-error {
  background-color: var(--status-error);
}

/* Individual Partition Files Section */
.partition-files-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--md-sys-color-outline-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.partition-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.partition-section-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.partition-section-title {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.partition-section-hint {
  font-size: 0.78rem;
  color: var(--md-sys-color-on-surface-variant);
}

.btn-clear-all {
  background: transparent;
  border: none;
  padding: 6px 12px;
  border-radius: var(--md-shape-sm);
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--status-error);
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}

.btn-clear-all:hover:not(:disabled) {
  background-color: var(--status-error-bg);
}

.btn-clear-all:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.partition-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.partition-item {
  position: relative;
  border: 1px solid var(--md-sys-color-primary);
  border-radius: var(--md-shape-md);
  background-color: var(--md-sys-color-surface-container-low);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.partition-item.dragging {
  opacity: 0.45;
  border-style: dashed;
}

.partition-item.drop-before {
  box-shadow: 0 -3px 0 0 var(--md-sys-color-primary);
}

.partition-item.drop-after {
  box-shadow: 0 3px 0 0 var(--md-sys-color-primary);
}

.partition-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 32px;
  color: var(--md-sys-color-outline);
  cursor: grab;
  flex-shrink: 0;
  border-radius: var(--md-shape-xs);
  transition: color 0.15s, background-color 0.15s;
}

.partition-drag-handle:hover {
  color: var(--md-sys-color-on-surface);
  background-color: var(--md-sys-color-surface-container-high);
}

.partition-drag-handle:active {
  cursor: grabbing;
}

.partition-drag-handle svg {
  width: 16px;
  height: 16px;
}

.partition-item .slot-badge {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.partition-file-trigger {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

.partition-target-input {
  height: 36px;
  width: 220px;
  padding: 0 12px;
  border-radius: var(--md-shape-sm);
  border: 1px solid var(--md-sys-color-outline-variant);
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: 'Roboto Mono', monospace;
  font-size: 0.8125rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.partition-target-input::placeholder {
  font-family: 'Roboto', sans-serif;
  color: var(--md-sys-color-outline);
}

.partition-target-input:hover:not(:disabled) {
  border-color: var(--md-sys-color-outline);
}

.partition-target-input:focus-visible,
.partition-target-input:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.partition-target-input:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

@media (max-width: 680px) {
  .partition-item .slot-right {
    width: 100%;
    justify-content: flex-end;
  }

  .partition-target-input {
    flex: 1;
    width: auto;
  }
}

/* Step 2: Advanced Options (folded by default) */
.advanced-options {
  margin-top: 20px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-md);
  background-color: var(--md-sys-color-surface);
}

.advanced-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 16px;
  border-radius: var(--md-shape-md);
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s;
}

.advanced-summary::-webkit-details-marker {
  display: none;
}

.advanced-summary:hover {
  background-color: var(--md-sys-color-surface-container-low);
}

.advanced-summary:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.advanced-options[open] > .advanced-summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

/* Chevron of the foldable sections, pointing down when unfolded */
.fold-chevron {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--md-sys-color-on-surface-variant);
  transition: transform 0.2s;
}

.advanced-options[open] .fold-chevron,
.log-toggle[aria-expanded="true"] .fold-chevron {
  transform: rotate(90deg);
}

.advanced-title {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

/* Non-default options, listed so they stay visible while folded */
.advanced-active {
  min-width: 0;
  padding: 3px 10px;
  border-radius: var(--md-shape-full);
  background-color: var(--status-warning-bg);
  color: var(--status-warning);
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.advanced-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 16px;
  border-top: 1px solid var(--md-sys-color-outline-subtle);
}

.options-fields-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-title {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.field-optional {
  font-weight: 400;
  color: var(--md-sys-color-outline);
}

.text-input-sm {
  height: 46px;
  padding: 0 14px;
  width: 100%;
  border-radius: var(--md-shape-sm);
  border: 1px solid var(--md-sys-color-outline-variant);
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: 'Roboto Mono', monospace;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}

.text-input-sm:not(:placeholder-shown) {
  text-transform: uppercase;
}

.text-input-sm:hover:not(:disabled) {
  border-color: var(--md-sys-color-outline);
}

.text-input-sm:focus-visible,
.text-input-sm:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.text-input-sm:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.pit-config-box {
  height: 46px;
  border-radius: var(--md-shape-sm);
  border-color: var(--md-sys-color-outline-variant);
  justify-content: center;
}

.pit-dropzone {
  padding: 6px 12px;
  height: 100%;
}

.pit-config-box .slot-badge {
  width: 40px;
  height: 28px;
  font-size: 0.72rem;
  border-radius: 6px;
}

.options-checks-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (max-width: 640px) {
  .options-checks-grid {
    grid-template-columns: 1fr;
  }
}

.option-tile {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-md);
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  background-color: var(--md-sys-color-surface);
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
  user-select: none;
}

.option-tile:hover {
  border-color: var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface-container-low);
}

.option-tile:has(input[type="checkbox"]:checked) {
  border-color: var(--md-sys-color-primary);
  background-color: var(--md-sys-color-surface-container-low);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.option-tile input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--md-sys-color-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.option-tile-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.option-tile-title {
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  line-height: 1.3;
}

.option-tile-desc {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* Flash actions; replaced by the progress panel while flashing */
.action-bar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--md-sys-color-outline-subtle);
}

.action-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.when-done-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-bar-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-left: auto;
}

/* Flash Progress Panel */
.flash-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 44px;
  justify-content: center;
}

.flash-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.flash-status-text {
  min-width: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-percent-pill {
  flex-shrink: 0;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--md-sys-color-on-primary-container);
  background-color: var(--md-sys-color-primary-container);
  padding: 4px 12px;
  border-radius: var(--md-shape-full);
}

.main-progress-bg {
  height: 8px;
  border-radius: var(--md-shape-full);
  /* Neutral track, so the unfilled part never reads as progress (notably in dark mode) */
  background-color: var(--md-sys-color-surface-container-high);
  overflow: hidden;
}

.main-progress-fill {
  background-color: var(--md-sys-color-primary);
}

/* Transfer speed and time left, below the progress bar */
.flash-detail-text {
  min-height: 1.25em;
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* Outcome of the last flash */
.flash-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-radius: var(--md-shape-md);
  font-size: 0.875rem;
  font-weight: 500;
}

.flash-result.result-success {
  background-color: var(--status-success-bg);
  color: var(--status-success);
}

.flash-result.result-error {
  background-color: var(--status-error-bg);
  color: var(--status-error);
}

.flash-result-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.flash-result-link {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 4px 6px;
  border-radius: var(--md-shape-xs);
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.flash-result-link:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.flash-result .btn-clear-slot {
  color: inherit;
}

/* Activity Log (folded by default, showing the latest line) */
.log-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 24px 8px 12px;
  flex-wrap: wrap;
}

.log-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 12px;
  border: none;
  border-radius: var(--md-shape-md);
  background: none;
  color: var(--md-sys-color-on-surface);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s;
}

.log-toggle:hover {
  background-color: var(--md-sys-color-surface-container-low);
}

.log-toggle:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.log-title {
  flex-shrink: 0;
  font-family: 'DM Sans', 'Roboto', sans-serif;
  font-size: 1.125rem;
  font-weight: 500;
}

.log-preview {
  min-width: 0;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.78rem;
  color: var(--md-sys-color-on-surface-variant);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.log-body {
  padding: 0 24px 24px;
}

.log-terminal {
  background-color: var(--terminal-bg);
  border-radius: var(--md-shape-md);
  padding: 12px 18px;
  height: 220px;
  overflow: auto;
  contain: strict;
}

.log-output {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.78rem;
  /* Pre-WASM fallback; overridden at runtime with log_line_height() from Rust */
  line-height: 20px;
  color: var(--terminal-text);
  white-space: pre;
  margin: 0;
}
