:root, [data-theme="light"] {
    --bg-color: #fafafa;
    --text-color: #111;
    --border-color: #eee;
    --primary-color: #000;
    --secondary-color: #666;
    --card-bg: #fff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --transition: all 0.3s ease;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --border-color: #333;
    --primary-color: #fff;
    --secondary-color: #aaa;
    --card-bg: #1e1e1e;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] button.primary-btn {
    background: var(--text-color);
    color: var(--bg-color);
}

[data-theme="dark"] button.primary-btn:hover {
    background: #bbb;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.4;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#app {
    width: 100%;
    max-width: 800px;
    background: var(--card-bg);
    min-height: 90vh;
    box-shadow: var(--shadow);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    color: var(--text-color);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.elo-display {
    font-weight: 800;
    font-size: 0.9rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hidden {
    display: none !important;
}

.screen {
    display: none;
    padding: 1.5rem 1rem;
    flex-grow: 1;
    flex-direction: column;
    overflow-y: auto;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.top-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
    z-index: 10;
    align-items: center;
}

.lang-switcher {
    display: flex;
    gap: 0.3rem;
}

.lang-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: bold;
    color: var(--text-color);
    transition: var(--transition);
}

.lang-btn.active {
    background: var(--primary-color);
    color: var(--bg-color);
    border-color: var(--primary-color);
}

.hero {
    text-align: center;
    margin: 2rem 0 1.5rem;
}

.hero h1 {
    font-size: clamp(1.8rem, 8vw, 3rem);
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 0.5rem;
    line-height: 1.1;
    color: var(--text-color);
}

.hero p {
    color: var(--secondary-color);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.main-stats {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.stat-bubble {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    white-space: nowrap;
    color: var(--text-color);
}

.modes-section {
    margin-bottom: 1.5rem;
}

.modes-section h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--secondary-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modes-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

@media (min-width: 600px) {
    .modes-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.mode-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    color: var(--text-color);
}

.mode-card:hover {
    border-color: var(--primary-color);
}

.mode-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.4rem;
}

.mode-card h3 {
    font-size: 1.1rem;
    margin: 0;
}

.mode-elo {
    font-size: 0.7rem;
    font-weight: bold;
    background: var(--card-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.mode-card p {
    font-size: 0.85rem;
    color: var(--secondary-color);
    line-height: 1.3;
}

.difficulty-selector {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 10px;
}

.difficulty-selector label {
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    color: var(--text-color);
}

button.primary-btn, .icon-btn {
    background: var(--primary-color);
    color: var(--bg-color);
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
}

.icon-btn {
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.icon-btn:hover {
    background: var(--bg-color);
}

/* Force centering for action buttons in game container */
#game-container .primary-btn {
    margin: 1.5rem auto 0;
    display: block;
}

/* Game Components */
.color-block {
    width: 100%;
    height: 150px;
    border-radius: 10px;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(0,0,0,0.1);
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

@media (min-width: 480px) {
    .options-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.option-btn {
    padding: 1rem;
    font-family: monospace;
    font-size: 1.1rem;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-color);
}

.option-btn:hover {
    border-color: var(--primary-color);
}

input[type="text"] {
    width: 100%;
    padding: 1rem;
    font-family: monospace;
    font-size: 1.2rem;
    text-align: center;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1rem;
    background: var(--card-bg);
    color: var(--text-color);
}

/* Sliders */
.slider-group {
    margin-bottom: 1.2rem;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.4rem;
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--text-color);
}

input[type="range"] {
    width: 100%;
    height: 15px;
    background: #eee;
    border-radius: 5px;
    outline: none;
}

[data-theme="dark"] input[type="range"] {
    background: #333;
}

.color-preview {
    width: 100%;
    height: 80px;
    border-radius: 10px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.elo-change {
    font-size: 1.8rem;
    font-weight: 800;
    margin: 1.5rem 0;
    text-align: center;
}

.elo-positive { color: #2ecc71; }
.elo-negative { color: #e74c3c; }

/* Stats Tabs */
.stats-tabs {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 1.5rem 0;
}

.tab-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color);
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--primary-color);
    color: var(--bg-color);
    border-color: var(--primary-color);
}

/* Stats Grid */
.mode-stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin: 1.5rem 0;
}

@media (min-width: 550px) {
    .mode-stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.mode-stat-box {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 10px;
}

.mode-stat-box h4 {
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    color: var(--text-color);
}

.mode-stat-line {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-color);
}

#btn-close-stats, #btn-close-help {
    margin-top: 1rem;
    width: 100%;
}

/* Toast System */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: #000; /* Force contrast */
    color: #fff;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    animation: toastIn 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards,
               toastOut 0.5s 4s ease forwards;
    border: 1px solid #333;
}

[data-theme="dark"] .toast {
    background: #ccc; /* Softer than pure white */
    color: #111;
    border-color: #bbb;
}

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

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

.toast-title {
    font-weight: 800;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.2rem;
}

.toast-msg {
    font-size: 0.95rem;
}

/* Achievements List */
.achievements-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    margin-top: 1rem;
}

@media (min-width: 480px) {
    .achievements-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.achievement-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    border-radius: 10px;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    opacity: 0.3;
    filter: grayscale(1);
    transition: var(--transition);
    color: var(--text-color);
}

.achievement-card.unlocked {
    opacity: 1;
    filter: grayscale(0);
    border-color: #f1c40f;
    background: var(--card-bg);
}

[data-theme="dark"] .achievement-card {
    background: #1a1a1a;
}

[data-theme="dark"] .achievement-card.unlocked {
    background: #2a2a10;
    box-shadow: 0 0 15px rgba(241, 196, 15, 0.15);
    border-color: #f1c40f;
}

.ach-icon {
    font-size: 1.5rem;
}

.ach-info h4 {
    font-size: 0.85rem;
    margin-bottom: 0.1rem;
}

.ach-info p {
    font-size: 0.75rem;
    color: var(--secondary-color);
}

@media (min-width: 600px) {
    #btn-close-stats, #btn-close-help {
        width: auto;
        align-self: center;
    }
}

.help-content {
    background: var(--bg-color);
    padding: 1.5rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    font-size: 0.95rem;
    margin-top: 1rem;
}

.help-content h3 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.help-content p {
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.help-list {
    margin-bottom: 1.5rem;
    color: var(--secondary-color);
}

.help-ex code, .help-list code {
    background: var(--card-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    font-weight: bold;
}

/* Color Diagrams */
.circles-container {
    position: relative;
    width: 140px;
    height: 140px;
    margin: 0 auto;
    background: #000;
    border-radius: 10px;
}
.circles-container.subtractive { background: #fff; }
.circle {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 50%;
}
.circle:nth-child(1) { top: 15px; left: 30px; }
.circle:nth-child(2) { top: 50px; left: 10px; }
.circle:nth-child(3) { top: 50px; left: 50px; }
.additive .circle { mix-blend-mode: screen; }
.additive .red { background: #ff0000; }
.additive .green { background: #00ff00; }
.additive .blue { background: #0000ff; }
.subtractive .circle { mix-blend-mode: multiply; }
.subtractive .cyan { background: #00ffff; }
.subtractive .magenta { background: #ff00ff; }
.subtractive .yellow { background: #ffff00; }
