/* ============================================================
   DemoCrafter API — demo player: surfaces, templates, API panel
   ============================================================ */

/* ---------- Player layout (standalone + builder preview) ---------- */
.player-stage {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    justify-content: center;
    padding: 1.1rem;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    min-height: 480px;
    position: relative;
    overflow: hidden;
}
.player-stage.fullbleed {
    border-radius: var(--radius);
    border: none;
    background:
        radial-gradient(ellipse 60% 50% at 20% 0%, rgba(109, 124, 255, 0.08), transparent),
        var(--bg);
    min-height: calc(100vh - 54px);
    height: 100%;
    overflow: auto;
}
.player-stage.tight { padding: 0; min-height: 420px; }
/* In the builder preview column, stack the surface above the API panel */
.player-stage.tight { flex-direction: column; align-items: center; }
.player-stage.tight .api-panel-dock { max-width: 620px; width: 100%; }

/* When API panel is docked */
.player-main { flex-shrink: 0; max-width: 100%; min-width: 0; }
.api-panel-dock { flex: 1; min-width: 0; max-width: 430px; }

/* ---------- Surface: desktop (browser chrome) ---------- */
.surface-desktop {
    width: 100%;
    max-width: 620px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #2a3040;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    background: #fff;
}
.browser-chrome {
    display: flex; align-items: center; gap: 0.7rem;
    background: #1a1e29;
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid #262c3a;
}
.browser-dots { display: flex; gap: 5px; flex-shrink: 0; }
.browser-dots span { width: 9px; height: 9px; border-radius: 50%; }
.browser-dots span:nth-child(1) { background: #f6645c; }
.browser-dots span:nth-child(2) { background: #f5bd4f; }
.browser-dots span:nth-child(3) { background: #62c554; }
.browser-url {
    flex: 1;
    background: #10131b;
    border-radius: 6px;
    padding: 0.22rem 0.7rem;
    font-size: 11px;
    color: #8f98ac;
    font-family: var(--mono);
    display: flex; align-items: center; gap: 0.4rem;
    overflow: hidden; white-space: nowrap;
}
.browser-url i { font-size: 8px; color: #5bda9d; }
.browser-url .url-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- Surface: mobile (phone frame) ---------- */
.surface-mobile {
    width: 288px;
    border-radius: 34px;
    border: 7px solid #1c202b;
    outline: 1px solid #333a4c;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    position: relative;
}
.phone-notch {
    position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
    width: 90px; height: 20px;
    background: #1c202b;
    border-radius: 0 0 14px 14px;
    z-index: 5;
}
.phone-screen { height: 560px; overflow-y: auto; scrollbar-width: none; }
.phone-screen::-webkit-scrollbar { display: none; }

/* ============================================================
   Demo templates (the visual templates demos render in)
   Each template scopes: .tpl-slate / .tpl-aurora / .tpl-paper / .tpl-carbon
   ============================================================ */

.demo-page {
    font-size: 13.5px;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}
.surface-mobile .demo-page { font-size: 12.5px; }

.dp-head { padding: 1.6rem 1.6rem 1rem; }
.dp-body { padding: 0 1.6rem 1.8rem; flex: 1; }
.dp-brandline { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 13px; letter-spacing: -0.01em; }
.dp-brandline .brand-mark {
    width: 20px; height: 20px; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-size: 9px; flex-shrink: 0;
}
.dp-headline { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; margin-top: 1rem; }
.dp-sub { font-size: 13px; margin-top: 0.35rem; opacity: 0.75; line-height: 1.5; }
.surface-mobile .dp-headline { font-size: 17px; }

.demo-form { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 0.4rem; }
.dp-section-title { font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; opacity: 0.6; margin-top: 0.4rem; }

.dp-field label {
    display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px;
}
.dp-field .dp-help { font-size: 11px; opacity: 0.6; margin-top: 3px; }
.dp-field .dp-err { font-size: 11px; color: #ef4444; margin-top: 3px; display: none; }
.dp-field.invalid .dp-err { display: block; }
.dp-field.invalid .dp-input { border-color: #ef4444 !important; }
.dp-field .req-star { color: #ef4444; }

.dp-input {
    width: 100%;
    font-size: 13.5px;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.dp-input:focus { outline: none; }
.dp-input::placeholder { opacity: 0.45; }
select.dp-input { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23888' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.7rem center; padding-right: 2rem; }
textarea.dp-input { resize: vertical; min-height: 60px; font-family: var(--mono); font-size: 12px; }

.dp-submit {
    margin-top: 0.6rem;
    width: 100%;
    border: none; cursor: pointer;
    font-weight: 600; font-size: 14px;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    transition: transform 0.12s ease, opacity 0.15s ease, box-shadow 0.2s ease;
}
.dp-submit:active { transform: scale(0.985); }
.dp-submit:disabled { opacity: 0.75; cursor: default; }
.dp-submit .btn-spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: none;
}
.dp-submit.loading .btn-spinner { display: inline-block; }
.dp-submit.loading .submit-arrow { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.dp-foot { text-align: center; font-size: 11px; opacity: 0.55; padding: 0 1.6rem 1.2rem; }

/* Field flash when its JSON line updates */
.dp-field.flash .dp-input { animation: fieldFlash 0.9s ease; }
@keyframes fieldFlash {
    0% { box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.35); border-color: #34d399; }
    100% { box-shadow: none; }
}

/* Shake on invalid submit */
.demo-form.shake { animation: shake 0.4s ease; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ---------- Result screen (inside the surface) ---------- */
.dp-result { text-align: center; padding: 1.2rem 0.4rem; animation: resultIn 0.35s ease; }
@keyframes resultIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.dp-result .result-icon {
    width: 52px; height: 52px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 22px; margin-bottom: 0.9rem;
}
.dp-result.ok .result-icon { background: rgba(16, 185, 129, 0.14); color: #10b981; }
.dp-result.fail .result-icon { background: rgba(239, 68, 68, 0.13); color: #ef4444; }
.dp-result h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.dp-result p { font-size: 13px; opacity: 0.72; margin-top: 0.4rem; line-height: 1.55; }
.dp-result .result-ref {
    margin-top: 1rem; display: block; max-width: 280px; margin-left: auto; margin-right: auto;
    font-family: var(--mono); font-size: 11px;
    padding: 0.3rem 0.7rem; border-radius: 20px;
    background: rgba(127, 127, 127, 0.12);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dp-result .dp-submit { margin-top: 1.1rem; max-width: 260px; }

/* ---------- Template: Slate (clean light SaaS) ---------- */
.tpl-slate {
    background: #f7f8fb; color: #171b26;
    font-family: "Inter", -apple-system, sans-serif;
}
.tpl-slate .dp-head { border-bottom: 1px solid #e6e9f0; background: #fff; }
.tpl-slate .dp-brandline { color: #171b26; }
.tpl-slate .dp-sub { color: #5b6472; }
.tpl-slate .dp-section-title { color: #6b7280; }
.tpl-slate .dp-field label { color: #2a3140; }
.tpl-slate .dp-help, .tpl-slate .dp-foot { color: #6b7280; opacity: 1; }
.tpl-slate .dp-input { background: #fff; border: 1px solid #d4d9e3; color: #171b26; }
.tpl-slate .dp-input:focus { border-color: var(--t-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--t-accent) 18%, transparent); }
.tpl-slate .dp-submit { background: var(--t-accent); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--t-accent) 35%, transparent); }
.tpl-slate .dp-submit:hover { box-shadow: 0 6px 18px color-mix(in srgb, var(--t-accent) 45%, transparent); }

/* ---------- Template: Aurora (dark, gradient, glass) ---------- */
.tpl-aurora {
    background:
        radial-gradient(ellipse 90% 45% at 85% -5%, color-mix(in srgb, var(--t-accent) 42%, transparent), transparent),
        radial-gradient(ellipse 70% 40% at 0% 100%, color-mix(in srgb, var(--t-accent) 20%, transparent), transparent),
        #0b0d16;
    color: #eef0f8;
    font-family: "Inter", -apple-system, sans-serif;
}
.tpl-aurora .dp-brandline { color: #fff; }
.tpl-aurora .dp-sub { color: #9aa3bd; }
.tpl-aurora .dp-section-title { color: #8d96b0; }
.tpl-aurora .dp-field label { color: #d6daea; }
.tpl-aurora .dp-help, .tpl-aurora .dp-foot { color: #8d96b0; opacity: 1; }
.tpl-aurora .dp-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.13);
    color: #fff;
    backdrop-filter: blur(6px);
}
.tpl-aurora .dp-input:focus { border-color: var(--t-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--t-accent) 22%, transparent); }
.tpl-aurora .dp-input option { color: #111; }
.tpl-aurora .dp-submit { background: linear-gradient(135deg, var(--t-accent), color-mix(in srgb, var(--t-accent) 60%, #c084fc)); color: #fff; box-shadow: 0 4px 20px color-mix(in srgb, var(--t-accent) 40%, transparent); }
.tpl-aurora .dp-foot { color: #7b839c; }

/* ---------- Template: Paper (warm minimal editorial) ---------- */
.tpl-paper {
    background: #faf8f4; color: #23201a;
    font-family: Georgia, "Times New Roman", serif;
}
.tpl-paper .dp-head { border-bottom: 1px solid #e8e3d8; }
.tpl-paper .dp-brandline { font-family: "Inter", sans-serif; font-size: 12px; text-transform: uppercase; letter-spacing: 0.14em; font-weight: 700; color: #23201a; }
.tpl-paper .dp-brandline .brand-mark { border-radius: 50%; }
.tpl-paper .dp-headline { font-size: 22px; font-weight: 500; font-style: italic; }
.tpl-paper .dp-sub, .tpl-paper .dp-help, .tpl-paper .dp-foot { color: #6f6a5e; opacity: 1; font-family: "Inter", sans-serif; font-size: 12px; }
.tpl-paper .dp-section-title { color: #8a8577; font-family: "Inter", sans-serif; }
.tpl-paper .dp-field label { color: #3a362d; font-size: 12.5px; }
.tpl-paper .dp-input {
    background: transparent;
    border: none; border-bottom: 1.5px solid #d8d2c4;
    border-radius: 0; color: #23201a; padding: 0.4rem 0.1rem;
    font-size: 14px;
}
.tpl-paper textarea.dp-input { border: 1px solid #d8d2c4; border-radius: 6px; padding: 0.5rem; }
.tpl-paper .dp-input:focus { border-color: var(--t-accent); box-shadow: none; }
.tpl-paper select.dp-input { background-position: right 0.2rem center; }
.tpl-paper .dp-submit {
    background: #23201a; color: #faf8f4; border-radius: 100px;
    font-family: "Inter", sans-serif; letter-spacing: 0.02em;
}
.tpl-paper .dp-submit:hover { background: var(--t-accent); }
.tpl-paper .dp-field .dp-err { color: #b3261e; }

/* ---------- Template: Carbon (dark fintech terminal) ---------- */
.tpl-carbon {
    background: #0c0e11; color: #e8ecef;
    font-family: "Inter", -apple-system, sans-serif;
}
.tpl-carbon .dp-head { border-bottom: 1px solid #1d2129; }
.tpl-carbon .dp-brandline { font-family: var(--mono); font-size: 12px; }
.tpl-carbon .dp-brandline .brand-mark { border-radius: 3px; font-family: var(--mono); }
.tpl-carbon .dp-headline { letter-spacing: -0.03em; }
.tpl-carbon .dp-sub, .tpl-carbon .dp-help, .tpl-carbon .dp-foot { color: #7d8595; opacity: 1; font-family: var(--mono); font-size: 11px; }
.tpl-carbon .dp-section-title { color: #657184; font-family: var(--mono); }
.tpl-carbon .dp-field label { color: #b9c1ce; font-family: var(--mono); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; }
.tpl-carbon .dp-input {
    background: #12151b;
    border: 1px solid #232936; border-radius: 6px;
    color: #eef1f5;
    font-family: var(--mono); font-size: 12.5px;
}
.tpl-carbon .dp-input:focus { border-color: var(--t-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--t-accent) 25%, transparent); }
.tpl-carbon .dp-submit { background: var(--t-accent); color: #fff; border-radius: 6px; font-family: var(--mono); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em; }
.tpl-carbon .dp-foot { color: #525b6b; }

/* ============================================================
   Live API activity panel
   ============================================================ */
.api-panel {
    background: #0e1117;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    font-family: var(--mono);
    font-size: 12px;
    display: flex; flex-direction: column;
    max-height: 640px;
    min-width: 0;
}
.api-panel-head {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.55rem 0.8rem;
    background: #12151d;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.api-panel-head .ap-title { font-family: "Inter", sans-serif; font-weight: 600; font-size: 12px; color: #cdd4e0; display: flex; align-items: center; gap: 0.45rem; }
.api-panel-head .ap-title i { color: var(--accent-strong); font-size: 11px; }
.api-panel-head .spacer { flex: 1; }

.status-pill {
    font-family: var(--mono); font-size: 10.5px; font-weight: 700;
    padding: 2px 8px; border-radius: 20px;
    background: #1a1f2b; color: #8f98ac;
    border: 1px solid #262d3c;
    transition: all 0.2s ease;
}
.status-pill.pending { color: var(--warning); border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.08); }
.status-pill.ok { color: var(--success); border-color: rgba(52, 211, 153, 0.4); background: var(--success-soft); }
.status-pill.err { color: var(--danger); border-color: rgba(248, 113, 113, 0.4); background: var(--danger-soft); }

.api-panel-body { padding: 0.7rem 0.8rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 0.75rem; }

.ap-block-label {
    font-family: "Inter", sans-serif;
    font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
    text-transform: uppercase; color: #5d6778;
    margin-bottom: 0.35rem;
    display: flex; align-items: center; gap: 0.4rem;
}

.endpoint-row {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 11.5px;
    color: #aeb6c6;
    background: #12151d;
    border: 1px solid var(--border);
    padding: 0.4rem 0.6rem; border-radius: 7px;
}
.method-chip { font-weight: 700; font-size: 10px; color: var(--accent-strong); background: var(--accent-soft); padding: 1px 6px; border-radius: 4px; }

.code-block {
    background: #0a0d13;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.55rem 0.7rem;
    overflow-x: auto;
    line-height: 1.65;
    font-size: 11.5px;
    color: #c4cbd9;
    white-space: pre;
    min-height: 1.6em;
}
.code-block .line { display: block; border-radius: 3px; padding: 0 4px; margin: 0 -4px; transition: background 0.25s ease; }
.code-block .line.hl-key { background: rgba(109, 124, 255, 0.18); }
.code-block .line.hl-flash { background: rgba(52, 211, 153, 0.16); }
.code-block .j-key { color: #8b96ff; }
.code-block .j-str { color: #7dd3a8; }
.code-block .j-num { color: #f5bd6c; }
.code-block .j-bool { color: #f59bc2; }
.code-block .j-null { color: #6b7280; }
.code-block .j-punc { color: #6b7488; }

/* Steps */
.ap-steps { display: flex; flex-direction: column; gap: 0.3rem; }
.ap-step {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.42rem 0.6rem;
    border-radius: 7px;
    border: 1px solid transparent;
    color: #6b7488;
    transition: all 0.25s ease;
    opacity: 0.55;
}
.ap-step .ap-step-icon { width: 16px; text-align: center; font-size: 11px; flex-shrink: 0; }
.ap-step .ap-step-note { margin-left: auto; font-size: 10px; color: #525b6b; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ap-step.idle { opacity: 0.4; }
.ap-step.active { opacity: 1; color: #d6dbe8; border-color: rgba(109, 124, 255, 0.35); background: rgba(109, 124, 255, 0.07); }
.ap-step.active .ap-step-icon i { color: var(--accent-strong); }
.ap-step.done { opacity: 1; color: #9aa3b5; }
.ap-step.done .ap-step-icon i { color: var(--success); }
.ap-step.failed { opacity: 1; color: #d6dbe8; border-color: rgba(248, 113, 113, 0.35); background: var(--danger-soft); }
.ap-step.failed .ap-step-icon i { color: var(--danger); }

/* Path selector */
.path-selector { display: inline-flex; gap: 3px; }
.path-selector button {
    display: inline-flex; align-items: center;
    background: transparent; border: 1px solid var(--border);
    border-radius: 6px;
    color: #8f98ac; font-size: 11px; font-weight: 600;
    line-height: 1.2; min-height: 24px;
    padding: 0.3rem 0.75rem; cursor: pointer;
    font-family: "Inter", sans-serif;
    transition: all 0.15s ease;
}
.path-selector button:hover { border-color: var(--border-strong); color: #c4cbd9; }
.path-selector button.active { background: var(--accent-soft); color: var(--accent-strong); border-color: rgba(109, 124, 255, 0.4); }

/* Typewriter caret on response */
.typing-caret::after {
    content: "▌"; color: var(--accent-strong);
    animation: blink 0.8s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Shared viewer chrome ---------- */
.viewer-topbar {
    display: flex; align-items: center; gap: 0.8rem;
    padding: 0.55rem 1rem;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    font-size: 12.5px; color: var(--text-dim);
}
.viewer-topbar .brand { font-size: 13px; }

.made-with-badge {
    position: fixed; bottom: 12px; right: 14px;
    z-index: 50;
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: rgba(14, 16, 21, 0.85);
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
    font-size: 11px; font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    backdrop-filter: blur(6px);
    transition: var(--transition);
}
.made-with-badge:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.made-with-badge i { color: var(--accent-strong); font-size: 10px; }

/* Player floating controls (present mode) */
.player-controls {
    position: fixed; top: 12px; right: 14px; z-index: 60;
    display: flex; gap: 0.5rem; align-items: center;
}
.player-controls .btn { box-shadow: var(--shadow); }

/* ---------- Responsive player ---------- */
@media (max-width: 900px) {
    .player-stage { flex-direction: column; align-items: center; }
    .api-panel-dock { max-width: 620px; width: 100%; }
    .api-panel { max-height: 400px; }
}
