html, body { height: 100%; overflow: hidden; }
body { display: flex; flex-direction: column; }

#codeTopbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    height: 46px;
    border-bottom: 1px solid var(--line);
    background: rgba(8, 9, 16, 0.78);
    backdrop-filter: blur(14px);
    flex-shrink: 0;
    z-index: 10;
    opacity: 0;
    animation: slideDown 0.4s var(--ease) 0.05s forwards;
    overflow-x: auto;
    scrollbar-width: none;
}

#codeTopbar::-webkit-scrollbar { display: none; }

@media (max-width: 640px) {
    .ct-brand .sub { display: none; }
    .ct-file { display: none; }
}

.ct-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--fg);
    letter-spacing: -0.01em;
}

.ct-brand .sub {
    font-size: 11px;
    color: var(--fg-3);
    font-weight: 400;
}

.ct-file {
    color: var(--fg-2);
    font-size: 12px;
    background: transparent;
    border: none;
    border-bottom: 1px dashed transparent;
    padding: 2px 0;
    min-width: 0;
    width: 110px;
    max-width: 200px;
    outline: none;
    text-overflow: ellipsis;
    transition: border-color 0.2s var(--ease), color 0.2s var(--ease), width 0.2s var(--ease);
}

.ct-file:focus { width: 180px; }

.ct-file:hover { border-bottom-color: var(--line-2); }
.ct-file:focus { border-bottom-color: var(--line-3); color: var(--fg); }

.ct-spacer { flex: 1; }

.ct-lang {
    background: rgba(200, 195, 230, 0.04);
    border: 1px solid var(--line-2);
    border-radius: 6px;
    color: var(--fg-2);
    padding: 5px 10px;
    font-size: 11.5px;
    transition: border-color 0.15s var(--ease), background 0.15s var(--ease), color 0.15s var(--ease);
    cursor: pointer;
    flex-shrink: 0;
}

.ct-lang:hover {
    border-color: var(--line-3);
    background: rgba(200, 195, 230, 0.08);
    color: var(--fg);
}

.ct-lang option { background: #0c0d18; color: var(--fg); }

.ct-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--fg-3);
    transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.12s var(--ease);
    cursor: pointer;
    flex-shrink: 0;
}

.ct-icon:hover {
    background: rgba(200, 195, 230, 0.06);
    color: var(--fg);
    border-color: var(--line-2);
}

.ct-icon:active { transform: scale(0.92); }

.ct-run {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: #0a0b14;
    border: none;
    border-radius: 6px;
    padding: 5px 12px 5px 10px;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s var(--ease), transform 0.12s var(--ease), box-shadow 0.15s var(--ease);
    flex-shrink: 0;
}

.ct-run:hover {
    background: #c9c1ee;
    box-shadow: 0 4px 14px rgba(184, 176, 218, 0.2);
    transform: translateY(-1px);
}

.ct-run:active { transform: translateY(0) scale(0.97); }

.ct-run svg { transform: translateY(0.5px); }

.ct-ai {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(184, 176, 218, 0.08);
    color: var(--accent);
    border: 1px solid rgba(184, 176, 218, 0.3);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.12s var(--ease);
    flex-shrink: 0;
}

.ct-ai:hover {
    background: rgba(184, 176, 218, 0.15);
    border-color: var(--accent);
    color: #d6cff2;
}

.ct-ai:active { transform: scale(0.97); }

#editor {
    flex: 1;
    width: 100%;
    min-height: 0;
    opacity: 0;
    animation: appFadeIn 0.4s var(--ease) 0.2s forwards;
}

#codeBooting {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fg-3);
    font-size: 11px;
    letter-spacing: 0.3em;
    text-transform: lowercase;
    z-index: 1;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#codeBooting.hide { opacity: 0; }

#codeBooting .dots {
    display: inline-block;
    width: 24px;
    text-align: left;
}

#codeBooting .dots::after {
    content: '';
    animation: bootDots 1.2s steps(4, end) infinite;
}

@keyframes bootDots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
    100% { content: ''; }
}

#codeStatusBar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 5px 14px;
    background: rgba(8, 9, 16, 0.78);
    border-top: 1px solid var(--line);
    font-size: 10.5px;
    color: var(--fg-3);
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    backdrop-filter: blur(12px);
}

#codeStatusBar .sep { color: var(--dim); }
#codeStatusBar .key { color: var(--fg-2); }

#stStatus.flash { color: var(--accent); animation: stFlash 0.7s var(--ease); }

