:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-2: #243044;
    --border: #2f3f56;
    --text: #eef2f7;
    --muted: #94a3b8;
    --brand: #22c55e;
    --brand-dim: #16a34a;
    --accent: #38bdf8;
    --error: #f87171;
    --radius: 14px;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(ellipse 80% 60% at 50% -10%, rgba(34, 197, 94, 0.15), transparent),
        radial-gradient(ellipse 60% 40% at 100% 0%, rgba(56, 189, 248, 0.08), transparent),
        var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 20px 64px;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(34, 197, 94, 0.15);
    color: var(--brand);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 16px;
}

h1 {
    margin: 0 0 12px;
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.lead {
    margin: 0 auto;
    max-width: 540px;
    color: var(--muted);
    font-size: 1.05rem;
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 800px) {
    .grid {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-head {
    padding: 20px 24px 0;
}

.card-head h2 {
    margin: 0 0 6px;
    font-size: 1.15rem;
}

.card-head p {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 0.92rem;
}

.tabs {
    display: flex;
    gap: 8px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
}

.tab {
    appearance: none;
    border: none;
    background: none;
    color: var(--muted);
    padding: 12px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
}

.panel {
    display: none;
    padding: 24px;
}

.panel.active {
    display: block;
}

#qrcode {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 280px;
    background: #fff;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 16px;
}

#qrcode canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.status {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    min-height: 1.4em;
}

.status.waiting {
    color: var(--accent);
}

.status.error {
    color: var(--error);
}

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 6px;
}

.field input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
}

.field input:focus {
    outline: 2px solid rgba(34, 197, 94, 0.45);
    border-color: var(--brand);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 18px;
    border: none;
    border-radius: 10px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, background 0.15s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--brand);
    color: #052e16;
}

.btn-primary:hover {
    background: var(--brand-dim);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    margin-top: 10px;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.scopes {
    padding: 16px 24px 0;
}

.scopes legend {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 10px;
}

.scope-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.scope-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.88rem;
    cursor: pointer;
}

.scope-list input {
    accent-color: var(--brand);
}

.result-card .card-body {
    padding: 24px;
}

.placeholder {
    color: var(--muted);
    text-align: center;
    padding: 48px 24px;
    font-size: 0.95rem;
}

.profile {
    display: none;
}

.profile.visible {
    display: block;
}

.avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: #052e16;
    margin-bottom: 16px;
}

.profile h3 {
    margin: 0 0 4px;
    font-size: 1.35rem;
}

.profile .subline {
    color: var(--muted);
    margin-bottom: 20px;
}

.kv {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
}

.kv-row {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 12px;
    align-items: start;
    font-size: 0.9rem;
}

.kv-row dt {
    color: var(--muted);
    margin: 0;
}

.kv-row dd {
    margin: 0;
    word-break: break-all;
    font-family: ui-monospace, monospace;
    font-size: 0.82rem;
}

.token-box {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    font-family: ui-monospace, monospace;
    font-size: 0.78rem;
    word-break: break-all;
    max-height: 120px;
    overflow: auto;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.actions .btn {
    width: auto;
    flex: 1;
    min-width: 140px;
}

footer {
    margin-top: 48px;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

footer a {
    color: var(--accent);
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
