:root {
    --ink: #14213d;
    --muted: #667085;
    --line: #d9e2ec;
    --panel: rgba(255, 255, 255, 0.94);
    --blue: #3157d5;
    --blue-dark: #2442a8;
    --canvas: #edf2f7;
    --code: #10233f;
    --success: #087a55;
    --danger: #c23b3b;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--canvas);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    background:
        radial-gradient(circle at 15% -10%, rgba(78, 115, 223, 0.17), transparent 30rem),
        radial-gradient(circle at 92% 3%, rgba(13, 148, 136, 0.11), transparent 26rem),
        var(--canvas);
}

button,
textarea {
    font: inherit;
}

.app-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 32px;
    max-width: 1680px;
    margin: 0 auto;
    padding: 28px 32px 22px;
}

.eyebrow,
.panel-kicker {
    color: var(--blue);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 7px;
    font-size: clamp(28px, 3vw, 42px);
    letter-spacing: -0.04em;
}

.app-header p {
    max-width: 720px;
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.55;
}

.header-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 10px;
}

.button,
.text-button {
    border: 0;
    cursor: pointer;
}

.button {
    min-height: 44px;
    padding: 0 16px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    font-size: 13px;
    font-weight: 750;
    transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.button.primary {
    color: #fff;
    background: var(--blue);
    box-shadow: 0 9px 24px rgba(49, 87, 213, 0.24);
}

.button.primary:hover {
    background: var(--blue-dark);
}

.button.secondary {
    color: #fff;
    background: #c9a227;
    border: 1px solid #c9a227;
}

.button.secondary:hover {
    background: #b08d1f;
    border-color: #b08d1f;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.button.is-running,
.toolbar-button.is-running {
    pointer-events: none;
}

.run-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.38);
    border-top-color: #fff;
    border-radius: 50%;
    display: none;
    flex: 0 0 auto;
    animation: run-spin 0.5s linear infinite;
}

.button.is-running .run-spinner,
.toolbar-button.is-running .run-spinner {
    display: inline-block;
}

.button.is-running .run-icon,
.toolbar-button.is-running .run-icon {
    display: none;
}

@keyframes run-spin {
    to { transform: rotate(360deg); }
}

kbd {
    padding: 3px 6px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 5px;
    color: rgba(255, 255, 255, 0.88);
    font-family: inherit;
    font-size: 10px;
    font-weight: 650;
}

.workspace {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 1680px;
    min-height: calc(100vh - 90px);
    margin: 0 auto;
    padding: 0 32px 32px;
}

.tab-bar {
    display: flex;
    gap: 4px;
    padding: 0 0 12px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 14px;
    flex-shrink: 0;
}

.tab-contents {
    flex: 1;
    min-height: 300px;
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.tab-btn {
    padding: 8px 18px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tab-btn:hover {
    background: rgba(49, 87, 213, 0.06);
    color: var(--ink);
}

.tab-btn.active {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}

.tab-content {
    display: none;
    position: absolute;
    inset: 0;
    flex-direction: column;
    min-height: 0;
}

.tab-content.active {
    display: flex;
}

.panel {
    min-width: 0;
    max-height: 100vh; /* limit to viewport height */
    overflow-y: auto; /* enable scrolling */
    border: 1px solid rgba(203, 213, 225, 0.9);
    border-radius: 17px;
    background: var(--panel);
    box-shadow: 0 16px 45px rgba(26, 43, 72, 0.08);
}

.source-panel,
.result-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto; /* allow panels to grow and shrink */
    min-height: 0; /* allow scrolling within panel */
}

#demo-frame {
    flex: 1;
    width: 100%;
    border: 0;
    min-height: 0;
    transition: width 0.3s ease, transform 0.2s ease;
    transform-origin: top left;
}

#demo-frame.mobile-view {
    width: 375px;
    margin: 0 auto;
}

#demo-frame.desktop-view {
    width: 1200px;
    min-width: 1200px;
}

.tab-content[data-tab-content="demo"] {
    overflow-x: auto;
    overflow-y: auto;
}

