:root {
    --bg: #eef1f8;
    --card: #ffffff;
    --card2: #f7f8fd;
    --ink: #1f2333;
    --muted: #6b7186;
    --line: #e3e6f0;
    --accent: #4f46e5;
    --accent2: #7c3aed;
    --accent-soft: #eef0ff;
    --accent-ink: #4338ca;
    --ok: #0f9d58;
    --ok-soft: #e6f6ec;
    --warn: #b45309;
    --warn-soft: #fdf1dc;
    --bad: #dc2626;
    --bad-soft: #fde8e8;
    --field-bg: #fff;
    --shadow: 0 1px 2px rgba(23, 27, 51, .05), 0 8px 24px -12px rgba(23, 27, 51, .18);
    --radius: 16px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="dark"] {
    --bg: #0d0f16;
    --card: #161a24;
    --card2: #1c2130;
    --ink: #e8eaf2;
    --muted: #9aa1b5;
    --line: #2a3040;
    --accent-soft: rgba(99, 102, 241, .18);
    --accent-ink: #a5b4fc;
    --ok: #34d399;
    --ok-soft: rgba(16, 185, 129, .14);
    --warn: #fbbf24;
    --warn-soft: rgba(245, 158, 11, .14);
    --bad: #f87171;
    --bad-soft: rgba(248, 113, 113, .14);
    --field-bg: #0f131d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

.backdrop {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(900px 420px at 12% -10%, rgba(124, 58, 237, .14), transparent 60%),
        radial-gradient(800px 420px at 88% -10%, rgba(79, 70, 229, .12), transparent 60%);
    pointer-events: none;
    z-index: -1;
}

.wrap {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: 0 20px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 20px;
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo { color: var(--accent); display: inline-flex; }

.brand h1 {
    margin: 0;
    font-size: 20px;
    letter-spacing: -.02em;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.chip {
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 11px;
    border-radius: 999px;
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--muted);
    white-space: nowrap;
    cursor: default;
}
.chip.ok  { color: var(--ok);   border-color: transparent; background: var(--ok-soft); }
.chip.bad { color: var(--bad);  border-color: transparent; background: var(--bad-soft); }

.chip.btn-theme {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    color: var(--muted);
}
.chip.btn-theme:hover { color: var(--accent); border-color: var(--accent); }
.chip.btn-theme .ic-sun { display: none; }
html[data-theme="dark"] .chip.btn-theme .ic-sun { display: inline; }
html[data-theme="dark"] .chip.btn-theme .ic-moon { display: none; }

main.wrap { flex: 1; display: flex; flex-direction: column; gap: 16px; padding-bottom: 40px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.alert { padding: 18px 22px; }
.alert.error { border-left: 4px solid var(--bad); }
.alert h3 { margin: 0 0 6px; font-size: 15px; }
.alert p { margin: 0; font-size: 13.5px; color: var(--muted); }
.alert code { background: var(--bad-soft); border-radius: 4px; padding: 1px 6px; }

kbd {
    font-family: inherit;
    font-size: 11px;
    padding: 1px 5px;
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--field-bg);
    color: var(--ink);
}

.drop {
    position: relative;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
    outline: none;
    border: 2px dashed #cdd3e8;
    background: linear-gradient(180deg, var(--card), var(--card2));
    overflow: hidden;
}
html[data-theme="dark"] .drop { border-color: #333a4d; }
.drop:focus-visible, .drop:hover { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.drop.drag { border-color: var(--accent2); background: var(--accent-soft); }

.drop-inner {
    padding: 40px 24px;
    text-align: center;
    pointer-events: none;
}

.drop-icon {
    display: inline-flex;
    color: var(--accent);
    background: var(--accent-soft);
    width: 66px;
    height: 66px;
    border-radius: 18px;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.drop h2 { margin: 0 0 6px; font-size: 17px; }
.drop .fmt { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; letter-spacing: .02em; }
.drop small { color: var(--muted); font-size: 12px; }

.urlrow {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    flex-wrap: wrap;
}
.urlrow .lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
.urlrow input[type="url"] {
    flex: 1;
    min-width: 220px;
}
.urlrow small { font-size: 11.5px; color: var(--muted); }

.opt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 22px;
    padding: 20px 22px;
}

.opt-group h4 {
    margin: 0 0 14px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

.opt-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.opt-row > label:first-child {
    font-size: 13px;
    color: var(--muted);
    min-width: 70px;
    font-weight: 500;
}
.opt-row .unit { color: var(--muted); font-size: 12.5px; }

.opt-hint { display: block; margin-top: 2px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }

.qrow input[type="range"] { flex: 1; accent-color: var(--accent); cursor: pointer; }
.qrow output {
    min-width: 34px;
    text-align: center;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    background: var(--accent-soft);
    color: var(--accent-ink);
    border-radius: 8px;
    padding: 2px 8px;
    font-size: 13px;
}

.auto-row { align-items: center; }
.target-wrap { display: flex; align-items: center; gap: 6px; }
.target-wrap input { width: 90px; }

input[type="text"], input[type="url"], input[type="number"], select {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    font-size: 13.5px;
    color: var(--ink);
    background: var(--field-bg);
    outline: none;
    font-family: inherit;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled, select:disabled { opacity: .5; cursor: not-allowed; }
input[type="text"] { width: 100%; }
input[type="url"] { width: auto; min-width: 260px; }

input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

select { min-width: 180px; cursor: pointer; }

.cb {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ink);
    cursor: pointer;
    user-select: none;
}

.actionbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    flex-wrap: wrap;
}
.actionbar .spacer { flex: 1; }
.limits { font-size: 11.5px; color: var(--muted); }

.btn {
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    border-radius: 10px;
    border: 1px solid transparent;
    padding: 10px 18px;
    cursor: pointer;
    transition: filter .12s ease, background .12s ease, color .12s ease, opacity .12s ease;
    white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #fff;
}
.btn.primary:not(:disabled):hover { filter: brightness(1.07); }
.btn.ghost { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn.ghost:not(:disabled):hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.btn.link { background: transparent; color: var(--muted); padding: 10px 8px; }
.btn.link:not(:disabled):hover { color: var(--bad); }
.btn.small { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.dl {
    background: var(--ok-soft);
    color: var(--ok);
    border-color: transparent;
    text-decoration: none;
}
.btn.dl:not(:disabled):hover { background: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:not(:disabled):hover { background: var(--bad-soft); }

.queue { padding: 16px 20px; }

.summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 11px 14px;
    margin-bottom: 14px;
    border-radius: 11px;
    background: var(--ok-soft);
    color: var(--ok);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.5;
}
.summary strong { font-weight: 700; }
html[data-theme="dark"] .summary { color: #6ee7b7; }

.q-head {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.q-head h3 { margin: 0; font-size: 15px; }
.q-head h3 span { color: var(--muted); font-weight: 600; }
.progress {
    flex: 1;
    min-width: 120px;
    height: 6px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
}
.progress > div {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    transition: width .25s ease;
    border-radius: 999px;
}
.progress-label { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 44px; }

.queue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
}
.item.errored { border-color: transparent; box-shadow: inset 0 0 0 1px var(--bad); }
.item.doned   { border-color: transparent; box-shadow: inset 0 0 0 1px var(--ok); opacity: .92; }

.thumb {
    width: 50px;
    height: 50px;
    flex: 0 0 50px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: var(--muted);
    font-size: 15px;
    letter-spacing: .04em;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.info { flex: 1; min-width: 0; }
.fname {
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.err {
    font-size: 11.5px;
    color: var(--bad);
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qfield input {
    width: 52px;
    padding: 5px 4px;
    font-size: 12px;
    text-align: center;
    border-radius: 7px;
    color: var(--accent-ink);
    -moz-appearance: textfield;
    appearance: textfield;
}
.qfield input::-webkit-outer-spin-button,
.qfield input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qfield input::placeholder { color: var(--muted); opacity: .7; }

.pill {
    font-size: 11.5px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
    flex: 0 0 auto;
}
.pill.pending    { background: var(--line); color: var(--muted); }
.pill.processing { background: var(--warn-soft); color: var(--warn); animation: pulse 1s infinite ease-in-out; }
.pill.done       { background: var(--ok-soft); color: var(--ok); }
.pill.error      { background: var(--bad-soft); color: var(--bad); }

@keyframes pulse { 50% { opacity: .5; } }

.item-actions { display: flex; gap: 6px; align-items: center; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.item-actions a { text-decoration: none; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    background: #1f2333;
    color: #fff;
    font-size: 13.5px;
    padding: 11px 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 90;
    max-width: min(92vw, 600px);
    text-align: center;
}
html[data-theme="dark"] .toast { background: #232a3b; }
.toast.show { animation: rise .2s ease; }
@keyframes rise { from { transform: translate(-50%, 10px); opacity: 0; } }

.modal-back {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 22, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}
.modal {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    width: min(92vw, 880px);
    max-height: 92vh;
    overflow: auto;
    padding: 18px 20px 20px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-x {
    border: none;
    background: var(--line);
    color: var(--ink);
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}
.modal-x:hover { background: var(--bad-soft); color: var(--bad); }

.cmp-meta {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 14px;
    overflow-wrap: anywhere;
}
.cmp-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 14px;
    align-items: start;
}
.cmp-grid figure { margin: 0; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cmp-grid figcaption {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cmp-img {
    background: repeating-conic-gradient(#c9cede 0 25%, transparent 0 50%) 50% / 16px 16px,
                var(--line);
    border: 1px solid var(--line);
    border-radius: 12px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.cmp-img img { max-width: 100%; max-height: 46vh; object-fit: contain; display: block; }
.cmp-arrow {
    align-self: center;
    color: var(--accent);
    font-size: 22px;
    font-weight: 700;
}
.ph {
    color: var(--muted);
    font-weight: 800;
    font-size: 20px;
    letter-spacing: .06em;
    width: 80px;
    height: 80px;
    border-radius: 16px;
    background: var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
}

.foot {
    padding: 18px 20px 30px;
    text-align: center;
    font-size: 11.5px;
    color: var(--muted);
    line-height: 1.6;
}

@media (max-width: 700px) {
    .opt-grid { grid-template-columns: 1fr; }
    .actionbar { justify-content: stretch; }
    .actionbar .btn { flex: 1; }
    .item { flex-wrap: wrap; }
    .cmp-grid { grid-template-columns: 1fr; }
    .cmp-arrow { transform: rotate(90deg); justify-self: center; }
}
