:root {
    color-scheme: dark;
    --bg0: #070913;
    --bg1: #05060c;
    --ink: #eef0ff;
    --muted: rgba(238, 240, 255, .68);
    --muted2: rgba(238, 240, 255, .48);
    --line: rgba(255, 255, 255, .12);
    --brand: rgba(34, 211, 238, 1);
    --gold: #ffd700;
    --silver: #e0e0e0;
    --neon: #f72585;
    --ease: cubic-bezier(.2, .9, .2, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }

body {
    background: 
        radial-gradient(1200px 900px at 70% 20%, rgba(139, 92, 246, .22), transparent 55%),
        radial-gradient(900px 700px at 30% 70%, rgba(34, 211, 238, .16), transparent 60%),
        linear-gradient(180deg, var(--bg0), var(--bg1));
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
}

.noise {
    pointer-events: none;
    position: fixed;
    inset: 0;
    opacity: .06;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
    z-index: 1;
}

#confetti {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1; 
}

.app-center {
    position: relative;
    z-index: 2;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

.stage-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: grid;
    place-items: center;
    perspective: 1200px;
    z-index: 5;
}

.coin-glow {
    position: absolute;
    width: 320px;
    height: 320px;
    background: radial-gradient(circle, rgba(34, 211, 238, 0.2), transparent 70%);
    filter: blur(50px);
    z-index: -1;
    animation: pulse 4s ease-in-out infinite;
}

@keyframes pulse { 
    0%, 100% { opacity: 0.5; transform: scale(1); } 
    50% { opacity: 0.8; transform: scale(1.1); } 
}

.coin-wrapper {
    position: relative;
    width: 240px;
    height: 240px;
    transform-style: preserve-3d;
    cursor: pointer;
    transition: transform 0.4s var(--ease);
}

@keyframes fly {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); }
    100% { transform: scale(1); }
}

.coin-wrapper.is-tossing {
    animation-name: fly;
    animation-timing-function: ease-in-out;
}

.coin-wrapper.is-winner {
    transform: scale(1.15);
}

.coin-container {
    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;
    font-size: 2.2rem;
    font-weight: 800;
    text-transform: uppercase;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5), 0 10px 30px rgba(0,0,0,0.5);
    border: 8px solid rgba(255,255,255,0.1);
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.coin-face::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    transform: translateZ(-2px);
}

.coin-face.heads { background: radial-gradient(circle at 30% 30%, #ffd700, #b8860b); color: #5c4004; }
.coin-face.tails { transform: rotateY(180deg); background: radial-gradient(circle at 30% 30%, #e0e0e0, #999); color: #333; }

.theme-silver .coin-face.heads { background: radial-gradient(circle at 30% 30%, #fff, #bdc3c7); color: #2c3e50; }
.theme-silver .coin-face.tails { background: radial-gradient(circle at 30% 30%, #bdc3c7, #7f8c8d); }

.theme-cyber .coin-face.heads { background: radial-gradient(circle at 30% 30%, #f72585, #7209b7); color: #fff; border-color: #4cc9f0; text-shadow: 0 0 10px rgba(255,255,255,0.8); }
.theme-cyber .coin-face.tails { transform: rotateY(180deg); background: radial-gradient(circle at 30% 30%, #4361ee, #3a0ca3); border-color: #f72585; }

.main-controls {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 220px);
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 10;
}

.instruction {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 280px);
    color: var(--muted2);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    white-space: nowrap;
    opacity: 0.8;
}

.pill-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 12px 24px;
    border-radius: 99px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s var(--ease);
}
.pill-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: var(--brand);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.icon-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--line);
    color: var(--ink);
    display: grid;
    place-items: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s var(--ease);
}
.icon-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: var(--brand);
    transform: translateY(-2px);
}
.icon-btn.muted {
    color: var(--neon);
    border-color: var(--neon);
    background: rgba(247, 37, 133, 0.15);
}

.credit {
    position: absolute;
    bottom: 24px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 11px;
    color: var(--muted2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 10;
}

.credit a {
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    transition: border-color 0.2s;
}

.credit a:hover {
    border-color: var(--brand);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s var(--ease);
}
.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: rgba(10, 12, 20, 0.95);
    border: 1px solid var(--line);
    border-radius: 24px;
    width: 90%;
    max-width: 480px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5);
    transform: scale(0.95);
    transition: transform 0.3s var(--ease);
}
.modal-backdrop.open .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ink);
}
.close-modal {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}
.close-modal:hover { color: var(--ink); }

.modal-body {
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.setting-group label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.full-select, input[type="text"] {
    width: 100%;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--line);
    padding: 12px;
    border-radius: 8px;
    color: var(--ink);
    outline: none;
    font-size: 14px;
}
.full-select:focus, input[type="text"]:focus { border-color: var(--brand); }

.row-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.sub-label {
    font-size: 11px !important;
    margin-bottom: 4px;
    display: block;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--brand);
}

.divider { height: 1px; background: var(--line); margin: 0; }

.credits-section {
    font-size: 12px;
    color: var(--muted2);
    line-height: 1.5;
}
.credits-section p { margin: 4px 0; }
.credits-section a { color: var(--muted); text-decoration: none; border-bottom: 1px solid rgba(255,255,255,0.1); }
.credits-section a:hover { color: var(--ink); border-color: var(--brand); }

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.text-btn {
    background: none;
    border: none;
    color: var(--brand);
    font-size: 12px;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: bold;
}
.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 150px;
    overflow-y: auto;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    border: 1px solid var(--line);
}
.history-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--line);
}
.history-item:last-child { border-bottom: none; }

.stats-mini {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: var(--muted);
    margin-top: 5px;
}
.stats-mini strong { color: var(--ink); }

@media (max-width: 600px) {
    .coin-container, .coin-wrapper { width: 180px; height: 180px; }
    .coin-glow { width: 240px; height: 240px; }
    .modal-content { width: 95%; max-height: 90vh; }
}