/* Reset and base styles */
:root {
    --bg-color: #f0f0f5;
    --text-color: #333;
    --section-bg: white;
    --border-color: #ccc;
    --input-bg: white;
    --input-border: #aaa;
    --dice-pool-bg: #f8f9fa;
    --dice-pool-border: #d0d7de;
    --toggle-bg: #e0e0e0;
    --toggle-active: #666;
    --button-bg: #f8f9fa;
    --button-border: #ccc;
    --button-hover: #e9ecef;
    --grid-color: rgba(150, 150, 150, 0.3);
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --section-bg: #2a2a2a;
    --border-color: #444;
    --input-bg: #333;
    --input-border: #555;
    --dice-pool-bg: #333;
    --dice-pool-border: #555;
    --toggle-bg: #444;
    --toggle-active: #888;
    --button-bg: #444;
    --button-border: #555;
    --button-hover: #555;
    --grid-color: rgba(200, 200, 200, 0.2);
}

body { 
    font-family: Arial; 
    background: var(--bg-color); 
    color: var(--text-color);
    padding: 20px; 
    margin: 0;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1 { 
    text-align: center; 
    color: var(--text-color); 
    margin-bottom: 20px; 
}

/* Theme toggle */
.theme-toggle-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

/* Modes container */
.modes-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: var(--section-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.modes-container h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: var(--text-color);
    text-align: center;
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mode-button {
    padding: 8px 16px;
    border: 1px solid var(--button-border);
    background: var(--button-bg);
    color: var(--text-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.2s;
    text-align: center;
    min-width: 80px;
}

.mode-button:hover {
    background: var(--button-hover);
}

.mode-button.active {
    background: #2196F3;
    color: white;
    border-color: #1976D2;
}

.mode-button.active:hover {
    background: #1976D2;
}

.theme-toggle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--section-bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.theme-icon {
    color: var(--text-color);
    transition: color 0.3s ease;
}

[data-theme="dark"] .theme-icon {
    color: #999;
}

/* Page container to control width and add side margins */
.container {
    max-width: 700px;
    margin: 0 auto;
}

/* Flex layout for compact top row */
.flex-container { 
    display: flex; 
    gap: 20px;  
    flex-wrap: wrap; 
    justify-content: center; 
    margin-bottom: 20px; 
}

/* Sections */
.section { 
    background: var(--section-bg); 
    color: var(--text-color);
    padding: 20px; 
    border-radius: 12px; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.1); 
    text-align: center; 
    position: relative; 
    transition: background-color 0.3s ease;
}

.flex-container .section { 
    flex: 1 1 250px; 
}

.section h2 { 
    margin-top: 0; 
    color: var(--text-color);
}

/* Dice buttons */
.dice-buttons { 
    display: flex; 
    gap: 8px; 
    flex-wrap: wrap; 
    justify-content: center; 
    margin: 10px 0; 
}

.dice-button { 
    width: 50px; 
    height: 50px; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    cursor: pointer; 
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border-radius: 4px;
    background: transparent;
    border: none;
    padding: 0;
}

.dice-button:hover { 
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.dice-button svg {
    width: 100%;
    height: 100%;
}

.dice-button:hover { 
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

/* Dice list */
.dice-pool-container {
    background: var(--dice-pool-bg);
    border: 2px dashed var(--dice-pool-border);
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.dice-list { 
    display: flex; 
    gap: 5px; 
    flex-wrap: wrap; 
    justify-content: center; 
    min-height: 30px; 
}

.dice-item { 
    padding: 5px 10px; 
    border-radius: 8px; 
    background: #cce5ff; 
    cursor: pointer; 
    transition: 0.2s; 
    color: #000;
}

.dice-item:hover { 
    background: #99ccff; 
}

[data-theme="dark"] .dice-item {
    color: #000;
}

/* Bonus controls */
.bonus-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.bonus-controls span {
    font-weight: bold;
    color: var(--text-color);
}

.bonus-btn {
    width: 30px;
    height: 30px;
    border: 1px solid var(--button-border);
    background: var(--button-bg);
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    transition: all 0.2s;
}

.bonus-btn:hover {
    background: var(--button-hover);
}

/* Fate difficulty display */
.fate-difficulty {
    margin-top: 8px;
    font-size: 14px;
    font-weight: bold;
    color: white;
    text-align: center;
    display: none;
    transition: all 0.3s ease;
    background: #666;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #555;
}

.fate-difficulty.visible {
    display: block;
}

[data-theme="dark"] .fate-difficulty {
    background: #555;
    border-color: #444;
}

/* Form inputs */
input[type="number"] { 
    width: 60px; 
    padding: 5px; 
    border-radius: 6px; 
    border: 1px solid var(--input-border); 
    background: var(--input-bg);
    color: var(--text-color);
    text-align: center; 
    margin: 0;
    appearance: textfield;
    -moz-appearance: textfield; /* Firefox */
    transition: all 0.2s;
}

/* Toggle switches */
.toggle-switch {
    position: relative;
    width: 50px;
    height: 24px;
    background: var(--toggle-bg);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    padding: 2px;
    margin: 0;
}

.toggle-switch.active {
    background: var(--toggle-active);
}

.toggle-slider {
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    top: 2px;
    left: 2px;
}

.toggle-switch.active .toggle-slider {
    transform: translateX(26px);
}

.toggle-text {
    position: absolute;
    left: 60px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    font-weight: bold;
    color: #999;
    pointer-events: none;
    white-space: nowrap;
    min-width: 200px;
}

/* Positioning for corner toggle */
#toggleMode {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 50px;
    height: 24px;
}

#toggleMode .toggle-slider {
    width: 20px;
    height: 20px;
    left: 2px;
}

#toggleMode.active .toggle-slider {
    transform: translateX(26px);
}

#toggleMode .toggle-text {
    font-size: 10px;
    line-height: 24px;
    right: 60px;
    left: auto;
    text-align: right;
    min-width: 60px;
}

/* Results container - collapsible */
.results-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out;
    opacity: 0;
    transition: max-height 0.4s ease-out, opacity 0.3s ease-out;
}

