/* Modern Color Variables */
:root {
    --primary-color: #4361ee;
    --primary-hover: #3a0ca3;
    --secondary-color: #f72585;
    --background-bg: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #2b2d42;
    --border-radius: 16px;
    --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-color);
    background-color: var(--background-bg);
}

.container {
    margin: 0 auto;
    padding: 40px;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(0, 0, 0, 0.02);
}

/* Sticky Note Style */
.sticky-note {
    background-color: #fff3cd;
    color: #856404;
    padding: 10px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: inline-block;
    border: 1px solid #ffeeba;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Form Styles */
.roulette-form {
    margin-bottom: 80px;
}

/* Tab Styles */
.tab-buttons {
    display: flex;
    border-bottom: 2px solid #e9ecef;
    margin-bottom: 25px;
    gap: 10px;
}

.tab-button {
    flex: 1;
    padding: 15px;
    background: #e9ecef;
    color: #6c757d;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    border-radius: 8px 8px 0 0;
}

.tab-button:hover {
    color: var(--primary-color);
    background: #dee2e6;
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: transparent;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Input Styles */
input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s ease;
    background-color: #fff;
    box-sizing: border-box;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(67, 97, 238, 0.1);
}

.item-row {
    background: white;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.delete-item {
    width: 36px;
    height: 36px;
    background-color: #ffeff0;
    color: #ff4d4f;
    border-radius: 8px;
    font-size: 1.2rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}

.delete-item:hover {
    background-color: #ff4d4f;
    color: white;
    transform: none;
}

/* Button & Helper Styles */
button {
    padding: 12px 24px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 6px rgba(67, 97, 238, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(67, 97, 238, 0.3);
}

#clear-settings,
#clear-text-input,
#clear-history {
    background-color: #fff;
    color: #adb5bd;
    border: 2px solid #e9ecef;
    box-shadow: none;
}

#clear-settings:hover,
#clear-text-input:hover,
#clear-history:hover {
    background-color: #fff0f0;
    color: #ff4d4f;
    border-color: #ff4d4f;
}

#download-csv {
    background-color: #10b981;
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.2);
}

#download-csv:hover {
    background-color: #059669;
}

/* Roulette Area */
.roulette-display {
    background: white;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    gap: 60px;
    align-items: flex-start;
}

.roulette-left {
    flex: 0 0 auto;
}

.roulette-right {
    flex: 1;
    padding-top: 20px;
}

.roulette-container {
    width: 500px;
    height: 500px;
    background: transparent;
    border-radius: 50%;
    margin-bottom: 30px;
    position: relative;
    overflow: visible;
}

.arrow {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: -20px;
    width: 40px;
    height: 50px;
    background: #e63946;
    border: none;
    border-radius: 4px 4px 20px 20px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.arrow::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 10px;
    width: 20px;
    height: 10px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
}

/* Placeholder */
#roulette-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 100%;
    z-index: 5;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#roulette-placeholder.hidden {
    opacity: 0;
    visibility: hidden;
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 10px;
    opacity: 0.3;
}

#roulette-placeholder p {
    color: #adb5bd;
    font-weight: 500;
    margin: 0;
    font-size: 1.1rem;
}

#result-display {
    text-align: center;
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-color);
    background: white;
    padding: 10px;
    border-radius: 12px;
    min-height: 48px;
    border: 2px solid #eff0f6;
    box-shadow: var(--shadow-sm);
    margin: 20px 0;
}

/* Control Panel Layout */
.control-panel {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    border: 1px solid #e9ecef;
}

.control-row-top {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.stop-time-setting {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0;
    white-space: nowrap;
}

/* Sound Toggle Switch */
.sound-toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 34px;
}

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

