* {
    box-sizing: border-box;
}

html {
    width: 100%;
    height: 100%;
    min-height: 100%;
}

body {
    margin: 0;

    min-height: 100vh;
    min-height: 100svh;

    overflow-x: hidden;

    font-family:
        "Noto Sans JP",
        sans-serif;

    color: #283126;

    background:
        radial-gradient(circle at 50% -10%,
            #edf5e5 0%,
            #dcebcf 38%,
            #c8dfb8 100%);

    transition:
        background 0.35s ease;
}

button {
    font: inherit;
}


/* ========================================
   GAME START
======================================== */

.start-message {
    position: fixed;

    left: 50%;
    top: 42%;

    z-index: 8000;

    opacity: 0;
    visibility: hidden;

    pointer-events: none;

    white-space: nowrap;

    color: #4c5d42;

    font-size: 58px;
    font-weight: 900;

    letter-spacing:
        0.05em;

    text-shadow:
        0 4px 0 #fff,
        4px 0 0 #fff,
        -4px 0 0 #fff,
        0 -4px 0 #fff,
        0 8px 17px rgba(52, 68, 45, 0.22);

    transform:
        translate(-50%, -50%) scale(0.4);
}


.start-message.show {
    visibility: visible;

    animation:
        startMessagePop 1.65s cubic-bezier(.18, .85, .24, 1) forwards;
}


@keyframes startMessagePop {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.25);
    }

    17% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scale(1.25);
    }

    32% {
        transform:
            translate(-50%, -50%) scale(0.92);
    }

    47% {
        transform:
            translate(-50%, -50%) scale(1.04);
    }

    76% {
        opacity: 1;
    }

    100% {
        opacity: 0;

        transform:
            translate(-50%, -72%) scale(0.88);
    }
}

/* ========================================
   FEVER BACKGROUND
======================================== */

body.fever-active {
    background:
        radial-gradient(circle at 50% -5%,
            #fff8c9 0%,
            #edf2c1 38%,
            #c9e1ae 100%);
}


/* ========================================
   MAIN
======================================== */

.game-wrap {
    min-height: 100vh;

    display: flex;

    justify-content: center;

    padding:
        18px 18px 30px;
}


.game-panel {
    width: 100%;

    max-width: 980px;

    text-align: center;
}


/* ========================================
   TITLE
======================================== */

.game-title {
    margin:
        0 0 12px;

    line-height: 0.9;

    white-space: nowrap;
}


.title-ohagi {
    display: inline-block;

    font-size: 46px;

    font-weight: 900;

    letter-spacing:
        0.035em;

    color: #313a2d;
}


.title-drop {
    display: inline-block;

    margin-left: 9px;

    font-size: 31px;

    font-weight: 900;

    letter-spacing:
        0.18em;

    color: #709364;
}


/* ========================================
   LAYOUT
======================================== */

.game-layout {
    display: grid;

    grid-template-columns:
        205px 300px 175px;

    justify-content: center;

    align-items: start;

    gap: 18px;
}


/* ========================================
   CHARACTER PANEL
======================================== */

.character-panel {
    display: flex;

    flex-direction: column;

    gap: 13px;
}


.character-card {
    width: 205px;

    padding:
        8px 10px 11px;

    overflow: visible;

    border:
        1px solid rgba(67, 82, 59, 0.20);

    border-radius: 20px;

    background:
        rgba(255, 255, 250, 0.64);

    box-shadow:
        0 10px 28px rgba(55, 74, 48, 0.08);
}


.tomioka-card {
    opacity: 0.94;
}


/* ========================================
   CHARACTER WRAP
======================================== */

.character-face-wrap {
    position: relative;

    width: 100%;

    max-width: 180px;

    margin:
        0 auto 5px;
}


.character-face {
    display: block;

    width: 100%;

    height: 148px;

    object-fit: contain;

    object-position: center;

    transform-origin:
        center bottom;

    animation:
        characterIdle 1.35s ease-in-out infinite;
}


@keyframes characterIdle {

    0%,
    100% {
        transform:
            translateY(0) scale(1);
    }

    42% {
        transform:
            translateY(-4px) scale(1.01);
    }

    56% {
        transform:
            translateY(-7px) scale(1.025);
    }

    72% {
        transform:
            translateY(0) scaleY(0.985);
    }
}


/* ========================================
   HAPPY
======================================== */

.character-face.happy {
    animation:
        happyBounce 0.46s ease-in-out infinite;
}


@keyframes happyBounce {

    0%,
    100% {
        transform:
            translateY(0) scale(1);
    }

    48% {
        transform:
            translateY(-11px) scale(1.055);
    }
}


/* ========================================
   FEVER JUMP
======================================== */

.character-face.fever-jump {
    animation:
        feverCharacterJump 0.40s ease-out;
}


@keyframes feverCharacterJump {

    0% {
        transform:
            translateY(0) scale(1);
    }

    32% {
        transform:
            translateY(-17px) scale(1.09);
    }

    58% {
        transform:
            translateY(2px) scale(0.96);
    }

    78% {
        transform:
            translateY(-5px) scale(1.03);
    }

    100% {
        transform:
            translateY(0) scale(1);
    }
}


/* ========================================
   ANGRY
======================================== */

.character-face.angry {
    animation:
        angryShake 0.11s linear infinite;
}


@keyframes angryShake {

    0% {
        transform:
            translateX(0) rotate(0);
    }

    25% {
        transform:
            translateX(-6px) rotate(-1.5deg);
    }

    50% {
        transform:
            translateX(6px) rotate(1.5deg);
    }

    75% {
        transform:
            translateX(-5px) rotate(-1deg);
    }

    100% {
        transform:
            translateX(0) rotate(0);
    }
}


/* ========================================
   CHARACTER EFFECTS
======================================== */

.character-effects {
    position: absolute;

    inset:
        -10px -18px -6px;

    overflow: visible;

    pointer-events: none;

    z-index: 5;
}


.character-effect {
    position: absolute;

    z-index: 5;

    opacity: 0;

    pointer-events: none;

    user-select: none;

    will-change:
        transform,
        opacity;
}


/* HEART */

.character-effect.heart {
    font-size: 25px;

    animation:
        heartFloat 1.15s ease-out forwards;
}


@keyframes heartFloat {

    0% {
        opacity: 0;

        transform:
            translate(-50%, 10px) scale(0.35) rotate(-8deg);
    }

    18% {
        opacity: 1;

        transform:
            translate(-50%, 0) scale(1.05);
    }

    65% {
        opacity: 1;
    }

    100% {
        opacity: 0;

        transform:
            translate(calc(-50% + var(--float-x)),
                -65px) scale(1.18) rotate(var(--rotate));
    }
}


/* SWEAT */

.character-effect.sweat {
    font-size: 27px;

    animation:
        sweatPop 0.90s ease-out forwards;
}


@keyframes sweatPop {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.3);
    }

    20% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scale(1.12);
    }

    70% {
        opacity: 1;
    }

    100% {
        opacity: 0;

        transform:
            translate(calc(-50% + var(--float-x)),
                23px) scale(0.92);
    }
}


/* ANGER */

.character-effect.anger {
    font-size: 30px;

    animation:
        angerPop 0.72s ease-out forwards;
}


