/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --accent: #f472b6;
    --accent-light: #f9a8d4;
    --bg-dark: #0f0f1a;
    --bg-card: #1a1a2e;
    --text: #f1f5f9;
    --text-dim: #94a3b8;
    --success: #22c55e;
    --warning: #f59e0b;
}

body {
    font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Navigation */
#demo-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: linear-gradient(180deg, rgba(15, 15, 26, 0.95) 0%, rgba(15, 15, 26, 0) 100%);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    gap: 2rem;
}

#demo-nav h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.demo-buttons {
    display: flex;
    gap: 0.5rem;
}

.demo-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: 0.5rem;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s ease;
}

.demo-btn:hover {
    background: var(--primary-dark);
    color: var(--text);
}

.demo-btn.active {
    background: var(--primary);
    border-color: var(--primary-light);
    color: var(--text);
}

.demo-btn .icon {
    font-size: 1.2rem;
}

.demo-btn .label {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Canvas Container */
#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#canvas-container canvas {
    display: block;
}

/* Control Panel - 左側に配置してゲームと分離 */
#control-panel {
    position: fixed;
    top: 5rem;
    left: 1rem;
    z-index: 100;
    background: var(--bg-card);
    border-radius: 1rem;
    width: 240px;
    max-height: calc(100vh - 7rem);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(99, 102, 241, 0.2);
    border-bottom: 1px solid rgba(99, 102, 241, 0.3);
}

.panel-header .title {
    font-weight: 600;
    font-size: 0.9rem;
}

#toggle-panel {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.25rem;
    transition: transform 0.2s ease;
}

#toggle-panel.collapsed {
    transform: rotate(180deg);
}

.panel-content {
    padding: 0.75rem;
    max-height: calc(100vh - 10rem);
    overflow-y: auto;
}

.panel-content.collapsed {
    display: none;
}

.demo-controls {
    display: none;
}

.demo-controls.active {
    display: block;
}

.control-group {
    margin-bottom: 0.75rem;
}

.control-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 0.4rem;
}

/* Switch Toggle */
.switch-label {
    display: flex !important;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    user-select: none;
}

.switch-label input {
    display: none;
}

.switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: #374151;
    border-radius: 12px;
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: var(--text);
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.switch-label input:checked + .switch {
    background: var(--primary);
}

.switch-label input:checked + .switch::after {
    transform: translateX(20px);
}

.switch-label span:last-child {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
}

/* Mini Toggle Switch for Options */
.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    padding: 0.35rem 0.4rem;
    margin: 0.2rem 0;
    border-radius: 0.5rem;
    transition: background 0.2s ease;
    position: relative;
}

.checkbox-label:hover {
    background: rgba(99, 102, 241, 0.1);
}

.checkbox-label input {
    display: none;
}