/* Demo tab: remove bottom edge limit so preview can show the entire website height.
   The tab-content becomes part of normal flow and can grow as tall as the rendered content. */
.tab-content[data-tab-content="demo"] {
    position: static;
    inset: auto;
    height: auto;
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
    min-height: 320px;
}

.tab-content[data-tab-content="demo"].active {
    display: block;
}

/* Remove viewport caps and internal scroll from the demo panel itself (the section has both .panel and .tab-content) */
.tab-content[data-tab-content="demo"].panel,
.tab-content[data-tab-content="demo"] .panel,
.tab-content.active[data-tab-content="demo"].panel,
.tab-content.active[data-tab-content="demo"] .panel {
    max-height: none !important;
    overflow: visible !important;
    height: auto !important;
}

.tab-content[data-tab-content="demo"] #demo-frame {
    flex: none;
    width: 100%;
    height: auto;
    min-height: 420px;
    display: block;
}

/* On small screens, avoid forcing a fixed min-height on demo that would clip natural content height */
@media (max-width: 760px) {
    .tab-content[data-tab-content="demo"].active {
        min-height: 0;
    }
}

/* Demo tab full-bleed (tràn viền) on small screens: breakout to full viewport width */
@media (max-width: 760px) {
    .tab-content.active[data-tab-content="demo"] {
        /* Break out to viewport edges while in normal flow */
        width: 100vw;
        margin-left: calc(50% - 50vw);
        margin-right: calc(50% - 50vw);
        /* Ensure it can be as wide as the viewport */
        max-width: 100vw;
    }

    /* Clean edge-to-edge panel look */
    .tab-content.active[data-tab-content="demo"].panel,
    .tab-content.active[data-tab-content="demo"] .panel {
        border-left: none;
        border-right: none;
        border-radius: 0;
        /* Give the preview area a subtle top/bottom edge only if desired; keep background */
    }

    /* The controls header should have breathing room from the true edges */
    .tab-content.active[data-tab-content="demo"] .panel-header {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* Allow the scaled wrapper to occupy the full bleed width (JS sets exact pixel size based on zoom) */
    .tab-content.active[data-tab-content="demo"] .demo-frame-wrap {
        margin-left: 0;
        margin-right: 0;
    }
}

/* Wrapper used by JS to make scaled iframe occupy correct visual footprint in layout */
.demo-frame-wrap {
    margin: 0 auto;
    line-height: 0;
    overflow: hidden;
}

/* On small screens the desktop-view wrap will be forced to full bleed width via the media query above + JS sizing. */

.demo-view-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-btn {
    background: none;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.view-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.view-btn.active {
    background: var(--blue);
    border-color: var(--blue);
}

.zoom-btn {
    background: none;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    min-width: 32px;
}

.zoom-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.zoom-level {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    min-width: 45px;
    text-align: center;
}

.panel-header {
    min-height: 68px;
    padding: 14px 17px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.panel-header h2 {
    margin: 3px 0 0;
    font-size: 15px;
    letter-spacing: -0.01em;
}

.text-button.icon-only {
    padding: 7px 9px;
    font-size: 16px;
}

@media (max-width: 760px) {
    .panel-header h2 {
        display: none;
    }
}

.text-button {
    padding: 7px 9px;
    color: var(--blue);
    border-radius: 7px;
    background: transparent;
    font-size: 12px;
    font-weight: 750;
}

.text-button:hover:not(:disabled) {
    background: #eef2ff;
}

.text-button:disabled {
    color: #9aa7b8;
    cursor: default;
}

.commands-toolbar {
    display: flex;
    gap: 6px;
    padding: 10px 17px;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    flex-wrap: wrap;
}

.toolbar-button {
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.toolbar-button:hover:not(:disabled) {
    background: #f1f5f9;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.toolbar-button:active:not(:disabled) {
    transform: translateY(0);
}

.toolbar-button.primary {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}

.toolbar-button.primary:hover:not(:disabled) {
    background: var(--blue-dark);
    border-color: var(--blue-dark);
}

.toolbar-button.secondary {
    background: #c9a227;
    color: #fff;
    border-color: #c9a227;
}

.toolbar-button.secondary:hover:not(:disabled) {
    background: #b08d1f;
    border-color: #b08d1f;
}

.toolbar-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.toolbar-button span {
    font-size: 14px;
}

.editor-shell {
    display: grid;
    grid-template-columns: 47px minmax(0, 1fr);
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #fbfdff;
}

.line-numbers {
    padding: 18px 10px 36px 0;
    overflow: hidden;
    color: #a3afbf;
    border-right: 1px solid #e6edf5;
    background: #f6f9fc;
    font: 13px/1.65 "Cascadia Code", Consolas, monospace;
    text-align: right;
    user-select: none;
    white-space: pre;
}

#source-editor,
#json-output {
    width: 100%;
    min-height: 0;
    padding: 18px;
    resize: none;
    border: 0;
    outline: 0;
    color: var(--code);
    background: #fbfdff;
    font: 13px/1.65 "Cascadia Code", Consolas, "Courier New", monospace;
    tab-size: 2;
    white-space: pre;
}

#source-editor {
    padding-left: 16px;
}

#source-editor:focus {
    box-shadow: inset 0 0 0 2px rgba(49, 87, 213, 0.13);
}

#json-output {
    flex: 1;
    color: #d8e6ff;
    background: #10233f;
}

