:root {
    --bg-base: #0f1115;
    --bg-surface: #1a1d24;
    --bg-surface-hover: #232730;
    --border-color: #2e3340;
    --primary-color: #f7554f; /* SCP Red-ish accent */
    --primary-hover: #fa6c67;
    --secondary-color: #3b4252;
    --secondary-hover: #4c566a;
    --success-color: #a3be8c;
    --success-hover: #b4cf9d;
    --danger-color: #bf616a;
    --text-main: #eceff4;
    --text-muted: #818b9c;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --font-sans: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
    
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Typography */
h1, h2, h3, h4 { font-weight: 600; }
a { color: var(--primary-color); text-decoration: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--secondary-color); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }

.btn-secondary { background: var(--secondary-color); color: var(--text-main); }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-hover); }
.btn-secondary.active { background: var(--border-color); box-shadow: inset 0 2px 4px rgba(0,0,0,0.2); }

.btn-success { background: var(--success-color); color: #000; }
.btn-success:hover:not(:disabled) { background: var(--success-hover); transform: translateY(-1px); }

.btn-large { padding: 12px 24px; font-size: 1rem; width: 100%; }

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 4px;
    display: inline-flex;
    transition: var(--transition);
}
.btn-icon:hover { color: var(--text-main); background: var(--secondary-color); }
.btn-delete:hover { color: var(--danger-color); background: rgba(191, 97, 106, 0.2); }

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary-color);
}
.logo h1 { font-size: 1.2rem; color: var(--text-main); letter-spacing: -0.5px; margin: 0; }
.logo i { font-size: 1.8rem; }
.logo-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.logo-text .author {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: -2px;
}

.header-actions {
    display: flex;
    gap: 12px;
}
.header-actions .btn.active {
    background: var(--bg-surface-hover);
    border-bottom: 2px solid var(--primary-color);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    color: #fff;
    box-shadow: inset 0 -24px 24px -24px rgba(247, 85, 79, 0.2);
}

/* Main Content */
.app-main {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view-section {
    position: absolute;
    inset: 0;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}
.view-section.active {
    opacity: 1;
    pointer-events: auto;
}

/* Import View */
.import-card {
    width: 100%;
    max-width: 800px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}
.import-card h2 { font-size: 1.5rem; }
.import-card p { color: var(--text-muted); }
.import-card textarea {
    width: 100%;
    height: 400px;
    background: #111317;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 16px;
    resize: none;
    outline: none;
}
.import-card textarea:focus { border-color: var(--primary-color); }

/* Editor View */
.editor-layout {
    width: 100%;
    height: 100%;
    display: flex;
    gap: 24px;
}

.groups-sidebar {
    width: 250px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0,0,0,0.1);
}
.sidebar-header h2 {
    font-size: 1rem;
    margin: 0;
}
.groups-sidebar ul {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}
.groups-sidebar li {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.groups-sidebar li:hover { background: var(--bg-surface-hover); }
.groups-sidebar li.active { background: var(--border-color); border-left: 4px solid var(--primary-color); }
.group-count {
    background: var(--secondary-color);
    color: var(--text-main);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}

.members-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.members-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0,0,0,0.1);
}
.members-header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}
.search-box {
    display: flex;
    align-items: center;
    background: #111317;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    gap: 8px;
    transition: var(--transition);
}
.search-box:focus-within {
    border-color: var(--primary-color);
}
.search-box i {
    color: var(--text-muted);
}
.search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    font-size: 0.9rem;
    font-family: inherit;
    width: 200px;
}
.members-grid {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    grid-auto-rows: min-content;
    align-items: start;
    gap: 16px;
    align-content: flex-start;
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 16px;
}
.empty-state i { font-size: 4rem; opacity: 0.2; }

