/* ========================================
   CSS Variables
   ======================================== */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #eef2ff;
    --secondary: #64748b;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
    --success: #10b981;
    --success-dark: #059669;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --radius: 12px;
    --r-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
    --shadow-hover: 0 4px 16px rgba(99,102,241,.15);
    --transition: all .2s ease;
}

/* ========================================
   Reset & Base
   ======================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ========================================
   Layout
   ======================================== */
.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 24px 16px 40px;
}

/* ========================================
   Header
   ======================================== */
.header {
    text-align: center;
    margin-bottom: 28px;
    padding: 28px 24px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    border-radius: var(--radius);
    color: white;
    box-shadow: 0 8px 30px rgba(99,102,241,.25);
    position: relative;
    overflow: hidden;
}
.header::before {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 160px; height: 160px;
    background: rgba(255,255,255,.06);
    border-radius: 50%;
}
.header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -.3px;
    position: relative; z-index: 1;
}
.header p {
    opacity: .85;
    margin-top: 4px;
    font-size: .85rem;
    position: relative; z-index: 1;
}

/* ========================================
   Card
   ======================================== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card h2::before {
    content: '';
    width: 4px;
    height: 18px;
    background: var(--primary);
    border-radius: 2px;
}

/* ========================================
   Link Rows
   ======================================== */
.link-row {
    display: grid;
    grid-template-columns: 130px 1fr 36px;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
    transition: var(--transition);
}
.link-row:hover { transform: translateX(2px); }

.link-row select {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    border: 1.5px solid var(--border);
    background: var(--primary-light);
    font-size: .85rem;
    cursor: pointer;
    color: var(--primary-dark);
    font-weight: 500;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236366f1' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
    transition: var(--transition);
}
.link-row select:hover { border-color: var(--primary); }
.link-row select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

.link-row input {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    border: 1.5px solid var(--border);
    font-size: .9rem;
    transition: var(--transition);
    width: 100%;
    color: var(--text);
    background: #fafbfc;
}
.link-row input::placeholder { color: #94a3b8; }
.link-row input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}

.btn-delete {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: 6px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-delete:hover { background: var(--danger-light); color: var(--danger); }

/* ========================================
   Actions
   ======================================== */
.actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid #f1f5f9;
}
.counter {
    margin-left: auto;
    color: var(--text-light);
    font-size: .8rem;
    background: #f1f5f9;
    padding: 4px 10px;
    border-radius: 20px;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    padding: 9px 16px;
    border-radius: var(--r-sm);
    border: none;
    cursor: pointer;
    font-size: .85rem;
    font-weight: 500;
    transition: var(--transition);
    font-family: inherit;
    white-space: nowrap;
}
.btn-secondary {
    background: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid rgba(99,102,241,.2);
}
.btn-secondary:hover {
    background: #e0e7ff;
    transform: translateY(-1px);
}

.btn-generate {
    display: block;
    width: 100%;
    padding: 15px;
    font-size: 1.05rem;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    margin: 22px 0;
    box-shadow: 0 4px 14px rgba(16,185,129,.3);
    transition: var(--transition);
    font-family: inherit;
}
.btn-generate:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16,185,129,.4);
}
.btn-generate:active { transform: translateY(0); }

/* ========================================
   Template Tabs
   ======================================== */
.template-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}
.btn-tab {
    padding: 7px 18px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: white;
    cursor: pointer;
    font-size: .82rem;
    font-weight: 500;
    color: var(--text-light);
    transition: var(--transition);
    font-family: inherit;
}
.btn-tab:hover { border-color: var(--primary); color: var(--primary); }
.btn-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ========================================
   Textarea
   ======================================== */
textarea {
    width: 100%;
    padding: 14px;
    border-radius: var(--r-sm);
    border: 1.5px solid var(--border);
    font-family: "SF Mono", "Fira Code", Consolas, monospace;
    font-size: .82rem;
    resize: vertical;
    transition: var(--transition);
    color: var(--text);
    background: #fafbfc;
    line-height: 1.7;
}
textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}

.variables-hint {
    margin-top: 10px;
    font-size: .75rem;
    color: var(--text-light);
}
.variables-hint code {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 2px 8px;
    border-radius: 4px;
    margin: 0 3px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: .72rem;
}

/* ========================================
   Output Card (Dark Theme)
   ======================================== */
.output-card {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #1e293b;
}
.output-card h2 {
    color: white;
}
.output-card h2::before {
    background: var(--success);
}
.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.output-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.status-badge {
    background: #1e293b;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: .75rem;
    color: #94a3b8;
    font-weight: 500;
}
#output-area {
    background: #1e293b;
    padding: 16px;
    border-radius: var(--r-sm);
    min-height: 140px;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: "SF Mono", "Fira Code", Consolas, monospace;
    font-size: .82rem;
    line-height: 1.8;
    color: #e2e8f0;
    border: 1px solid #334155;
    margin: 0;
}
.btn-icon {
    background: #334155;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: .82rem;
    transition: var(--transition);
    font-family: inherit;
}
.btn-icon:hover { background: #475569; }

/* ========================================
   Footer
   ======================================== */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: .8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.live-dot {
    width: 7px;
    height: 7px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16,185,129,.4); }
    50% { opacity: .5; box-shadow: 0 0 0 4px rgba(16,185,129,0); }
}

/* ========================================
   Toast
   ======================================== */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(60px);
    background: var(--text);
    color: white;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 500;
    opacity: 0;
    transition: all .35s cubic-bezier(.4,0,.2,1);
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 8px 30px rgba(0,0,0,.15);
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 600px) {
    .container { padding: 16px 10px 30px; }
    .header { padding: 22px 16px; margin-bottom: 20px; }
    .header h1 { font-size: 1.3rem; }
    .card { padding: 16px; }
    .link-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    .link-row select { width: 100%; }
    .btn-delete { justify-self: end; }
    .actions { flex-wrap: wrap; }
}

/* ========================================
   Scrollbar
   ======================================== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
#output-area::-webkit-scrollbar-thumb { background: #475569; }
