* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Orbitron', 'Noto Sans JP', sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

@keyframes bg-gradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes pulse-glow {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.02); filter: brightness(1.2); }
    100% { transform: scale(1); filter: brightness(1); }
}

@keyframes pop-toast {
    0% { transform: translate(-50%, -30%) scale(0.5); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -60%) scale(1); opacity: 1; }
}

/* Glitch Animation */
@keyframes glitch-anim-1 {
    0% { clip-path: inset(20% 0 80% 0); transform: translate(-2px, 1px); }
    20% { clip-path: inset(60% 0 10% 0); transform: translate(2px, -1px); }
    40% { clip-path: inset(40% 0 50% 0); transform: translate(1px, 2px); }
    60% { clip-path: inset(80% 0 5% 0); transform: translate(-1px, -2px); }
    80% { clip-path: inset(10% 0 70% 0); transform: translate(2px, 2px); }
    100% { clip-path: inset(30% 0 50% 0); transform: translate(-2px, -1px); }
}
@keyframes glitch-anim-2 {
    0% { clip-path: inset(10% 0 60% 0); transform: translate(2px, -1px); }
    20% { clip-path: inset(30% 0 20% 0); transform: translate(-2px, 2px); }
    40% { clip-path: inset(70% 0 10% 0); transform: translate(1px, -2px); }
    60% { clip-path: inset(20% 0 50% 0); transform: translate(-1px, 1px); }
    80% { clip-path: inset(50% 0 30% 0); transform: translate(2px, -1px); }
    100% { clip-path: inset(5% 0 80% 0); transform: translate(-2px, 2px); }
}

body {
    background: linear-gradient(-45deg, #020617, #1e1b4b, #0f172a, #312e81);
    background-size: 400% 400%;
    animation: bg-gradient 15s ease infinite;
    color: #f8fafc;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    touch-action: none;
}

#background-fx {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 30px 30px;
    z-index: 0;
}

#game-container {
    position: relative;
    width: 100vw;
    max-width: 600px;
    height: 100vh;
    background: transparent;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    overflow: hidden;
    z-index: 1;
}

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

header {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stats {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.stat-box {
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 10px 15px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    flex: 1;
}

.stat-box .label {
    font-size: 0.7rem;
    color: #94a3b8;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.stat-box .value {
    font-size: 1.5rem;
    font-weight: 900;
    background: linear-gradient(to right, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#level {
    background: linear-gradient(to right, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#life {
    background: none;
    -webkit-text-fill-color: #ef4444;
    text-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

.rule-box {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(20px);
    border: 2px solid;
    padding: 15px;
    border-radius: 20px;
    text-align: center;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: pulse-glow 2s infinite;
}

.rule-box.color-rule {
    border-color: rgba(59, 130, 246, 0.8);
    box-shadow: 0 0 25px rgba(59, 130, 246, 0.5), inset 0 0 15px rgba(59, 130, 246, 0.3);
}

.rule-box.color-rule #current-rule {
    color: #93c5fd;
    text-shadow: 0 0 15px rgba(59, 130, 246, 0.8);
}

.rule-box.text-rule {
    border-color: rgba(236, 72, 153, 0.8);
    box-shadow: 0 0 25px rgba(236, 72, 153, 0.5), inset 0 0 15px rgba(236, 72, 153, 0.3);
}

.rule-box.text-rule #current-rule {
    color: #f9a8d4;
    text-shadow: 0 0 15px rgba(236, 72, 153, 0.8);
}

.rule-label {
    font-size: 0.85rem;
    color: #cbd5e1;
    display: block;
    margin-bottom: 5px;
    letter-spacing: 1px;
}

#current-rule {
    font-size: 2.2rem;
    font-weight: 900;
    letter-spacing: 4px;
}

#controls-container {
    position: absolute;
    bottom: 30px;
    left: 0;
    width: 100%;
    height: 90px;
    display: flex;
    pointer-events: auto;
    padding: 0 20px;
    gap: 15px;
}

.color-btn {
    flex: 1;
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: 24px;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5), inset 0 2px 10px rgba(255,255,255,0.5);
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.color-btn::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 50%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.4), rgba(255,255,255,0));
    pointer-events: none;
}

.color-btn:active {
    transform: translateY(12px) scale(0.95);
    box-shadow: 0 2px 5px rgba(0,0,0,0.5), inset 0 4px 15px rgba(0,0,0,0.6);
    filter: brightness(1.3);
}

