:root {
    --bg-base: #f8fafc;
    --bg-panel: rgba(255, 255, 255, 0.85);
    --bg-input: #ffffff;
    --bg-hover: rgba(148, 163, 184, 0.1);

    --border-light: rgba(15, 23, 42, 0.1);

    --text-main: #0f172a;
    --text-muted: #64748b;

    --primary: #3b82f6;
    /* Blue for Heads */
    --primary-hover: #2563eb;
    --secondary: #ec4899;
    /* Pink for Tails */

    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-coin: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);

    --radius-lg: 16px;
    --radius-md: 8px;

    --coin-size: 200px;
    --coin-thickness: 16px;
}

[data-theme="dark"] {
    --bg-base: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --bg-input: #1e293b;
    --bg-hover: rgba(148, 163, 184, 0.15);

    --border-light: rgba(255, 255, 255, 0.1);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --secondary: #f472b6;

    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-coin: 0 30px 40px -10px rgba(0, 0, 0, 0.6), 0 15px 15px -10px rgba(0, 0, 0, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, color 0.3s;
}

svg {
    display: block;
}

.w-4 {
    width: 1rem;
}

.h-4 {
    height: 1rem;
}

.w-5 {
    width: 1.25rem;
}

.h-5 {
    height: 1.25rem;
}

.w-6 {
    width: 1.5rem;
}

.h-6 {
    height: 1.5rem;
}

.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

.text-primary {
    color: var(--primary);
}

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

.text-sm {
    font-size: 0.875rem;
}

.font-mono {
    font-family: 'JetBrains Mono', monospace;
}

.mt-4 {
    margin-top: 1rem;
}

.py-4 {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

/* Buttons & Inputs */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--text-main);
    color: var(--bg-base);
}

.btn-primary:hover {
    background: var(--text-muted);
    transform: translateY(-1px);
}

.btn-icon {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

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

/* Toggle */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.toggle-label input {
    display: none;
}

.toggle-switch {
    width: 2.5rem;
    height: 1.25rem;
    background: var(--border-light);
    border-radius: 1rem;
    position: relative;
    transition: background 0.3s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(1.25rem - 4px);
    height: calc(1.25rem - 4px);
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.toggle-label input:checked+.toggle-switch {
    background: var(--text-main);
}

.toggle-label input:checked+.toggle-switch::after {
    transform: translateX(1.25rem);
}

[data-theme="dark"] .toggle-switch::after {
    background: var(--text-main);
}

[data-theme="dark"] .toggle-label input:checked+.toggle-switch::after {
    background: var(--bg-base);
}

.toggle-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

/* Glass Panel */
.glass-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
}

/* Layout */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    margin: 1rem 1.5rem;
    border-radius: var(--radius-md);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--text-main);
    color: var(--bg-base);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 1.5rem;
    padding: 0 1.5rem 2rem;
    flex: 1;
}

@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Scene Panel */
.scene-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.scene-container {
    flex: 1;
    min-height: 400px;
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    perspective: 1000px;
}

.controls {
    padding: 1.5rem;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.btn-flip {
    width: 100%;
    padding: 1rem;
    font-size: 1.125rem;
}

.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-light);
}

/* 3D Coin */
.coin-wrapper {
    width: var(--coin-size);
    height: var(--coin-size);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.1s;
    /* initial shadow on the wrapper */
    filter: drop-shadow(var(--shadow-coin));
}

.coin {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
}

.coin-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e2e8f0 0%, #94a3b8 100%);
    border: 4px solid #cbd5e1;
    box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.2), inset 0px 4px 10px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .coin-face {
    background: linear-gradient(135deg, #334155 0%, #0f172a 100%);
    border-color: #475569;
    box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.05), inset 0px 4px 10px rgba(0, 0, 0, 0.4);
}

.coin-front {
    transform: translateZ(calc(var(--coin-thickness) / 2));
    color: var(--primary);
}

.coin-back {
    transform: rotateY(180deg) translateZ(calc(var(--coin-thickness) / 2));
    color: var(--secondary);
}

.coin-inner {
    width: 80%;
    height: 80%;
    border-radius: 50%;
    border: 2px dashed rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

[data-theme="dark"] .coin-inner {
    border-color: rgba(255, 255, 255, 0.1);
}

.coin-text {
    font-size: 5rem;
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .coin-text {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Coin Edge - A pseudo cylinder using repeating gradients */
.coin-edge {
    position: absolute;
    width: var(--coin-size);
    height: var(--coin-size);
    border-radius: 50%;
    background: #cbd5e1;
    transform: translateZ(calc(var(--coin-thickness) / -2));
    /* This cheap hack creates depth without 50 divs */
    box-shadow:
        0 0 0 calc(var(--coin-thickness)) #cbd5e1,
        /* The extrusion */
        inset 0 0 10px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .coin-edge {
    background: #1e293b;
    box-shadow: 0 0 0 calc(var(--coin-thickness)) #1e293b, inset 0 0 10px rgba(0, 0, 0, 0.4);
}

/* Result Overlay */
.result-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--bg-base), 0.5);
    backdrop-filter: blur(4px);
    z-index: 10;
    animation: fadeIn 0.3s ease forwards;
}

.result-text {
    font-size: 4rem;
    font-weight: 800;
    color: var(--text-main);
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Stats Panel */
.stats-panel {
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.stat-card {
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

.stat-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-weight: 500;
}

.fairness-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.progress-bar-wrap {
    background: var(--bg-input);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

.progress-bar {
    height: 8px;
    background: var(--border-light);
    border-radius: 4px;
    display: flex;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.progress-fill {
    height: 100%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.heads-fill {
    background: var(--primary);
}

.tails-fill {
    background: var(--secondary);
}

.progress-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    font-weight: 600;
}

.history-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.history-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

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

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    animation: slideInX 0.3s ease;
}

.history-item .number {
    color: var(--text-muted);
    font-size: 0.75rem;
}

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

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

@keyframes slideInX {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}