:root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #21252e;
    --border: #2a2f3a;
    --text: #e6e8ee;
    --muted: #8b94a3;
    --primary: #6366f1;
    --primary-hover: #4f52d9;
    --danger: #e53e3e;
    --ok: #2e9c6d;
    --warn: #d19a3a;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: #8ab4ff; text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #272a33; padding: 0 4px; border-radius: 3px; font-size: 13px; }

.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 18px;
}

.muted { color: var(--muted); }
.hidden { display: none !important; }

label { display: block; margin: 12px 0; }
label > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; }
label.inline > span { margin: 0; }

input[type=text], input[type=password], input[type=number], input:not([type]), textarea, select {
    width: 100%;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font: inherit;
}
textarea { resize: vertical; }
textarea[data-sample="1"] { color: var(--muted); font-style: italic; }
input:focus, textarea:focus { outline: none; border-color: var(--primary); }

button {
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 9px 18px;
    font: inherit;
    cursor: pointer;
}
button:hover { background: var(--primary-hover); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: #2b303a; }
button.link { background: transparent; color: #8ab4ff; padding: 0; }

.alert { padding: 10px 12px; border-radius: 6px; margin: 10px 0; }
.alert-ok  { background: rgba(46,156,109,.15); border: 1px solid var(--ok); }
.alert-err { background: rgba(229,62,62,.15);  border: 1px solid var(--danger); }

.site-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.site-header h1 { margin: 0; font-size: 20px; }
.quota-chip {
    background: var(--surface-2); border: 1px solid var(--border);
    padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--muted);
}
.quota-chip b { color: var(--text); }

.generator { max-width: 760px; margin: 24px auto; padding: 0 16px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; }
.hint { margin-top: 8px; font-size: 12px; }

.result img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
    /* let the image keep its native aspect ratio */
}
.result img.hidden { display: none; }
.result-meta {
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}
.result-meta b { color: var(--text); font-weight: 600; }

/* Aliyun captcha SDK container — the SDK injects its popup elements here.
   Kept out of layout flow so it doesn't push content around. */
#aliyun-captcha-container { position: fixed; left: 0; top: 0; z-index: 9999; }