input:checked+.slider {
    background-color: var(--primary-color);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked+.slider:before {
    -webkit-transform: translateX(26px);
    -ms-transform: translateX(26px);
    transform: translateX(26px);
}

.sound-label {
    font-size: 1.5rem;
    color: #6c757d;
}

input:checked~.sound-label {
    color: var(--primary-color);
}

/* Controls - Buttons */
#fullscreen-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: #2a9d8f;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 6px rgba(42, 157, 143, 0.2);
}

#fullscreen-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(42, 157, 143, 0.3);
}

#start-roulette {
    width: 80%;
    max-width: 300px;
    background: linear-gradient(135deg, #f72585 0%, #b5179e 100%);
    font-size: 1.1rem;
    padding: 15px 30px;
    border-radius: 50px;
    box-shadow: 0 6px 15px rgba(247, 37, 133, 0.3);
}

#start-roulette:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 20px rgba(247, 37, 133, 0.4);
}

.mode-selection {
    width: 100%;
    margin: 0 0 20px 0;
    background: transparent;
    border: none;
    padding: 0;
    text-align: left;
}

.mode-selection label {
    display: block;
    margin-bottom: 8px;
    color: #6c757d;
    font-size: 0.9rem;
    font-weight: 600;
}

.mode-selection select {
    width: 100%;
}

/* History */
.history-container {
    background: white;
    border: 2px solid #e9ecef;
    padding: 20px;
    border-radius: 12px;
    width: 100%;
}

.history-container p {
    margin-bottom: 10px;
    color: #2c3e50;
    font-weight: 600;
    display: inline-block;
    margin-right: 10px;
}

.history-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

#history-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.history-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    color: var(--text-color);
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Fullscreen Overrides */
.fullscreen-mode {
    overflow: hidden;
}

.fullscreen-mode .container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2147483647;
    /* Max z-index to overlay WP header */
    overflow: auto;
    box-sizing: border-box;
    max-width: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: none;
    border: none;
    border-radius: 0;
    padding-top: 100px !important;
    /* Shift down to avoid WP header */
}


.fullscreen-mode .roulette-container {
    width: min(80vmin, 600px);
    height: min(80vmin, 600px);
    margin-bottom: 20px;
}

.fullscreen-mode .roulette-display {
    width: 100%;
    margin: 0;
    padding: 0;
    justify-content: center;
    gap: 40px;
}

.fullscreen-mode .roulette-left {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.fullscreen-mode .roulette-right {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /* Center children horizontally */
    flex: 0 0 auto;
    /* Prevent taking too much width causing left-shift */
    width: auto;
    padding-top: 0;
}

.fullscreen-mode .control-panel {
    background: transparent;
    padding: 0;
    margin-bottom: 20px;
    border: none;
    flex-direction: column;
    gap: 20px;
}

.fullscreen-mode .control-row-top {
    justify-content: center;
}

.fullscreen-mode #fullscreen-btn {
    display: none;
}

.fullscreen-mode .roulette-form,
.fullscreen-mode .sticky-note {
    display: none;
}

.fullscreen-mode #result-display {
    width: 100%;
    margin: 0;
}

.fullscreen-mode .history-container {
    max-height: 40vh;
    overflow-y: auto;
    width: 100%;
    max-width: 500px;
    margin-top: 20px;
    text-align: center;
    /* Center text inside if needed */
}

/* Ensure history list items are centered */
.fullscreen-mode #history-list {
    justify-content: center;
}

/* Close button for fullscreen */
.fullscreen-close-btn {
    position: fixed;
    top: 150px !important;
    /* Ensure below header */
    right: 40px !important;
    width: 50px !important;
    height: 50px !important;
    min-width: 50px !important;
    /* Force width */
    min-height: 50px !important;
    /* Force height */
    padding: 0 !important;
    /* Reset padding */
    margin: 0 !important;
    background: rgba(231, 76, 60, 0.9) !important;
    color: white !important;
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer;
    font-size: 24px !important;
    font-weight: bold;
    line-height: 50px !important;
    /* Center text vertically */
    text-align: center !important;
    z-index: 2147483647;
    /* Over everything */
    transition: all 0.3s ease;
    display: none;
    align-items: center;
    justify-content: center;
    box-sizing: border-box !important;
    -webkit-appearance: none !important;
    /* Remove browser styles */
    appearance: none !important;
}