/* Member Card */
.member-card {
    background: #111317;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
.member-card:hover { border-color: var(--primary-hover); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.member-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.member-role-badge {
    background: var(--secondary-color);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}
.member-actions { display: flex; gap: 4px; }
.member-card-body { display: flex; flex-direction: column; gap: 8px; }
.member-name { font-size: 1.1rem; color: #fff; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: var(--font-mono);
}
.member-detail i { font-size: 1rem; }

.member-badge-preview {
    margin-top: 4px;
    padding: 6px 10px;
    border-radius: 4px;
    border-left: 3px solid var(--text-muted);
    background: rgba(255,255,255,0.03);
    font-size: 0.85rem;
    font-weight: 600;
}
/* Color mapping classes added via JS dynamically, e.g. .c-red */
.c-pink { border-left-color: #FF96DE; color: #FF96DE; }
.c-red { border-left-color: #C50000; color: #C50000; }
.c-brown { border-left-color: #944710; color: #944710; }
.c-silver { border-left-color: #A0A0A0; color: #A0A0A0; }
.c-light_green { border-left-color: #32CD32; color: #32CD32; }
.c-crimson { border-left-color: #DC143C; color: #DC143C; }
.c-cyan { border-left-color: #00B7EB; color: #00B7EB; }
.c-aqua { border-left-color: #00FFFF; color: #00FFFF; }
.c-deep_pink { border-left-color: #FF1493; color: #FF1493; }
.c-tomato { border-left-color: #FF6448; color: #FF6448; }
.c-yellow { border-left-color: #FAFF86; color: #FAFF86; }
.c-magenta { border-left-color: #FF0090; color: #FF0090; }
.c-blue_green { border-left-color: #4DFFB8; color: #4DFFB8; }
.c-orange { border-left-color: #FF9966; color: #FF9966; }
.c-lime { border-left-color: #BFFF00; color: #BFFF00; }
.c-green { border-left-color: #228B22; color: #228B22; }
.c-emerald { border-left-color: #50C878; color: #50C878; }
.c-carmine { border-left-color: #960018; color: #960018; }
.c-nickel { border-left-color: #727472; color: #727472; }
.c-mint { border-left-color: #98FF98; color: #98FF98; }
.c-army_green { border-left-color: #4B5320; color: #4B5320; }
.c-pumpkin { border-left-color: #EE7600; color: #EE7600; }
.c-default { border-left-color: #FFFFFF; color: #FFFFFF; }

.member-stats {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px dashed var(--border-color);
    padding-top: 8px;
}
.stat { display: flex; align-items: center; gap: 4px; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}
.modal.active { opacity: 1; pointer-events: auto; }

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 900px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}
.small-modal { max-width: 450px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}
.modal-body {
    padding: 24px;
    overflow-y: auto;
}
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* Modal text area for export */
#config-output {
    width: 100%;
    height: 50vh;
    background: #111317;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--success-hover);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 16px;
    margin-top: 16px;
    resize: none;
    outline: none;
    white-space: pre;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.form-group input, .form-group select {
    width: 100%;
    padding: 10px 12px;
    background: #111317;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: #fff;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus {
    border-color: var(--primary-color);
}
.form-row {
    display: flex;
    gap: 16px;
}
.form-row .form-group { flex: 1; }
.checkbox-row {
    margin-top: 16px;
    background: #111317;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

/* Permissions Modal Styles */
.permissions-modal-content {
    max-width: 800px;
}
.permissions-toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 12px;
}
.permissions-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-main);
    margin: 0;
}
.perm-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}
.perm-item:hover {
    background: var(--bg-surface-hover);
}
.perm-name {
    font-weight: 600;
}
.perm-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding-left: 28px;
    font-style: italic;
    line-height: 1.2;
}
.perm-missing {
    font-size: 0.75rem;
    color: var(--danger-color);
    padding-left: 28px;
    font-weight: 500;
    margin-top: 2px;
}
.permissions-grid input[type="checkbox"] {
    appearance: none;
    background-color: var(--bg-base);
    margin: 0;
    font: inherit;
    width: 1.25em;
    height: 1.25em;
    border: 1px solid #ff5555;
    border-radius: 4px;
    background-position: center;
    background-repeat: no-repeat;
    background-size: 80%;
    cursor: pointer;
    transition: all 0.2s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ff5555' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E");
}
.permissions-grid input[type="checkbox"]:checked {
    border-color: #55ff55;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2355ff55' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
}
.permissions-grid input[type="checkbox"]:indeterminate {
    border-color: #ffff55;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffff55' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='5' y1='12' x2='19' y2='12'%3E%3C/line%3E%3C/svg%3E");
}

/* ===============================
   Gameplay Editor Styles
=============================== */
.mode-badge {
    background: var(--bg-surface-hover);
    color: var(--primary-color);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 12px;
    border: 1px solid var(--border-color);
}

.gameplay-layout {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.gameplay-settings-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 16px;
    align-content: start;
}

.gameplay-setting-item {
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-name {
    font-weight: 600;
    color: var(--primary-color);
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.setting-comment {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.4;
    white-space: pre-wrap;
    margin-bottom: 4px;
}

/* Switch Styles */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-color);
    transition: .4s;
    border-radius: 22px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--success-color);
}
input:checked + .slider:before {
    transform: translateX(18px);
}

/* Array Editor */
.array-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}
.array-item {
    display: flex;
    gap: 8px;
}
.array-item input {
    flex: 1;
}
.array-add-btn {
    align-self: flex-start;
    font-size: 0.8rem;
    padding: 4px 12px;
}

/* ===============================
   Mobile Responsiveness
=============================== */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px;
    }
    
    .header-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding-bottom: 4px;
    }
    
    .header-actions .btn {
        flex: 1;
        white-space: nowrap;
        font-size: 0.85rem;
        padding: 8px 12px;
    }
    
    .view-section {
        padding: 12px;
    }
    
    .import-card {
        padding: 16px;
        margin-top: 0;
    }
    
    .import-card h2 {
        font-size: 1.25rem;
    }
    
    .import-card p {
        font-size: 0.85rem;
    }
    
    .editor-layout {
        flex-direction: column;
    }
    
    .groups-sidebar {
        width: 100%;
        height: auto;
        max-height: 180px;
    }
    
    .members-area {
        height: auto;
        min-height: 400px;
    }
    
    .members-grid {
        grid-template-columns: 1fr;
    }
    
    .permissions-grid {
        grid-template-columns: 1fr;
    }
    
    .gameplay-settings-list {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 95%;
        margin: 10px auto;
        padding: 16px;
    }
    
    .permissions-modal-content {
        max-width: 95%;
        height: 90vh;
    }
    
    .import-card textarea {
        height: 250px;
    }
    
    .import-actions {
        flex-direction: column;
    }
}
