*, *::before, *::after {
    box-sizing: border-box;
}

/* ===== Theme Variables ===== */

:root {
    --bg-body: #0f1119;
    --bg-card: #1a1d2e;
    --bg-card-alt: linear-gradient(135deg, #1a1d2e, #1e2240);
    --bg-card-board: linear-gradient(135deg, #1a2a3e, #1a1d2e);
    --bg-input: rgba(255, 255, 255, 0.06);
    --bg-hover: rgba(255, 255, 255, 0.1);
    --border-card: rgba(255, 255, 255, 0.06);
    --border-input: rgba(255, 255, 255, 0.1);
    --border-input-hover: rgba(255, 255, 255, 0.12);
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --text-muted: rgba(255, 255, 255, 0.5);
    --text-faint: rgba(255, 255, 255, 0.3);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-canvas: drop-shadow(0 8px 32px rgba(0, 0, 0, 0.4));
    --glow-color: rgba(139, 92, 246, 0.15);
    --header-bg: linear-gradient(135deg, #1a1c2e 0%, #2d1b4e 50%, #1a2a5e 100%);
    --header-glow1: rgba(139, 92, 246, 0.08);
    --header-glow2: rgba(59, 130, 246, 0.08);
    --accent: #8b5cf6;
    --accent-secondary: #6366f1;
    --accent-shadow: rgba(99, 102, 241, 0.3);
    --accent-shadow-hover: rgba(99, 102, 241, 0.5);
    --ghost-bg: rgba(255, 255, 255, 0.06);
    --ghost-border: rgba(255, 255, 255, 0.1);
    --ghost-text: rgba(255, 255, 255, 0.7);
    --danger-bg: rgba(239, 68, 68, 0.08);
    --danger-bg-hover: rgba(239, 68, 68, 0.2);
    --danger-text: #f87171;
    --clear-hover-bg: rgba(239, 68, 68, 0.1);
    --clear-hover-border: rgba(239, 68, 68, 0.2);
    --category-btn-bg: #1a1d2e;
    --category-btn-hover: rgba(139, 92, 246, 0.12);
    --category-btn-border-hover: rgba(139, 92, 246, 0.3);
    --scrollbar-thumb: rgba(255, 255, 255, 0.15);
    --board-result-bg: rgba(139, 92, 246, 0.1);
    --board-result-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --full-board-bg: rgba(255, 255, 255, 0.04);
    --ring-outer: #2d1b4e;
    --ring-mid: #1a1d2e;
    --ring-center: #0f1119;
    --ring-stroke: rgba(255, 255, 255, 0.3);
    --segment-stroke: rgba(255, 255, 255, 0.2);
    --outer-ring-fill: rgba(139, 92, 246, 0.2);
    --outer-ring-stroke: rgba(139, 92, 246, 0.4);
}

[data-theme="light"] {
    --bg-body: #f0f1f5;
    --bg-card: #ffffff;
    --bg-card-alt: linear-gradient(135deg, #ffffff, #f5f3ff);
    --bg-card-board: linear-gradient(135deg, #f8fafc, #f0f1f5);
    --bg-input: rgba(0, 0, 0, 0.04);
    --bg-hover: rgba(0, 0, 0, 0.06);
    --border-card: rgba(0, 0, 0, 0.08);
    --border-input: rgba(0, 0, 0, 0.12);
    --border-input-hover: rgba(0, 0, 0, 0.2);
    --text-primary: #1a1a2e;
    --text-secondary: #374151;
    --text-muted: rgba(0, 0, 0, 0.45);
    --text-faint: rgba(0, 0, 0, 0.3);
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-canvas: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.15));
    --glow-color: rgba(139, 92, 246, 0.08);
    --header-bg: linear-gradient(135deg, #6366f1 0%, #7c3aed 50%, #4f46e5 100%);
    --header-glow1: rgba(255, 255, 255, 0.1);
    --header-glow2: rgba(255, 255, 255, 0.08);
    --ghost-bg: rgba(0, 0, 0, 0.04);
    --ghost-border: rgba(0, 0, 0, 0.1);
    --ghost-text: rgba(0, 0, 0, 0.6);
    --danger-bg: rgba(239, 68, 68, 0.06);
    --danger-bg-hover: rgba(239, 68, 68, 0.12);
    --danger-text: #dc2626;
    --clear-hover-bg: rgba(239, 68, 68, 0.08);
    --clear-hover-border: rgba(239, 68, 68, 0.15);
    --category-btn-bg: #ffffff;
    --category-btn-hover: rgba(139, 92, 246, 0.08);
    --category-btn-border-hover: rgba(139, 92, 246, 0.25);
    --scrollbar-thumb: rgba(0, 0, 0, 0.15);
    --board-result-bg: rgba(139, 92, 246, 0.06);
    --board-result-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    --full-board-bg: rgba(0, 0, 0, 0.03);
    --ring-outer: #ddd6fe;
    --ring-mid: #ede9fe;
    --ring-center: #f5f3ff;
    --ring-stroke: rgba(0, 0, 0, 0.08);
    --segment-stroke: rgba(255, 255, 255, 0.4);
    --outer-ring-fill: rgba(139, 92, 246, 0.12);
    --outer-ring-stroke: rgba(139, 92, 246, 0.25);
}

/* ===== Base ===== */

body {
    background: var(--bg-body);
    margin: 0;
    padding: 0;
    color: var(--text-secondary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

button {
    cursor: pointer;
    font-family: inherit;
}

/* ===== Header ===== */

#header {
    background: var(--header-bg);
    padding: 40px 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

#header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, var(--header-glow1) 0%, transparent 50%),
                radial-gradient(circle at 70% 50%, var(--header-glow2) 0%, transparent 50%);
    pointer-events: none;
}

#header_inner {
    position: relative;
    z-index: 1;
}

#header_title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    cursor: pointer;
}

.logo-icon {
    width: 52px;
    height: 52px;
    object-fit: contain;
    background: #fff;
    border-radius: 50%;
    padding: 4px;
}

.title-light {
    font-size: 28px;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 1px;
}

.title-bold {
    font-size: 28px;
    font-weight: 800;
    color: #fff;
    margin-left: 8px;
    letter-spacing: -0.5px;
}

.header-subtitle {
    margin: 8px 0 0;
    color: rgba(255, 255, 255, 0.4);
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Theme toggle */
#theme_toggle {
    position: absolute;
    top: 16px;
    right: 20px;
    z-index: 2;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    cursor: pointer;
    line-height: 1;
}

#theme_toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== Layout ===== */

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 32px 20px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-card);
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.clear {
    clear: both;
}

.displayed {
    display: block;
}

.hidden {
    display: none;
}

/* ===== Buttons ===== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    padding: 10px 20px;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    box-shadow: 0 2px 12px var(--accent-shadow);
}

.btn-primary:hover {
    box-shadow: 0 4px 20px var(--accent-shadow-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 8px var(--accent-shadow);
}

.btn-ghost {
    background: var(--ghost-bg);
    color: var(--ghost-text);
    border: 1px solid var(--ghost-border);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-small {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: 8px;
}

/* ===== Hints ===== */

.hint-text {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.6;
    margin: 0 0 16px;
    text-align: center;
}

.hint-text strong {
    color: var(--text-secondary);
    font-weight: 600;
}

/* ===== Category Page ===== */

#category_page {
    text-align: center;
}

#category_actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
}

