:root {
    --bg-color: #09090b;
    --card-bg: rgba(24, 24, 27, 0.8);
    --card-border: rgba(63, 63, 70, 0.5);
    --text-primary: #f8fafc;
    --text-secondary: #a1a1aa;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    
    --win-normal: #10b981; /* Emerald */
    --win-rush: #ef4444; /* Red */
    --win-super: #eab308; /* Yellow/Gold */
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(239, 68, 68, 0.05) 0px, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem 1rem;
    overflow-x: hidden;
    transition: background-image 0.5s ease;
}

body.rush-active {
    background-image: 
        radial-gradient(at 0% 0%, rgba(239, 68, 68, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(234, 179, 8, 0.15) 0px, transparent 50%);
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

h1 {
    font-size: 2.5rem;
    font-weight: 900;
    background: linear-gradient(to right, #60a5fa, #34d399, #facc15);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-secondary);
    font-weight: 600;
}

.machine-selector {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.machine-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.machine-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.machine-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.dashboard {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2rem;
}

@media (min-width: 1024px) {
    .dashboard {
        grid-template-columns: 400px minmax(0, 1fr);
    }
}

/* Control Panel */
.control-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* State Card */
.game-state-card {
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 1rem;
    padding: 1.5rem;
    width: 100%;
    text-align: center;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.normal-state {
    border-color: #3b82f6;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.2);
}

.rush-state {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.4);
    animation: pulseBorder 1.5s infinite alternate, rainbowHue 6s linear infinite;
}

@keyframes pulseBorder {
    0% { box-shadow: 0 0 15px rgba(239, 68, 68, 0.3); }
    100% { box-shadow: 0 0 35px rgba(239, 68, 68, 0.6); }
}

@keyframes rainbowHue {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

.state-label {
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: 0.1em;
}

.normal-state .state-label { color: #60a5fa; }
.rush-state .state-label { 
    color: #fca5a5;
    text-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
}

.st-counter {
    margin-top: 0.5rem;
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text-primary);
}

.st-value {
    font-size: 2rem;
    color: #facc15;
}

/* Row for Stats */
.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    width: 100%;
}

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

.stats-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 1rem;
    padding: 1.25rem;
    width: 100%;
    text-align: center;
    backdrop-filter: blur(10px);
}

.stats-card.highlight {
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.1);
}

.rush-active .stats-card.highlight {
    border-color: rgba(239, 68, 68, 0.5);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.1);
}

.payout-card {
    border-color: rgba(16, 185, 129, 0.5);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.1);
}
.payout-card .stat-value { color: #34d399; }

.max-payout-card {
    border-color: rgba(234, 179, 8, 0.5);
    box-shadow: 0 0 15px rgba(234, 179, 8, 0.1);
}
.max-payout-card .stat-value { color: #facc15; }

.min-hamari-card, .max-hamari-card {
    border-color: rgba(255, 255, 255, 0.2);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

/* Big Button */
.button-container {
    position: relative;
    width: 240px;
    height: 240px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 1rem 0;
}

.progress-ring {
    position: absolute;
    top: 0;
    left: 0;
    transform: rotate(-90deg);
}

.progress-ring__circle {
    transition: stroke-dashoffset 0.1s linear;
}

.progress-value {
    stroke-dasharray: 691; 
    stroke-dashoffset: 691;
    transition: stroke 0.3s;
}

.draw-btn {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: none;
    background: radial-gradient(circle at 30% 30%, #3f3f46, #18181b);
    color: white;
    cursor: pointer;
    position: relative;
    z-index: 10;
    box-shadow: 
        inset 0 4px 10px rgba(255, 255, 255, 0.1),
        0 10px 20px rgba(0, 0, 0, 0.5),
        0 0 0 4px rgba(39, 39, 42, 0.8);
    transition: transform 0.1s, box-shadow 0.1s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.draw-btn:active {
    transform: scale(0.95);
    box-shadow: 
        inset 0 4px 10px rgba(255, 255, 255, 0.1),
        0 2px 5px rgba(0, 0, 0, 0.5),
        0 0 0 4px rgba(39, 39, 42, 0.8);
}

.draw-btn.auto-active {
    background: radial-gradient(circle at 30% 30%, #3b82f6, #1d4ed8);
    box-shadow: 
        inset 0 4px 10px rgba(255, 255, 255, 0.3),
        0 0 30px rgba(59, 130, 246, 0.5),
        0 0 0 4px rgba(29, 78, 216, 0.8);
    animation: pulseNormal 1s infinite alternate;
}

.rush-active .draw-btn {
    background: radial-gradient(circle at 30% 30%, #ef4444, #991b1b);
    box-shadow: 
        inset 0 4px 10px rgba(255, 255, 255, 0.3),
        0 0 80px 20px rgba(239, 68, 68, 0.6),
        0 0 0 4px rgba(153, 27, 27, 0.8);
    animation: rainbowHue 6s linear infinite;
}

.rush-active .draw-btn.auto-active {
    animation: rainbowHue 6s linear infinite, pulseRush 0.3s infinite alternate;
}

@keyframes pulseNormal {
    0% { transform: scale(0.98); }
    100% { transform: scale(1.02); }
}

@keyframes pulseRush {
    0% { transform: scale(0.95); }
    100% { transform: scale(1.05); }
}

.btn-text {
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: 0.1em;
}

.auto-status {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    transition: color 0.3s;
}

.draw-btn.auto-active .auto-status {
    color: #fff;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}

/* Settings */
.settings {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

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

.speed-toggle {
    display: flex;
    background: #27272a;
    border-radius: 999px;
    padding: 0.25rem;
}

.speed-toggle input[type="radio"] { display: none; }

.speed-toggle label {
    padding: 0.5rem 1rem;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.speed-toggle input[type="radio"]:checked + label {
    background: var(--primary);
    color: white;
}
.rush-active .speed-toggle input[type="radio"]:checked + label {
    background: var(--win-rush);
    animation: rainbowHue 6s linear infinite;
}

.auto-settings {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

/* Data Panel */
.data-panel {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.panel-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 1rem;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.panel-card h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 0.5rem;
}

/* Chart */
.chart-container {
    width: 100%;
}

.chart-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 0.5rem;
}

.chart-scroll-wrapper::-webkit-scrollbar { height: 8px; }
.chart-scroll-wrapper::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 4px; }
.chart-scroll-wrapper::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 4px; }

.chart-inner-wrapper {
    height: 300px;
    width: 100%;
    min-width: 100%;
    position: relative;
}

/* Pie Chart */
.pie-chart-container {
    align-items: center;
}
.canvas-wrapper-pie {
    width: 300px;
    height: 300px;
    margin: 0 auto;
}

/* History List */
.history-container {
    max-height: 400px;
}

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

.history-list::-webkit-scrollbar { width: 6px; }
.history-list::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 3px; }
.history-list::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 3px; }

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem 0;
    font-style: italic;
}

.history-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    animation: slideIn 0.3s ease-out;
}

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

.history-item.win-single { border-left: 4px solid var(--primary); }
.history-item.win-rush { 
    border-left: 4px solid var(--win-rush);
    background: rgba(239, 68, 68, 0.1);
}

.rush-active .history-item.win-rush {
    animation: rainbowHue 6s linear infinite;
}

.history-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.history-chain {
    font-size: 1.1rem;
    color: white;
    font-weight: bold;
}

.history-draws {
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.history-type-detail {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.history-payout {
    color: #facc15;
    font-weight: bold;
    font-size: 0.9rem;
}

/* Splash animation for win */
.flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.5s;
}

.flash.normal { background: radial-gradient(circle, transparent 40%, rgba(59,130,246,0.6) 100%); }
.flash.rush { background: radial-gradient(circle, transparent 40%, rgba(239,68,68,0.8) 100%); }
.flash.super { 
    background: radial-gradient(circle, transparent 40%, rgba(234,179,8,0.9) 100%); 
    animation: superFlash 0.5s ease-out;
}

.rush-active .flash.rush {
    animation: rainbowHue 6s linear infinite;
}

@keyframes superFlash {
    0% { opacity: 1; background-color: white; }
    100% { opacity: 0; }
}
