:root { 
    --bg-purple: #f3e5f5; 
    --accent-purple: #9c27b0; 
    --deep-purple: #4a148c;
    --white: #ffffff; 
    --gold: #ffd700; 
    --miss-c: #00ffff;
    --red: #ff4d4d;
}

body { 
    background: linear-gradient(135deg, var(--bg-purple) 0%, #faedf8 100%);
    font-family: 'Segoe UI', system-ui, sans-serif;
    margin: 0; 
    padding: 15px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    min-height: 100vh;
    box-sizing: border-box;
}

.btn-back {
    position: absolute;
    top: 15px;
    left: 15px;
    background: var(--white);
    color: var(--accent-purple);
    border: 2px solid var(--accent-purple);
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
    text-transform: uppercase;
    display: none;
    z-index: 100;
    transition: 0.2s;
}

.btn-back:hover { background: var(--accent-purple); color: var(--white); }

.header-logo { 
    display: block; 
    margin: 10px auto 20px; 
    width: 250px; 
    max-width: 90%;
    height: auto; 
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.15));
}

h1 { 
    color: var(--white); 
    text-shadow: 2px 2px 0px var(--accent-purple); 
    margin: 0 0 20px; 
    text-transform: uppercase; 
    letter-spacing: 2px;
    text-align: center;
    font-size: 24px;
}

.card { 
    width: 100%; 
    max-width: 340px; 
    background: var(--white); 
    border: 3px solid var(--accent-purple); 
    border-radius: 30px; 
    padding: 15px; 
    margin: 0 auto 15px; 
    box-shadow: 0 8px 16px rgba(156, 39, 176, 0.1); 
    display: flex; 
    flex-direction: column; 
    gap: 12px;
    box-sizing: border-box;
}

.search-row { display: flex; gap: 10px; align-items: center; }

.search-container { 
    flex: 1; 
    background: var(--white); 
    border: 2px solid #e1bee7; 
    border-radius: 20px; 
    padding: 8px 12px; 
    display: flex; 
    align-items: center;
    transition: 0.3s;
} 

.search-container:focus-within {
    border-color: var(--accent-purple);
    box-shadow: 0 0 5px rgba(156, 39, 176, 0.2);
}

#qSearch { 
    border: none; 
    outline: none; 
    background: transparent; 
    width: 100%; 
    font-weight: bold; 
    font-size: 14px; 
    color: #444;
}

.btn-icon { 
    background: var(--white); 
    border: 2px solid var(--accent-purple); 
    border-radius: 50%; 
    cursor: pointer; 
    font-size: 18px; 
    width: 40px; 
    height: 40px; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    transition: 0.2s;
    color: var(--accent-purple);
    flex-shrink: 0;
}

.btn-icon:hover { background: var(--accent-purple); color: var(--white); }

.format-settings { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 10px; 
    background: rgba(156, 39, 176, 0.04);
    padding: 10px;
    border-radius: 20px;
}

.format-item { 
    display: flex; 
    flex-direction: column; 
    gap: 4px; 
    font-size: 10px; 
    font-weight: 800; 
    color: var(--deep-purple);
    text-transform: uppercase;
}

select, input[type="range"] { 
    padding: 6px; 
    border-radius: 12px; 
    border: 2px solid #e1bee7; 
    outline: none; 
    font-weight: bold;
    background: white;
    font-size: 11px;
}

/* CHALLENGE PICKER STYLES */
.challenge-picker-box {
    background: rgba(156, 39, 176, 0.04);
    padding: 10px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.challenge-picker-title {
    font-size: 11px;
    font-weight: 900;
    color: var(--deep-purple);
    text-align: center;
    margin: 0 0 4px;
    text-transform: uppercase;
}

.challenge-list-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
    padding-right: 4px;
}

.chall-select-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10px;
    font-weight: 800;
    color: var(--deep-purple);
}

.chall-select-row select {
    width: 60%;
}

#dynamicPanel { 
    display: none; 
    background: #fff; 
    padding: 12px; 
    border-radius: 20px; 
    border: 2px dashed var(--accent-purple); 
    text-align: center;
}

#statEditor { 
    display: none; 
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: var(--white); 
    padding: 20px; 
    border-radius: 25px; 
    border: 4px solid var(--accent-purple); 
    text-align: center;
    width: 85%;
    max-width: 280px;
    z-index: 9999;
    box-shadow: 0 0 0 1000px rgba(74, 20, 140, 0.4);
}

.history-box {
    font-size: 11px;
    color: #666;
    margin: 8px 0 12px;
    background: #fdf4ff;
    padding: 8px;
    border-radius: 12px;
    font-style: italic;
    border: 1px solid #e1bee7;
}

.queen-grid { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 12px; 
    width: 100%; 
    max-width: 340px; 
    margin: 0 auto 20px; 
}

