/* ===================================
   HTML Runner — SWE402
   Molten Gold Premium Dark Theme
   Refined warm accents on deep dark
   =================================== */

:root {
    /* === Core Colors — Deep Warm Dark === */
    --bg-primary: #09090d;
    --bg-secondary: #111118;
    --bg-tertiary: #191921;
    --bg-elevated: #222230;
    --bg-hover: #2a2a3a;

    --border-subtle: #1e1e2a;
    --border-default: #2d2d40;
    --border-strong: #3d3d55;

    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b8;
    --text-muted: #606078;

    /* === Accent Colors — Molten Gold === */
    --accent-primary: #f59e0b;
    --accent-primary-dim: #d97706;
    --accent-secondary: #fbbf24;
    --accent-glow: rgba(245, 158, 11, 0.15);
    --accent-glow-strong: rgba(245, 158, 11, 0.35);

    /* === Secondary Accent — Rose Quartz === */
    --accent-rose: #f472b6;
    --accent-rose-dim: #db2777;

    /* === State Colors === */
    --success: #34d399;
    --warning: #fbbf24;
    --error: #f87171;

    /* === Shadows === */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 8px 50px rgba(0, 0, 0, 0.7);
    --shadow-glow: 0 0 40px var(--accent-glow);
    --shadow-glow-strong: 0 0 60px var(--accent-glow-strong);

    /* === Transitions === */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: 'Geist', 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

/* === Selection === */
::selection {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

/* === Toolbar Header === */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border-subtle);
    gap: 16px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
}

.toolbar::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
    opacity: 0.4;
}

.toolbar-left, .toolbar-center, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    white-space: nowrap;
}

.logo span {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-rose));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo span::selection {
    background: var(--accent-primary);
    -webkit-text-fill-color: #3b82f6;
    color: #3b82f6;
}

/* === Device Mode Buttons === */
.device-modes {
    display: flex;
    gap: 4px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
}

.device-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.device-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.device-btn:hover {
    color: var(--text-secondary);
}

.device-btn:hover::before {
    opacity: 0.1;
}

.device-btn.active {
    color: var(--bg-primary);
    text-shadow: 0 0 20px var(--accent-glow-strong);
}

.device-btn.active::before {
    opacity: 1;
}

.device-btn.active svg {
    filter: drop-shadow(0 0 4px var(--accent-primary));
}

.device-btn span {
    position: relative;
    z-index: 1;
}

.device-btn svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    transition: filter var(--transition-fast);
}

/* === Action Buttons === */
.btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn:hover::before {
    opacity: 1;
}

.btn:active {
    transform: scale(0.97);
}

.btn-run {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-primary-dim));
    color: var(--bg-primary);
    box-shadow: 0 2px 16px var(--accent-glow-strong);
}

.btn-run:hover {
    box-shadow: 0 4px 30px var(--accent-glow-strong), 0 0 60px var(--accent-glow);
}

.btn-about {
    background: var(--bg-tertiary);
    color: var(--accent-secondary);
    border: 1px solid var(--border-default);
}

.btn-about:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-primary-dim);
    color: var(--accent-primary);
}

.btn-save {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}

.btn-save:hover {
    background: var(--bg-elevated);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

/* === Main Layout === */
.main-container {
    display: flex;
    height: calc(100vh - 60px - 44px);
    min-height: 500px;
    position: relative;
}

/* === Resize Handle === */
.resize-handle {
    width: 6px;
    background: var(--bg-tertiary);
    cursor: col-resize;
    position: relative;
    flex-shrink: 0;
    transition: background var(--transition-fast);
    z-index: 10;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--accent-primary);
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 30px;
    background: var(--border-strong);
    border-radius: 1px;
}

.resize-handle:hover::after {
    background: var(--bg-primary);
}

/* === Editor Panel === */
.editor-panel {
    width: 35%;
    min-width: 250px;
    max-width: 60%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-primary);
    resize: none;
    overflow: hidden;
}

.editor-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 16px;
    gap: 4px;
}

.tab-btn {
    padding: 14px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    letter-spacing: 0.03em;
    text-transform: uppercase;
    position: relative;
}

.tab-btn::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 2px;
    background: var(--accent-primary);
    transition: width var(--transition-normal);
}

.tab-btn:hover {
    color: var(--text-secondary);
}

.tab-btn.active {
    color: var(--accent-primary);
}

.tab-btn.active::after {
    width: 100%;
}

.editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.code-editor {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 20px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: none;
    resize: none;
    font-family: 'Geist Mono', 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.8;
    tab-size: 4;
    display: none;
}

.code-editor.active {
    display: block;
}

.code-editor:focus {
    outline: none;
    background: #08080c;
}

.code-editor::placeholder {
    color: var(--text-muted);
}

/* === Preview Panel === */
.preview-panel {
    width: 65%;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    height: auto;
    min-height: 48px;
    gap: 12px;
    flex-wrap: wrap;
}