@keyframes angerPop {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.3) rotate(-12deg);
    }

    20% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scale(1.25) rotate(7deg);
    }

    42% {
        transform:
            translate(-54%, -50%) scale(0.95) rotate(-5deg);
    }

    60% {
        transform:
            translate(-46%, -50%) scale(1.08) rotate(3deg);
    }

    100% {
        opacity: 0;

        transform:
            translate(-50%, -65%) scale(1.05);
    }
}


/* SPARKLE */

.character-effect.sparkle {
    font-size: 23px;

    animation:
        characterSparkle 0.95s ease-out forwards;
}

/* ========================================
   GAME OVER SANEMI POYA
   満腹でぽやぽや
======================================== */

.character-effect.poya {
    font-size: 27px;

    color:
        rgba(255, 255, 255, 0.92);

    text-shadow:
        0 0 7px rgba(255, 255, 255, 0.95),
        0 0 13px rgba(235, 205, 155, 0.55);

    animation:
        sanemiPoyaFloat 2s ease-out forwards;
}


.character-effect.poya-small {
    font-size: 18px;

    color:
        rgba(255, 255, 255, 0.78);

    text-shadow:
        0 0 6px rgba(255, 255, 255, 0.92);

    animation:
        sanemiPoyaFloat 2.15s ease-out forwards;
}


.character-effect.poya-sparkle {
    font-size: 20px;

    color:
        #fff0b7;

    text-shadow:
        0 0 7px #fff,
        0 0 13px rgba(255, 210, 108, 0.72);

    animation:
        sanemiPoyaSparkle 1.9s ease-out forwards;
}


@keyframes sanemiPoyaFloat {

    0% {
        opacity: 0;

        transform:
            translate(-50%, 5px) scale(0.35);
    }

    20% {
        opacity: 0.85;

        transform:
            translate(-50%, 0) scale(1);
    }

    70% {
        opacity: 0.7;
    }

    100% {
        opacity: 0;

        transform:
            translate(calc(-50% + var(--float-x)),
                -46px) scale(1.18) rotate(var(--rotate));
    }
}


@keyframes sanemiPoyaSparkle {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.2);
    }

    25% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scale(1.25);
    }

    65% {
        opacity: 0.8;
    }

    100% {
        opacity: 0;

        transform:
            translate(calc(-50% + var(--float-x)),
                -35px) scale(0.65) rotate(45deg);
    }
}

@keyframes characterSparkle {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.15) rotate(0);
    }

    25% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scale(1.3) rotate(20deg);
    }

    70% {
        opacity: 1;
    }

    100% {
        opacity: 0;

        transform:
            translate(calc(-50% + var(--float-x)),
                -45px) scale(0.7) rotate(60deg);
    }
}


/* ========================================
   SPEECH
======================================== */

.speech {
    min-height: 45px;

    display: flex;

    align-items: center;

    justify-content: center;

    padding:
        7px 10px;

    border-radius: 13px;

    background:
        rgba(255, 255, 255, 0.62);

    color: #343d30;

    font-size: 13px;

    font-weight: 700;

    line-height: 1.45;
}


/* ========================================
   BOARD
======================================== */

.board-area {
    position: relative;
}


#gameCanvas {
    display: block;

    width: 300px;

    height: 600px;

    border:
        1.5px solid rgba(77, 65, 48, 0.56);

    border-radius: 14px;

    background: #fffaf0;

    box-shadow:
        0 12px 32px rgba(63, 51, 35, 0.11);

    transition:
        box-shadow 0.25s ease,
        filter 0.25s ease;
}


body.fever-active #gameCanvas {
    box-shadow:
        0 0 0 5px rgba(255, 214, 65, 0.18),

        0 0 42px rgba(255, 205, 43, 0.48),

        0 14px 32px rgba(72, 57, 24, 0.12);
}


/* ========================================
   HUD
======================================== */

.info-panel {
    width: 175px;

    padding:
        8px 4px;

    display: flex;

    flex-direction: column;

    gap: 19px;

    text-align: left;
}


.hud-block {
    padding:
        4px 2px;
}


.hud-label {
    color:
        rgba(45, 58, 40, 0.57);

    font-size: 10px;

    font-weight: 900;

    letter-spacing:
        0.20em;
}


/* ========================================
   SCORE
======================================== */

.score-value {
    display: inline-block;

    margin-top: 3px;

    position: relative;

    color: #2d3629;

    font-size: 36px;

    font-weight: 900;

    letter-spacing:
        -0.025em;

    line-height: 1;

    transform-origin:
        left center;
}


.score-value.score-pop {
    animation:
        scoreBounce 0.45s ease-out;
}


@keyframes scoreBounce {

    0% {
        transform:
            translateY(0) scale(1);
    }

    30% {
        transform:
            translateY(-7px) scale(1.28);
    }

    53% {
        transform:
            translateY(2px) scale(0.94);
    }

    75% {
        transform:
            translateY(-2px) scale(1.06);
    }

    100% {
        transform:
            translateY(0) scale(1);
    }
}


body.fever-active .score-value {
    color: #c5790a;

    text-shadow:
        0 0 14px rgba(255, 198, 37, 0.42);
}


body.fever-active .score-value.score-pop {
    animation:
        feverScoreBounce 0.48s ease-out;
}


@keyframes feverScoreBounce {

    0% {
        transform:
            translateY(0) scale(1);
    }

    25% {
        transform:
            translateY(-11px) scale(1.48) rotate(-2deg);
    }

    52% {
        transform:
            translateY(3px) scale(0.90) rotate(1deg);
    }

    75% {
        transform:
            translateY(-3px) scale(1.11);
    }

    100% {
        transform:
            translateY(0) scale(1);
    }
}


/* ========================================
   FEVER
======================================== */

.fever-header {
    display: flex;

    align-items: center;

    justify-content: space-between;

    gap: 10px;
}


#feverValue {
    font-size: 15px;

    font-weight: 900;
}


.fever-bar {
    height: 11px;

    margin-top: 7px;

    overflow: hidden;

    border-radius: 999px;

    background:
        rgba(50, 65, 44, 0.12);
}


.fever-bar-fill {
    width: 0%;

    height: 100%;

    border-radius: inherit;

    background:
        linear-gradient(90deg,
            #e8a62d,
            #ffd353,
            #fff2a3);

    box-shadow:
        0 0 9px rgba(255, 191, 38, 0.45);

    transition:
        width 0.22s ease;
}


body.fever-active .fever-block {
    animation:
        feverHudPulse 0.48s ease-in-out infinite alternate;
}


@keyframes feverHudPulse {

    from {
        transform:
            scale(1);
    }

    to {
        transform:
            scale(1.045);
    }
}


/* ========================================
   NEXT
======================================== */

.next-block {
    text-align: center;
}


.next-block .hud-label {
    display: block;

    text-align: left;
}


#nextCanvas {
    display: block;

    width: 108px;

    height: 108px;

    margin:
        2px auto 0;
}


/* ========================================
   CONTROL HELP
======================================== */

.controls {
    padding-top: 10px;

    border-top:
        1px solid rgba(54, 70, 48, 0.12);

    color:
        rgba(42, 52, 38, 0.69);

    font-size: 11px;

    line-height: 1.7;
}


.key-help {
    margin:
        3px 0;
}


.key-help span {
    display: inline-block;

    min-width: 69px;

    margin-right: 3px;

    color:
        rgba(47, 56, 44, 0.84);

    font-weight: 900;
}


