:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #6b7385;
  --line: #dfe3ea;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --crop: #e5484d;
  --crop-fill: rgba(229, 72, 77, .10);
  --shade: rgba(20, 24, 33, .38);
  --notice: #fff6e0;
  --notice-line: #f0d48a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --card: #1b2029;
    --text: #e6e9ef;
    --muted: #98a1b3;
    --line: #2c3340;
    --accent: #5b8cff;
    --notice: #2f2814;
    --notice-line: #6b5a23;
    --shade: rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar { padding: 18px 16px 6px; max-width: 1320px; margin: 0 auto; width: 100%; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 22px; color: var(--accent); }
.brand span { color: var(--text); }
.tag { margin: 4px 0 0; color: var(--muted); }

.drop {
  margin-top: 24px;
  border: 2px dashed var(--line);
  border-radius: 16px;
  background: var(--card);
  padding: 56px 16px;
  text-align: center;
  color: var(--muted);
  transition: border-color .15s, background .15s;
}
.drop p { margin: 6px 0; }
.drop strong { color: var(--text); }
.drop.over { border-color: var(--accent); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.filebar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.fname { font-weight: 600; word-break: break-all; }

.notice { background: var(--notice); border: 1px solid var(--notice-line); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }

.layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  position: sticky;
  top: 12px;
}
@media (max-width: 820px) { .panel { position: static; } }
.panel h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 0 10px; }
.panel h2:not(:first-child) { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-weight: 500; }
.field .val { float: right; font-weight: 400; color: var(--muted); }
.field label, label.field { position: relative; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
select, input[type=text], input[type=number], input[type=password] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

details { margin-bottom: 14px; }
summary { cursor: pointer; font-weight: 500; margin-bottom: 8px; }
.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.grid4 label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; padding: 8px 0; border: 0; background: var(--bg); color: var(--text); font: inherit; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seglabel { font-size: 13px; color: var(--muted); font-weight: 400; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: var(--card); color: var(--text); }
#go { width: 100%; margin-top: 8px; padding: 12px; }
#progress { margin-top: 8px; min-height: 18px; }

.main { min-width: 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; cursor: pointer; }
.tab.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tab:disabled { opacity: .5; cursor: default; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.grid.out { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.thumb { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.thumb.off { opacity: .35; }
.thumb .frame { position: relative; line-height: 0; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.thumb canvas { width: 100%; height: auto; display: block; }
.thumb .box { position: absolute; border: 2px solid var(--crop); background: var(--crop-fill); box-shadow: 0 0 0 9999px var(--shade); pointer-events: none; }
.thumb .frame { overflow: hidden; }
.thumb .cap { margin-top: 6px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }

.outbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; background: var(--card); color: var(--text); width: min(400px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 12, 18, .55); }
dialog h3 { margin: 0 0 6px; }
dialog p { margin: 0 0 12px; color: var(--muted); }
dialog p.err { color: var(--crop); }
dialog input[type=password], dialog input[type=text] { margin-bottom: 10px; }
dialog p strong { color: var(--text); }
.steps { margin: 0 0 12px; padding-left: 18px; font-size: 14px; }
.steps li { margin-bottom: 4px; }
.outbtns { display: flex; gap: 8px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

footer { text-align: center; padding: 16px; }
