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

body {
    background: #000;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    font-family: 'Outfit', monospace;
}

#game-canvas {
    display: block;
    image-rendering: pixelated;
    cursor: none;
}

#ui-container {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 100;
    pointer-events: none;
}

#ally-status {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ally-card-2d {
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(0, 255, 255, 0.4);
    border-radius: 4px;
    padding: 6px 10px;
    min-width: 100px;
    font-family: monospace;
    font-size: 0.7rem;
    color: #ccc;
}

/* ULT Cut-in */
.ult-cutin {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    color: white;
    background: rgba(0, 0, 0, 0.55);
    overflow: hidden;
    transition: opacity 0.5s;
    pointer-events: none;
}

.stripe-bg {
    position: absolute;
    width: 200%;
    height: 110px;
    background: linear-gradient(90deg, #ff00ff, #00ffff, #ffff00);
    transform: rotate(-5deg);
    opacity: 0.85;
    box-shadow: 0 0 60px #fff;
}

.cutin-text {
    position: absolute;
    left: 8%;
    font-size: 5.5rem;
    font-weight: 900;
    font-style: italic;
    text-shadow: 4px 4px 0 #000, -2px -2px 0 #0ff;
    animation: slideInLeft 0.3s ease-out forwards;
    letter-spacing: 4px;
}

.speech-text {
    position: absolute;
    right: 10%;
    font-size: 2.6rem;
    font-weight: bold;
    background: #000;
    padding: 8px 36px;
    transform: skewX(-15deg);
    border: 3px solid #fff;
    animation: slideInRight 0.4s ease-out forwards;
    letter-spacing: 2px;
}

.character-portrait {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    background-repeat: no-repeat;
    background-position: left top;
    opacity: 0;
    animation: portraitZoomInCenter 0.3s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
    z-index: 5;
    image-rendering: pixelated; /* Keep pixel art crisp */
}

.character-portrait.tank {
    background-image: url('../assets/characters/tank_ult.png');
    background-size: 700% 100%;
    filter: drop-shadow(4px 4px 0 #4444ff) drop-shadow(-4px -4px 0 #00ffff);
}
.character-portrait.attacker {
    background-image: url('../assets/characters/attacker_ult.png');
    background-size: 600% 100%;
    filter: drop-shadow(4px 4px 0 #ffaa00) drop-shadow(-4px -4px 0 #ffff00);
}
.character-portrait.flanker {
    background-image: url('../assets/characters/flanker_ult.png');
    background-size: 800% 100%;
    filter: drop-shadow(4px 4px 0 #00ffaa) drop-shadow(-4px -4px 0 #00ff00);
}

@keyframes slideInLeft {
    from { transform: translateX(-200%) skewX(-20deg); opacity: 0; }
    to   { transform: translateX(0)     skewX(-20deg); opacity: 1; }
}
@keyframes slideInRight {
    from { transform: translateX(200%) skewX(-15deg); opacity: 0; }
    to   { transform: translateX(0)    skewX(-15deg); opacity: 1; }
}

@keyframes portraitZoomInCenter {
    from { transform: translate(-50%, -40%) scale(0.85); opacity: 0; }
    to   { transform: translate(-50%, -50%) scale(1.0); opacity: 1; }
}

/* ── Init Screen ── */
#init-screen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    color: #fff;
    cursor: pointer;
    font-size: min(8vw, 6vh);
    font-weight: bold;
    letter-spacing: 6px;
    transition: opacity 0.4s ease;
}

#init-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.blink-text {
    animation: flash 1.5s infinite;
}

/* ── Title Screen ── */
#title-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, #001122 0%, #000000 100%);
    color: white;
    transition: opacity 0.8s ease;
}

#title-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

#title-screen .glitch {
    font-size: min(15vw, 12vh); /* Responsive font size */
    font-weight: 900;
    font-style: italic;
    color: #fff;
    text-shadow: 4px 4px 0 #ff00ff, -4px -4px 0 #00ffff;
    letter-spacing: 8px;
    margin-bottom: 2vh;
}

#title-screen .subtitle {
    font-size: min(4vw, 3vh);
    color: #00ffcc;
    letter-spacing: 4px;
    margin-bottom: 4vh;
    text-shadow: 0 0 10px rgba(0,255,204,0.5);
}