.preview-header .device-modes {
    flex: 1;
    justify-content: center;
    min-width: 140px;
}

.preview-header .device-modes {
    flex: 1;
    justify-content: center;
}

.preview-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.preview-dimensions {
    font-size: 11px;
    color: var(--accent-secondary);
    font-family: 'Geist Mono', monospace;
    font-weight: 500;
    padding: 5px 10px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
}

.preview-wrapper {
    flex: 1;
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    padding: 32px;
    overflow: auto;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(245, 158, 11, 0.04) 0%, transparent 50%),
        var(--bg-primary);
}

#previewFrame {
    width: 1200px;
    height: 100%;
    background: #fff;
    border-radius: 8px;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 4px 12px rgba(0, 0, 0, 0.04);
    flex-shrink: 1;
    overflow: auto;
    position: relative;
    will-change: width;
}

#previewFrame[data-device="tablet"] {
    width: 768px;
    border-radius: 10px;
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.04),
        0 8px 24px rgba(0, 0, 0, 0.06);
}

#previewFrame[data-device="mobile"] {
    width: 375px;
    border-radius: 24px;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.04),
        0 12px 40px rgba(0, 0, 0, 0.08);
}

/* Smooth width/box-shadow/radius transitions */
#previewFrame {
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                border-radius 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Smooth settle animation */
@keyframes deviceSettle {
    0% {
        opacity: 0.85;
    }
    100% {
        opacity: 1;
    }
}

#previewFrame.just-switched {
    animation: deviceSettle 0.25s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

/* Subtle warm shimmer on switch */
#previewFrame.just-switched::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    background: linear-gradient(
        135deg,
        rgba(245, 158, 11, 0.04) 0%,
        transparent 40%,
        rgba(245, 158, 11, 0.02) 100%
    );
    animation: ambientGlow 0.6s ease-out forwards;
    pointer-events: none;
    z-index: 1;
}

@keyframes ambientGlow {
    0% {
        opacity: 0;
    }
    20% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* === Footer === */
.footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    font-size: 12px;
    color: var(--text-secondary);
    height: 44px;
}

.footer span {
    color: var(--text-secondary);
}

.footer span:first-child::after {
    content: '·';
    margin-left: 8px;
    opacity: 0.4;
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 5, 10, 0.9);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: 24px;
    padding: 40px;
    max-width: 640px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow:
        0 0 0 1px var(--border-subtle),
        var(--shadow-lg),
        0 0 120px rgba(245, 158, 11, 0.1);
}

.modal-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
    opacity: 0.6;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: 0 0 20px var(--accent-glow);
}

.modal-body {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.8;
}

.modal-body h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    letter-spacing: -0.02em;
}

.modal-body h2 {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-primary);
    margin-top: 28px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modal-body h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 20px;
    margin-bottom: 8px;
}

.modal-body p {
    margin-bottom: 14px;
}

.modal-body ul {
    padding-left: 20px;
    margin-bottom: 14px;
}

.modal-body li {
    margin-bottom: 8px;
}

.modal-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 13px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-default);
}

.modal-body th,
.modal-body td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-body th {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
}

.modal-body td {
    background: var(--bg-primary);
}

.modal-body tr:last-child td {
    border-bottom: none;
}

.modal-body pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 20px;
    overflow-x: auto;
    margin: 20px 0;
}

.modal-body code {
    font-family: 'Geist Mono', monospace;
    font-size: 12px;
    color: var(--accent-secondary);
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* === Responsive: Stack on Mobile === */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 60px - 44px);
    }

    .editor-panel {
        width: 100% !important;
        min-width: unset;
        max-width: unset;
        height: 400px;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }

    .preview-panel {
        width: 100% !important;
        height: 320px;
    }

    .resize-handle {
        display: none;
    }

    .toolbar {
        justify-content: center;
        height: auto;
        padding: 12px 16px;
    }

    .toolbar-left {
        display: none;
    }

    .device-btn span {
        display: none;
    }

    .device-btn {
        padding: 10px;
    }

    #previewFrame {
        max-width: 100% !important;
        width: 100%;
        height: 100%;
        min-height: 240px;
        border-radius: 12px;
    }

    .footer {
        font-size: 11px;
        flex-wrap: wrap;
        height: auto;
        padding: 12px 20px;
    }
}

@media (max-width: 480px) {
    .toolbar {
        padding: 10px 12px;
        gap: 8px;
    }

    .toolbar-center {
        order: 1;
    }

    .toolbar-right {
        order: 2;
    }

    .btn {
        padding: 8px 12px;
    }

    .btn span {
        display: none;
    }

    .btn svg {
        width: 14px;
        height: 14px;
    }

    .preview-wrapper {
        padding: 16px;
    }

    .preview-panel {
        height: 280px;
    }

    #previewFrame {
        min-height: 200px;
        border-radius: 10px;
    }
}