.compile-status {
    min-height: 45px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    color: var(--muted);
    background: #f8fafc;
    font-size: 12px;
    line-height: 1.45;
}

.compile-status.success {
    color: var(--success);
    background: #ecfdf5;
}

.compile-status.error {
    color: var(--danger);
    background: #fff1f2;
}

.reference-panel {
    align-self: start;
}

.reference-content {
    padding: 5px 17px 19px;
}

.reference-content section {
    padding: 15px 0;
    border-bottom: 1px solid #e7edf4;
}

.reference-content section:last-child {
    border-bottom: 0;
}

.reference-content h3 {
    margin-bottom: 8px;
    font-size: 13px;
}

.reference-content p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.55;
}

.reference-content code {
    color: #2442a8;
    font: 11px/1.6 "Cascadia Code", Consolas, monospace;
}

.reference-content > section > code {
    display: block;
    overflow-x: auto;
    padding: 8px 9px;
    border: 1px solid #dce5f1;
    border-radius: 8px;
    background: #f5f8fc;
    white-space: nowrap;
}

.reference-content .tip {
    margin-top: 12px;
    padding: 13px;
    border: 1px solid #bfdbfe;
    border-radius: 11px;
    background: #eff6ff;
}

.tip strong {
    font-size: 12px;
}

/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 16px;
    max-width: 800px;
    max-height: 90vh;
    width: 90%;
    overflow: hidden;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    color: var(--ink);
}

.close-button {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.15s ease;
}

.close-button:hover {
    background: #e2e8f0;
    color: var(--ink);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(90vh - 80px);
}

.command-section {
    margin-bottom: 24px;
}

.command-section h3 {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--ink);
}

.command-desc {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 14px;
}

.command-syntax {
    margin: 0 0 16px;
    padding: 12px 16px;
    background: #f5f8fc;
    border: 1px solid #dce5f1;
    border-radius: 8px;
}

.command-syntax code {
    color: #2442a8;
    font: 13px/1.6 "Cascadia Code", Consolas, monospace;
}

.command-params {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.command-params th,
.command-params td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #e7edf4;
}

.command-params th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 12px;
    color: var(--ink);
}

.command-params td {
    font-size: 13px;
    color: var(--muted);
}

.command-params code {
    color: #2442a8;
    font: 12px/1.5 "Cascadia Code", Consolas, monospace;
    background: #f5f8fc;
    padding: 2px 6px;
    border-radius: 4px;
}

.command-example {
    margin-top: 20px;
}

.command-example h4 {
    margin: 0 0 8px;
    font-size: 14px;
    color: var(--ink);
}