.pause-btn {
    width: 100%;

    margin-bottom: 7px;

    padding:
        8px 7px;

    cursor: pointer;

    border:
        1px solid rgba(74, 69, 55, 0.30);

    border-radius: 10px;

    background:
        rgba(255, 252, 239, 0.65);

    color: #4b4335;

    font-size: 11px;

    font-weight: 900;

    letter-spacing:
        0.12em;
}


/* ========================================
   GENERAL EVENT
======================================== */

.event-message {
    position: absolute;

    left: 50%;

    top: 44%;

    width: 88%;

    z-index: 80;

    padding:
        13px 10px;

    opacity: 0;

    pointer-events: none;

    transform:
        translate(-50%, -50%) scale(0.82);

    border-radius: 16px;

    background:
        rgba(255, 253, 241, 0.95);

    color: #36452f;

    box-shadow:
        0 10px 25px rgba(47, 63, 40, 0.16);

    font-size: 20px;

    font-weight: 900;

    line-height: 1.4;

    white-space: pre-line;

    transition:
        opacity 0.15s ease,
        transform 0.15s ease;
}


.event-message.show {
    opacity: 1;

    transform:
        translate(-50%, -50%) scale(1);
}


/* ========================================
   WATER FLASH
======================================== */

.water-flash {
    position: fixed;

    inset: 0;

    z-index: 3500;

    opacity: 0;

    visibility: hidden;

    pointer-events: none;

    background:
        radial-gradient(circle at center,
            rgba(235, 252, 255, 0.82),
            rgba(79, 185, 229, 0.35) 48%,
            rgba(23, 105, 151, 0.18) 100%);
}


.water-flash.show {
    visibility: visible;

    animation:
        waterFlash 0.48s ease-out forwards;
}


@keyframes waterFlash {
    0% {
        opacity: 0;
    }

    12% {
        opacity: 0.95;
    }

    36% {
        opacity: 0.42;
    }

    100% {
        opacity: 0;
    }
}


/* ========================================
   WATER EFFECT ROOT
======================================== */

.water-effects {
    position: fixed;

    inset: 0;

    z-index: 4600;

    overflow: hidden;

    pointer-events: none;
}


/* WATER DROPLET */

.water-particle {
    position: fixed;

    pointer-events: none;

    border-radius:
        55% 45% 60% 40%;

    background:
        linear-gradient(160deg,
            rgba(255, 255, 255, 0.98) 0%,
            rgba(190, 241, 255, 0.96) 22%,
            rgba(90, 199, 236, 0.92) 60%,
            rgba(28, 135, 196, 0.82) 100%);

    box-shadow:
        0 0 10px rgba(145, 228, 255, 0.75),
        0 0 18px rgba(88, 192, 235, 0.42);

    transform-origin: center center;

    animation:
        waterParticleFly var(--duration) cubic-bezier(.16, .72, .28, 1) forwards;
}

@keyframes waterParticleFly {
    0% {
        opacity: 0;
        transform:
            translate(-50%, -50%) scale(0.18) rotate(0deg);
    }

    14% {
        opacity: 1;
    }

    42% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform:
            translate(calc(-50% + var(--dx)),
                calc(-50% + var(--dy))) scale(0.72) rotate(var(--rotate));
    }
}





@keyframes waterParticleFly {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.2);
    }

    14% {
        opacity: 1;
    }

    100% {
        opacity: 0;

        transform:
            translate(calc(-50% + var(--dx)),
                calc(-50% + var(--dy))) scale(0.7) rotate(var(--rotate));
    }
}


/* WATER RING */

.water-ring {
    position: fixed;

    width: 90px;

    height: 34px;

    z-index: 4550;

    pointer-events: none;

    border:
        4px solid rgba(148, 224, 251, 0.80);

    border-radius: 50%;

    opacity: 0;

    transform:
        translate(-50%, -50%) scale(0.3);

    animation:
        waterRingExpand 0.72s ease-out forwards;
}


@keyframes waterRingExpand {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.2);
    }

    20% {
        opacity: 0.9;
    }

    100% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(2.8);
    }
}


/* ========================================
   GIYU FULLSCREEN
======================================== */

.giyu-attack-overlay {
    position: fixed;

    inset: 0;

    z-index: 3600;

    display: flex;

    align-items: center;

    justify-content: center;

    opacity: 0;

    visibility: hidden;

    pointer-events: none;

    background:
        radial-gradient(circle,
            rgba(117, 206, 239, 0.07),
            rgba(17, 106, 153, 0.04));

    transition:
        opacity 0.20s ease,
        visibility 0.20s ease;
}


.giyu-attack-overlay img {
    width:
        min(92vw, 920px);

    height:
        min(92vh, 920px);

    object-fit: contain;

    opacity: 0.18;

    filter:
        saturate(0.88) brightness(1.10);
}


.giyu-attack-overlay.show {
    opacity: 1;

    visibility: visible;
}


.giyu-attack-overlay.show img {
    animation:
        giyuOverlayMove 0.72s ease-in-out infinite alternate;
}


@keyframes giyuOverlayMove {

    from {
        transform:
            translateX(-7px) scale(1.02);
    }

    to {
        transform:
            translateX(7px) scale(1.10);
    }
}


/* ========================================
   GIYU WATER ATTACK
======================================== */

.giyu-attack-message {
    position: fixed;

    left: 50%;
    top: 42%;

    z-index: 4700;

    width:
        min(720px, 92vw);

    min-height: 120px;

    display: flex;

    align-items: center;
    justify-content: center;

    gap: 18px;

    opacity: 0;
    visibility: hidden;

    pointer-events: none;

    transform:
        translate(-50%, -50%) scale(0.35);
}


/* 水しぶきの広がり */

.giyu-attack-message::before {
    content: "";

    position: absolute;

    left: 50%;
    top: 50%;

    width: 760px;
    height: 180px;

    z-index: -1;

    opacity: 0;

    transform:
        translate(-50%, -50%) scaleX(0.25);

    background:
        linear-gradient(100deg,
            transparent 0%,
            rgba(146, 224, 250, 0.15) 8%,
            rgba(90, 194, 232, 0.85) 20%,
            rgba(232, 251, 255, 0.98) 38%,
            rgba(80, 181, 225, 0.88) 58%,
            rgba(193, 239, 255, 0.70) 76%,
            transparent 100%);

    clip-path:
        polygon(0 56%,
            8% 42%,
            15% 51%,
            23% 26%,
            31% 48%,
            40% 18%,
            48% 45%,
            58% 22%,
            67% 49%,
            76% 31%,
            84% 54%,
            92% 41%,
            100% 57%,
            90% 66%,
            82% 59%,
            72% 76%,
            62% 57%,
            52% 83%,
            42% 59%,
            32% 77%,
            22% 61%,
            12% 72%);

    filter:
        drop-shadow(0 0 13px rgba(61, 177, 225, 0.75));
}


.giyu-attack-message::after {
    content: "";

    position: absolute;

    left: 50%;
    top: 50%;

    width: 690px;
    height: 95px;

    z-index: -2;

    opacity: 0;

    transform:
        translate(-50%, -50%) scaleX(0.2);

    background:
        linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.2),
            rgba(255, 255, 255, 0.95),
            rgba(180, 235, 255, 0.85),
            transparent);

    clip-path:
        polygon(0 48%,
            12% 39%,
            24% 51%,
            37% 34%,
            50% 51%,
            65% 36%,
            78% 53%,
            90% 42%,
            100% 51%,
            88% 58%,
            75% 52%,
            62% 66%,
            48% 56%,
            34% 68%,
            20% 55%,
            8% 62%);

    filter:
        blur(1px) drop-shadow(0 0 9px rgba(213, 247, 255, 0.95));
}


