:root {
  color-scheme: light;
  --brand: #882c84;
  --brand-dark: #5f1f5c;
  --accent: #ef7d22;
  --dfu: #1769aa;
  --ink: #25212a;
  --muted: #6f6874;
  --panel: rgba(255, 255, 255, 0.95);
  --line: #e5dfe7;
  --good: #147a49;
  --warn: #a75d00;
  --bad: #b42318;
  --busy: #1769aa;
  --shadow: 0 18px 50px rgba(56, 28, 58, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(145deg, #f7f2f7 0%, #fff8ef 48%, #f0f6fb 100%);
  padding: 32px 18px;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }

.background-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(4px);
  opacity: 0.34;
  pointer-events: none;
  z-index: -1;
}
.orb-one { width: 320px; height: 320px; background: #d7a9d4; top: -100px; right: -70px; }
.orb-two { width: 280px; height: 280px; background: #ffd4ac; bottom: -80px; left: -80px; }

.app-shell { width: min(980px, 100%); margin: 0 auto; }

.brand-header,
.file-panel,
.control-panel,
.progress-panel,
.log-panel,
.help-panel,
.notice {
  background: var(--panel);
  border: 1px solid rgba(136, 44, 132, 0.12);
  box-shadow: var(--shadow);
  border-radius: 20px;
}

.brand-header { display: flex; align-items: center; gap: 22px; padding: 26px 30px; }
.brand-logo { width: 116px; height: auto; object-fit: contain; }
.brand-copy { min-width: 0; }
.eyebrow { color: var(--brand); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.6rem, 4vw, 2.45rem); line-height: 1.1; }
h1 small { color: var(--muted); font-size: 0.46em; font-weight: 700; vertical-align: middle; }
.brand-copy p { margin-bottom: 0; color: var(--muted); }

.notice {
  margin-top: 18px;
  padding: 14px 20px;
  color: #5a2d10;
  background: rgba(255, 244, 226, 0.96);
  border-color: rgba(239, 125, 34, 0.26);
  font-weight: 650;
}

.file-panel, .control-panel, .progress-panel, .log-panel, .help-panel { margin-top: 18px; padding: 24px; }
.section-heading, .log-heading, .progress-row, .progress-meta { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading > div { display: flex; align-items: center; gap: 12px; }
.section-heading h2, .log-heading h2 { margin: 0; font-size: 1.08rem; }
.step { display: inline-grid; place-items: center; width: 30px; height: 30px; color: white; background: var(--brand); border-radius: 50%; font-weight: 800; }

[data-state="good"] { color: var(--good); }
[data-state="warn"] { color: var(--warn); }
[data-state="bad"] { color: var(--bad); }
[data-state="busy"] { color: var(--busy); }
[data-state="neutral"] { color: var(--muted); }

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 150px;
  margin-top: 18px;
  padding: 22px;
  text-align: center;
  border: 2px dashed #c8b7ca;
  border-radius: 16px;
  background: #fcf9fc;
  transition: 160ms ease;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--brand); background: #f8edf7; transform: translateY(-1px); }
.drop-zone input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.upload-icon { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 8px; color: white; background: var(--brand); border-radius: 50%; font-size: 1.5rem; }
.file-result { display: grid; gap: 5px; margin-top: 14px; }
.file-result span { color: var(--muted); font-size: 0.92rem; overflow-wrap: anywhere; }

.actions { display: flex; flex-wrap: wrap; gap: 11px; margin-top: 18px; }
.actions button, .dialog-actions button {
  border: 0;
  border-radius: 12px;
  padding: 12px 17px;
  color: white;
  font-weight: 800;
  box-shadow: 0 7px 18px rgba(49, 31, 51, 0.12);
}
.primary { background: var(--brand); }
.accent { background: var(--accent); }
.dfu { background: var(--dfu); }
.secondary { background: #716b74; }
.danger { background: var(--bad); }

.chooser-help { margin: 13px 0 0; color: var(--muted); font-size: 0.9rem; }
.state-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-top: 20px; }
.state-grid > div { min-height: 82px; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: #fbfafb; }
.state-grid span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 0.78rem; font-weight: 750; text-transform: uppercase; letter-spacing: 0.06em; }
.state-grid strong { overflow-wrap: anywhere; }

.progress-panel progress { width: 100%; height: 18px; margin: 15px 0 10px; accent-color: var(--brand); }
.progress-row strong { color: var(--brand); font-size: 1.28rem; }
.progress-row span, .progress-meta { color: var(--muted); }
.progress-meta { font-size: 0.88rem; }

.log-heading > div { display: flex; gap: 8px; }
.text-button { border: 0; padding: 7px 10px; color: var(--brand); background: transparent; font-weight: 750; }
pre { min-height: 220px; max-height: 390px; overflow: auto; margin: 16px 0 0; padding: 17px; color: #e9f0f7; background: #17141a; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font: 0.84rem/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.help-panel summary { cursor: pointer; color: var(--brand-dark); font-weight: 800; }
.help-panel ul { margin-bottom: 0; padding-left: 22px; }
.help-panel li + li { margin-top: 8px; }
footer { display: flex; justify-content: space-between; gap: 15px; padding: 20px 6px 0; color: var(--muted); font-size: 0.86rem; }

.warning-dialog {
  width: min(610px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  overflow: auto;
  border: 0;
  border-radius: 19px;
  padding: 27px;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(28, 16, 30, 0.36);
}
.warning-dialog::backdrop { background: rgba(24, 17, 26, 0.62); }
.warning-mark { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 13px; border-radius: 50%; color: white; background: var(--bad); font-size: 1.6rem; font-weight: 900; }
.warning-dialog h2 { margin-bottom: 9px; }
.warning-dialog p { color: #514b53; line-height: 1.48; }
.hash-grid { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 9px 13px; margin: 17px 0; padding: 15px; background: #f6f3f6; border-radius: 12px; }
.hash-grid span { color: var(--muted); font-weight: 750; }
.hash-grid code { overflow-wrap: anywhere; }
.acknowledge { display: flex; align-items: flex-start; gap: 10px; padding: 13px; border: 1px solid #e1d9e3; border-radius: 12px; background: #fffdfd; }
.acknowledge input { margin-top: 3px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

@media (max-width: 780px) {
  body { padding: 14px 10px 210px; }
  .brand-header { align-items: center; padding: 15px 16px; gap: 13px; }
  .brand-logo { width: 64px; }
  .eyebrow { display: none; }
  h1 { margin: 0 0 3px; font-size: 1.18rem; }
  .brand-copy p { font-size: 0.82rem; }
  .notice { margin-top: 10px; padding: 9px 12px; border-radius: 13px; font-size: 0.82rem; }

  .file-panel, .control-panel, .log-panel, .help-panel { margin-top: 10px; padding: 13px; border-radius: 14px; }
  .file-panel .section-heading { gap: 8px; }
  .step { width: 25px; height: 25px; font-size: 0.8rem; }
  .section-heading h2 { font-size: 0.96rem; }
  .drop-zone { min-height: 72px; margin-top: 10px; padding: 10px; border-radius: 12px; }
  .upload-icon { width: 30px; height: 30px; margin-bottom: 3px; font-size: 1rem; }
  .drop-zone strong { font-size: 0.88rem; }
  .file-result { margin-top: 8px; }
  .file-result span { display: none; }

  .control-panel { padding-bottom: 12px; }
  .chooser-help { display: none; }
  .state-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 10px; }
  .state-grid > div { min-height: 58px; padding: 8px 9px; border-radius: 10px; }
  .state-grid span { margin-bottom: 3px; font-size: 0.63rem; letter-spacing: 0.03em; }
  .state-grid strong { font-size: 0.82rem; line-height: 1.15; }
  .state-grid > div:last-child { grid-column: 1 / -1; min-height: 48px; }

  .actions {
    position: fixed;
    z-index: 120;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 0;
    padding: 10px max(10px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    background: rgba(255,255,255,0.98);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(40, 24, 42, 0.16);
  }
  .actions button { width: 100%; min-width: 0; padding: 12px 5px; font-size: 0.9rem; border-radius: 10px; }
  .actions [hidden] { display: none !important; }

  .progress-panel {
    position: fixed;
    z-index: 115;
    left: 8px;
    right: 8px;
    bottom: calc(68px + env(safe-area-inset-bottom));
    margin: 0;
    padding: 9px 11px;
    border-radius: 13px;
    box-shadow: 0 8px 28px rgba(40, 24, 42, 0.19);
  }
  .progress-row { gap: 8px; align-items: center; }
  .progress-row strong { flex: 0 0 auto; font-size: 1rem; }
  .progress-row span { min-width: 0; font-size: 0.78rem; line-height: 1.2; text-align: right; }
  .progress-panel progress { height: 10px; margin: 7px 0 3px; }
  .progress-meta { display: none; }

  .log-panel, .help-panel { box-shadow: none; }
  pre { min-height: 150px; max-height: 45vh; font-size: 0.74rem; }

  .warning-dialog { width: calc(100% - 16px); max-height: calc(100dvh - 16px); padding: 15px 14px; border-radius: 15px; }
  .warning-mark { width: 34px; height: 34px; margin-bottom: 7px; font-size: 1.15rem; }
  .warning-dialog h2 { font-size: 1.15rem; }
  .warning-dialog p { margin-bottom: 10px; font-size: 0.88rem; line-height: 1.35; }
  .hash-grid { grid-template-columns: 1fr 1fr; gap: 5px 8px; margin: 9px 0; padding: 9px; font-size: 0.76rem; }
  .acknowledge { padding: 9px; font-size: 0.84rem; }
  .dialog-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 12px -14px -15px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,0.98);
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 520px) {
  .brand-header { display: flex; }
  .brand-logo { margin: 0; }
  .section-heading { align-items: center; }
  footer { flex-direction: row; align-items: center; }
  .hash-grid { grid-template-columns: 1fr; }
  .dialog-actions { flex-direction: row; }
  .dialog-actions button { flex: 1 1 0; width: auto; }
}
