/* ===== CSS Variables ===== */
:root {
    --bg-dark: #0a0a0f;
    --bg-card: #12121a;
    --bg-surface: #1a1a24;
    --accent-primary: #ff6b35;
    --accent-secondary: #00ff9d;
    --text-main: #e8e8e8;
    --text-dim: #6b6b7b;
    --border-subtle: #1f1f2e;
    --border-accent: rgba(255, 107, 53, 0.3);
}

/* ===== Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100%;
    width: 100%;
    background-color: var(--bg-dark);
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    color: var(--text-main);
}

/* Background effects */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(255, 107, 53, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 107, 53, 0.02) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 0;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(255, 107, 53, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(0, 255, 157, 0.04) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ===== Main Layout ===== */
.main-layout {
    display: grid;
    grid-template-columns: 230px 1fr 320px;
    grid-template-rows: 1fr auto;
    grid-template-areas: 
        "controls cubes leaderboard"
        "editor editor editor";
    height: 100vh;
    width: 100vw;
    gap: 12px;
    padding: 16px;
    padding-top: 70px;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* ===== Logo ===== */
#logo {
    position: fixed;
    top: 16px;
    left: 16px;
    font-family: 'Unbounded', 'Arial Black', sans-serif;
    font-size: 20px;
    font-weight: bold;
    color: var(--text-main);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    padding: 10px 16px;
    border-radius: 10px;
    z-index: 110;
    cursor: pointer;
    transition: all 0.3s ease;
}

#logo:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 20px rgba(255, 107, 53, 0.2);
}

/* ===== Model Title ===== */
#model-title-top {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Unbounded', 'Arial Black', sans-serif;
    font-size: 20px;
    font-weight: bold;
    color: var(--accent-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-accent);
    padding: 10px 24px;
    border-radius: 10px;
    z-index: 110;
    box-shadow: 0 4px 20px rgba(255, 107, 53, 0.1);
}

/* ===== Cube Containers ===== */
.cube-containers {
    grid-area: cubes;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.cubes-row {
    display: flex;
    gap: 12px;
    flex: 1;
    height: 100%;
    min-height: 0;
}

.canvas-container {
    flex: 1;
    position: relative;
    height: 100%;
    background: #1a1a24;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
}

#reference-container, #user-container {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#reference-canvas, #user-canvas {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    border: none;
    overflow: hidden;
}

#reference-canvas canvas, 
#user-canvas canvas {
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

.canvas-label {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    font-weight: bold;
    font-size: 12px;
    color: var(--text-dim);
    z-index: 5;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ===== Controls Panel ===== */
#controls {
    grid-area: controls;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    padding: 16px;
    border-radius: 12px;
    z-index: 100;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#controls p {
    color: var(--accent-primary);
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 13px;
}

#controls ul {
    color: var(--text-dim);
    padding-left: 16px;
    font-size: 12px;
    line-height: 1.8;
}

#controls li {
    margin-bottom: 4px;
}

.color-ref {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 12px 0;
}

.color-box {
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#reset {
    margin-top: auto;
    margin-bottom: 0;
}

/* ===== Buttons ===== */
button {
    margin: 4px 0;
    padding: 10px 16px;
    border: 1px solid var(--border-accent);
    background: rgba(255, 107, 53, 0.1);
    color: var(--accent-primary);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: bold;
    transition: all 0.3s ease;
}

button:hover {
    background: var(--accent-primary);
    color: var(--bg-dark);
    box-shadow: 0 4px 15px rgba(255, 107, 53, 0.3);
}

/* ===== Code Editor ===== */
#code-editor {
    grid-area: editor;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px 12px 0 0;
    padding: 16px;
    z-index: 100;
    position: relative;
    overflow: visible;
    margin-bottom: 0;
    border-bottom: none;
}

.code-editor-container {
    display: flex;
    flex-direction: column;
    position: relative;
}

.editor-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.editor-top h2 {
    font-family: 'Unbounded', sans-serif;
    font-size: 16px;
    color: var(--text-main);
}

.stats-container {
    display: flex;
    gap: 16px;
    align-items: center;
}

#char-count {
    color: var(--text-dim);
    font-size: 13px;
}

#score {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    transition: all 0.3s ease;
}

#match-score {
    font-weight: bold;
}

h2 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-main);
}

/* CodeMirror dark theme */
.CodeMirror {
    height: 180px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    font-size: 13px;
    overflow: hidden;
    background: var(--bg-surface) !important;
    color: var(--text-main) !important;
}

.CodeMirror-gutters {
    background: var(--bg-dark) !important;
    border-right: 1px solid var(--border-subtle) !important;
}

.CodeMirror-linenumber {
    color: var(--text-dim) !important;
}

.CodeMirror-cursor {
    border-left-color: var(--accent-primary) !important;
}

.CodeMirror-selected {
    background: rgba(255, 107, 53, 0.2) !important;
}