.giyu-attack-message.show {
    visibility: visible;

    animation:
        giyuSplashMessage 1.65s cubic-bezier(.15, .8, .2, 1) forwards;
}


.giyu-attack-message.show::before {
    animation:
        giyuSplashBurst 1.15s ease-out forwards;
}


.giyu-attack-message.show::after {
    animation:
        giyuSplashFlash 0.9s ease-out forwards;
}


.giyu-attack-message-text {
    position: relative;

    z-index: 3;

    color: #124965;

    font-size: 40px;
    font-weight: 900;

    font-style: italic;

    letter-spacing:
        0.08em;

    white-space: nowrap;

    text-shadow:
        0 3px 0 #fff,
        3px 0 0 #fff,
        -3px 0 0 #fff,
        0 -3px 0 #fff,
        0 0 13px rgba(255, 255, 255, 0.9),
        6px 7px 0 rgba(26, 104, 144, 0.18);
}


.water-slash {
    color: rgba(255, 255, 255, 0.98);

    font-size: 52px;
    font-weight: 900;

    text-shadow:
        0 0 10px #fff,
        0 0 20px rgba(80, 192, 236, 0.98);

    animation:
        waterSplashMark 0.24s ease-in-out infinite alternate;
}


@keyframes waterSplashMark {
    from {
        transform:
            translateX(-8px) translateY(3px) rotate(-12deg) scale(0.90);
    }

    to {
        transform:
            translateX(8px) translateY(-5px) rotate(9deg) scale(1.18);
    }
}


@keyframes giyuSplashMessage {

    0% {
        opacity: 0;

        transform:
            translate(-70%, -50%) scale(0.45);
    }

    14% {
        opacity: 1;

        transform:
            translate(-48%, -50%) scale(1.18);
    }

    28% {
        transform:
            translate(-50%, -50%) scale(0.94);
    }

    42% {
        transform:
            translate(-50%, -50%) scale(1.04);
    }

    76% {
        opacity: 1;
    }

    100% {
        opacity: 0;

        transform:
            translate(-32%, -60%) scale(0.90);
    }
}


@keyframes giyuSplashBurst {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scaleX(0.15) scaleY(0.65);
    }

    16% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scaleX(1.10) scaleY(1.05);
    }

    38% {
        opacity: 0.95;

        transform:
            translate(-50%, -50%) scaleX(1.18) scaleY(0.92);
    }

    100% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scaleX(1.42) scaleY(0.72);
    }
}


@keyframes giyuSplashFlash {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scaleX(0.15);
    }

    18% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scaleX(1.12);
    }

    100% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scaleX(1.34);
    }
}



/* ========================================
   FEVER START
======================================== */

.fever-start-message {
    position: fixed;

    left: 50%;

    top: 42%;

    z-index: 6000;

    display: flex;

    align-items: center;

    justify-content: center;

    gap: 13px;

    opacity: 0;

    visibility: hidden;

    white-space: nowrap;

    pointer-events: none;

    transform:
        translate(-50%, -50%) scale(0.25);
}


.festival-text {
    color: #d27a10;

    font-size: 72px;

    font-weight: 900;

    letter-spacing:
        0.025em;

    -webkit-text-stroke:
        2px #fff9df;

    paint-order:
        stroke fill;

    text-shadow:
        0 4px 0 #fff,

        4px 0 0 #fff,

        -4px 0 0 #fff,

        0 -4px 0 #fff,

        0 8px 0 #9f5511,

        0 13px 19px rgba(91, 51, 10, 0.25),

        0 0 27px rgba(255, 211, 55, 0.96);
}


.ohagi-mark {
    color: #75432c;

    font-size: 45px;

    text-shadow:
        0 4px 0 rgba(83, 42, 24, 0.20),

        0 0 12px rgba(255, 208, 63, 0.54);
}


.fever-start-message::before,
.fever-start-message::after {
    content: "✨";

    position: absolute;

    font-size: 42px;

    filter:
        drop-shadow(0 0 8px rgba(255, 213, 55, 0.85));
}


.fever-start-message::before {
    left: -62px;

    top: -32px;

    transform:
        rotate(-12deg);
}


.fever-start-message::after {
    right: -62px;

    bottom: -32px;

    transform:
        rotate(12deg);
}


.fever-start-message.show {
    visibility: visible;

    animation:
        festivalPop 2.7s cubic-bezier(.18, .86, .24, 1) forwards;
}


.fever-start-message.show .ohagi-mark {
    animation:
        festivalOhagiBounce 0.40s ease-in-out infinite alternate;
}


@keyframes festivalPop {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.18) rotate(-8deg);
    }

    14% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scale(1.36) rotate(4deg);
    }

    27% {
        transform:
            translate(-50%, -50%) scale(0.90) rotate(-2deg);
    }

    41% {
        transform:
            translate(-50%, -50%) scale(1.08);
    }

    72% {
        opacity: 1;

        transform:
            translate(-50%, -53%) scale(1);
    }

    87% {
        opacity: 1;
    }

    100% {
        opacity: 0;

        transform:
            translate(-50%, -82%) scale(0.84);
    }
}


@keyframes festivalOhagiBounce {

    from {
        transform:
            translateY(3px) scale(0.94);
    }

    to {
        transform:
            translateY(-10px) scale(1.12);
    }
}


/* ========================================
   SCORE POPUP
======================================== */

.score-popup {
    position: fixed;

    z-index: 3000;

    pointer-events: none;

    color: #c94f2c;

    font-size: 27px;

    font-weight: 900;

    text-shadow:
        0 2px 0 #fff,

        2px 0 0 #fff,

        -2px 0 0 #fff,

        0 -2px 0 #fff;

    animation:
        scorePopup 0.90s ease-out forwards;
}


.score-popup.big {
    font-size: 35px;
}


.score-popup.fever-score {
    z-index: 5900;

    color: #e59c0c;

    font-size: 40px;

    text-shadow:
        0 3px 0 #fff,

        3px 0 0 #fff,

        -3px 0 0 #fff,

        0 -3px 0 #fff,

        0 0 15px rgba(255, 200, 40, 0.82);

    animation:
        feverScorePopup 1.0s ease-out forwards;
}


.score-popup.fever-score.big {
    font-size: 51px;
}


@keyframes scorePopup {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -30%) scale(0.5);
    }

    20% {
        opacity: 1;

        transform:
            translate(-50%, -55%) scale(1.22);
    }

    100% {
        opacity: 0;

        transform:
            translate(-50%, -135%) scale(0.83);
    }
}


@keyframes feverScorePopup {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -20%) scale(0.22) rotate(-6deg);
    }

    18% {
        opacity: 1;

        transform:
            translate(-50%, -54%) scale(1.50) rotate(3deg);
    }

    39% {
        transform:
            translate(-50%, -64%) scale(0.90) rotate(-1deg);
    }

    65% {
        opacity: 1;

        transform:
            translate(-50%, -82%) scale(1.12);
    }

    100% {
        opacity: 0;

        transform:
            translate(-50%, -158%) scale(0.72);
    }
}


/* ========================================
   FEVER SPARKLES
======================================== */

.fever-sparkle {
    position: fixed;

    z-index: 5950;

    pointer-events: none;

    font-size: 23px;

    color: #efaa1e;

    text-shadow:
        0 0 5px #fff,

        0 0 11px rgba(255, 205, 50, 0.9);

    animation:
        feverSparkleFly 0.78s ease-out forwards;
}


