/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #a5b4fc;
    --secondary-color: #1e1b4b;
    --background: #0f0f23;
    --surface: #1a1a2e;
    --surface-light: #25253d;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --success: #10b981;
    --accent: #f59e0b;
    --border-radius: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: 0.3s ease;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    padding: 1.5rem 0;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--primary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Sections */
section {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

section h2 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Dice Selection */
.dice-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.dice-btn {
    background: var(--surface-light);
    border: 2px solid transparent;
    color: var(--text-primary);
    padding: 1rem 0.5rem;
    border-radius: 8px;
    font-size: 1.25rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.dice-btn:hover {
    background: var(--primary-color);
    transform: translateY(-2px);
}

.dice-btn.selected {
    background: var(--primary-color);
    border-color: var(--primary-light);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

/* Dice Configuration */
.dice-config {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.config-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.config-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.number-input {
    display: flex;
    align-items: center;
    background: var(--surface-light);
    border-radius: 8px;
    overflow: hidden;
}

.number-input button {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.number-input button:hover {
    background: var(--primary-color);
}

.number-input input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: center;
    font-size: 1.25rem;
    font-weight: 600;
    padding: 0.5rem;
    width: 100%;
    min-width: 0;
}

.number-input input:focus {
    outline: none;
}

/* Remove number input spinners */
.number-input input::-webkit-outer-spin-button,
.number-input input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.number-input input[type=number] {
    -moz-appearance: textfield;
}

/* Roll Display */
.roll-display {
    text-align: center;
    padding: 2rem 1.25rem;
}

.roll-formula {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-family: 'Courier New', monospace;
}

.dice-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
    margin-bottom: 1.5rem;
}

.dice-visual {
    width: 100px;
    height: 100px;
    background: linear-gradient(145deg, var(--primary-color), var(--secondary-color));
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow:
        0 10px 30px rgba(99, 102, 241, 0.3),
        inset 0 2px 10px rgba(255, 255, 255, 0.1);
    transition: transform 0.1s ease;
}

.dice-visual.rolling {
    animation: rollDice 0.6s ease-out;
}

@keyframes rollDice {
    0% { transform: rotateX(0deg) rotateY(0deg) scale(1); }
    25% { transform: rotateX(90deg) rotateY(45deg) scale(1.1); }
    50% { transform: rotateX(180deg) rotateY(90deg) scale(1); }
    75% { transform: rotateX(270deg) rotateY(135deg) scale(1.1); }
    100% { transform: rotateX(360deg) rotateY(180deg) scale(1); }
}

.dice-face {
    font-size: 3rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.roll-result {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.result-label {
    font-size: 1.25rem;
    color: var(--text-secondary);
}

.result-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
    min-width: 80px;
}

.result-value.animate {
    animation: popIn 0.3s ease-out;
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.individual-rolls {
    color: var(--text-secondary);
    font-size: 0.875rem;
    min-height: 1.5rem;
}

.individual-rolls span {
    display: inline-block;
    background: var(--surface-light);
    padding: 0.25rem 0.5rem;
    margin: 0.15rem;
    border-radius: 4px;
}

.individual-rolls .max-roll {
    color: var(--success);
    font-weight: 600;
}

.individual-rolls .min-roll {
    color: #ef4444;
    font-weight: 600;
}

/* Roll Button */
.roll-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    border: none;
    color: white;
    padding: 1.25rem 2rem;
    border-radius: var(--border-radius);
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    width: 100%;
}

.roll-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(99, 102, 241, 0.5);
}

.roll-btn:active {
    transform: translateY(0);
}

.roll-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* History Section */
.history-section {
    background: var(--surface);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.history-header h2 {
    margin-bottom: 0;
}

.clear-history {
    background: transparent;
    border: 1px solid var(--text-secondary);
    color: var(--text-secondary);
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}

.clear-history:hover {
    border-color: #ef4444;
    color: #ef4444;
}

.history-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.no-history {
    color: var(--text-secondary);
    text-align: center;
    padding: 1rem;
    font-style: italic;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-light);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    animation: slideIn 0.3s ease-out;
}

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

.history-formula {
    font-family: 'Courier New', monospace;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.history-result {
    font-weight: 700;
    color: var(--accent);
    font-size: 1.125rem;
}

.history-details {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Custom scrollbar */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--surface);
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Footer */
footer {
    text-align: center;
    padding: 1.5rem;
    margin-top: 1rem;
    border-top: 1px solid var(--surface-light);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-light);
    text-decoration: none;
    transition: var(--transition);
}

footer a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .app-container {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .dice-buttons {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    .dice-btn {
        padding: 0.75rem 0.25rem;
        font-size: 1.1rem;
    }

    .dice-config {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .number-input button {
        width: 36px;
        height: 40px;
    }

    .dice-visual {
        width: 80px;
        height: 80px;
    }

    .dice-face {
        font-size: 2.5rem;
    }

    .result-value {
        font-size: 2rem;
    }

    .roll-btn {
        padding: 1rem 1.5rem;
        font-size: 1.25rem;
    }
}

@media (min-width: 768px) {
    .dice-buttons {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles */
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}