.cm-keyword { color: #c586c0 !important; }
.cm-def { color: #4ec9b0 !important; }
.cm-variable { color: #9cdcfe !important; }
.cm-variable-2 { color: #9cdcfe !important; }
.cm-property { color: #9cdcfe !important; }
.cm-string { color: #ce9178 !important; }
.cm-string-2 { color: #ce9178 !important; }
.cm-number { color: #b5cea8 !important; }
.cm-comment { color: #6a9955 !important; }
.cm-operator { color: #d4d4d4 !important; }
.cm-builtin { color: #dcdcaa !important; }
.cm-atom { color: #569cd6 !important; }
.cm-punctuation { color: #d4d4d4 !important; }

#run-code {
    background: rgba(0, 255, 157, 0.1);
    border-color: rgba(0, 255, 157, 0.3);
    color: var(--accent-secondary);
    margin-top: 12px;
    width: 100%;
}

#run-code:hover {
    background: var(--accent-secondary);
    color: var(--bg-dark);
    box-shadow: 0 4px 15px rgba(0, 255, 157, 0.3);
}

/* ===== Submit Section ===== */
#submit-container {
    display: none;
    margin-top: 12px;
    position: relative;
    z-index: 101;
    align-items: center;
    gap: 8px;
    height: auto;
    min-height: 40px;
    transition: all 0.3s ease;
}

#submit-nickname {
    flex: 1;
    padding: 10px 12px;
    box-sizing: border-box;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    margin-right: 8px;
    height: 42px;
    background: var(--bg-surface);
    color: var(--text-main);
    font-family: inherit;
    font-size: 13px;
}

#submit-nickname:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(255, 107, 53, 0.2);
}

#submit-nickname::placeholder {
    color: var(--text-dim);
}

#submit-button {
    background: rgba(255, 107, 53, 0.2);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    flex-shrink: 0;
}

#submit-button:hover:not(:disabled) {
    background: var(--accent-primary);
    color: var(--bg-dark);
}

#submit-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Leaderboard ===== */
#leaderboard {
    grid-area: leaderboard;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    padding: 16px;
    border-radius: 12px;
    z-index: 100;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#leaderboard-items {
    flex: 1;
}

#leaderboard h2 {
    font-family: 'Unbounded', sans-serif;
    color: var(--accent-primary);
    font-size: 13px;
    margin-bottom: 10px;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 11px;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-nick {
    font-weight: bold;
    color: var(--text-main);
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-length {
    color: var(--accent-secondary);
    font-size: 10px;
}

.view-code-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 2px 6px;
    font-size: 10px;
    margin: 0 0 0 6px;
    color: var(--text-dim);
}

.view-code-btn:hover {
    background: var(--accent-primary);
    color: var(--bg-dark);
    border-color: var(--accent-primary);
}

#refresh-leaderboard {
    width: 100%;
    margin-top: auto;
    background: var(--bg-surface);
    border-color: var(--border-subtle);
    color: var(--text-dim);
}

#refresh-leaderboard:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(255, 107, 53, 0.1);
}

/* ===== Result Messages ===== */
#result-message {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    display: none;
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    max-width: 80%;
    font-size: 13px;
}

.success-message {
    background: rgba(0, 255, 157, 0.1);
    border: 1px solid rgba(0, 255, 157, 0.3);
    color: var(--accent-secondary);
}

.error-message {
    background: rgba(255, 82, 82, 0.1);
    border: 1px solid rgba(255, 82, 82, 0.3);
    color: #ff5252;
}

#loading {
    display: none;
    text-align: center;
    margin-top: 12px;
    font-style: italic;
    color: var(--text-dim);
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    padding: 8px 16px;
    border-radius: 8px;
    z-index: 201;
    font-size: 12px;
}

/* ===== Modal ===== */
#code-view-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.code-view-content {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    padding: 24px;
    border-radius: 16px;
    width: 80%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

.code-view-content h3 {
    font-family: 'Unbounded', sans-serif;
    color: var(--accent-primary);
    margin-bottom: 16px;
}

.code-view-content pre {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    color: var(--text-main);
    font-size: 13px;
}

#password-container {
    margin-bottom: 16px;
}

#password-input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    box-sizing: border-box;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--bg-surface);
    color: var(--text-main);
    font-family: inherit;
}

#password-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

#password-error {
    color: #ff5252;
    font-size: 13px;
    margin-bottom: 12px;
    display: none;
}

#close-code-view {
    width: 100%;
    margin-top: 16px;
}

/* ===== Footer ===== */
#footer {
    position: fixed;
    top: 16px;
    right: 16px;
    font-size: 11px;
    color: var(--text-dim);
    z-index: 121;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    padding: 8px 14px;
    border-radius: 8px;
}

#footer a {
    color: var(--accent-primary);
    text-decoration: none;
}

#footer a:hover {
    text-decoration: underline;
}

/* ===== Main Page Styles ===== */
.main-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: auto;
}

.main-container {
    max-width: 1000px;
    padding: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    text-align: center;
}

h1 {
    font-family: 'Unbounded', sans-serif;
    font-size: 48px;
    margin-bottom: 20px;
    color: var(--text-main);
}

.models {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 20px;
    margin: 40px 0;
}

.model-card {
    width: 240px;
    padding: 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    transition: all 0.3s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.model-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent-primary);
    box-shadow: 0 10px 30px rgba(255, 107, 53, 0.2);
}

.model-card img {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 16px;
}

.model-card h2 {
    font-family: 'Unbounded', sans-serif;
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text-main);
}

.model-card p {
    color: var(--text-dim);
    margin-bottom: 16px;
    flex-grow: 1;
    font-size: 13px;
}

.btn {
    display: inline-block;
    padding: 12px 20px;
    background: rgba(255, 107, 53, 0.1);
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    transition: all 0.3s ease;
}

.btn:hover {
    background: var(--accent-primary);
    color: var(--bg-dark);
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto auto;
        grid-template-areas: 
            "controls"
            "cubes"
            "leaderboard"
            "editor";
        padding-top: 70px;
    }
    
    .cube-containers {
        height: 50vh;
        min-height: 300px;
    }
    
    #controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 16px;
    }
    
    .color-ref {
        margin: 0;
    }
}

@media (max-width: 600px) {
    #logo {
        font-size: 16px;
        padding: 8px 12px;
    }
    
    #model-title-top {
        font-size: 16px;
        padding: 8px 16px;
    }
}