@keyframes stFlash {
    0%   { color: #fff; text-shadow: 0 0 8px rgba(200, 195, 230, 0.5); }
    100% { color: var(--fg-3); text-shadow: none; }
}

#outputPanel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 27px;
    height: 0;
    overflow: hidden;
    background: rgba(8, 9, 16, 0.94);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
    transition: height 0.3s var(--ease);
    z-index: 40;
    display: flex;
    flex-direction: column;
}

#outputPanel.open {
    height: 240px;
    animation: outSlideIn 0.3s var(--ease);
}

#outputPanel.open-preview {
    height: 60vh;
}

@keyframes outSlideIn {
    from { transform: translateY(12px); opacity: 0.5; }
    to   { transform: translateY(0); opacity: 1; }
}

#outputHeader {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.oh-label {
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--fg-3);
    font-weight: 500;
}

.oh-spacer { flex: 1; }

#outputLog {
    flex: 1;
    overflow-y: auto;
    padding: 8px 14px;
    font-family: 'JetBrains Mono', Menlo, monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--fg-2);
    min-height: 0;
    position: relative;
}

#outputPanel.open-preview #outputLog {
    padding: 0;
    overflow: hidden;
}

.ol-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    display: block;
    animation: olFade 0.22s var(--ease);
}

@keyframes olFade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ol-json {
    color: var(--fg);
    white-space: pre-wrap;
    font-family: 'JetBrains Mono', Menlo, monospace;
    font-size: 12px;
    padding: 2px 0;
    margin: 0;
}

#prefsPanel {
    display: none;
    position: fixed;
    top: 54px;
    right: 16px;
    width: 260px;
    background: rgba(12, 13, 24, 0.96);
    backdrop-filter: blur(18px);
    border: 1px solid var(--line-2);
    border-radius: 10px;
    padding: 12px 14px 14px;
    z-index: 80;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.6);
    animation: ppIn 0.18s var(--ease);
}

#prefsPanel.open { display: block; }

@keyframes ppIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.pp-title {
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--fg-3);
    margin-bottom: 10px;
    font-weight: 500;
}

.pp-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    font-size: 12px;
    color: var(--fg-2);
}

.pp-row label { cursor: pointer; }

.pp-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pp-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    color: var(--fg-3);
    min-width: 38px;
    text-align: right;
}

#prefFont {
    width: 110px;
    height: 2px;
    background: rgba(200, 195, 230, 0.12);
    border-radius: 2px;
    -webkit-appearance: none;
    outline: none;
}

#prefFont::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(184, 176, 218, 0.4);
}

#prefFont::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

#templateOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 6, 13, 0.7);
    backdrop-filter: blur(6px);
    z-index: 100;
    align-items: flex-start;
    justify-content: center;
    padding: 80px 20px 20px;
}

#templateOverlay.open {
    display: flex;
    animation: olFade 0.18s var(--ease);
}

#templateModal {
    width: min(760px, 100%);
    background: rgba(12, 13, 24, 0.97);
    border: 1px solid var(--line-2);
    border-radius: 12px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: tmIn 0.2s var(--ease);
}

@keyframes tmIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tm-head {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.tm-title {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--fg);
    letter-spacing: -0.01em;
}

#templateGrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    padding: 16px;
    overflow-y: auto;
}

.tm-card {
    background: rgba(200, 195, 230, 0.02);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px;
    cursor: pointer;
    transition: border-color 0.15s var(--ease), background 0.15s var(--ease), transform 0.15s var(--ease);
    text-align: left;
    color: inherit;
    font: inherit;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tm-card:hover {
    border-color: var(--line-3);
    background: rgba(200, 195, 230, 0.04);
    transform: translateY(-1px);
}

.tm-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--fg);
}

.tm-lang {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--accent);
    letter-spacing: 0.04em;
    text-transform: lowercase;
}

.tm-desc {
    font-size: 11.5px;
    color: var(--fg-3);
    line-height: 1.5;
    margin-top: 2px;
}

.ol {
    padding: 1px 0;
    white-space: pre-wrap;
    word-break: break-word;
    animation: olIn 0.15s var(--ease);
}

@keyframes olIn {
    from { opacity: 0; transform: translateX(-3px); }
    to   { opacity: 1; transform: translateX(0); }
}

.ol-log   { color: var(--fg); }
.ol-info  { color: var(--fg-3); }
.ol-warn  { color: #e0c17c; }
.ol-error { color: #e07cb8; }
.ol-meta  { color: var(--fg-3); font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; padding-top: 6px; padding-bottom: 2px; }

.monaco-editor .cursor {
    transition: opacity 0.12s var(--ease) !important;
}

.monaco-editor .view-overlays .current-line {
    border: none !important;
    background: rgba(200, 195, 230, 0.025) !important;
}

.monaco-editor .margin, .monaco-editor .monaco-editor-background {
    background-color: transparent !important;
}
