:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1d1b18;
  --muted: #6f6a60;
  --line: #e3ddd0;
  --accent: #c2410c;
  --ok: #2f7d4f;
  --bad: #b42318;
  --btn: #1d1b18;
  --btn-ink: #fffdf8;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #211f1c;
    --ink: #f1ede4;
    --muted: #a39d91;
    --line: #34312c;
    --accent: #f08a4b;
    --ok: #6cc28e;
    --bad: #f0806f;
    --btn: #f1ede4;
    --btn-ink: #161513;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px 4px;
  max-width: 640px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 18px; letter-spacing: .01em; }
.brand img { border-radius: 7px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 0; background: transparent; border-radius: 10px; color: var(--muted);
}
.icon-btn:active { background: var(--line); }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px 48px; display: grid; gap: 16px; }

.input-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: grid; gap: 12px;
}
.label { font-size: 13px; color: var(--muted); font-weight: 550; }
.field { position: relative; }
input[type=url], input[type=password], input[readonly] {
  width: 100%; height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  outline: none; font-size: 15px;
}
.field input { padding-right: 44px; }
input:focus { border-color: var(--ink); }
.clear {
  position: absolute; right: 4px; top: 4px; width: 40px; height: 40px;
  border: 0; background: transparent; color: var(--muted); display: grid; place-items: center;
}

.primary {
  height: 54px; border: 0; border-radius: 12px; background: var(--btn); color: var(--btn-ink);
  font-weight: 650; font-size: 17px; letter-spacing: .02em;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: transform .08s ease, opacity .15s;
}
.primary:active { transform: scale(.985); }
.primary:disabled { opacity: .55; }
.primary.small { height: 40px; padding: 0 16px; font-size: 15px; border-radius: 10px; }
.secondary {
  height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 550; font-size: 15px; white-space: nowrap;
  display: inline-flex; align-items: center;
}
.secondary:active { background: var(--line); }
.danger { color: var(--bad); }
.hint, .note { margin: 0; font-size: 13px; color: var(--muted); }

.status {
  border-radius: var(--radius); padding: 14px 16px; font-size: 15px;
  display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--line); background: var(--surface);
}
.status.error { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); color: var(--bad); }
.status.ok { color: var(--ok); }
.spinner {
  width: 18px; height: 18px; flex: none; margin-top: 2px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status .sub { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }

.result { display: grid; gap: 12px; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 2px; }
.result-title { font-weight: 650; }
.result-sub { font-size: 13px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.grid.one { grid-template-columns: 1fr; }
.tile {
  position: relative; border-radius: 12px; overflow: hidden; background: var(--line);
  aspect-ratio: 4 / 5;
}
.grid.one .tile { aspect-ratio: auto; max-height: 70vh; }
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid.one .tile img, .grid.one .tile video { object-fit: contain; max-height: 70vh; background: #000; }
.tile .badge {
  position: absolute; left: 8px; top: 8px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.55); color: #fff;
}
.tile .save {
  position: absolute; right: 8px; bottom: 8px; height: 34px; padding: 0 12px;
  border: 0; border-radius: 999px; background: rgba(255,253,248,.92); color: #1d1b18;
  font-size: 13px; font-weight: 600;
}
.tile .save.done { background: var(--ok); color: #fff; }

.section-title { font-size: 13px; color: var(--muted); font-weight: 550; padding: 0 4px 6px; }
.history ul { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.history li {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; font-size: 14px;
  border-top: 1px solid var(--line);
}
.history li:first-child { border-top: 0; }
.history .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ok); }
.history .dot.bad { background: var(--bad); }
.history .u { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .t { color: var(--muted); font-size: 12px; flex: none; }
.history button { border: 0; background: transparent; padding: 0; text-align: left; flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; }

dialog {
  border: 0; padding: 0; background: transparent; color: var(--ink);
  width: 100%; max-width: 640px; margin: auto auto 0; max-height: 92dvh;
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.sheet {
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 8px 18px calc(24px + env(safe-area-inset-bottom));
  display: grid; gap: 18px; max-height: 92dvh; overflow-y: auto;
}
@media (min-width: 700px) { dialog { margin: auto; } .sheet { border-radius: 18px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.group { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.switch { display: flex; gap: 10px; align-items: center; font-size: 15px; padding: 4px 0; }
.switch input { width: 20px; height: 20px; accent-color: var(--ink); }
.link { color: var(--accent); font-size: 14px; text-decoration: none; font-weight: 550; }
.file-btn { cursor: pointer; }
.version { font-size: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--btn); color: var(--btn-ink); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; transition: all .2s ease; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