.results-container.expanded {
    max-height: 300px;
    opacity: 1;
    transition: max-height 0.4s ease-in, opacity 0.3s ease-in 0.1s;
}

/* Canvas and results */
canvas { 
    display: block; 
    margin: 20px auto; 
    border: 1px solid var(--border-color); 
    border-radius: 8px; 
    transition: border-color 0.3s ease;
}

.result { 
    font-size: 20px; 
    margin-top: 10px; 
    font-weight: bold; 
    text-align: center; 
    color: var(--text-color);
}

/* Fate Success with Style display */
.fate-success-style {
    font-size: 14px;
    margin-top: 10px;
    font-weight: bold;
    text-align: left;
    color: #888;
    display: none;
    transition: all 0.3s ease;
}

.fate-success-style.visible {
    display: block;
}

[data-theme="dark"] .fate-success-style {
    color: #aaa;
}

/* Hide number input spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Smaller corner button inside To Beat */
#toggleMode {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    font-size: 12px;
    margin: 0;
}

/* Small mode button and explanation */
#toggleModeType {
    display: inline-block;
    padding: 4px 8px;
    font-size: 12px;
    margin: 0;
    vertical-align: middle;
}

#modeDescription {
    display: inline-block;
    font-size: 10px;
    color: gray;
    margin-left: 6px;
    vertical-align: middle;
}

/* Responsive design */
@media (max-width: 600px) {
    .flex-container {
        flex-direction: column;
    }
    
    .container {
        padding: 0 10px;
    }
    
    body {
        padding: 10px;
    }
    
    .dice-buttons {
        gap: 6px;
    }
    
    .dice-button {
        width: 45px;
        height: 45px;
        font-size: 12px;
    }
}