/* ==========================================
   2D Dice Roller - Master Stylesheet with Suspense Buffer Animations
   ========================================== */

/* --- CSS Variables & Design System --- */
:root {
    --bg-dark: #090d16;
    --card-bg: rgba(23, 31, 51, 0.75);
    --card-border: rgba(255, 255, 255, 0.15);
    --card-glow: rgba(99, 102, 241, 0.25);
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.5);
    
    --accent: #ec4899;
    --accent-glow: rgba(236, 72, 153, 0.5);
    
    --gold: #fbbf24;
    --gold-glow: rgba(251, 191, 36, 0.6);
    
    --success: #10b981;
    --warning: #f59e0b;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    
    --font-heading: 'Outfit', 'Noto Sans SC', sans-serif;
    --font-body: 'Noto Sans SC', sans-serif;
    
    --dice-size: 72px;
    --dice-radius: 16px;
}

/* --- Base & Reset --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px 12px;
}

/* Background Ambient Glow Spheres */
.background-decor {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.glow-sphere {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.35;
    animation: floatGlow 20s infinite ease-in-out alternate;
}

.sphere-1 {
    width: 450px;
    height: 450px;
    background: radial-gradient(circle, #6366f1 0%, rgba(99,102,241,0) 70%);
    top: -100px;
    left: -100px;
}

.sphere-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #ec4899 0%, rgba(236,72,153,0) 70%);
    bottom: -150px;
    right: -100px;
    animation-delay: -5s;
}

.sphere-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, #8b5cf6 0%, rgba(139,92,246,0) 70%);
    top: 40%;
    left: 60%;
    animation-delay: -10s;
}

@keyframes floatGlow {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(50px, 30px) scale(1.15); }
    100% { transform: translate(-30px, 60px) scale(0.9); }
}

/* Container & Layout */
.app-container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 2px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 4px;
}

.logo-icon {
    font-size: 2.2rem;
    filter: drop-shadow(0 0 16px var(--primary-glow));
    animation: floatLogo 4s ease-in-out infinite alternate;
}

@keyframes floatLogo {
    0% { transform: translateY(0) rotate(0deg); }
    100% { transform: translateY(-6px) rotate(12deg); }
}

.logo h1 {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 40%, #818cf8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* Glassmorphism Cards */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 22px;
    padding: 22px;
    box-shadow: 0 12px 35px -10px rgba(0, 0, 0, 0.5),
                inset 0 1px 1px rgba(255, 255, 255, 0.15);
}

/* Grid Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
}

.display-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: fit-content;
}

.history-stats-section {
    grid-column: 1 / -1;
}

/* --- Score Card --- */
.total-score-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.85), rgba(15, 23, 42, 0.95));
}

.score-main-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.score-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
}

.score-value-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.score-number {
    font-family: var(--font-heading);
    font-size: 3.4rem;
    font-weight: 800;
    line-height: 1;
    background: linear-gradient(135deg, #ffffff 0%, #a5b4fc 40%, #f472b6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 20px rgba(129, 140, 248, 0.5));
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.score-number.suspense {
    animation: suspensePulse 0.4s infinite alternate ease-in-out;
}

@keyframes suspensePulse {
    0% { opacity: 0.4; transform: scale(0.92); }
    100% { opacity: 1; transform: scale(1.08); filter: drop-shadow(0 0 25px var(--accent)); }
}

.score-number.bump {
    animation: scoreExplode 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.3);
}

@keyframes scoreExplode {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); filter: drop-shadow(0 0 35px #ec4899); }
    100% { transform: scale(1); }
}

.special-tag {
    background: linear-gradient(135deg, #fbbf24, #ef4444);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 800;
    padding: 4px 14px;
    border-radius: 16px;
    box-shadow: 0 0 16px rgba(251, 191, 36, 0.6);
    animation: tagShine 1.2s infinite ease-in-out alternate;
}

.special-tag.hidden {
    display: none;
}

@keyframes tagShine {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); box-shadow: 0 0 25px rgba(239, 68, 68, 0.8); }
}

.score-details {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.score-details span {
    color: var(--text-main);
    font-weight: 700;
}

/* ==========================================
   2D DICE STAGE & HIGH-END DICE CARDS
   ========================================== */
.dice-stage {
    min-height: 320px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 30px 20px;
    background: radial-gradient(circle at center, rgba(30, 41, 59, 0.6) 0%, rgba(15, 23, 42, 0.85) 100%);
    position: relative;
    overflow: hidden;
}

.dice-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 32px;
    width: 100%;
}

/* 2D Dice Card Container */
.dice-card-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Floor Shadow under 2D Dice */
.dice-card-shadow {
    width: var(--dice-size);
    height: 14px;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 70%);
    border-radius: 50%;
    margin-top: -6px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.dice-card-wrapper.tumbling .dice-card-shadow {
    animation: shadowTumble 0.35s infinite alternate ease-in-out;
}

@keyframes shadowTumble {
    0% { transform: scale(0.5); opacity: 0.2; }
    100% { transform: scale(1.2); opacity: 0.7; }
}