#category_new_toggler {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    border: none;
    padding: 12px 28px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 2px 16px var(--accent-shadow);
    transition: all 0.2s ease;
}

#category_new_toggler:hover {
    box-shadow: 0 4px 24px var(--accent-shadow-hover);
    transform: translateY(-1px);
}

.btn-icon {
    font-size: 18px;
    font-weight: 700;
    margin-right: 4px;
}

#category_clear_button {
    background: var(--ghost-bg);
    color: var(--text-muted);
    border: 1px solid var(--ghost-border);
    padding: 12px 28px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s ease;
}

#category_clear_button:hover {
    background: var(--clear-hover-bg);
    color: var(--danger-text);
    border-color: var(--clear-hover-border);
}

/* New list form */
#category_new_input {
    display: none;
    max-width: 420px;
    margin: 0 auto 24px;
    text-align: left;
}

#category_new_input h3 {
    margin: 0 0 16px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

#category_new_text {
    width: 100%;
    height: 44px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 10px;
    padding: 0 16px;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

#category_new_text:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.form-actions .btn {
    flex: 1;
}

/* Category list */
#category_list {
    list-style: none;
    padding: 0;
    margin: 0 auto 32px;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category_text {
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.category_text_button {
    flex: 1;
    background: var(--category-btn-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-card);
    border-radius: 12px;
    padding: 14px 20px;
    font-size: 15px;
    font-weight: 500;
    text-align: left;
    transition: all 0.2s ease;
}

.category_text_button:hover {
    background: var(--category-btn-hover);
    border-color: var(--category-btn-border-hover);
    color: var(--text-primary);
    transform: translateX(4px);
}

.delete {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: var(--danger-bg);
    color: var(--danger-text);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.delete::after {
    content: '\00d7';
}

.delete:hover {
    background: var(--danger-bg-hover);
}

/* How it works */
#site_info {
    max-width: 560px;
    margin: 0 auto;
    background: var(--bg-card-alt);
}

#site_info h2 {
    margin: 0 0 20px;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 700;
    text-align: center;
}

.steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.step {
    display: flex;
    align-items: center;
    gap: 16px;
}

.step-number {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    color: #fff;
    flex-shrink: 0;
}

.step p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
}

/* ===== Roulette Page ===== */

#roulette_page {
    display: none;
}

#roulette_page.active {
    display: block;
}

/* Canvas */
#canvas_panel {
    text-align: center;
    margin-bottom: 24px;
    position: relative;
}

#canvas_glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70%;
    height: 70%;
    background: radial-gradient(circle, var(--glow-color) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
}

#wheelcanvas {
    cursor: grab;
    max-width: 100%;
    touch-action: none;
    position: relative;
    z-index: 1;
    filter: var(--shadow-canvas);
}

#wheelcanvas:active {
    cursor: grabbing;
}

.empty-wheel-hint {
    text-align: center;
    padding: 40px 24px;
}

.empty-wheel-hint .empty-wheel-icon {
    font-size: 48px;
    margin-bottom: 12px;
    line-height: 1;
}

.empty-wheel-hint > p:not(.hint-text) {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 8px;
}

#spin_hint {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-faint);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
    pointer-events: none;
    z-index: 2;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

/* Information panel */
#information_panel {
    margin-bottom: 24px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.panel-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Input group */
.input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.input-group input {
    flex: 1;
    height: 40px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 10px;
    padding: 0 14px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

.input-group input::placeholder {
    color: var(--text-faint);
}

/* Toggle switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: var(--bg-input);
    border-radius: 10px;
}

.toggle-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

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

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--ghost-border);
    border-radius: 22px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    left: 3px;
    top: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* Choices list */
#choices {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 400px;
    overflow-y: auto;
}

#choices::-webkit-scrollbar {
    width: 4px;
}

#choices::-webkit-scrollbar-track {
    background: transparent;
}

#choices::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

#choices > div {
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideIn 0.2s ease;
}

.roulette_choice {
    flex: 1;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    transition: all 0.3s ease;
}

.selected_choice {
    box-shadow: 0 0 0 2px #fff, 0 0 20px rgba(255, 235, 59, 0.4);
}

.choice-drawn {
    opacity: 0.35;
    pointer-events: none;
}

.choice-drawn .roulette_choice::after {
    content: ' \2714';
    margin-left: 6px;
    font-size: 12px;
}

.segment-color-0 { background: linear-gradient(135deg, #7c3aed, #6d28d9); }
.segment-color-1 { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.segment-color-2 { background: linear-gradient(135deg, #0d9488, #0f766e); }
.segment-color-3 { background: linear-gradient(135deg, #059669, #047857); }
.segment-color-4 { background: linear-gradient(135deg, #d97706, #b45309); }
.segment-color-5 { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.segment-color-6 { background: linear-gradient(135deg, #db2777, #be185d); }
.segment-color-7 { background: linear-gradient(135deg, #9333ea, #7e22ce); }

.btn_remove {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: var(--danger-bg);
    color: var(--danger-text);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    cursor: pointer;
}

.btn_remove::after {
    content: '\00d7';
}

.btn_remove:hover {
    background: var(--danger-bg-hover);
}

/* Board panel */
#board_panel {
    position: relative;
    background: var(--bg-card-board);
    overflow: visible;
}

#board_panel .panel-header h2 {
    color: var(--text-primary);
}

#full_board {
    color: var(--text-muted);
    font-size: 13px;
    padding: 10px 16px;
    background: var(--full-board-bg);
    border-radius: 8px;
    margin-bottom: 12px;
}

#boards {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.board_entry {
    animation: slideIn 0.3s ease;
}

.board_number {
    background: var(--board-result-bg);
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    border-left: 4px solid var(--accent);
    letter-spacing: 0.3px;
    text-shadow: var(--board-result-shadow);
    transition: background 0.3s ease, color 0.3s ease;
}

/* ===== Responsive ===== */

@media (min-width: 768px) {
    #roulette_page.active {
        display: grid;
        grid-template-columns: 520px 1fr;
        gap: 24px;
    }

    #roulette_page > .clear {
        display: none;
    }

    #canvas_panel {
        grid-row: 1 / -1;
    }
}

@media (max-width: 767px) {
    .container {
        padding: 16px;
    }

    #header {
        padding: 28px 16px;
    }

    .title-light, .title-bold {
        font-size: 22px;
    }

    .logo-icon {
        width: 42px;
        height: 42px;
    }

    #category_actions {
        flex-direction: column;
        align-items: stretch;
        max-width: 300px;
        margin: 0 auto 24px;
    }

    #theme_toggle {
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
}

/* ===== Toast ===== */

#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-card);
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 100;
}

#toast.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
