:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --card: rgba(255, 255, 255, 0.96);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --accent: #0a67d8;
  --accent-strong: #0057c2;
  --soft: #eef5ff;
  --success: #18864b;
  --warning: #b26200;
  --danger: #c62828;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.07);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  background:
    radial-gradient(circle at top right, rgba(10, 103, 216, 0.09), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
}
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 14px calc(env(safe-area-inset-bottom) + 30px);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 8px 18px;
}
.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
}
h1 { margin: 0; font-size: clamp(29px, 7vw, 42px); letter-spacing: -.04em; }
.subtitle { margin: 8px 0 0; color: var(--muted); line-height: 1.55; font-size: 15px; }

.card {
  background: var(--card);
  border: 1px solid rgba(140, 140, 145, .22);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.privacy-card {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  background: linear-gradient(135deg, rgba(235, 249, 241, .98), rgba(246, 255, 250, .98));
}
.privacy-card p { margin: 4px 0 0; color: #466352; line-height: 1.45; font-size: 14px; }
.privacy-icon {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; color: white; background: var(--success); font-weight: 800;
}

.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 15px; }
.section-heading > div { display: flex; align-items: center; gap: 10px; min-width: 0; }
h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.step {
  width: 29px; height: 29px; border-radius: 50%; display: grid; place-items: center;
  color: white; background: var(--accent); font-weight: 800; font-size: 14px; flex: 0 0 auto;
}
.badge, .status-label {
  color: var(--muted); background: rgba(118,118,128,.1); border-radius: 999px;
  padding: 6px 10px; font-size: 12px; font-weight: 650; white-space: nowrap;
}

.file-picker {
  min-height: 152px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed #a9bcd5; border-radius: 18px; padding: 20px; text-align: center;
  background: linear-gradient(180deg, rgba(244, 249, 255, .95), rgba(250, 252, 255, .95));
  cursor: pointer;
}
.file-picker:active { transform: scale(.995); }
.file-picker-icon {
  width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center;
  color: white; background: var(--accent); font-size: 29px; line-height: 1; margin-bottom: 10px;
}
.file-picker-title { font-weight: 780; font-size: 18px; }
.file-picker-subtitle { margin-top: 6px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.selected-summary { margin-top: 12px; padding: 12px; border-radius: 14px; background: rgba(118,118,128,.08); color: var(--muted); font-size: 13px; line-height: 1.5; word-break: break-word; }

.setting-group { margin: 0 0 18px; }
.setting-group:last-child { margin-bottom: 0; }
.setting-grid { display: grid; gap: 14px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.setting-label { display: block; font-weight: 720; font-size: 14px; margin-bottom: 8px; }
.setting-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.setting-label-row .setting-label { margin: 0; }
small, .hint { color: var(--muted); line-height: 1.45; }
.setting-group small { display: block; font-size: 12px; margin-top: 6px; }
select, input[type="number"] {
  width: 100%; border: 1px solid var(--line); border-radius: 13px; padding: 12px 13px;
  color: var(--text); background: rgba(250,250,252,.92); outline: none;
}
select:focus, input[type="number"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,103,216,.14); }
.range-label { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.range-label .setting-label { margin-bottom: 4px; }
output { color: var(--accent); font-weight: 800; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.switch-row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 14px; margin: 2px 0 18px; border-radius: 15px; background: rgba(118,118,128,.07);
  cursor: pointer;
}
.switch-row small { display: block; margin-top: 4px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 52px; height: 31px; border-radius: 999px; background: #b6b6ba; position: relative; transition: .2s;
}
.switch::after {
  content: ""; width: 27px; height: 27px; border-radius: 50%; background: white; position: absolute;
  top: 2px; left: 2px; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: .2s;
}
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(21px); }

.edge-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.edge-grid label { color: var(--muted); font-size: 12px; text-align: center; }
.edge-grid input { margin-top: 6px; text-align: center; padding-inline: 4px; font-variant-numeric: tabular-nums; }

.button-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.primary-button, .secondary-button, .text-button, .icon-button {
  border: 0; border-radius: 14px; font-weight: 760; cursor: pointer;
}
.primary-button { min-height: 50px; padding: 13px 18px; color: white; background: var(--accent); }
.primary-button:active { background: var(--accent-strong); }
.secondary-button { min-height: 50px; padding: 13px 17px; color: var(--accent); background: var(--soft); }
.text-button { padding: 7px 4px; color: var(--accent); background: transparent; font-size: 13px; }
.icon-button {
  width: 39px; height: 39px; display: grid; place-items: center; flex: 0 0 auto;
  color: var(--text); background: rgba(118,118,128,.12); font-size: 21px;
}
button:disabled { opacity: .45; cursor: default; }

.progress-wrap { margin-top: 15px; }
.progress-track { height: 9px; border-radius: 999px; overflow: hidden; background: rgba(118,118,128,.15); }
.progress-bar { width: 0; height: 100%; background: var(--accent); transition: width .2s ease; }
.progress-wrap p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.pending-template-box { margin-top: 14px; padding: 14px; border-radius: 16px; background: rgba(10,103,216,.08); border: 1px solid rgba(10,103,216,.18); }
.pending-template-text { margin: 0 0 12px; color: var(--text); font-size: 14px; line-height: 1.6; }
.pending-template-actions { grid-template-columns: 1fr; }


.results-list { display: grid; gap: 13px; margin-top: 16px; }
.result-card { border: 1px solid var(--line); border-radius: 17px; padding: 13px; overflow: hidden; }
.result-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.result-title { margin: 0; font-size: 15px; word-break: break-all; }
.result-state { flex: 0 0 auto; border-radius: 999px; padding: 5px 8px; font-size: 11px; font-weight: 750; }
.state-success { color: var(--success); background: rgba(24,134,75,.1); }
.state-review { color: var(--warning); background: rgba(178,98,0,.11); }
.state-error { color: var(--danger); background: rgba(198,40,40,.1); }
.result-meta { margin: 6px 0 8px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.strategy-note { margin: 0 0 10px; color: var(--accent); font-size: 12px; font-weight: 700; line-height: 1.45; }
.preview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: start; }
.preview-grid.one-column { grid-template-columns: 1fr; }
.preview-block { min-width: 0; }
.preview-label { display: block; color: var(--muted); font-size: 11px; margin: 0 0 5px 2px; }
.preview-frame {
  position: relative; border-radius: 11px; overflow: hidden;
  display: block; background:
    linear-gradient(45deg, #ddd 25%, transparent 25%),
    linear-gradient(-45deg, #ddd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd 75%),
    linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  padding: 6px;
}
.preview-frame img { display: block; width: 100%; height: auto; object-fit: contain; background: rgba(255,255,255,.72); border-radius: 8px; cursor: zoom-in; }
.result-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.result-actions button { min-height: 42px; border-radius: 12px; }

footer { padding: 13px 12px 0; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }
footer p { margin: 4px 0; }

.hidden { display: none !important; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 22px); transform: translate(-50%, 24px);
  z-index: 20; max-width: calc(100vw - 32px); padding: 11px 15px; border-radius: 13px;
  color: white; background: rgba(20,20,22,.92); opacity: 0; pointer-events: none; transition: .22s;
  text-align: center; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.22);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog { border: 0; padding: 0; background: transparent; max-width: min(92vw, 500px); }
dialog::backdrop { background: rgba(0,0,0,.42); backdrop-filter: blur(4px); }
.dialog-card { background: var(--card); color: var(--text); border-radius: 22px; padding: 19px; box-shadow: 0 24px 60px rgba(0,0,0,.27); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.dialog-card ol { padding-left: 22px; line-height: 1.8; }
.dialog-card p { color: var(--muted); line-height: 1.5; }
.dialog-card > .primary-button { width: 100%; }

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

@media (max-width: 560px) {
  .app-shell { padding-inline: 10px; }
  .card { padding: 15px; border-radius: 19px; }
  .two-columns { grid-template-columns: 1fr; }
  .edge-grid { grid-template-columns: repeat(4, 1fr); }
  .section-heading { align-items: flex-start; }
  .results-heading { align-items: center; }
  .status-label { white-space: normal; text-align: right; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101012;
    --card: rgba(30,30,32,.96);
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --line: #46464a;
    --soft: rgba(10,103,216,.18);
    --shadow: 0 14px 40px rgba(0,0,0,.3);
  }
  body { background: radial-gradient(circle at top right, rgba(10,103,216,.16), transparent 28rem), var(--bg); }
  .privacy-card { background: linear-gradient(135deg, rgba(18,55,36,.98), rgba(21,44,32,.98)); }
  .privacy-card p { color: #a8cbb6; }
  .file-picker { background: linear-gradient(180deg, rgba(24,37,53,.95), rgba(28,31,36,.95)); border-color: #4b6c94; }
  select, input[type="number"] { background: rgba(40,40,43,.95); }
  .preview-frame img { background: rgba(20,20,22,.76); }
}

.micro-adjust-box { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.micro-adjust-title { margin: 0 0 8px; font-size: 13px; font-weight: 720; color: var(--text); }
.micro-adjust-hint { margin: 6px 0 10px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.micro-adjust-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.micro-adjust-actions button { min-height: 40px; border-radius: 12px; }
@media (max-width: 560px) { .micro-adjust-actions { grid-template-columns: 1fr; } }