/* 2D Dice Card Styling */
.dice-card {
    width: var(--dice-size);
    height: var(--dice-size);
    background: linear-gradient(145deg, #ffffff 0%, #f1f5f9 60%, #cbd5e1 100%);
    border-radius: var(--dice-radius);
    border: 2px solid rgba(255, 255, 255, 0.9);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.15),
                inset 0 2px 2px rgba(255, 255, 255, 1),
                0 10px 25px rgba(0, 0, 0, 0.4);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 8px;
    position: relative;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

/* Suspense Tumbling & Shaking Animation Keyframes */
.dice-card-wrapper.tumbling .dice-card {
    animation: diceTumble 0.35s infinite ease-in-out;
}

@keyframes diceTumble {
    0% { transform: translateY(0) rotate(0deg) scale(1); filter: brightness(1); }
    25% { transform: translateY(-28px) rotate(22deg) scale(1.18); filter: brightness(1.2); }
    50% { transform: translateY(6px) rotate(-18deg) scale(0.92); filter: brightness(0.9); }
    75% { transform: translateY(-16px) rotate(14deg) scale(1.1); }
    100% { transform: translateY(0) rotate(0deg) scale(1); filter: brightness(1); }
}

/* 2D Dice Dots (Pips) */
.pip {
    width: 13px;
    height: 13px;
    background: radial-gradient(circle at 35% 35%, #475569 0%, #1e293b 70%, #0f172a 100%);
    border-radius: 50%;
    justify-self: center;
    align-self: center;
    box-shadow: inset 0 1.5px 3px rgba(0, 0, 0, 0.7), 0 1px 1px rgba(255, 255, 255, 0.9);
}

/* Red Dot for Face 1 & Face 4 */
.dice-card.face-1 .pip {
    width: 22px;
    height: 22px;
    background: radial-gradient(circle at 35% 35%, #f87171 0%, #dc2626 70%, #991b1b 100%);
    box-shadow: inset 0 1.5px 3px rgba(0, 0, 0, 0.6), 0 0 12px rgba(220, 38, 38, 0.6);
}

.dice-card.face-4 .pip {
    background: radial-gradient(circle at 35% 35%, #f87171 0%, #dc2626 70%, #991b1b 100%);
}

/* Non-D6 Polyhedral Card Fallback */
.polyhedral-card-2d {
    width: 76px;
    height: 76px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(236, 72, 153, 0.3));
    border: 2px solid var(--primary);
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px var(--primary-glow);
    transition: transform 0.2s ease;
}

.polyhedral-card-2d.tumbling {
    animation: polyTumble 0.35s infinite ease-in-out;
}

@keyframes polyTumble {
    0% { transform: translateY(0) rotate(0deg) scale(1); }
    50% { transform: translateY(-24px) rotate(180deg) scale(1.2); }
    100% { transform: translateY(0) rotate(360deg) scale(1); }
}

.poly-type {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--accent);
}

.poly-val {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 800;
    color: #fff;
}

/* --- Control Panel Elements --- */
.panel-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.row-section {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.section-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 600;
}

.section-label-sm {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
}

.count-badge {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 800;
    box-shadow: 0 0 10px var(--primary-glow);
}

/* Slider */
.slider-wrapper {
    padding: 4px 0;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.12);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    box-shadow: 0 0 12px var(--primary), 0 0 0 4px rgba(99, 102, 241, 0.35);
    transition: transform 0.15s ease;
}

/* Preset Buttons */
.preset-buttons {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.btn-preset {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 8px 0;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-preset:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.btn-preset.active {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 0 12px var(--primary-glow);
}

/* Custom Select & Sound Toggle */
.custom-select {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.custom-select option {
    background-color: #111827;
    color: #fff;
}

.btn-icon-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-muted);
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon-toggle.active {
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.4);
    background: rgba(16, 185, 129, 0.12);
}

/* Roll Button */
.btn-primary-roll {
    position: relative;
    width: 100%;
    padding: 16px 20px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    color: #ffffff;
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 25px -5px rgba(99, 102, 241, 0.6);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary-roll:active {
    transform: scale(0.98);
}

.btn-primary-roll.rolling {
    pointer-events: none;
    opacity: 0.88;
    animation: btnPulse 0.6s infinite alternate ease-in-out;
}

@keyframes btnPulse {
    0% { filter: brightness(1); }
    100% { filter: brightness(1.3) drop-shadow(0 0 15px var(--accent)); }
}

/* --- History & Stats --- */
.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.panel-sub {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

.panel-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.btn-text-sm {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
}

.distribution-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dist-row {
    display: grid;
    grid-template-columns: 30px 1fr 30px;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
}

.bar-track {
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    width: 0%;
    transition: width 0.4s ease;
}

.history-list-wrapper {
    max-height: 160px;
    overflow-y: auto;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    font-size: 0.82rem;
}

.history-total {
    font-weight: 700;
    color: var(--accent);
}

.history-empty {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.82rem;
    padding: 15px 0;
}

.app-footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.82rem;
    margin-top: 5px;
}

/* ==========================================
   MOBILE ADAPTATIONS (<= 768px)
   ========================================== */
@media (max-width: 768px) {
    body {
        padding: 10px 8px;
    }

    .app-container {
        gap: 12px;
    }

    .logo h1 {
        font-size: 1.6rem;
    }

    .main-content {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .dice-stage {
        min-height: 250px;
        padding: 20px 10px;
    }

    .total-score-card {
        padding: 12px 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .score-number {
        font-size: 2.8rem;
    }

    .grid-2-col {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .control-panel {
        position: sticky;
        bottom: 8px;
        z-index: 100;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.7);
        background: rgba(15, 23, 42, 0.94);
        backdrop-filter: blur(25px);
        padding: 16px;
        border-radius: 20px;
    }

    .btn-primary-roll {
        padding: 18px;
        font-size: 1.2rem;
    }
}