.queen-card { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    cursor: pointer; 
    position: relative;
}

.q-circle { 
    width: 70px; 
    height: 70px; 
    border-radius: 50%; 
    border: 3px solid var(--accent-purple); 
    background: #fff center/cover no-repeat; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 24px; 
    position: relative; 
    overflow: hidden; 
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.btn-action {
    position: absolute;
    border-radius: 50%;
    width: 22px; height: 22px;
    font-size: 11px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    z-index: 30;
    border: none;
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.btn-edit-stats { bottom: 25px; right: 6px; background: var(--accent-purple); }
.btn-remove-queen { top: 0; right: 6px; background: var(--red); font-weight: 900; }

.queen-card.selected .q-circle { 
    border-color: var(--gold); 
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.8); 
}

.q-name { 
    font-weight: 800; 
    font-size: 10px; 
    text-align: center; 
    margin-top: 6px; 
    color: #333; 
    text-transform: uppercase;
    line-height: 1.1;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 6px 0;
    font-size: 11px;
    font-weight: bold;
    color: var(--deep-purple);
}

.btn-primary { 
    background: linear-gradient(to bottom, var(--accent-purple), #ba68c8);
    color: var(--white); 
    border: none; 
    padding: 12px; 
    border-radius: 20px; 
    width: 100%; 
    max-width: 340px; 
    display: block;
    margin: 0 auto; 
    font-weight: 900; 
    font-size: 15px; 
    cursor: pointer; 
    text-transform: uppercase; 
    letter-spacing: 1px;
    transition: 0.2s; 
    box-shadow: 0 4px 0px rgba(74, 20, 140, 0.3); 
}

.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0px rgba(74, 20, 140, 0.3); }

/* UPGRADED STABLE TABLE STYLES */
.tr-container { 
    width: 100%; 
    max-width: 100%;
    overflow-x: auto; 
    margin-top: 15px; 
    background: white; 
    border-radius: 20px; 
    padding: 10px; 
    box-sizing: border-box;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border: 2px solid #e1bee7;
}

table { 
    border-collapse: collapse; 
    table-layout: fixed; 
    margin: 0 auto; 
    border: 1px solid #e0e0e0; 
    background: white; 
    width: auto;
}

th, td { 
    border: 1px solid #e0e0e0; 
    width: 55px; 
    min-width: 55px; 
    max-width: 55px;
    height: 38px; 
    text-align: center; 
    font-size: 10px; 
    font-weight: bold; 
    vertical-align: middle; 
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 2px;
    box-sizing: border-box;
}

/* Fixed structural columns */
th:nth-child(1), td:nth-child(1) { width: 45px; min-width: 45px; max-width: 45px; background: #fcfcfc; } 
th:nth-child(2), td:nth-child(2) { width: 130px; min-width: 130px; max-width: 130px; text-align: left; padding: 4px 6px; background: #fcfcfc; } 
th:nth-child(3), td:nth-child(3) { width: 50px; min-width: 50px; max-width: 50px; background: #fcfcfc; color: var(--deep-purple); } 

.table-q-info { display: flex; align-items: center; gap: 6px; overflow: hidden; }
.table-q-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-q-circle { width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--accent-purple); background: #eee center/cover no-repeat; flex-shrink: 0; }

/* MULTI-LINE CHALLENGE HEADER WRAPPING FIX */
.chall-row td { 
    background: #f3e5f5; 
    color: var(--deep-purple); 
    height: 38px; 
    font-size: 8px; 
    text-transform: uppercase; 
    font-weight: 800; 
    white-space: normal; 
    line-height: 1.1; 
    word-wrap: break-word;
    padding: 2px 1px;
}

/* Placement Styling */
.Winner { background: #ffff00; color: #000; } 
.Runner-Up { background: #d3d3d3; color: #000; } 
.WIN { background: #00008b; color: #fff; } 
.HIGH { background: #add8e6; color: #000; } 
.SAFE { background: #ffffff; color: #000; }
.LOW { background: #ffcccc; color: #000; }
.BTM { background: #ff9999; color: #000; }
.ELIM { background: #b30000; color: #ffffff; font-style: italic; }
.OUT { background: #e0e0e0; color: #e0e0e0; }
.GUEST { background: #888888; color: #ffffff; }
.MISS-C { background: var(--miss-c); color: #000; }

.judging-layout { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 10px 0; }
.judge-item { display: flex; flex-direction: column; align-items: center; cursor: pointer; width: 65px; }
.judge-item .q-circle { width: 50px; height: 50px; }
.judge-item.active-win .q-circle { border-color: var(--gold) !important; border-width: 4px; box-shadow: 0 0 10px rgba(255, 215, 0, 0.8); }
.judge-item.active-btm .q-circle { border-color: var(--red) !important; border-width: 4px; box-shadow: 0 0 8px rgba(255, 77, 77, 0.5); }
