/* ============================================================
   X-Out Level Editor — Style Sheet
   ============================================================ */

/* --- Design Tokens (inherit from main site) --- */
:root {
    --bg:         #faf7f6;
    --bg-card:    #ffffff;
    --bg-surface: #f5f0ee;
    --text:       #1a1210;
    --text-muted: #7a6560;
    --text-dim:   #c4b0aa;
    --accent:     #d4847d;
    --accent-dim: #c07069;
    --border:     rgba(26, 18, 16, 0.08);
    --border-h:   rgba(26, 18, 16, 0.16);
    --radius:     16px;
    --radius-sm:  10px;
    --font-display: 'Fraunces', Georgia, serif;
    --font-body:    'Instrument Sans', system-ui, -apple-system, sans-serif;
    --sidebar-w:  240px;
    --topbar-h:   56px;
    --bottombar-h: 52px;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    overflow: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--accent-dim);
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.2;
}

/* --- Top Bar (Nav) --- */
.nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--topbar-h);
    padding: 0 clamp(16px, 3vw, 32px);
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(250, 247, 246, 0.95);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--border);
}

.nav-brand {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--text);
    text-decoration: none;
    transition: color 0.2s ease;
}

.nav-brand:hover {
    color: var(--accent);
}

.nav-sep {
    margin: 0 8px;
    color: var(--text-dim);
    font-size: 15px;
}

.nav-current {
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
}

.nav-link {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--accent);
}

.nav-right {
    margin-left: auto;
    display: flex;
    gap: 16px;
    align-items: center;
}

/* --- Editor Layout --- */
.editor-layout {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: var(--bottombar-h);
    display: flex;
    overflow: hidden;
}

/* --- Left Sidebar (Tool Palette) --- */
.sidebar-left {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-left h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding: 4px 0;
}

/* --- Tool Palette --- */
#tool-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.palette-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 4px 8px;
    border: 2px solid transparent;
    border-radius: 6px;
    background: var(--bg-surface);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    font-family: var(--font-body);
    font-size: 0.75rem;
    color: var(--text);
    text-align: left;
}

.palette-btn:hover {
    border-color: var(--border-h);
    background: #fff;
}

.palette-btn.active {
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 1px var(--accent);
}

.palette-swatch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    font-size: 12px;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.08);
}

.palette-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Center Canvas Area --- */
.editor-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-surface);
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.canvas-toolbar label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.canvas-toolbar select,
.canvas-toolbar input[type="number"] {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-surface);
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text);
}

.canvas-toolbar select:focus,
.canvas-toolbar input:focus {
    outline: none;
    border-color: var(--accent);
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
}

.toolbar-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-surface);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text);
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: #fff;
    border-color: var(--border-h);
}

.toolbar-spacer {
    flex: 1;
}

#cell-tooltip {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.canvas-scroll-area {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 16px;
}

#editor-canvas {
    display: block;
    image-rendering: pixelated;
    cursor: crosshair;
    box-shadow: 0 4px 24px rgba(26, 18, 16, 0.1);
    border-radius: 4px;
}

/* --- Right Sidebar (Properties & Entities) --- */
.sidebar-right {
    width: 280px;
    min-width: 280px;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* --- Sidebar Sections --- */
.sidebar-section {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    overflow: hidden;
}

.sidebar-section + .sidebar-section {
    margin-top: 4px;
}

.section-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    background: var(--bg-surface);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    transition: background 0.15s;
}

.section-toggle:hover {
    background: #eee8e5;
}

.section-toggle::before {
    content: '\25BC';
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.sidebar-section.collapsed .section-toggle::before {
    transform: rotate(-90deg);
}

.section-body {
    padding: 10px;
}

.sidebar-section.collapsed .section-body {
    display: none;
}

/* --- Form Fields --- */
.form-group {
    margin-bottom: 8px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-surface);
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group textarea {
    resize: vertical;
    min-height: 48px;
}

.form-group .readonly-field {
    background: var(--bg);
    color: var(--text-muted);
    font-style: italic;
    cursor: default;
}

/* --- Entity Editor --- */
.entity-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.entity-section-header h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
}

.entity-add-btn {
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-surface);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    transition: background 0.15s;
}

.entity-add-btn:hover {
    background: #fff;
}

.entity-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 6px;
    margin-bottom: 4px;
    background: var(--bg-surface);
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 0.75rem;
}

.entity-row label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.entity-row input[type="number"] {
    width: 44px;
    padding: 3px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    font-size: 0.75rem;
    font-family: var(--font-body);
    color: var(--text);
    text-align: center;
}

.entity-row input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.entity-row input[type="text"] {
    flex: 1;
    min-width: 60px;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    font-size: 0.75rem;
    font-family: var(--font-body);
    color: var(--text);
}

.entity-row input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

.entity-remove {
    padding: 2px 6px;
    border: none;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.entity-remove:hover {
    opacity: 1;
}

.entity-empty {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-style: italic;
    padding: 4px 0;
}

/* --- Bottom Bar (Actions) --- */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottombar-h);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    z-index: 100;
}

.action-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    white-space: nowrap;
}

.action-btn:hover {
    background: #fff;
    border-color: var(--border-h);
    transform: translateY(-1px);
}

.action-btn.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

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

.action-btn.danger {
    color: #c03030;
    border-color: rgba(192, 48, 48, 0.2);
}

.action-btn.danger:hover {
    background: #fff0f0;
    border-color: rgba(192, 48, 48, 0.4);
}

.action-separator {
    width: 1px;
    height: 28px;
    background: var(--border);
}

/* --- Export Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(26, 18, 16, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(26, 18, 16, 0.2);
    padding: 24px;
    width: min(700px, 90vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-content h2 {
    font-size: 1.25rem;
}

.modal-content textarea {
    width: 100%;
    min-height: 300px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text);
    resize: vertical;
    line-height: 1.4;
}

.modal-content textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.modal-warning {
    font-size: 0.8rem;
    color: #c03030;
    background: #fff0f0;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid rgba(192, 48, 48, 0.15);
}

/* --- Hidden file input --- */
#import-file {
    display: none;
}

/* --- Scrollbar Styling --- */
.sidebar-left::-webkit-scrollbar,
.sidebar-right::-webkit-scrollbar,
.canvas-scroll-area::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.sidebar-left::-webkit-scrollbar-track,
.sidebar-right::-webkit-scrollbar-track,
.canvas-scroll-area::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-left::-webkit-scrollbar-thumb,
.sidebar-right::-webkit-scrollbar-thumb,
.canvas-scroll-area::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 3px;
}

.sidebar-left::-webkit-scrollbar-thumb:hover,
.sidebar-right::-webkit-scrollbar-thumb:hover,
.canvas-scroll-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Responsive (mainly desktop, but handle smaller) --- */
@media (max-width: 1100px) {
    :root {
        --sidebar-w: 200px;
    }

    .sidebar-right {
        width: 240px;
        min-width: 240px;
    }
}

@media (max-width: 900px) {
    :root {
        --sidebar-w: 180px;
    }

    .sidebar-right {
        width: 200px;
        min-width: 200px;
    }

    .palette-label {
        display: none;
    }

    .palette-btn {
        width: 32px;
        padding: 4px;
        justify-content: center;
    }

    #tool-palette {
        display: grid;
        grid-template-columns: repeat(auto-fill, 32px);
        gap: 3px;
    }
}

@media (max-width: 700px) {
    .sidebar-left,
    .sidebar-right {
        display: none;
    }

    .editor-layout {
        flex-direction: column;
    }

    .bottom-bar {
        flex-wrap: wrap;
        height: auto;
        padding: 8px;
    }
}