.fever-sparkle.big {
    font-size: 34px;
}


@keyframes feverSparkleFly {

    0% {
        opacity: 0;

        transform:
            translate(-50%, -50%) scale(0.15);
    }

    20% {
        opacity: 1;

        transform:
            translate(-50%, -50%) scale(1.3);
    }

    100% {
        opacity: 0;

        transform:
            translate(calc(-50% + var(--dx)),
                calc(-50% + var(--dy))) scale(0.65) rotate(var(--rotate));
    }
}


/* ========================================
   BOARD EFFECTS
======================================== */

#gameCanvas.clear-flash {
    animation:
        clearFlash 0.18s ease-out;
}


@keyframes clearFlash {

    0% {
        filter:
            brightness(1);
    }

    42% {
        filter:
            brightness(1.75);
    }

    100% {
        filter:
            brightness(1);
    }
}


#gameCanvas.attacking {
    animation:
        boardAttackShake 0.16s 6;
}


@keyframes boardAttackShake {

    0% {
        transform:
            translateX(0);
    }

    25% {
        transform:
            translateX(-7px);
    }

    50% {
        transform:
            translateX(7px);
    }

    75% {
        transform:
            translateX(-4px);
    }

    100% {
        transform:
            translateX(0);
    }
}


.tomioka-card.attacking-card {
    border-color:
        rgba(58, 165, 211, 0.50);

    background:
        rgba(218, 245, 255, 0.80);

    box-shadow:
        0 0 25px rgba(61, 173, 220, 0.18);
}


/* ========================================
   PAUSE
======================================== */

.pause-panel {
    position: absolute;

    inset: 0;

    z-index: 200;

    display: flex;

    flex-direction: column;

    justify-content: center;

    align-items: center;

    border-radius: 14px;

    background:
        rgba(29, 25, 20, 0.65);

    color: #fff;
}


.pause-panel.hidden {
    display: none;
}


.pause-title {
    font-size: 36px;

    font-weight: 900;

    letter-spacing:
        0.14em;
}


.pause-text {
    margin-top: 13px;

    font-size: 16px;

    font-weight: 700;
}


/* ========================================
   GAME OVER
======================================== */

.game-over {
    position: absolute;

    inset: 0;

    z-index: 7000;

    display: flex;

    flex-direction: column;

    justify-content: center;

    align-items: center;

    border-radius: 14px;

    background:
        rgba(37, 27, 19, 0.31);

    color: #fff;
}


.game-over.hidden {
    display: none;
}


.game-over-text {
    margin-bottom: 22px;

    font-size: 34px;

    font-weight: 900;

    text-shadow:
        0 3px 8px rgba(0, 0, 0, 0.30);
}


#restartBtn {
    padding:
        11px 27px;

    cursor: pointer;

    border: 0;

    border-radius: 999px;

    background: #f0bd44;

    color: #3d2d1c;

    font-weight: 900;

    box-shadow:
        0 6px 14px rgba(68, 43, 15, 0.20);
}


/* ========================================
   GAME OVER SANEMI
======================================== */

.sanemi-gameover-overlay {
    position: fixed;

    inset: 0;

    z-index: 6500;

    display: flex;

    justify-content: center;

    align-items: center;

    opacity: 0;

    visibility: hidden;

    pointer-events: none;

    transition:
        opacity 0.35s ease,
        visibility 0.35s ease;
}


.sanemi-gameover-overlay img {
    width:
        min(96vw, 1000px);

    height:
        min(96vh, 1000px);

    object-fit: contain;

    opacity: 0.32;
}


.sanemi-gameover-overlay.show {
    opacity: 1;

    visibility: visible;
}


.sanemi-gameover-overlay.show img {
    animation:
        gameOverSanemiAppear 2.01s ease-out forwards,

        gameOverSanemiPoyon 0.95s 0.95s ease-in-out infinite;
}


/* ========================================
   GAME OVER SANEMI
======================================== */

.sanemi-gameover-overlay {
    position: fixed;

    inset: 0;

    z-index: 6500;

    display: flex;

    justify-content: center;
    align-items: center;

    opacity: 0;
    visibility: hidden;

    pointer-events: none;

    transition:
        opacity 0.35s ease,
        visibility 0.35s ease;
}


.sanemi-gameover-overlay img {
    width:
        min(96vw, 1000px);

    height:
        min(96vh, 1000px);

    object-fit: contain;

    opacity: 0.32;

    transform-origin:
        center bottom;
}


.sanemi-gameover-overlay.show {
    opacity: 1;
    visibility: visible;
}


.sanemi-gameover-overlay.show img {
    animation:
        gameOverSanemiAppear 1.05s ease-out forwards,

        gameOverSanemiPoyon 0.92s 1.05s ease-in-out infinite;
}


/* 最初に大きくぽよん */

@keyframes gameOverSanemiAppear {

    0% {
        opacity: 0;

        transform:
            translateY(42px) scaleX(0.72) scaleY(0.72);
    }

    34% {
        opacity: 0.40;

        transform:
            translateY(-13px) scaleX(1.11) scaleY(0.92);
    }

    54% {
        transform:
            translateY(6px) scaleX(0.94) scaleY(1.08);
    }

    72% {
        transform:
            translateY(-5px) scaleX(1.045) scaleY(0.975);
    }

    86% {
        transform:
            translateY(2px) scaleX(0.985) scaleY(1.025);
    }

    100% {
        opacity: 0.32;

        transform:
            translateY(0) scaleX(1) scaleY(1);
    }
}


/* その後ずっとぽよんぽよん */

@keyframes gameOverSanemiPoyon {
    0% {
        transform: translateY(0) scale(1);
    }

    18% {
        transform: translateY(-8px) scale(1.04);
    }

    36% {
        transform: translateY(0) scale(0.97);
    }

    54% {
        transform: translateY(-4px) scale(1.02);
    }

    72% {
        transform: translateY(0) scale(1);
    }

    100% {
        transform: translateY(0) scale(1);
    }
}


/* ========================================
   MOBILE CONTROL
======================================== */

.mobile-controls {
    display: none;
}


/* ========================================
   MOBILE
======================================== */