/* Mini toggle track */
.checkbox-label::before {
    content: '';
    flex-shrink: 0;
    width: 32px;
    height: 18px;
    background: #374151;
    border-radius: 9px;
    position: relative;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* Mini toggle thumb */
.checkbox-label::after {
    content: '';
    position: absolute;
    left: calc(0.4rem + 2px);
    top: 50%;
    width: 14px;
    height: 14px;
    background: #94a3b8;
    border-radius: 50%;
    transform: translateY(-50%);
    transition: left 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
}

.checkbox-label:has(input:checked)::before {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

.checkbox-label:has(input:checked)::after {
    left: calc(0.4rem + 16px);
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.checkbox-label span {
    font-size: 0.8rem;
    color: var(--text);
    font-weight: 500;
    transition: color 0.2s ease;
    margin-left: 2.2rem;
}

.checkbox-label:has(input:checked) span {
    color: var(--primary-light);
}

.juice-options {
    padding: 0.4rem;
    border-left: 3px solid var(--primary);
    margin-left: 0.2rem;
    background: rgba(99, 102, 241, 0.05);
    border-radius: 0 0.5rem 0.5rem 0;
}

/* Sound Selection */
.sound-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.35rem 0;
}

.sound-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    width: 50px;
    flex-shrink: 0;
}

.sound-select {
    flex: 1;
    padding: 0.3rem 0.4rem;
    font-size: 0.75rem;
    background: var(--bg-dark);
    border: 1px solid #374151;
    border-radius: 4px;
    color: var(--text);
    min-width: 0;
}

.sound-play-btn, .sound-stop-btn {
    padding: 0.2rem 0.4rem;
    font-size: 0.7rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.sound-play-btn {
    background: #22c55e;
    color: white;
}

.sound-stop-btn {
    background: #ef4444;
    color: white;
}

.sound-play-btn:hover, .sound-stop-btn:hover {
    opacity: 0.8;
}

/* Select */
select {
    width: 100%;
    padding: 0.45rem;
    background: var(--bg-dark);
    border: 1px solid #374151;
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Range Slider */
input[type="range"] {
    width: 100%;
    height: 6px;
    background: #374151;
    border-radius: 3px;
    appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

/* Buttons */
.action-btn {
    width: 100%;
    padding: 0.6rem;
    background: var(--primary);
    border: none;
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.action-btn:active {
    transform: translateY(0);
}

.button-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.button-row .action-btn {
    flex: 1;
}

.pause-btn {
    background: var(--warning);
}

.pause-btn:hover {
    background: #fbbf24;
}

.pause-btn.paused {
    background: var(--success);
}

.pause-btn.paused:hover {
    background: #4ade80;
}

.hint {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
    text-align: center;
}

.hint-box {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.6rem;
    margin-top: 0.4rem;
}

.hint-box .hint {
    margin-bottom: 0.25rem;
    text-align: left;
    font-size: 0.75rem;
}

.hint-box .hint:last-child {
    margin-bottom: 0;
}

/* Info Overlay */
#info-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.5s ease;
}

#info-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.info-content {
    text-align: center;
    max-width: 500px;
    padding: 2rem;
}

.info-content h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.info-content p {
    font-size: 1.2rem;
    color: var(--text-dim);
    margin-bottom: 1.5rem;
}

.info-content ul {
    list-style: none;
    text-align: left;
    margin-bottom: 2rem;
}

.info-content li {
    padding: 0.5rem 0;
    font-size: 1rem;
}

.info-content li strong {
    color: var(--accent);
}

#close-info {
    padding: 1rem 3rem;
    font-size: 1.2rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    border-radius: 2rem;
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#close-info:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.5);
}

/* Celebration */
#celebration {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#celebration.hidden {
    display: none;
}

.celebration-text {
    font-size: 6rem;
    font-weight: 900;
    background: linear-gradient(135deg, #ffd700, #ff6b6b, #4ecdc4, #a855f7);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: celebrationGradient 1s ease infinite, celebrationPulse 0.3s ease infinite;
    text-shadow: 0 0 60px rgba(255, 215, 0, 0.5);
}

@keyframes celebrationGradient {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes celebrationPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #demo-nav {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
    }

    #demo-nav h1 {
        font-size: 1.2rem;
    }

    .demo-btn .label {
        display: none;
    }

    #control-panel {
        top: auto;
        bottom: 1rem;
        left: 1rem;
        right: 1rem;
        width: auto;
        max-height: 40vh;
    }

    .celebration-text {
        font-size: 3rem;
    }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s ease;
}

/* Score Display */
#score-display {
    position: fixed;
    top: 5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* Ball Count Display */
#ball-count-display {
    position: fixed;
    top: 5rem;
    right: 2rem;
    z-index: 50;
    text-align: right;
}

#ball-count-display .ball-count-label {
    font-size: 1.2rem;
    font-weight: 600;
    color: #4dabf7;
    margin-bottom: 0.5rem;
}

#ball-count-display .ball-count-value {
    letter-spacing: 0.2em;
}

#ball-count-display .ball-count-tips {
    margin-top: 1rem;
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.5;
}