.btn-red { background: linear-gradient(135deg, #f87171, #dc2626); border-color: #fca5a5; }
.btn-blue { background: linear-gradient(135deg, #60a5fa, #2563eb); border-color: #93c5fd; }
.btn-green { background: linear-gradient(135deg, #4ade80, #16a34a); border-color: #86efac; }
.btn-yellow { background: linear-gradient(135deg, #facc15, #ca8a04); border-color: #fef08a; }

#level-up-toast {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: 900;
    color: #fbbf24;
    text-shadow: 0 0 30px rgba(251, 191, 36, 0.8), 2px 2px 0px #000;
    pointer-events: none;
    z-index: 100;
    opacity: 0;
}

#level-up-toast.show {
    animation: pop-toast 1.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* タイトル・ゲームオーバー画面共通設定 */
#start-screen, #game-over {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(15px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    z-index: 20;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

#start-screen.hidden, #game-over.hidden {
    opacity: 0;
    pointer-events: none;
}

.glitch-text, .glitch-text-small {
    position: relative;
    color: white;
    font-weight: 900;
    text-align: center;
    margin-bottom: 10px;
}

.glitch-text {
    font-size: 4rem;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.glitch-text-small {
    font-size: 3.5rem;
    color: transparent;
    -webkit-text-stroke: 2px #ef4444;
    background: linear-gradient(to bottom, #ef4444, #991b1b);
    -webkit-background-clip: text;
    text-shadow: 0 0 30px rgba(239, 68, 68, 0.4);
}

.glitch-text::before, .glitch-text::after,
.glitch-text-small::before, .glitch-text-small::after {
    content: attr(data-text);
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: transparent;
}

.glitch-text::before {
    left: 3px;
    text-shadow: -2px 0 #ff00c1;
    animation: glitch-anim-1 2s infinite linear alternate-reverse;
}

.glitch-text::after {
    left: -3px;
    text-shadow: -2px 0 #00fff9;
    animation: glitch-anim-2 3s infinite linear alternate-reverse;
}

.glitch-text-small::before {
    left: 2px;
    text-shadow: -2px 0 #ff00c1;
    -webkit-text-stroke: 0px;
    color: #ef4444;
    animation: glitch-anim-1 2s infinite linear alternate-reverse;
}

.glitch-text-small::after {
    left: -2px;
    text-shadow: 2px 0 #00fff9;
    -webkit-text-stroke: 0px;
    color: #ef4444;
    animation: glitch-anim-2 3s infinite linear alternate-reverse;
}

.subtitle {
    font-size: 1.2rem;
    color: #94a3b8;
    letter-spacing: 5px;
    margin-bottom: 40px;
}

.tutorial-box {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 40px;
    text-align: center;
    max-width: 90%;
}

.tutorial-box h3 {
    color: #cbd5e1;
    margin-bottom: 15px;
    font-size: 1.2rem;
    letter-spacing: 2px;
}

.tutorial-box p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 10px;
    color: #f8fafc;
}

.text-blue { color: #60a5fa; font-weight: bold; }
.text-pink { color: #f472b6; font-weight: bold; }

.final-score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 40px;
    background: rgba(255,255,255,0.05);
    padding: 20px 40px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.1);
}

.final-score-label {
    font-size: 1.2rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 4px;
    margin-bottom: 10px;
}

#final-score {
    font-size: 4rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 20px rgba(255,255,255,0.5);
}

#start-btn, #restart-btn {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border: none;
    padding: 20px 50px;
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: 2px;
    color: white;
    border-radius: 40px;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4), inset 0 2px 10px rgba(255,255,255,0.4);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#start-btn:hover, #restart-btn:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 15px 40px rgba(99, 102, 241, 0.6), inset 0 2px 10px rgba(255,255,255,0.4);
}

#start-btn:active, #restart-btn:active {
    transform: translateY(2px) scale(0.98);
}

/* Countdown */
#countdown-display {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(2, 6, 23, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    pointer-events: auto;
    transition: opacity 0.3s;
}
#countdown-display.hidden {
    opacity: 0;
    pointer-events: none;
}
#countdown-text {
    font-size: 8rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 40px rgba(236, 72, 153, 0.8), 4px 4px 0px #000;
    animation: pulse-glow 0.8s infinite;
}

/* 統一戻るボタンの共通スタイル */
.back-to-portal-game {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px 18px;
    border-radius: 50px;
    color: #fff;
    text-decoration: none;
    font-family: 'Orbitron', 'Noto Sans JP', sans-serif;
    font-size: 0.9rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
}

.back-to-portal-game:hover {
    background: rgba(15, 23, 42, 0.8);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 243, 255, 0.3);
    border-color: rgba(0, 243, 255, 0.5);
}

@media (max-width: 768px) {
    .back-to-portal-game {
        top: 15px;
        left: 15px;
        padding: 8px 14px;
        font-size: 0.8rem;
    }
}