@media (max-width: 820px) {

    html,
    body {
        width: 100%;
        height: var(--app-height, 100svh);
        min-height: 0;
        overflow: hidden;
        overscroll-behavior: none;
    }

    body {
        position: fixed;
        inset: 0;
        padding: 0;
        touch-action: manipulation;
    }

    .game-wrap {
        width: 100%;
        height: var(--app-height, 100svh);
        min-height: 0;
        overflow: hidden;
        padding:
            max(4px, env(safe-area-inset-top)) 6px max(5px, env(safe-area-inset-bottom));
    }

    .game-panel {
        width: 100%;
        height: 100%;
        max-width: 430px;
        display: flex;
        flex-direction: column;
        align-items: center;
        min-height: 0;
    }

    .game-title {
        display: none;
    }

    .game-layout {
        width: 100%;
        min-height: 0;
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 5px;
    }

    /* キャラは盤面より上。Safari下部UIに隠させない */
    .character-panel {
        order: 1;
        width: min(96vw, 408px);
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        flex: 0 0 auto;
    }

    .character-card {
        width: auto;
        min-width: 0;
        height: 76px;
        padding: 3px 5px;
        display: grid;
        grid-template-columns: 66px minmax(0, 1fr);
        align-items: center;
        gap: 3px;
        border-radius: 13px;
        overflow: visible;
    }

    .character-face-wrap {
        width: 66px;
        max-width: 66px;
        margin: 0;
    }

    .character-face {
        width: 66px;
        height: 66px;
        object-fit: contain;
    }

    .speech {
        min-width: 0;
        min-height: 0;
        height: auto;
        padding: 4px 4px;
        border-radius: 10px;
        font-size: 10px;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }

    .board-area {
        order: 2;
        flex: 0 0 auto;
        width:
            clamp(178px,
                calc((var(--app-height, 100svh) - 186px) / 2),
                292px);
        max-width: 78vw;
    }

    #gameCanvas {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 2;
        border-radius: 12px;
        touch-action: none;
    }

    .info-panel {
        order: 3;
        width: min(94vw, 398px);
        min-height: 44px;
        padding: 0 3px;
        display: grid;
        grid-template-columns: 0.72fr 1.28fr;
        align-items: center;
        gap: 8px;
        flex: 0 0 auto;
        text-align: left;
    }

    .score-block,
    .fever-block {
        padding: 1px 2px;
    }

    .hud-label {
        font-size: 8px;
        letter-spacing: 0.16em;
    }

    .score-value {
        margin-top: 1px;
        font-size: 26px;
        line-height: 0.95;
    }

    .fever-header {
        gap: 6px;
    }

    #feverValue {
        font-size: 13px;
    }

    .fever-bar {
        height: 9px;
        margin-top: 4px;
    }

    .next-block,
    .controls {
        display: none;
    }

    /* スマホ専用操作。方向3個を一塊、回転を別にする */
    .mobile-controls {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 68px;
        align-items: stretch;
        width: min(96vw, 408px);
        height: 56px;
        margin: 5px auto 0;
        gap: 7px;
        flex: 0 0 auto;
        z-index: 500;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    .move-pad {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 5px;
        min-width: 0;
    }

    .mobile-controls button {
        width: 100%;
        height: 56px;
        padding: 0;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
        border: 1px solid rgba(69, 63, 49, 0.27);
        border-radius: 14px;
        background: rgba(255, 253, 242, 0.96);
        color: #394035;
        box-shadow: 0 3px 8px rgba(50, 54, 44, 0.10);
        font-size: 25px;
        font-weight: 900;
        line-height: 1;
    }

    .mobile-controls button:active,
    .mobile-controls button.is-pressed {
        transform: translateY(1px) scale(0.96);
        background: rgba(232, 244, 214, 0.99);
    }

    .rotate-button {
        color: #4b7654 !important;
        font-size: 27px !important;
    }

    .giyu-attack-message {
        width: 92vw;
        min-height: 74px;
        gap: 7px;
        padding: 10px 12px;
    }

    .giyu-attack-message-text {
        font-size: 24px;
        letter-spacing: 0.03em;
    }

    .water-slash {
        font-size: 28px;
    }

    .festival-text {
        font-size: 35px;
        -webkit-text-stroke: 1px #fff9df;
    }

    .ohagi-mark {
        font-size: 24px;
    }

    .fever-start-message {
        gap: 5px;
    }

    .fever-start-message::before,
    .fever-start-message::after {
        font-size: 21px;
    }

    .fever-start-message::before {
        left: -25px;
    }

    .fever-start-message::after {
        right: -25px;
    }

    .score-popup.fever-score {
        font-size: 31px;
    }

    .score-popup.fever-score.big {
        font-size: 39px;
    }

    .game-over-text {
        font-size: 25px;
    }

    .start-message {
        top: 47%;
        font-size: 40px;
    }
}

@media (max-width: 820px) and (max-height: 670px) {

    .character-panel {
        width: min(94vw, 392px);
    }

    .character-card {
        height: 64px;
        grid-template-columns: 55px minmax(0, 1fr);
    }

    .character-face-wrap,
    .character-face {
        width: 55px;
        max-width: 55px;
        height: 55px;
    }

    .speech {
        font-size: 9px;
    }

    .board-area {
        width:
            clamp(170px,
                calc((var(--app-height, 100svh) - 168px) / 2),
                262px);
    }

    .info-panel {
        min-height: 38px;
    }

    .mobile-controls,
    .mobile-controls button {
        height: 50px;
    }
}

@media (max-width: 350px) {

    .character-card {
        grid-template-columns: 52px minmax(0, 1fr);
    }

    .character-face-wrap,
    .character-face {
        width: 52px;
        max-width: 52px;
        height: 52px;
    }

    .mobile-controls {
        grid-template-columns: minmax(0, 1fr) 60px;
    }
}

/* ========================================
   FIRST START GATE / iOS AUDIO
======================================== */

.start-gate {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(232, 242, 222, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.start-gate.hidden {
    display: none;
}

.start-gate-card {
    width: min(88vw, 340px);
    padding: 24px 20px;
    border: 1px solid rgba(67, 82, 59, 0.22);
    border-radius: 24px;
    background: rgba(255, 253, 245, 0.97);
    box-shadow: 0 18px 45px rgba(55, 74, 48, 0.16);
    text-align: center;
}

.start-gate-title {
    margin: 0 0 6px;
    font-size: 28px;
    font-weight: 900;
    color: #313a2d;
}

.start-gate-note {
    margin: 0 0 16px;
    font-size: 12px;
    line-height: 1.5;
    color: rgba(45, 58, 40, 0.68);
}

.start-game-btn {
    width: 100%;
    min-height: 56px;
    border: 0;
    border-radius: 16px;
    background: #6f955f;
    color: #fff;
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 0.08em;
    box-shadow: 0 6px 0 #4d7042;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.start-game-btn:active {
    transform: translateY(3px);
    box-shadow: 0 3px 0 #4d7042;
}


/* ==================================================
   SMARTPHONE GAME LAYOUT
   ================================================== */

@media (max-width: 820px) {

    html,
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
        overscroll-behavior: none;
    }

    body {
        position: fixed;
        inset: 0;
    }

    .game-wrap {
        width: 100%;
        height: 100svh;
        min-height: 0;

        padding:
            max(4px, env(safe-area-inset-top)) 6px 4px;

        overflow: hidden;
    }

    .game-panel {
        width: 100%;
        height: 100%;

        display: flex;
        flex-direction: column;
        align-items: center;

        min-height: 0;
    }

    /* スマホではタイトルを消す */
    .game-title {
        display: none !important;
    }

    .game-layout {
        width: 100%;
        height: 100%;

        display: grid;

        /*
        キャラ
        HUD
        盤面
        操作
        */
        grid-template-rows:
            58px 42px minmax(0, 1fr) 62px;

        grid-template-columns: 1fr;

        gap: 4px;

        justify-items: center;
        align-items: center;

        min-height: 0;
    }

    /* ========================
       CHARACTERS
       ======================== */

    .character-panel {
        grid-row: 1;

        width: min(96vw, 400px);
        height: 58px;

        display: grid;

        grid-template-columns:
            repeat(2, minmax(0, 1fr));

        gap: 5px;
    }

    .character-card {
        width: 100%;
        height: 58px;

        padding: 2px 5px;

        display: grid;

        grid-template-columns:
            48px minmax(0, 1fr);

        align-items: center;

        gap: 3px;

        border-radius: 11px;
    }

    .character-face-wrap {
        width: 48px;
        max-width: 48px;

        margin: 0;
    }

    .character-face {
        width: 48px;
        height: 48px;

        object-fit: contain;
    }

    .speech {
        min-height: 0;

        padding: 2px;

        background: transparent;

        font-size: 9px;
        line-height: 1.15;

        overflow-wrap: anywhere;
    }

    /* ========================
       HUD
       ======================== */

    .info-panel {
        grid-row: 2;

        width: min(94vw, 380px);
        height: 42px;

        padding: 0;

        display: grid;

        grid-template-columns:
            110px minmax(0, 1fr);

        gap: 12px;

        align-items: center;
    }

    .hud-block {
        padding: 0;
    }

    .hud-label {
        font-size: 8px;
    }

    .score-value {
        margin: 0;

        font-size: 24px;
    }

    .fever-header {
        margin: 0;
    }

    #feverValue {
        font-size: 12px;
    }

    .fever-bar {
        height: 8px;
        margin-top: 2px;
    }

    /* NEXTとPC操作説明はスマホでは不要 */
    .next-block,
    .controls {
        display: none !important;
    }

    /* ========================
       BOARD
       ======================== */

    .board-area {
        grid-row: 3;

        /*
        高さを最優先。
        盤面は1:2なので
        残り高さの半分が横幅になる。
        */
        height: 100%;
        width: auto;

        aspect-ratio: 1 / 2;

        max-width: 78vw;
        min-height: 0;
    }

    #gameCanvas {
        display: block;

        width: 100%;
        height: 100%;

        aspect-ratio: 1 / 2;

        border-radius: 10px;
    }

    /* ========================
       MOBILE CONTROLS
       ======================== */

    .mobile-controls {
        grid-row: 4;

        width: min(96vw, 400px);
        height: 58px;

        display: grid !important;

        grid-template-columns:
            minmax(0, 1fr) 64px;

        gap: 7px;

        position: static !important;

        margin: 0;
        padding: 0;

        background: transparent;

        z-index: 100;
    }

    .move-pad {
        display: grid;

        grid-template-columns:
            repeat(3, 1fr);

        gap: 5px;
    }

    .mobile-controls button {
        width: 100%;
        height: 58px;

        min-width: 0;

        padding: 0;

        border-radius: 13px;

        font-size: 27px;

        touch-action: manipulation;

        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;

        -webkit-tap-highlight-color:
            transparent;
    }

    .mobile-controls button[data-action="rotate"] {
        font-size: 25px;
    }
}


