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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --accent-color: #f59e0b;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --gold: #fbbf24;
    --silver: #9ca3af;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

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

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

/* Header Styles */
header {
    text-align: center;
    padding: 2rem 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

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

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

/* Main Content */
main {
    flex: 1;
}

section {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Coin Section */
.coin-section {
    text-align: center;
    padding: 2rem;
}

.coin-container {
    perspective: 1000px;
    margin-bottom: 1.5rem;
}

.coin {
    width: 150px;
    height: 150px;
    margin: 0 auto;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.1s ease-out;
    cursor: pointer;
}

.coin.flipping {
    animation: coinFlip 0.6s ease-out forwards;
}

.coin.flipping-multi {
    animation: coinFlipFast 0.3s ease-out forwards;
}

@keyframes coinFlip {
    0% {
        transform: rotateY(0deg) rotateX(0deg);
    }
    50% {
        transform: rotateY(900deg) rotateX(180deg);
    }
    100% {
        transform: rotateY(1800deg) rotateX(0deg);
    }
}

@keyframes coinFlipFast {
    0% {
        transform: rotateY(0deg);
    }
    100% {
        transform: rotateY(720deg);
    }
}

.coin.show-heads {
    transform: rotateY(0deg);
}

.coin.show-tails {
    transform: rotateY(180deg);
}

.coin-side {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1rem;
    backface-visibility: hidden;
    box-shadow:
        inset 0 0 20px rgba(0, 0, 0, 0.3),
        0 5px 15px rgba(0, 0, 0, 0.3);
}

.coin-heads {
    background: linear-gradient(145deg, #fde047, #ca8a04);
    border: 4px solid #a16207;
    color: #713f12;
}

.coin-tails {
    background: linear-gradient(145deg, #d1d5db, #6b7280);
    border: 4px solid #4b5563;
    color: #1f2937;
    transform: rotateY(180deg);
}

.coin-text {
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.3);
    max-width: 80%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-display {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    min-height: 2rem;
}

.result-display.heads {
    color: var(--gold);
}

.result-display.tails {
    color: var(--silver);
}

/* Controls Section */
.controls-section {
    text-align: center;
}

.flip-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.multi-flip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: center;
}

.multi-flip label {
    color: var(--text-secondary);
}

.multi-flip select {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--surface-hover);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    min-width: 150px;
    font-size: 1.2rem;
    padding: 1rem 2rem;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #475569;
}

.btn-accent {
    background: var(--accent-color);
    color: #1f2937;
}

.btn-accent:hover:not(:disabled) {
    background: #d97706;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--surface-hover);
}

/* Custom Section */
.custom-section h2 {
    margin-bottom: 1.25rem;
}

.custom-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

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

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

.input-group input {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--surface-hover);
    color: var(--text-primary);
    font-size: 1rem;
    width: 150px;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Statistics Section */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--surface-hover);
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-card.heads {
    border-left: 4px solid var(--gold);
}

.stat-card.tails {
    border-left: 4px solid var(--silver);
}

.stat-card.streak {
    border-left: 4px solid var(--primary-color);
}

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

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-percent,
.stat-detail {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* History Section */
.history-controls {
    margin-bottom: 1rem;
}

.history-container {
    max-height: 300px;
    overflow-y: auto;
    background: var(--surface-hover);
    border-radius: 8px;
    padding: 0.5rem;
}

.history-empty {
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-radius: 6px;
    font-size: 0.9rem;
}

.history-item.heads {
    border-left: 3px solid var(--gold);
}

.history-item.tails {
    border-left: 3px solid var(--silver);
}

.history-result {
    font-weight: 600;
}

.history-item.heads .history-result {
    color: var(--gold);
}

.history-item.tails .history-result {
    color: var(--silver);
}

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

.history-number {
    color: var(--text-secondary);
    min-width: 30px;
}

/* Multi-flip results */
.multi-flip-results {
    background: var(--surface);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.5rem;
    border-left: 3px solid var(--primary-color);
}

.multi-flip-header {
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
}

.multi-flip-summary {
    display: flex;
    gap: 1rem;
    font-size: 0.9rem;
}

.multi-flip-summary .heads-result {
    color: var(--gold);
}

.multi-flip-summary .tails-result {
    color: var(--silver);
}

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

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

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

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

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
    border-radius: 4px;
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Mobile Responsive */
@media (max-width: 600px) {
    header h1 {
        font-size: 2rem;
    }

    .coin {
        width: 120px;
        height: 120px;
    }

    .coin-text {
        font-size: 0.85rem;
    }

    .result-display {
        font-size: 1.25rem;
    }

    .btn-primary {
        width: 100%;
        max-width: 200px;
    }

    .multi-flip {
        flex-direction: column;
    }

    .multi-flip select,
    .multi-flip .btn {
        width: 100%;
        max-width: 200px;
    }

    .custom-inputs {
        flex-direction: column;
        align-items: stretch;
    }

    .input-group {
        width: 100%;
    }

    .input-group input {
        width: 100%;
    }

    .custom-inputs .btn {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-value {
        font-size: 1.5rem;
    }

    section {
        padding: 1rem;
    }
}

@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    header {
        padding: 1.5rem 0.5rem;
    }
}

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

.history-item {
    animation: fadeIn 0.3s ease;
}

.multi-flip-results {
    animation: fadeIn 0.3s ease;
}
