:root {
    --bg: #f5f7f8;
    --text: #1f2937;
    --panel: #ffffff;
    --panel-2: #f8fafc;
    --border: #e2e8f0;
    --accent: #00d084;
    --accent-hover: #00b873;
    --muted: #6b7280;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body.dark {
    --bg: #0f1720;
    --text: #e5eef5;
    --panel: #1a2332;
    --panel-2: #141d2b;
    --border: #2d3748;
    --accent: #00d084;
    --accent-hover: #00e08f;
    --muted: #a0aec0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    transition: background 0.3s ease, color 0.3s ease;
}

.page-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 70px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    gap: 20px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-logo {
    width: 100px;
    height: 100px;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
    transition: transform 0.3s ease;
    position: relative;
    z-index: 150;
    margin-top: -8px;
    margin-bottom: -8px;
}

.brand-logo:hover {
    transform: scale(1.05);
}

.brand-badge {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, #00b873 100%);
    box-shadow: 0 0 0 4px rgba(0, 208, 132, 0.15), 0 0 12px rgba(0, 208, 132, 0.3);
    flex-shrink: 0;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 4px rgba(0, 208, 132, 0.15), 0 0 12px rgba(0, 208, 132, 0.3);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(0, 208, 132, 0.1), 0 0 16px rgba(0, 208, 132, 0.4);
    }
}

.topbar h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.02em;
}

.actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn,
.host-btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 11px 20px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    position: relative;
    overflow: hidden;
}

.btn::before,
.host-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.btn:hover::before,
.host-btn:hover::before {
    transform: translateX(100%);
}

.run-btn {
    background: linear-gradient(135deg, var(--accent) 0%, #00b873 100%);
    color: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(0, 208, 132, 0.25);
}

.run-btn:hover {
    background: linear-gradient(135deg, #00b873 0%, var(--accent) 100%);
    border-color: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 208, 132, 0.35);
}

.run-btn:active {
    transform: translateY(0);
}

.host-btn {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
    border-width: 2px;
}

.host-btn:hover {
    background: rgba(0, 208, 132, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 208, 132, 0.15);
}

.mode-btn {
    background: var(--panel-2);
    color: var(--text);
    border-color: var(--border);
    min-width: 44px;
}

.mode-btn:hover {
    background: var(--border);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.wrapper {
    display: flex;
    gap: 20px;
    flex: 1;
    min-height: 0;
    padding: 20px;
}

.editor-pane,
.preview-pane {
    width: 50%;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    min-height: calc(100vh - 70px - 20px - 20px - 56px);
}

.editor-pane:hover,
.preview-pane:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.editor-pane,
.preview-pane {
    display: flex;
    flex-direction: column;
}

.pane-title {
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--muted);
    position: relative;
}

.pane-title::before {
    content: '';
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 40px;
    height: 2px;
    background: var(--accent);
    opacity: 0.6;
}

.editor-holder {
    flex: 1;
    min-height: 0;
    background: var(--panel);
}

.CodeMirror {
    height: 100% !important;
    font-size: 15px;
    line-height: 1.6;
    background: var(--panel);
    color: var(--text);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.CodeMirror-gutters {
    background: var(--panel-2);
    border-right: 1px solid var(--border);
    padding-right: 4px;
}

.CodeMirror-linenumber {
    color: var(--muted);
    padding: 0 8px 0 4px;
}

.CodeMirror-cursor {
    border-left: 2px solid var(--accent);
}

.CodeMirror-selected {
    background: rgba(0, 208, 132, 0.1);
}

iframe {
    width: 100%;
    height: 100%;
    border: 0;
    background: #ffffff;
    flex: 1;
}

/* Footer */
.site-footer {
    margin-top: auto;
    padding: 8px 20px 12px;
    background: transparent;
}

.site-footer-inner {
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
    font-size: 12px;
    line-height: 1.4;
    letter-spacing: 0.2px;
    color: var(--muted);
    border-top: 1px solid var(--border);
    padding-top: 10px;
    opacity: 0.9;
}

/* Access Modal Overlay */
.access-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
    }
}

.access-modal {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 480px;
    width: 100%;
    padding: 48px 40px;
    text-align: center;
    position: relative;
    transform: scale(0.9);
    animation: scaleIn 0.4s ease 0.1s forwards;
}

@keyframes scaleIn {
    to {
        transform: scale(1);
    }
}

.access-modal-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    background: linear-gradient(135deg, rgba(0, 208, 132, 0.1) 0%, rgba(0, 184, 115, 0.1) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    box-shadow: 0 0 0 12px rgba(0, 208, 132, 0.05);
}

.access-modal h2 {
    margin: 0 0 16px;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.access-modal p {
    margin: 0 0 32px;
    font-size: 16px;
    line-height: 1.6;
    color: var(--muted);
}

.access-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.access-modal-btn {
    appearance: none;
    border: 2px solid transparent;
    border-radius: 14px;
    padding: 16px 32px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.access-modal-btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, #00b873 100%);
    color: #ffffff;
    box-shadow: 0 4px 16px rgba(0, 208, 132, 0.3);
}

.access-modal-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 208, 132, 0.4);
}

.access-modal-btn-primary:active {
    transform: translateY(0);
}

.access-modal-btn-secondary {
    background: transparent;
    color: var(--muted);
    border-color: var(--border);
}

.access-modal-btn-secondary:hover {
    background: var(--panel-2);
    color: var(--text);
}

.access-modal-features {
    margin: 32px 0;
    padding: 24px;
    background: var(--panel-2);
    border-radius: 16px;
    text-align: left;
}

.access-modal-features h3 {
    margin: 0 0 16px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--accent);
}

.access-modal-features ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.access-modal-features li {
    padding: 8px 0 8px 28px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    position: relative;
}

.access-modal-features li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: bold;
    font-size: 16px;
}

@media (max-width: 980px) {
    .topbar {
        height: auto;
        min-height: 70px;
        padding: 16px 20px;
        align-items: flex-start;
        flex-direction: column;
    }

    .actions {
        width: 100%;
        justify-content: flex-start;
    }

    .wrapper {
        height: auto;
        min-height: auto;
        flex-direction: column;
        gap: 16px;
        padding: 16px;
    }

    .editor-pane,
    .preview-pane {
        width: 100%;
        height: 50vh;
        min-height: 400px;
    }
}

@media (max-width: 640px) {
    .topbar {
        padding: 12px 16px;
    }

    .topbar h1 {
        font-size: 18px;
    }

    .btn,
    .host-btn {
        width: 100%;
        padding: 12px 16px;
        min-height: 48px;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .mode-btn {
        width: 100%;
    }

    .wrapper {
        padding: 12px;
        gap: 12px;
    }

    .editor-pane,
    .preview-pane {
        border-radius: 12px;
        min-height: 360px;
    }

    .access-modal {
        padding: 32px 24px;
        border-radius: 20px;
    }

    .access-modal h2 {
        font-size: 24px;
    }

    .access-modal p {
        font-size: 15px;
    }

    .access-modal-btn {
        padding: 14px 24px;
        font-size: 15px;
    }

    .site-footer {
        padding: 6px 16px 10px;
    }

    .site-footer-inner {
        font-size: 11px;
        padding-top: 8px;
    }
}