/* 高さが特に短いiPhone */
@media (max-width: 820px) and (max-height: 700px) {

    .game-layout {
        grid-template-rows:
            48px 34px minmax(0, 1fr) 52px;
    }

    .character-panel,
    .character-card {
        height: 48px;
    }

    .character-face-wrap,
    .character-face {
        width: 40px;
        height: 40px;
    }

    .character-card {
        grid-template-columns:
            40px minmax(0, 1fr);
    }

    .speech {
        font-size: 8px;
    }

    .info-panel {
        height: 34px;
    }

    .mobile-controls,
    .mobile-controls button {
        height: 50px;
    }
}

@media (max-width: 820px) {

    html,
    body,
    .game-wrap,
    .game-panel,
    .game-layout,
    .board-area,
    #gameCanvas,
    .mobile-controls,
    .mobile-controls button {
        touch-action: manipulation !important;
        -webkit-user-select: none !important;
        user-select: none !important;
        -webkit-touch-callout: none !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    #gameCanvas,
    .mobile-controls {
        touch-action: none !important;
    }
}

/* ==================================================
   FINAL MOBILE OVERRIDE
   ================================================== */

@media (max-width: 820px) {

    html,
    body {
        width: 100% !important;
        height: var(--app-height, 100svh) !important;
        min-height: 0 !important;

        margin: 0 !important;
        padding: 0 !important;

        overflow: hidden !important;
        overscroll-behavior: none !important;

        touch-action: none !important;

        -webkit-user-select: none !important;
        user-select: none !important;

        -webkit-touch-callout: none !important;
        -webkit-text-size-adjust: 100% !important;
    }

    body {
        position: fixed !important;
        inset: 0 !important;
    }

    .game-wrap {
        width: 100% !important;
        height: var(--app-height, 100svh) !important;

        min-height: 0 !important;

        padding:
            max(3px, env(safe-area-inset-top)) 5px max(4px, env(safe-area-inset-bottom)) !important;

        overflow: hidden !important;
    }

    .game-panel {
        width: 100% !important;
        height: 100% !important;

        max-width: 430px !important;
        min-height: 0 !important;

        margin: 0 auto !important;

        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }

    .game-title {
        display: none !important;
    }

    .game-layout {
        width: 100% !important;
        height: 100% !important;
        min-height: 0 !important;

        display: grid !important;

        grid-template-columns: 1fr !important;

        grid-template-rows:
            54px 44px minmax(0, 1fr) 58px !important;

        gap: 3px !important;

        align-items: center !important;
        justify-items: center !important;
    }

    /* ------------------------------
       キャラ
       ------------------------------ */

    .character-panel {
        grid-row: 1 !important;
        order: unset !important;

        width: min(96vw, 410px) !important;
        height: 54px !important;

        display: grid !important;

        grid-template-columns:
            repeat(2, minmax(0, 1fr)) !important;

        gap: 5px !important;

        margin: 0 !important;
    }

    .character-card {
        width: 100% !important;
        height: 54px !important;

        min-width: 0 !important;

        padding: 2px 4px !important;

        display: grid !important;

        grid-template-columns:
            46px minmax(0, 1fr) !important;

        align-items: center !important;

        gap: 3px !important;

        border-radius: 10px !important;
    }

    .character-face-wrap {
        width: 46px !important;
        max-width: 46px !important;
        height: 46px !important;

        margin: 0 !important;
    }

    .character-face {
        width: 46px !important;
        height: 46px !important;

        object-fit: contain !important;
    }

    .speech {
        min-height: 0 !important;

        padding: 2px !important;

        font-size: 9px !important;
        line-height: 1.1 !important;

        background: transparent !important;
    }

    /* ------------------------------
       SCORE / FEVER / NEXT / PAUSE
       ------------------------------ */

    .info-panel {
        grid-row: 2 !important;
        order: unset !important;

        width: min(96vw, 410px) !important;
        height: 44px !important;

        display: grid !important;

        grid-template-columns:
            78px minmax(0, 1fr) 48px 58px !important;

        align-items: center !important;

        gap: 5px !important;

        padding: 0 !important;
        margin: 0 !important;
    }

    .score-block,
    .fever-block,
    .next-block {
        display: block !important;

        min-width: 0 !important;

        margin: 0 !important;
        padding: 0 !important;
    }

    .hud-label {
        margin: 0 !important;

        font-size: 7px !important;
        line-height: 1 !important;
    }

    .score-value {
        margin: 0 !important;

        font-size: 20px !important;
        line-height: 1 !important;
    }

    .fever-header {
        margin: 0 !important;
    }

    #feverValue {
        font-size: 10px !important;
    }

    .fever-bar {
        height: 7px !important;
        margin-top: 2px !important;
    }

    /* NEXTを復活 */
    .next-block {
        width: 48px !important;
        height: 43px !important;

        overflow: hidden !important;
    }

    #nextCanvas {
        display: block !important;

        width: 40px !important;
        height: 40px !important;

        margin: 0 auto !important;
    }

    /* controls自体を復活させる */
    .controls {
        display: flex !important;

        width: 58px !important;
        height: 38px !important;

        align-items: center !important;
        justify-content: center !important;

        margin: 0 !important;
        padding: 0 !important;

        font-size: 0 !important;
    }

    /* PAUSEボタンを必ず表示 */
    #pauseBtn {
        display: block !important;

        width: 58px !important;
        height: 36px !important;

        margin: 0 !important;
        padding: 0 !important;

        border-radius: 10px !important;

        font-size: 9px !important;
        font-weight: 800 !important;

        touch-action: none !important;
    }

    /* ------------------------------
       盤面
       ------------------------------ */

    .board-area {
        grid-row: 3 !important;
        order: unset !important;

        height: 100% !important;
        width: auto !important;

        max-height: 100% !important;
        max-width: 72vw !important;

        min-height: 0 !important;
        min-width: 0 !important;

        aspect-ratio: 1 / 2 !important;

        margin: 0 !important;
    }

    #gameCanvas {
        display: block !important;

        width: 100% !important;
        height: 100% !important;

        max-width: 100% !important;
        max-height: 100% !important;

        aspect-ratio: 1 / 2 !important;

        touch-action: none !important;

        -webkit-user-select: none !important;
        user-select: none !important;
    }

    /* ------------------------------
       操作
       ------------------------------ */

    .mobile-controls {
        grid-row: 4 !important;
        order: unset !important;

        display: grid !important;

        grid-template-columns:
            minmax(0, 1fr) 64px !important;

        width: min(96vw, 410px) !important;
        height: 56px !important;

        gap: 6px !important;

        position: static !important;

        inset: auto !important;

        margin: 0 !important;
        padding: 0 !important;

        background: transparent !important;

        touch-action: none !important;

        z-index: 1000 !important;
    }

    .move-pad {
        display: grid !important;

        grid-template-columns:
            repeat(3, minmax(0, 1fr)) !important;

        gap: 5px !important;
    }

    .mobile-controls button {
        width: 100% !important;
        height: 56px !important;

        min-width: 0 !important;

        margin: 0 !important;
        padding: 0 !important;

        border-radius: 13px !important;

        font-size: 25px !important;

        touch-action: none !important;

        -webkit-user-select: none !important;
        user-select: none !important;

        -webkit-touch-callout: none !important;
        -webkit-tap-highlight-color: transparent !important;
    }
}