.fullscreen-close-btn:hover {
    background: rgba(192, 57, 43, 1) !important;
    transform: scale(1.1);
}

.fullscreen-mode .fullscreen-close-btn {
    display: flex !important;
}

/* Helpers */
.button-group,
.text-input-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

.button-group {
    justify-content: space-between;
}

.button-group-left {
    display: flex;
    gap: 10px;
}

.item-name {
    flex: 2;
}

.item-probability {
    flex: 1;
}

/* Responsive */
@media (max-width: 900px) {
    .roulette-display {
        flex-direction: column;
        align-items: center;
        gap: 30px;
    }

    .roulette-right {
        width: 100%;
        padding-top: 0;
    }

    .roulette-container {
        width: 70vmin;
        height: 70vmin;
        margin-bottom: 20px;
    }

    .container {
        padding: 20px;
        margin: 10px;
        width: auto;
    }

    .fullscreen-mode .roulette-display {
        flex-direction: column;
        height: auto;
        overflow-y: auto;
    }

    .fullscreen-mode .roulette-container {
        width: 60vmin;
        height: 60vmin;
    }
}

/* Smartphone Specific */
@media (max-width: 600px) {

    /* Hide fullscreen button on mobile */
    #fullscreen-btn {
        display: none !important;
    }

    /* Reduce font sizes */
    button,
    .tab-button,
    input,
    select,
    label,
    .history-item,
    #result-display,
    .sticky-note {
        font-size: 0.9rem !important;
    }

    #start-roulette {
        font-size: 1rem !important;
        padding: 12px 20px;
    }

    #result-display {
        font-size: 1.5rem !important;
        padding: 15px;
    }

    .control-panel {
        padding: 15px;
    }

    h1,
    h2,
    h3 {
        font-size: 1.2rem;
    }

    .placeholder-icon {
        font-size: 3rem;
    }

    #roulette-placeholder p {
        font-size: 0.9rem;
    }

    /* 2x2 Button Layout for Mobile */
    .button-group {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-top: 15px;
        /* Ensure spacing */
    }

    .button-group-left {
        display: contents;
        /* Un-nest children to participate in parent grid */
    }

    /* Target specific buttons to ensure full width/height in grid cells */
    .button-group button,
    .button-group-left button {
        width: 100%;
        margin: 0;
        height: 100%;
        /* Match heights */
        padding: 10px 5px;
        /* Compact padding */
        font-size: 0.85rem !important;
        /* Slightly smaller text for fit */
    }

    /* Reorder Layout on Mobile: Button > Mode > Rest of Controls */
    .roulette-right {
        display: flex;
        flex-direction: column;
        align-items: center;
        /* Robust centering */
    }

    .control-panel {
        display: contents;
        /* Unwrap to sort children */
    }

    /* 1. Start Button (Top) */
    #start-roulette {
        order: -2;
        width: 80%;
        /* Consistent with desktop ratio, or could be 100% */
        margin: 0 auto 24px auto !important;
        /* Force margin */
    }

    /* 2. Mode Selection (Middle) */
    .mode-selection {
        order: -1;
        margin-bottom: 20px;
    }

    .control-row-top {
        order: 0;
        background: #f8f9fa;
        padding: 15px;
        border-radius: 12px;
        border: 1px solid #e9ecef;
        margin-bottom: 20px;
        width: 100%;
        box-sizing: border-box;
        justify-content: center;
    }

    /* Force History Buttons to be Horizontal on Mobile */
    .history-buttons {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 10px;
    }

    .history-buttons button {
        flex: 1;
        /* Equal width */
        font-size: 0.8rem !important;
        /* Smaller text to fit */
        padding: 10px 5px !important;
        white-space: nowrap;
    }
}