#title-screen #high-score-box {
    font-size: 1.2rem;
    color: #fff700;
    text-shadow: 0 0 10px rgba(255, 247, 0, 0.5);
    margin-bottom: 5vh;
    font-weight: bold;
    letter-spacing: 2px; /* Fixed syntax error here */
}

#title-screen .start-btn { /* Fixed syntax error here */
    font-size: 1.5rem;
    padding: 15px 40px;
    border: 2px solid #0ff;
    color: #0ff;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
}

#title-screen .start-btn:hover {
    background: #0ff;
    color: #000;
    box-shadow: 0 0 20px #0ff;
}

@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ── Ultimate Cut-in (Base / PC - EXACT ORIGINAL) ── */
.ult-cutin {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 15000;
    color: white;
    background: rgba(0, 0, 0, 0.55);
    overflow: hidden;
    transition: opacity 0.5s;
    pointer-events: none;
}

.ult-cutin .stripe-bg {
    position: absolute;
    width: 200%;
    height: 110px;
    background: linear-gradient(90deg, #ff00ff, #00ffff, #ffff00);
    transform: rotate(-5deg);
    opacity: 0.85;
    box-shadow: 0 0 60px #fff;
}

.ult-cutin .cutin-text {
    position: absolute;
    top: 12%;
    left: 8%;
    font-size: 5.5rem;
    font-weight: 900;
    font-style: italic;
    text-shadow: 4px 4px 0 #000, -2px -2px 0 #0ff;
    animation: slideInLeft 0.3s ease-out forwards;
    letter-spacing: 4px;
}

.ult-cutin .speech-text {
    position: absolute;
    bottom: 18%;
    right: 10%;
    font-size: 2.6rem;
    font-weight: bold;
    background: #000;
    padding: 8px 36px;
    transform: skewX(-15deg);
    border: 3px solid #fff;
    animation: slideInRight 0.4s ease-out forwards;
    letter-spacing: 2px;
    z-index: 20; /* セリフをキャラの手前に */
}

.ult-cutin .character-portrait {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 380px;
    height: 380px;
    background-repeat: no-repeat;
    background-position: left top;
    opacity: 0;
    animation: portraitZoomInCenter 0.3s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
    z-index: 5;
    image-rendering: pixelated; 
}

/* Character Portrait Images */
.character-portrait.tank {
    background-image: url('../assets/characters/tank_ult.png');
    background-size: 700% 100%;
    filter: drop-shadow(4px 4px 0 #4444ff) drop-shadow(-4px -4px 0 #00ffff);
}
.character-portrait.attacker {
    background-image: url('../assets/characters/attacker_ult.png');
    background-size: 600% 100%;
    filter: drop-shadow(4px 4px 0 #ffaa00) drop-shadow(-4px -4px 0 #ffff00);
}
.character-portrait.flanker {
    background-image: url('../assets/characters/flanker_ult.png');
    background-size: 800% 100%;
    filter: drop-shadow(4px 4px 0 #00ffaa) drop-shadow(-4px -4px 0 #00ff00);
}

@keyframes slideInLeft {
    from { transform: translateX(-200%) skewX(-20deg); opacity: 0; }
    to   { transform: translateX(0)     skewX(-20deg); opacity: 1; }
}
@keyframes slideInRight {
    from { transform: translateX(200%) skewX(-15deg); opacity: 0; }
    to   { transform: translateX(0)    skewX(-15deg); opacity: 1; }
}
@keyframes portraitZoomInCenter {
    from { transform: translate(-50%, -40%) scale(0.85); opacity: 0; }
    to   { transform: translate(-50%, -50%) scale(1.0); opacity: 1; }
}

/* ── Ultimate Cut-in (Mobile Specific) ── */
.is-mobile .ult-cutin {
    z-index: 15000 !important;
    overflow: hidden !important;
    background: rgba(0, 0, 0, 0.82) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important; /* Mobile specific */
    transition: opacity 0.5s ease !important;
    pointer-events: auto !important; /* Allow interaction on mobile if needed */
}

.is-mobile .ult-cutin .stripe-bg {
    position: absolute !important;
    width: 200% !important;
    height: 100% !important;
    background: repeating-linear-gradient(
        45deg,
        rgba(0, 255, 255, 0.05),
        rgba(0, 255, 255, 0.05) 40px,
        transparent 40px,
        transparent 80px
    ) !important;
    animation: stripeMove 2s linear infinite !important;
    transform: none !important; /* Override PC transform */
    opacity: 1 !important; /* Override PC opacity */
    box-shadow: none !important; /* Override PC box-shadow */
}

@keyframes stripeMove {
    from { transform: translateX(0); }
    to   { transform: translateX(-80px); }
}

.is-mobile .ult-cutin .character-portrait {
    position: absolute !important;
    bottom: -30px !important; /* Much higher so it doesn't get cut off */
    left: -40px !important; 
    width: min(70vw, 400px) !important; /* Considerably smaller portrait */
    height: min(70vw, 400px) !important;
    background-size: auto 100% !important;
    background-repeat: no-repeat !important;
    background-position: bottom left !important; /* Mobile specific */
    filter: drop-shadow(0 0 30px rgba(0,255,255,0.5)) !important; /* Mobile specific */
    z-index: 15001 !important;
    opacity: 1.0 !important; /* Full opacity on mobile layout */
    animation: portraitSlide 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards !important;
    image-rendering: pixelated !important;
    top: auto !important; /* Override PC top */
    transform: none !important; /* Override PC transform */
}

/* Character Portrait Images (Mobile specific overrides for background-position/size if needed, but shared paths are fine) */
/* The shared .character-portrait.tank/attacker/flanker rules above already handle the image paths.
   The !important flags in .is-mobile .ult-cutin .character-portrait will override generic properties.
   If specific background-size/position are needed for mobile, they would go here with !important.
   For now, the shared rules are sufficient for the image paths. */

@keyframes portraitSlide {
    to { left: 0; }
}

.is-mobile .ult-cutin .cutin-text {
    position: absolute !important;
    top: 35% !important;
    left: 8% !important;
    font-size: min(15vw, 70px) !important; /* Smaller text */
    font-weight: 900 !important;
    color: #fff !important;
    text-shadow: 0 0 30px #f0f !important; /* Mobile specific */
    letter-spacing: 15px !important;
    z-index: 15002 !important;
    margin: 0 !important;
    animation: none !important; /* Remove PC animation */
    transform: none !important; /* Override PC transform */
    font-style: normal !important; /* Override PC font-style */
}

.is-mobile .ult-cutin .speech-text {
    position: absolute !important;
    bottom: 15% !important; /* Mobile specific */
    right: 5% !important; /* Mobile specific */
    margin-top: 0 !important;
    background: rgba(0, 0, 0, 0.8) !important;
    color: #fff700 !important;
    padding: 10px 30px !important; /* Mobile specific */
    font-size: min(4vw, 1.2rem) !important; /* Smaller text */
    border-right: 6px solid #fff700 !important; /* Mobile specific */
    border: none !important; /* Override PC border */
    z-index: 15003 !important;
    animation: speechSlide 0.6s 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28) both !important; /* Mobile specific animation */
    transform: none !important; /* Override PC transform */
    font-weight: bold !important;
    letter-spacing: normal !important;
}

@keyframes speechSlide {
    from { transform: translateX(100px); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

/* ── Orientation Overlay ── */
#rotate-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    color: #fff;
    display: none; /* Hidden by default */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20000;
    text-align: center;
    padding: 20px;
}

@media (orientation: portrait) {
    #rotate-overlay {
        display: flex;
    }
}

.rotate-icon {
    width: 60px;
    height: 100px;
    border: 4px solid #fff;
    border-radius: 8px;
    margin-bottom: 30px;
    position: relative;
    animation: rotateDevice 2s ease-in-out infinite;
}

.rotate-icon::after {
    content: '';
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    border: 2px solid #fff;
    border-radius: 50%;
}

@keyframes rotateDevice {
    0%   { transform: rotate(0deg); }
    30%  { transform: rotate(90deg); }
    70%  { transform: rotate(90deg); }
    100% { transform: rotate(0deg); }
}

#rotate-overlay p {
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: 2px;
    color: #0ff;
}

/* ── Mobile Controls ── */
#mobile-controls {
    position: fixed;
    bottom: 95px; /* Above the HUD bar (80px) */
    right: 40px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

#mobile-controls button {
    background: rgba(0, 0, 0, 0.4);
    color: #0ff;
    border: 1.5px solid rgba(0, 255, 255, 0.5);
    padding: 8px 15px; /* Smaller */
    font-size: 0.9rem; /* Smaller */
    font-family: inherit;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.2);
    touch-action: manipulation;
    transition: all 0.2s ease;
}

#mobile-controls button:active { /* Fixed syntax error here */
    background: #0ff;
    color: #000;
}