/* 高さの短いスマホ */
@media (max-width: 820px) and (max-height: 700px) {

    .game-layout {
        grid-template-rows:
            46px 38px minmax(0, 1fr) 50px !important;
    }

    .character-panel,
    .character-card {
        height: 46px !important;
    }

    .character-face-wrap,
    .character-face {
        width: 39px !important;
        height: 39px !important;
    }

    .character-card {
        grid-template-columns:
            39px minmax(0, 1fr) !important;
    }

    .speech {
        font-size: 8px !important;
    }

    .info-panel {
        height: 38px !important;
    }

    .mobile-controls,
    .mobile-controls button {
        height: 48px !important;
    }
}


/* ========================================
   GAME OVER RESULT / RANKING
======================================== */


.result-score {
    margin: -4px auto 18px;
    text-align: center;
}

.result-score-label {
    margin-bottom: 2px;
    color: rgba(255, 255, 255, 0.68);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.result-score-value {
    color: #fff;
    font-size: 40px;
    font-weight: 900;
    line-height: 1;
    text-shadow:
        0 3px 8px rgba(0, 0, 0, 0.28);
}

.result-score-unit {
    margin-left: 3px;
    font-size: 14px;
    font-weight: 800;
}

.ranking-area {
    width: min(100%, 240px);
    margin: 0 auto 18px;
    text-align: center;
}





.ranking-name-input {
    box-sizing: border-box;

    width: 100%;
    height: 40px;

    margin: 0 0 8px;
    padding: 0 12px;

    border: 0;
    border-radius: 999px;

    background: rgba(255, 255, 255, 0.92);
    color: #3b3029;

    font-family: inherit;
    font-size: 12px;
    font-weight: 700;

    text-align: center;

    outline: none;

    box-shadow:
        inset 0 0 0 2px rgba(83, 65, 50, 0.12);
}

.ranking-login-hint {
    margin: -2px 0 8px;

    color: rgba(255, 255, 255, 0.78);

    font-size: 9px;
    font-weight: 700;
    text-align: center;
}

.ranking-submit-btn.is-saved:disabled {
    background: #5f8750;
    opacity: 1;
}

.ranking-name-input:focus {
    box-shadow:
        inset 0 0 0 2px #7a9f68;
}

.ranking-submit-btn {
    width: 100%;
    height: 42px;

    margin-bottom: 8px;

    border: 0;
    border-radius: 999px;

    background: #7a9f68;
    color: #fff;

    font-family: inherit;
    font-size: 13px;
    font-weight: 900;

    cursor: pointer;

    box-shadow:
        0 3px 0 rgba(62, 82, 52, 0.4);
}

.ranking-submit-btn:active {
    transform: translateY(2px);

    box-shadow:
        0 1px 0 rgba(62, 82, 52, 0.4);
}

.ranking-submit-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.ranking-view-btn {
    display: inline-block;

    margin: 0;
    padding: 3px 6px;

    border: 0;
    background: transparent;

    color: rgba(255, 255, 255, 0.92);

    font-family: inherit;
    font-size: 11px;
    font-weight: 800;

    text-decoration: underline;
    text-underline-offset: 3px;

    cursor: pointer;
}

.ranking-message {
    min-height: 14px;
    margin-top: 5px;

    color: rgba(255, 255, 255, 0.88);

    font-size: 10px;
    font-weight: 700;
    text-align: center;
}

.game-over #restartBtn {
    width: min(100%, 210px);

    margin: 0 auto 10px;
    padding: 10px 18px;

    border: 0;
    border-radius: 999px;

    background: #f4efe4;
    color: #493b31;

    font-size: 14px;
    font-weight: 900;

    box-shadow:
        0 3px 0 rgba(83, 65, 50, 0.22);
}

.game-over #restartBtn:active {
    transform: translateY(2px);
    box-shadow:
        0 1px 0 rgba(83, 65, 50, 0.22);
}


.bluesky-share-btn {
    width: min(100%, 210px);
    margin: 0 auto;
    padding: 11px 14px;
    border: 0;
    border-radius: 999px;
    background: #1689ff;
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

.bluesky-share-btn:active {
    transform: scale(0.97);
}

/* ========================================
   SHORT DESKTOP WINDOW
   高さが足りないPCブラウザ用
======================================== */

@media (min-width: 821px) and (max-height: 900px) and (hover: hover) and (pointer: fine) {

    .game-wrap {
        min-height: 100vh;
        padding: 4px 0;
        align-items: flex-start;
    }

    .game-panel {
        zoom: 0.82;
    }
}

@media (min-width: 821px) and (max-height: 780px) and (hover: hover) and (pointer: fine) {

    .game-panel {
        zoom: 0.72;
    }
}

.music-credit {
    margin: 12px 0 0;
    color: rgba(60, 70, 55, 0.65);
    font-size: 12px;
    line-height: 1.4;
}

.music-credit {
    margin-top: 12px;
    color: rgba(45, 58, 40, 0.52);
    font-size: 10px;
    line-height: 1.5;
    text-align: left;
}

.start-title-image {
    display: block;
    width: min(300px, 80vw);
    height: auto;
    margin: 0 auto 12px;
}

.game-title-image {
    display: block;
    width: 220px;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}