/* notice banner (used for errors & lightweight success toasts) */
.notice {
    padding: 10px 14px;
    margin: 0 0 16px;
    border-radius: 8px;
    font-size: 14px;
    border: 1px solid transparent;
    white-space: pre-line;   /* honour \n from server hint messages */
    word-break: break-word;
    line-height: 1.5;
}
.notice-ok  { background: rgba(46,156,109,.15); border-color: var(--ok);     color: #a0e5c2; }
.notice-err { background: rgba(229,62,62,.15);  border-color: var(--danger); color: #f3a6a6; }

/* ratio picker */
.ratio-group { margin: 14px 0 6px; }
.ratio-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.ratio-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.ratio-item { margin: 0; flex: 1 1 90px; min-width: 80px; }
.ratio-item input { position: absolute; opacity: 0; pointer-events: none; }
.ratio-item span {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 10px 6px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface-2); cursor: pointer; font-size: 13px; font-weight: 600;
    transition: border-color .15s, background .15s;
    text-align: center;
}
.ratio-item span small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; margin-top: 2px; }
.ratio-item input:checked + span { border-color: var(--primary); background: rgba(99,102,241,.12); }
.ratio-item span:hover { border-color: #444a5a; }

/* progress */
.progress-card { padding: 18px 20px; }
.progress-row {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 14px; margin-bottom: 8px;
}
.progress-row #progress-percent { color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-track {
    height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden;
    border: 1px solid var(--border);
}
.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #6366f1, #8b5cf6, #ec4899);
    background-size: 200% 100%;
    border-radius: 999px;
    transition: width .3s ease-out;
    animation: progress-shine 2.2s linear infinite;
}
.progress-bar.done { animation: none; background: linear-gradient(90deg, #2e9c6d, #4ade80); }
.progress-bar.error { animation: none; background: linear-gradient(90deg, #e53e3e, #f87171); }
@keyframes progress-shine {
    0%   { background-position: 0% 0%; }
    100% { background-position: 200% 0%; }
}
.progress-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.progress-steps .step {
    padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px;
    font-size: 12px; color: var(--muted); background: var(--surface-2);
}
.progress-steps .step.active { color: var(--text); border-color: var(--primary); background: rgba(99,102,241,.15); }
.progress-steps .step.done   { color: var(--ok); border-color: var(--ok); }

/* table horizontal scroll wrapper — prevents admin pages from overflowing on mobile */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap .table { min-width: 640px; }

/* --- Responsive: tablets and below --- */
@media (max-width: 900px) {
    .container { padding: 0 14px; margin: 14px auto; }
    .nav { flex-wrap: wrap; row-gap: 8px; padding: 10px 14px; }
    .nav .brand { width: 100%; margin-right: 0; }
    .nav > span[style*="flex"] { display: none; } /* drop the flex-spacer on mobile */
    .generator { margin: 16px auto; padding: 0 12px; }
    .card { padding: 16px; }
    .filter { flex-wrap: wrap; }
    .filter input { flex: 1 1 180px; max-width: none; }
}

/* --- Responsive: phones --- */
@media (max-width: 600px) {
    html, body { font-size: 14px; }

    /* iOS auto-zooms on <16px inputs — bump to 16px to stop that. */
    input[type=text], input[type=password], input[type=number], input[type=email],
    input:not([type]), textarea, select { font-size: 16px; }

    .site-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 14px 14px;
    }
    .site-header h1 { font-size: 17px; }
    .quota-chip { font-size: 12px; padding: 4px 10px; }

    .card { padding: 14px; border-radius: 8px; }

    .ratio-picker { gap: 6px; }
    .ratio-item { flex: 1 1 calc(33.333% - 6px); min-width: 0; }
    .ratio-item span { padding: 8px 4px; font-size: 12px; }
    .ratio-item span small { font-size: 10px; }

    .row { flex-direction: column; align-items: stretch; gap: 8px; }
    button { padding: 11px 16px; width: 100%; min-height: 44px; }
    button.link { width: auto; min-height: 0; padding: 0; }
    button.secondary { width: auto; align-self: flex-start; }

    .progress-card { padding: 14px; }
    .progress-steps .step { font-size: 11px; padding: 2px 8px; }

    /* admin */
    .nav { font-size: 13px; gap: 10px; }
    .nav a { padding: 4px 0; }
    .stat { font-size: 22px; }
    .stat-grid { gap: 10px; }
    .pager { flex-wrap: wrap; }
    .ellipsis { max-width: 140px; }

    .alert { font-size: 13px; }
}

/* very small phones — extra tightening */
@media (max-width: 360px) {
    .ratio-item { flex: 1 1 calc(50% - 6px); }
}

#status-line { margin-bottom: 10px; font-size: 14px; }
#optimized-box { margin-top: 12px; }
#optimized-text { white-space: pre-wrap; background: var(--surface-2); padding: 10px; border-radius: 6px; }

/* admin */
.nav {
    display: flex; gap: 14px; align-items: center;
    padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.nav .brand { font-weight: 600; margin-right: 14px; }
.nav a { color: var(--muted); }
.nav a.active, .nav a:hover { color: var(--text); }
.container { max-width: 1100px; margin: 18px auto; padding: 0 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; }
.stat { font-size: 28px; font-weight: 700; }

.table {
    width: 100%; border-collapse: collapse; background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.table th, .table td {
    padding: 8px 10px; border-bottom: 1px solid var(--border);
    font-size: 13px; text-align: left; vertical-align: top;
}
.table th { background: var(--surface-2); color: var(--muted); font-weight: 500; }
.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-ok               { color: var(--ok); }
.status-blocked_prompt,
.status-blocked_optimized,
.status-blocked_image    { color: var(--danger); }
.status-generate_failed,
.status-save_failed      { color: var(--warn); }

.filter { display: flex; gap: 8px; margin-bottom: 14px; }
.filter input { max-width: 260px; }
.pager { margin-top: 16px; display: flex; gap: 6px; }
.pager a { padding: 4px 10px; border: 1px solid var(--border); border-radius: 4px; }
.pager a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