#ball-count-display .ball-count-tips p {
    margin: 0.25rem 0;
}

#ball-count-display .ball-count-tips .danger-text {
    color: #ff6b6b;
}

/* Combo Display - ポップで楽しい（画面中央） */
#combo-display {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    font-size: 2rem;
    font-weight: 900;
    color: #fff;
    opacity: 0;
    transition: opacity 0.15s ease;
    text-shadow:
        0 0 10px currentColor,
        0 0 20px currentColor,
        2px 2px 0 #000;
    pointer-events: none;
    white-space: pre-line;
    text-align: center;
}

#combo-display.visible {
    opacity: 1;
    animation: comboPop 0.3s ease-out;
}

#combo-display.combo-3 { color: #4ade80; font-size: 2.5rem; }
#combo-display.combo-5 { color: #facc15; font-size: 3rem; }
#combo-display.combo-7 { color: #fb923c; font-size: 3.5rem; }
#combo-display.combo-10 { color: #f87171; font-size: 4rem; animation: comboRainbow 0.5s linear infinite, comboPop 0.3s ease-out; }

@keyframes comboPop {
    0% { transform: translate(-50%, -50%) scale(0.5); }
    50% { transform: translate(-50%, -50%) scale(1.3); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes comboRainbow {
    0% { color: #f87171; text-shadow: 0 0 20px #f87171; }
    25% { color: #facc15; text-shadow: 0 0 20px #facc15; }
    50% { color: #4ade80; text-shadow: 0 0 20px #4ade80; }
    75% { color: #60a5fa; text-shadow: 0 0 20px #60a5fa; }
    100% { color: #f87171; text-shadow: 0 0 20px #f87171; }
}

/* Instructions */
#instructions {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    font-size: 1rem;
    color: var(--text-dim);
    text-align: center;
    pointer-events: none;
}

/* ================================
   Game Effects
   ================================ */

/* Final Score */
.final-score {
    color: #fff;
}

.final-score-label {
    font-size: 1.5rem;
    color: #94a3b8;
    margin-bottom: 0.5rem;
}

.final-score-value {
    font-size: 4rem;
    font-weight: 900;
    background: linear-gradient(135deg, #ffd700, #ff6b6b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@keyframes finalScorePop {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
    20% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }
    80% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
}

/* Focus Lines (for last block slow-mo) */
@keyframes focusLine {
    0% {
        transform: scaleX(0);
        opacity: 1;
    }
    100% {
        transform: scaleX(1);
        opacity: 0;
    }
}

/* Rainbow Border Animation */
@keyframes rainbowBorder {
    0% { border-color: #ff6b6b; box-shadow: 0 0 30px #ff6b6b; }
    16% { border-color: #ffa94d; box-shadow: 0 0 30px #ffa94d; }
    33% { border-color: #ffd700; box-shadow: 0 0 30px #ffd700; }
    50% { border-color: #69db7c; box-shadow: 0 0 30px #69db7c; }
    66% { border-color: #4dabf7; box-shadow: 0 0 30px #4dabf7; }
    83% { border-color: #da77f2; box-shadow: 0 0 30px #da77f2; }
    100% { border-color: #ff6b6b; box-shadow: 0 0 30px #ff6b6b; }
}

/* Screen Flash */
@keyframes screenFlash {
    0% { background: rgba(255, 255, 255, 0); }
    10% { background: rgba(255, 255, 255, 0.8); }
    100% { background: rgba(255, 255, 255, 0); }
}

.screen-flash {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 170;
    pointer-events: none;
    animation: screenFlash 0.3s ease-out forwards;
}

/* Glow effect for last block */
@keyframes lastBlockGlow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    }
    50% {
        box-shadow: 0 0 40px rgba(255, 215, 0, 0.8), 0 0 60px rgba(255, 215, 0, 0.4);
    }
}

/* Mobile adjustments for game effects */
@media (max-width: 768px) {
    .final-score-value {
        font-size: 3rem;
    }
}

