/* Base resets and Typography */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: #050505; /* Blacker background */
    color: #f3f4f6;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Background Atmosphere & "Antigravity" Orbs */
.background-orbs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(circle at center, #0a0a0d 0%, #000000 100%);
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: drift 25s infinite ease-in-out alternate;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: #ea580c; /* Deep orange */
    top: -10%;
    left: -10%;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: #9a3412; /* Burnt orange/brown */
    bottom: -5%;
    right: -5%;
    animation-delay: -5s;
    animation-duration: 30s;
}

.orb-3 {
    width: 300px;
    height: 300px;
    background: #44403c; /* Stone grey glow */
    top: 40%;
    left: 40%;
    animation-delay: -12s;
    animation-duration: 20s;
}

@keyframes drift {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, -40px) scale(1.1); }
    100% { transform: translate(-20px, 20px) scale(0.9); }
}

/* Glassmorphism Containers */
.glass-container {
    max-width: 1600px;
    margin: 40px auto;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 1;
}

.app-header {
    text-align: center;
    margin-bottom: 10px;
}

.app-header h1 {
    font-weight: 800;
    font-size: 3rem;
    letter-spacing: -1px;
    background: linear-gradient(135deg, #fff, #f97316);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.glass-panel {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 24px;
    transition: transform 0.4s ease, box-shadow 0.4s ease;
}

.glass-panel:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.15);
}

/* Controls */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
    justify-content: space-between;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.divider {
    width: 2px;
    height: 40px;
    background: rgba(255,255,255,0.1);
}

.glass-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    font-family: 'Outfit', sans-serif;
    outline: none;
    transition: border 0.3s;
}

.glass-input:focus {
    border-color: #f97316;
}

select.glass-input option {
    background: #111115; /* Fallback for select dropdowns */
    color: #fff;
}

/* Buttons ("Condensed Light") */
.glass-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.glass-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(255, 255, 255, 0.1);
}

.primary-btn {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border: 1px solid #fb923c;
    box-shadow: 0 0 15px rgba(234, 88, 12, 0.4);
}

.primary-btn:hover {
    background: linear-gradient(135deg, #fb923c 0%, #f97316 100%);
    box-shadow: 0 0 25px rgba(234, 88, 12, 0.6);
    transform: translateY(-3px);
}

/* Table Responsive Styles */
.table-responsive {
    overflow-x: auto;
    padding: 0; /* Remove padding to make table flush with border */
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1800px;
}

th, td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    min-width: 150px;
}

/* Sticky First Column (Traits) */
th:first-child, 
td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background: #111115;
    min-width: 240px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.3);
}

th:first-child {
    z-index: 11;
}

.compact-mode th:first-child, 
.compact-mode td:first-child {
    min-width: 200px; /* Preserve more width for labels in compact mode */
    background: #111115; /* Ensure background remains opaque */
}

.trait-label-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.trait-label {
    display: flex;
    align-items: center;
}

.reorder-mode .trait-label,
.reorder-mode .header-label {
    cursor: grab;
}

.char-name-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid transparent;
    color: #f3f4f6;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    width: 140px;
    padding: 2px 4px;
    transition: border-bottom 0.3s, background 0.3s;
}

.char-name-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid #f97316;
}

.char-name-input:hover {
    background: rgba(255, 255, 255, 0.03);
}

.header-grip {
    display: none;
    color: #9ca3af;
}

.reorder-mode .header-grip {
    display: inline-flex;
    cursor: grab;
}

.grip-handle {
    display: none; /* Hidden by default */
    align-items: center;
}

.reorder-mode .grip-handle {
    display: inline-flex; /* Shown only in reorder mode */
}

th {
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #9ca3af;
}

td {
    font-weight: 300;
}

tbody tr {
    transition: background 0.3s;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Locking Controls */
.lock-btn {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.2s, color 0.2s;
    padding: 0;
    display: inline-flex;
    align-items: center;
}

/* Add spacing depending on side */
th .lock-btn, 
td:first-child .lock-btn {
    margin-left: 8px;
}

.cell-content .lock-btn {
    margin-right: 8px;
}

.lock-btn:hover {
    transform: scale(1.1);
    color: #f97316;
}

.lock-btn svg {
    display: block;
    width: 14px; /* Slightly smaller to fit better */
    height: auto;
}

.lock-btn.locked {
    color: #f97316; /* Solid orange when locked */
}

.header-label {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    margin-bottom: 8px;
}

tr.dragging, th.dragging {
    opacity: 0.4;
    background: rgba(249, 115, 22, 0.1) !important;
}

.cell-content {
    display: flex;
    align-items: flex-start; /* Align lock to top of wrapped text */
    gap: 8px;
    justify-content: flex-start;
}

.cell-content span {
    overflow-wrap: break-word; /* Only break if word is longer than column */
    line-height: 1.4;
}

/* Compact Mode Styles */
.compact-mode table {
    min-width: 1400px;
}

.compact-mode th, 
.compact-mode td {
    padding: 6px 10px;
    font-size: 0.82rem;
    min-width: 100px;
}

.compact-mode .trait-label-container,
.compact-mode .cell-content {
    justify-content: flex-start; /* Ensure everything stays left-aligned */
    gap: 8px;
}

.compact-mode .glass-panel {
    padding: 12px;
}

.compact-mode .table-responsive {
    padding: 0;
}

.compact-mode .app-header h1 {
    font-size: 2.2rem;
}

/* Custom Toggle Switch Styles */
.toggle-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 20px;
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #9ca3af;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 22px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 22px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #f97316;
}

input:focus + .slider {
    box-shadow: 0 0 1px #f97316;
}

input:checked + .slider:before {
    transform: translateX(22px);
}

/* Media Queries for Mobile */
@media (max-width: 768px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    .control-group {
        justify-content: space-between;
    }
    .toggle-group {
        margin-left: 0;
        margin-top: 10px;
        width: 100%;
        justify-content: center;
    }
    .divider {
        width: 100%;
        height: 1px;
    }
    .app-header h1 {
        font-size: 2.2rem;
    }
}