.command-example pre {
    margin: 0;
    padding: 14px 16px;
    background: #10233f;
    border-radius: 8px;
    overflow-x: auto;
}

.command-example code {
    color: #d8e6ff;
    font: 12px/1.6 "Cascadia Code", Consolas, monospace;
}

.tab-content[data-tab-content="reference"] {
    min-height: max(720px, calc(100vh - 190px));
    max-height: none;
    overflow: hidden;
    flex-direction: column;
}

.tab-content[data-tab-content="reference"] .reference-content {
    flex: 1 1 auto;
    min-height: 640px;
    overflow: auto;
}

.tab-content[data-tab-content="reference"]:fullscreen {
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    max-height: none;
    border: 0;
    border-radius: 0;
    background: #fff;
}

.tab-content[data-tab-content="reference"]:fullscreen .reference-content {
    min-height: 0;
}

.command-param-row { cursor:pointer; }
.command-param-row:hover td,
.command-param-row.is-open td { background:#eff6ff; }
.command-param-row td:first-child::before { content:'›'; display:inline-block; margin-right:7px; color:#64748b; transition:transform .15s ease; }
.command-param-row.is-open td:first-child::before { transform:rotate(90deg); }
.command-param-detail td { padding:0 !important; background:#f8fafc !important; }
.command-param-detail-card { display:grid;gap:6px;padding:12px 16px;border-bottom:1px solid #dbeafe;color:#334155;font-size:13px;line-height:1.55; }

.markdown-reference {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    gap: 28px;
    max-width: 1220px;
    margin: 0 auto;
    padding: 24px;
    line-height: 1.7;
}

.reference-toc {
    position: sticky;
    top: 16px;
    align-self: start;
    max-height: calc(100vh - 32px);
    overflow: auto;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
}

.reference-toc a {
    display: block;
    padding: 5px 8px;
    border-radius: 6px;
    color: #475569;
    text-decoration: none;
    font-size: 13px;
}

.reference-toc a:hover {
    color: #2442a8;
    background: #eaf0ff;
}

.reference-toc-level-3 { padding-left: 18px !important; }
.reference-toc-level-4 { padding-left: 30px !important; font-size: 12px !important; }
.reference-document { min-width: 0; }

.markdown-reference h2,
.markdown-reference h3,
.markdown-reference h4 {
    margin: 28px 0 12px;
    color: var(--ink);
}

.markdown-reference h2:first-child {
    margin-top: 0;
}

.markdown-reference p,
.markdown-reference li {
    color: var(--muted);
}

.markdown-reference pre {
    overflow-x: auto;
    padding: 16px;
    border-radius: 8px;
    background: #10233f;
}

.markdown-reference pre code {
    color: #d8e6ff;
    font: 12px/1.65 "Cascadia Code", Consolas, monospace;
}

.markdown-reference :not(pre) > code {
    padding: 2px 6px;
    border-radius: 4px;
    color: #2442a8;
    background: #f5f8fc;
    font: 12px/1.5 "Cascadia Code", Consolas, monospace;
}

.markdown-reference hr {
    border: 0;
    border-top: 1px solid #e7edf4;
    margin: 28px 0;
}

.reference-loading {
    text-align: center;
}

@media (max-width: 1180px) {
    .reference-content:not(.markdown-reference) {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        gap: 18px;
    }

    .reference-content section {
        border-bottom: 0;
    }
}

@media (max-width: 760px) {
    .markdown-reference {
        grid-template-columns: 1fr;
    }

    .reference-toc {
        position: static;
        max-height: 260px;
    }
    .app-header {
        align-items: stretch;
        flex-direction: column;
        padding: 22px 16px 16px;
    }

    .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    kbd {
        display: none;
    }

    .workspace {
        padding: 0 16px 22px;
    }

    .tab-content.active {
        min-height: 560px;
    }

    .reference-content {
        display: block;
    }

    .reference-content section {
        border-bottom: 1px solid #e7edf4;
    }
}
