:root {
    --primary: #7c4dff;
    --primary-light: #b47cff;
    --primary-dark: #4a1dcc;
    --secondary: #ff6b6b;
    --dark: #2d3436;
    --light: #f8f9fa;
    --text-light: #ffffff;
    --text-dark: #2d3436;
    --wheel-border: #e0e0e0;
    --success: #00b894;
    --danger: #ff4757;
    --warning: #ffa502;
    --bg-color: #f5f7fa;
    --card-bg: white;
    --border-color: #e0e0e0;
    --text-color: #2d3436;
    --wheel-bg: linear-gradient(135deg, #7c4dff 0%, #4a1dcc 100%);
}

.dark-mode {
    --primary: #9c7aff;
    --primary-light: #c5a6ff;
    --primary-dark: #6a3dff;
    --secondary: #ff8a80;
    --dark: #eceff1;
    --light: #263238;
    --text-light: #ffffff;
    --text-dark: #eceff1;
    --wheel-border: #37474f;
    --success: #69f0ae;
    --danger: #ff5252;
    --warning: #ffd740;
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --border-color: #37474f;
    --text-color: #eceff1;
    --wheel-bg: linear-gradient(135deg, #6a3dff 0%, #4a1dcc 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

body {
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

.app-container {
    width: 100%;
    max-width: 1200px;
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: 24px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15);
    margin: 1rem 0;
    position: relative;
    overflow: hidden;
    transition: background 0.3s ease, border-color 0.3s ease;
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
    position: relative;
}

h1 {
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

header p {
    font-size: 1rem;
    color: var(--text-color);
    opacity: 0.8;
    font-weight: 400;
    max-width: 600px;
    margin: 0 auto;
}

.wheel-type-selector {
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.wheel-type-btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    font-size: clamp(0.8rem, 3vw, 0.9rem);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    color: var(--text-color);
}

.wheel-type-btn.active {
    color: white;
    background: var(--wheel-bg);
    border-color: var(--primary-dark);
}

.wheel-type-btn[data-wheel-type="color"] {
    border-left: 4px solid #FF6384;
    border-right: 4px solid #36A2EB;
    border-top: 4px solid #FFCE56;
    border-bottom: 4px solid #4BC0C0;
}

.wheel-type-btn[data-wheel-type="number"] {
    border: 4px solid #9966FF;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Wheel Section */
.wheel-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    order: 1;
    position: relative;
}

.wheel-container {
    position: relative;
    width: 100%;
    max-width: min(100vw - 2rem, 500px);
    aspect-ratio: 1/1;
    margin: 1rem 0;
}

.wheel {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    border: 10px solid var(--primary);
    box-shadow: 0 0 0 4px var(--border-color), 0 8px 32px rgba(31, 38, 135, 0.2);
    transition: transform 4s cubic-bezier(0.17, 0.67, 0.12, 0.99);
    transform: rotate(0deg);
    background: white;
}

.wheel-pointer {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--danger);
    font-size: 3rem;
    z-index: 5;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.result-container {
    width: 100%;
    max-width: min(100vw - 2rem, 500px);
    margin-top: 1rem;
    background: var(--card-bg);
    border-radius: 14px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.result-display {
    padding: 1.2rem;
    font-size: clamp(1rem, 4vw, 1.3rem);
    font-weight: 600;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--card-bg);
    color: var(--text-color);
    transition: all 0.3s ease;
}

.result-display.highlight {
    animation: highlightPulse 0.8s infinite alternate;
    border: 3px solid var(--card-bg);
    box-shadow: 0 0 20px rgba(255,255,255,0.7);
}

@keyframes highlightPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(255,255,255,0.5);
    }
    100% {
        transform: scale(1.05);
        box-shadow: 0 0 30px rgba(255,255,255,0.9);
    }
}

.winning-segment {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10;
    animation: segmentGlow 1.5s infinite alternate;
}

@keyframes segmentGlow {
    0% {
        box-shadow: inset 0 0 15px rgba(255,255,255,0.5);
    }
    100% {
        box-shadow: inset 0 0 30px rgba(255,255,255,0.9);
    }
}

/* Editor Section */
.editor-section {
    background: var(--card-bg);
    border-radius: 18px;
    padding: 1.2rem;
    order: 2;
    border: 1px solid var(--border-color);
}

.editor-tabs {
    display: flex;
    margin-bottom: 1.2rem;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}

.tab-btn {
    padding: 0.6rem 1.2rem;
    background: transparent;
    border: none;
    border-bottom: 4px solid transparent;
    cursor: pointer;
    font-weight: 700;
    color: #666;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    position: relative;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--primary);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.tab-btn.active:after {
    transform: scaleX(1);
}

.segment-list {
    margin-bottom: 1.2rem;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.segment-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.6rem;
    background: var(--card-bg);
    border-radius: 10px;
    margin-bottom: 0.6rem;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease;
}

.segment-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.segment-color {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.segment-input {
    flex: 1;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
    background: var(--card-bg);
    color: var(--text-color);
    min-width: 0;
}

.segment-input:focus {
    border-color: var(--primary);
    outline: none;
}

.segment-actions {
    display: flex;
    flex-shrink: 0;
}

.segment-actions button {
    padding: 0.4rem;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    cursor: pointer;
    transition: background 0.2s ease;
    color: var(--text-color);
}

.segment-actions button:hover {
    background: rgba(0, 0, 0, 0.1);
}

.add-segment {
    width: 100%;
    padding: 0.8rem;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    background: var(--success);
    color: white;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.add-segment:hover {
    background: #00a884;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

/* Settings Tab */
#settings-tab {
    display: none;
}

#settings-tab.active {
    display: block;
}

.settings-option {
    margin-bottom: 1.2rem;
}

.settings-option label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.95rem;
}

.settings-option input {
    width: 100%;
    padding: 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.3s ease;
    background: var(--card-bg);
    color: var(--text-color);
}

.settings-option input:focus {
    border-color: var(--primary);
    outline: none;
}

.settings-option select {
    width: 100%;
    padding: 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.3s ease;
    background: var(--card-bg);
    color: var(--text-color);
}

.settings-option select:focus {
    border-color: var(--primary);
    outline: none;
}

.history-list {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.4rem;
    background: var(--card-bg);
    font-size: 0.9rem;
}

.history-item {
    padding: 0.7rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease;
    color: var(--text-color);
}

.history-item:hover {
    background: rgba(0,0,0,0.02);
}

.history-item:last-child {
    border-bottom: none;
}

.history-item .result {
    font-weight: 600;
    font-size: 0.95rem;
}

.history-item .time {
    color: var(--text-color);
    opacity: 0.7;
    font-size: 0.8rem;
}

.clear-history {
    width: 100%;
    padding: 0.8rem;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    background: var(--danger);
    color: white;
    margin-top: 1rem;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.clear-history:hover {
    background: #ff3d4f;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

/* Celebration Popup */
.celebration-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
}

.celebration-popup.active {
    opacity: 1;
    pointer-events: all;
}

.celebration-content {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 1.5rem;
    text-align: center;
    width: 90%;
    max-width: 350px;
    position: relative;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.celebration-result {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 1.2rem 0;
    padding: 1.2rem;
    border-radius: 14px;
}

.celebration-actions {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
}

.celebration-actions button {
    padding: 0.7rem 1.2rem;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    font-size: 0.95rem;
}

.celebration-done {
    background: var(--success);
    color: white;
}

.celebration-done:hover {
    background: #00a884;
    transform: translateY(-2px);
}

.celebration-share {
    background: var(--primary);
    color: white;
}

.celebration-share:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

/* Confetti */
.confetti {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: currentColor;
    opacity: 0;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

/* Dark Mode Toggle */
.dark-mode-toggle {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 45px;
    height: 22px;
    border-radius: 11px;
    background: var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 0 3px;
    transition: background 0.3s ease;
    z-index: 10;
}

.dark-mode-toggle::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    transition: transform 0.3s ease;
}

body:not(.dark-mode) .dark-mode-toggle::before {
    transform: translateX(0);
}

body.dark-mode .dark-mode-toggle::before {
    transform: translateX(23px);
}

.dark-mode-toggle i {
    font-size: 11px;
    color: white;
    z-index: 1;
}

.dark-mode-toggle .sun {
    margin-right: auto;
}

.dark-mode-toggle .moon {
    margin-left: auto;
}

/* Responsive Adjustments */
@media (min-width: 600px) {
    .app-container {
        padding: 2rem;
    }
    
    .wheel-container {
        max-width: min(100vw - 3rem, 500px);
    }
    
    .result-container {
        max-width: min(100vw - 3rem, 500px);
    }
    
    .segment-item {
        padding: 0.8rem;
    }
    
    .segment-color {
        width: 28px;
        height: 28px;
    }
    
    .segment-input {
        padding: 0.8rem;
    }
}

@media (min-width: 768px) {
    .main-content {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 2rem;
    }
    
    .wheel-section {
        flex: 1;
        min-width: 300px;
        max-width: 500px;
    }
    
    .editor-section {
        flex: 1;
        min-width: 300px;
        max-width: 500px;
    }
    
    .segment-list {
        max-height: 300px;
    }
}

@media (min-width: 992px) {
    .main-content {
        gap: 2.5rem;
    }
    
    .wheel-section {
        max-width: 550px;
    }
    
    .editor-section {
        max-width: 550px;
    }
}