:root {
    --bg-color: #1a1a24;
    --primary-color: #ffd700; /* 工場の警告色っぽい黄色 */
    --text-main: #ffffff;
    --text-sub: #a0a0b0;
    
    --color-red: #ff3366;
    --color-blue: #00c3ff;
    
    --font-main: 'M PLUS Rounded 1c', sans-serif;
    --font-num: 'Teko', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-main);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 600px;
    background: #111118;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}

.bg-effect {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 200%;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 50px,
        rgba(255, 255, 255, 0.03) 50px,
        rgba(255, 255, 255, 0.03) 100px
    );
    z-index: 0;
    transform: translateY(-50%);
}

.bg-effect.moving {
    animation: scrollBg 2s linear infinite;
}

@keyframes scrollBg {
    from { transform: translateY(-50%); }
    to { transform: translateY(0); }
}

canvas {
    z-index: 1;
}

#ui-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 10;
    pointer-events: none;
}

.hidden {
    display: none !important;
}

.rule-display {
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid var(--primary-color);
    padding: 5px 20px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
    transition: all 0.2s;
}

.rule-display.changed {
    transform: scale(1.1);
    transform-origin: top right;
    border-color: #ff3366;
    box-shadow: 0 0 20px rgba(255, 51, 102, 0.8);
}

.rule-label {
    display: block;
    font-size: 0.8rem;
    color: var(--primary-color);
    letter-spacing: 2px;
}

.rule-text {
    display: block;
    font-size: 1.8rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 5px #fff;
}

.score-hud {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.score-box { display: flex; flex-direction: column; }

.score-label {
    font-family: var(--font-num);
    font-size: 1.2rem;
    color: var(--text-sub);
}

.score-value {
    font-family: var(--font-num);
    font-size: 3rem;
    line-height: 0.8;
    color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.5);
}

.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
    background: rgba(17, 17, 24, 0.9);
    backdrop-filter: blur(5px);
    pointer-events: auto;
    overflow-y: auto; /* 内容がはみ出る場合はスクロール可能に */
    padding: 20px;
    box-sizing: border-box;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

.title-container { text-align: center; margin-bottom: 1rem; }

.main-title {
    font-family: var(--font-num);
    font-size: 3.5rem;
    line-height: 0.9;
    color: var(--primary-color);
    text-shadow: 2px 2px 0 #000, 4px 4px 0px rgba(255,215,0,0.5);
    letter-spacing: 2px;
}

.subtitle {
    font-size: 1.2rem;
    font-weight: bold;
    color: #fff;
    margin-top: 10px;
    letter-spacing: 4px;
}

.instruction-card {
    background: rgba(0,0,0,0.6);
    border: 1px solid #444;
    padding: 1rem;
    border-radius: 10px;
    text-align: center;
    margin-bottom: 1rem;
    width: 90%;
    max-width: 400px;
}

.instruction-card h3 { color: var(--primary-color); margin-bottom: 10px; }

.how-to-flex {
    display: flex; justify-content: center; gap: 15px; margin: 15px 0;
}

.how-to-box {
    border: 2px solid; padding: 5px 10px; border-radius: 8px; font-weight: bold;
    white-space: nowrap; font-size: 0.95rem;
}

.left-box { border-color: var(--color-red); color: var(--color-red); }
.right-box { border-color: var(--color-blue); color: var(--color-blue); }

.warning-text { color: #ff3366; font-weight: bold; font-size: 0.9rem; }

.action-btn {
    font-family: var(--font-main);
    font-size: 1.2rem;
    font-weight: 900;
    padding: 12px 30px;
    border: none;
    border-radius: 50px;
    background: var(--primary-color);
    color: #000;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
    transition: transform 0.1s;
    letter-spacing: 2px;
}

.action-btn:active { transform: scale(0.95); }

.glass-panel {
    background: rgba(20, 20, 30, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 2rem;
    width: 90%;
    max-width: 400px;
    border-radius: 15px;
    height: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.result-title {
    color: var(--primary-color);
    font-size: 2rem;
    text-align: center;
    margin-bottom: 1.5rem;
}

.result-stats {
    display: flex; justify-content: space-around; margin-bottom: 1rem;
    background: rgba(0,0,0,0.5); padding: 15px; border-radius: 10px;
}

.stat-item { text-align: center; }
.stat-label { display: block; font-size: 0.8rem; color: var(--text-sub); }
.stat-value { font-family: var(--font-num); font-size: 2.5rem; color: #fff; line-height: 1; }

.best-score-container {
    text-align: center;
    margin-bottom: 1.5rem;
    position: relative;
}

.best-score-label {
    font-size: 0.9rem;
    color: var(--primary-color);
    font-weight: bold;
}

.new-record {
    position: absolute;
    top: -20px; right: 0;
    background: #ff3366;
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: bold;
    transform: rotate(10deg);
    box-shadow: 0 0 10px #ff3366;
}

.rank-container { text-align: center; margin-bottom: 2rem; }
.rank-label { font-size: 0.9rem; color: var(--text-sub); }
.rank-text { font-size: 1.8rem; font-weight: 900; color: var(--primary-color); }

.action-buttons { display: flex; flex-direction: column; gap: 10px; }

.action-btn.primary { font-size: 1.2rem; padding: 0.8rem; }
.action-btn.secondary, .action-btn.tertiary {
    background: transparent;
    padding: 0.6rem;
    font-size: 1rem;
    box-shadow: none;
}
.action-btn.secondary { border: 2px solid var(--text-sub); color: #fff; }
.action-btn.tertiary { border: 2px solid var(--text-sub); color: var(--text-sub); }

.touch-zone {
    position: absolute; bottom: 0; width: 50%; height: 60%; z-index: 15;
    pointer-events: auto;
    touch-action: manipulation;
}
#touch-left { left: 0; }
#touch-right { right: 0; }

@keyframes blinker { 50% { opacity: 0; } }
.blink { animation: blinker 1s linear infinite; }
 
.rule-alert {
    position: absolute;
    top: 40%; left: 0; width: 100%;
    transform: translateY(-50%);
    text-align: center;
    z-index: 50;
    pointer-events: none;
    background: rgba(17, 17, 24, 0.95);
    border-top: 4px solid #ffd700;
    border-bottom: 4px solid #ffd700;
    padding: 20px 0;
    box-shadow: 0 0 50px rgba(255, 215, 0, 0.3);
    animation: alertSlam 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.rule-alert::before, .rule-alert::after {
    content: ''; position: absolute; left: 0; width: 100%; height: 8px;
    background: repeating-linear-gradient(45deg, #000, #000 10px, #ffd700 10px, #ffd700 20px);
}
.rule-alert::before { top: -12px; }
.rule-alert::after { bottom: -12px; }

.rule-alert.hidden { display: none !important; }
.alert-warning { display: block; font-size: 1.2rem; color: #ffd700; font-family: var(--font-num); font-weight: bold; letter-spacing: 5px; }
.alert-text { display: block; font-size: 4.5rem; color: #fff; font-weight: 900; text-shadow: 4px 4px 0 #ff3366, -3px -3px 0 #00c3ff; line-height: 1.1; }

@keyframes alertSlam { 
    0% { transform: translateY(-50%) scale(1.1); opacity: 0; } 
    100% { transform: translateY(-50%) scale(1); opacity: 1; } 
}
