:root {
  --bg: #0f0a1a;
  --bg2: #1a1228;
  --card: #241833;
  --card2: #2d1f40;
  --text: #f5f0ff;
  --muted: #a89bc0;
  --primary: #8b5cf6;
  --primary2: #7c3aed;
  --primary-press: #6d28d9;
  --accent: #f472b6;
  --warn-bg: #3b2a12;
  --warn-border: #d97706;
  --ok: #34d399;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 8px 28px rgba(0,0,0,.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  min-height: 100dvh;
  padding-bottom: calc(72px + var(--safe-b));
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(139,92,246,.35), transparent 55%),
    radial-gradient(900px 500px at 110% 10%, rgba(244,114,182,.22), transparent 50%),
    var(--bg);
}

.app-header {
  padding: calc(14px + var(--safe-t)) 18px 10px;
}
.header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.app-header h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: .02em;
  background: linear-gradient(120deg, #fff, #e9d5ff 40%, #fbcfe8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }

.icon-btn {
  border: none;
  background: var(--card);
  color: var(--text);
  width: 42px; height: 42px;
  border-radius: 12px;
  font-size: 1.2rem;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.tab-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 14px 12px;
  padding: 6px;
  background: rgba(36,24,51,.85);
  backdrop-filter: blur(12px);
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.06);
}
.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 6px;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
}
.tab.active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 4px 14px rgba(139,92,246,.4);
}

.content { padding: 0 14px 24px; max-width: 720px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid rgba(255,255,255,.06);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }

.drop-zone {
  position: relative;
  border: 1.5px dashed rgba(167,139,250,.45);
  border-radius: 14px;
  min-height: 180px;
  background: rgba(0,0,0,.2);
  overflow: hidden;
  cursor: pointer;
  margin-bottom: 12px;
}
.drop-hint {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 180px; gap: 4px; pointer-events: none;
}
.drop-icon { font-size: 2rem; }
.drop-hint p { margin: 0; }
.preview-wrap { position: relative; }
.preview-wrap img, .preview-wrap canvas {
  display: block; width: 100%; max-height: 360px; object-fit: contain; background: #000;
}
.chip-btn {
  position: absolute; right: 10px; bottom: 10px;
  border: none; border-radius: 999px;
  padding: 8px 12px; background: rgba(0,0,0,.65); color: #fff;
  font-size: .85rem; cursor: pointer;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: .92rem; }
.field em { color: var(--accent); font-style: normal; }
.input, .textarea {
  width: 100%;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(0,0,0,.28);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
.input:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139,92,246,.25); }

.btn {
  border: none; border-radius: 12px;
  padding: 12px 16px; font-size: 1rem; font-weight: 700;
  cursor: pointer;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 6px 18px rgba(139,92,246,.35);
}
.btn-primary:not(:disabled):active { background: var(--primary-press); }
.btn-ghost {
  background: rgba(255,255,255,.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.1);
}
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: .85rem; font-weight: 600; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1 1 auto; min-width: 110px; }

.banner {
  border-radius: 12px; padding: 12px; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.banner.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
}
.banner p { margin: 0; font-size: .9rem; line-height: 1.4; }

.status { min-height: 1.2em; color: var(--muted); font-size: .9rem; margin: 10px 0 0; }
.status.err { color: var(--danger); }
.status.ok { color: var(--ok); }

.compare {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.compare figure { margin: 0; }
.compare figcaption {
  font-size: .8rem; color: var(--muted); margin-bottom: 4px; text-align: center;
}
.compare img {
  width: 100%; border-radius: 10px; background: #000; max-height: 280px; object-fit: contain;
}

.local-tools { margin-top: 4px; }
.tool-group { margin-bottom: 14px; }
.tool-label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: .88rem;
  cursor: pointer;
}
.chip.active {
  background: rgba(139,92,246,.35);
  border-color: var(--primary);
  color: #fff;
}
.slider-field { display: block; margin-bottom: 10px; font-size: .9rem; }
.slider-field span { display: flex; justify-content: space-between; margin-bottom: 4px; color: var(--muted); }
.slider-field b { color: var(--text); font-weight: 600; }
.slider-field input[type=range] { width: 100%; accent-color: var(--primary); }

.toolbar {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; align-items: center;
  background: var(--card); border-radius: 14px; padding: 10px;
  border: 1px solid rgba(255,255,255,.06);
}
.history-item img {
  width: 72px; height: 72px; object-fit: cover; border-radius: 10px; background: #000;
}
.history-item .meta { min-width: 0; }
.history-item .meta p {
  margin: 0; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item .meta .time { color: var(--muted); font-size: .75rem; margin-top: 4px; }

.empty-hint { text-align: center; color: var(--muted); padding: 40px 12px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; line-height: 1.45; }
.link { color: #c4b5fd; }
.hidden { display: none !important; }

.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.55);
}
.modal-sheet {
  position: relative;
  width: 100%; max-width: 560px;
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b));
  box-shadow: var(--shadow);
  animation: sheet .22s ease;
}
@keyframes sheet { from { transform: translateY(40%); } to { transform: none; } }
.modal-sheet h2 { margin: 0 0 8px; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  background: rgba(20,10,30,.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 200;
  border: 1px solid rgba(255,255,255,.12);
  max-width: 90vw;
  text-align: center;
}

@media (min-width: 720px) {
  .modal { align-items: center; }
  .modal-sheet { border-radius: 20px; margin: 16px; }
}

.pick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
  pointer-events: auto;
}
.pick-actions .btn { min-width: 120px; }
.drop-hint .pick-actions { pointer-events: auto; }
.change-sheet {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  position: absolute;
  right: 10px;
  bottom: 10px;
}
.change-sheet .chip-btn { position: static; }
