:root {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface2: #f1f5f9;
    --border: #e2e8f0;
    --text: #1f2937;
    --muted: #6b7280;
    --accent: #16a34a;
    --accent-soft: #f0fdf4;
    --accent-border: #bbf7d0;
    --err-bg: #fef2f2;
    --err-border: #fecaca;
    --err-text: #dc2626;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #111a2b;
    --surface2: #1a2436;
    --border: #243247;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --accent: #4ade80;
    --accent-soft: rgba(74, 222, 128, 0.08);
    --accent-border: rgba(74, 222, 128, 0.25);
    --err-bg: rgba(220, 38, 38, 0.08);
    --err-border: rgba(220, 38, 38, 0.3);
    --err-text: #f87171;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.2s, color 0.2s;
}

.wrap { max-width: 860px; margin: 0 auto; padding: 32px 20px 60px; }

/* ── Header ── */
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.head-left { display: flex; gap: 14px; align-items: flex-start; }
.logo {
    width: 48px; height: 48px; border-radius: 12px; flex-shrink: 0;
    background: var(--accent-soft); border: 1px solid var(--accent-border);
    display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.head h1 { font-size: 20px; margin: 0 0 4px; }
.head p { margin: 0; font-size: 13px; color: var(--muted); max-width: 480px; }
.head-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.badge {
    font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
    background: var(--accent-soft); color: var(--accent);
    border: 1px solid var(--accent-border); padding: 6px 12px; border-radius: 8px;
}
.icon-btn {
    background: var(--surface2); border: 1px solid var(--border); color: var(--text);
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
.icon-btn:hover { border-color: var(--accent); }

/* ── Cards ── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}

/* ── Tabs ── */
.tabs { display: inline-flex; gap: 4px; background: var(--surface2); padding: 4px; border-radius: 10px; margin-bottom: 16px; }
.tabs.small { margin-bottom: 0; }
.tab {
    border: none; background: transparent; color: var(--muted); cursor: pointer;
    font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: 7px; transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* ── Form ── */
.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.muted { color: var(--muted); font-weight: 400; }
.input, .textarea {
    width: 100%; background: var(--surface2); border: 2px solid var(--border); color: var(--text);
    border-radius: 9px; padding: 10px 14px; font-size: 14px; font-family: inherit; outline: none;
    transition: border-color 0.15s;
}
.input:focus, .textarea:focus { border-color: var(--accent); }
.textarea { resize: vertical; line-height: 1.55; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row.bottom { margin-top: 16px; justify-content: space-between; }
.field { flex: 1; min-width: 160px; }
.row.bottom .field { flex: 0 0 200px; }

.btn {
    display: inline-flex; align-items: center; gap: 8px; justify-content: center;
    background: var(--accent); color: #fff; border: none; cursor: pointer;
    font-size: 14px; font-weight: 700; padding: 11px 24px; border-radius: 9px; transition: opacity 0.15s, transform 0.05s;
}
[data-theme="dark"] .btn { color: #04140a; }
.btn:hover { opacity: 0.9; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Loading ── */
.loading-head { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.loading-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.loading-log { display: flex; flex-direction: column; gap: 9px; }
.log-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.spinner {
    width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
    border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.log-done { color: var(--accent); font-weight: 700; }
.log-text-done { color: var(--muted); }

/* ── Error ── */
.card.error { display: flex; align-items: flex-start; gap: 10px; background: var(--err-bg); border-color: var(--err-border); }
.err-icon { flex-shrink: 0; }
#errorMsg { color: var(--err-text); font-size: 14px; }

/* ── Result ── */
.meta-line { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.meta-line .muted { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.meta-line strong { font-size: 17px; }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.meta-grid > div { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.meta-grid .muted { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.meta-grid code { font-size: 12px; color: var(--accent); word-break: break-all; }
.chip {
    display: inline-block; font-size: 11px; background: var(--surface2); border: 1px solid var(--border);
    padding: 2px 8px; border-radius: 999px; margin: 2px 4px 2px 0;
}

.result-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; }
.ghost {
    background: var(--surface); border: 1px solid var(--border); color: var(--text); cursor: pointer;
    font-size: 12px; font-weight: 600; padding: 7px 12px; border-radius: 8px; transition: border-color 0.15s;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

.tabpane { margin: 0; }
.preview { font-size: 15px; }
.preview h1 { font-size: 26px; line-height: 1.25; margin: 0 0 14px; }
.preview h2 { font-size: 20px; margin: 26px 0 10px; }
.preview h3 { font-size: 16px; margin: 20px 0 8px; }
.preview p { margin: 0 0 14px; }
.preview ul, .preview ol { margin: 0 0 14px; padding-left: 22px; }
.preview li { margin-bottom: 6px; }
.preview a { color: var(--accent); }
.preview blockquote { border-left: 3px solid var(--accent); margin: 0 0 14px; padding: 4px 16px; color: var(--muted); }

.code {
    background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
    padding: 16px; font-size: 12.5px; line-height: 1.55; overflow: auto; max-height: 520px;
    white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.copy-feedback {
    margin-top: 12px; text-align: center; font-size: 12px; color: var(--accent);
    background: var(--accent-soft); border-radius: 8px; padding: 6px;
}

/* ── Empty + footer ── */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-icon { font-size: 38px; opacity: 0.4; margin-bottom: 10px; }
.empty p { margin: 4px 0; font-size: 13px; }
.foot { text-align: center; font-size: 12px; margin-top: 28px; }

@media (max-width: 600px) {
    .meta-grid { grid-template-columns: 1fr; }
    .row.bottom { flex-direction: column; align-items: stretch; }
    .row.bottom .field { flex: 1 1 auto; }
    .head { flex-direction: column; }
}
