body {
    /* アプリ全体の土台になる背景色と余白です。 */
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(circle at top, #2f4f8f 0%, #132342 45%, #09111f 100%);
    color: #f5f7ff;
    font-family: "Segoe UI", sans-serif;
    transition: background 0.45s ease;
}

body.awakening-mode {
    background:
        radial-gradient(circle at top, #5d6fd8 0%, #2c2c68 34%, #120f2a 68%, #080d18 100%);
}

[hidden] {
    display: none !important;
}

#app {
    /* 上・中央・下の3段構成で画面を組み立てます。 */
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 20px;
    padding: 20px;
    box-sizing: border-box;
}

#status-bar,
#progress-panel,
#control-bar {
    background: rgba(10, 19, 36, 0.82);
    border: 1px solid rgba(170, 200, 255, 0.28);
    border-radius: 18px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
}

#status-bar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding: 14px 16px;
}

.status-item {
    padding: 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.05);
}

.status-label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    color: #9eb7ff;
    letter-spacing: 0.08em;
}

.status-item strong {
    font-size: clamp(20px, 3vw, 28px);
}

#game-screen {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 360px);
    gap: 20px;
    align-items: stretch;
}

#stage-area {
    display: flex;
    width: 100%;
}

#kanji-stage {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    position: relative;
    overflow: hidden;
    min-height: 420px;
    border-radius: 28px;
    background:
        radial-gradient(circle at top, rgba(130, 170, 255, 0.22), transparent 52%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
    border: 1px solid rgba(170, 200, 255, 0.22);
    box-shadow: inset 0 0 60px rgba(120, 180, 255, 0.08);
    transition: background 0.35s ease, box-shadow 0.35s ease, border-color 0.35s ease;
}

body.awakening-mode #kanji-stage {
    background:
        radial-gradient(circle at top, rgba(255, 221, 128, 0.26), transparent 50%),
        radial-gradient(circle at bottom, rgba(88, 215, 255, 0.18), transparent 58%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
    border-color: rgba(255, 225, 138, 0.34);
    box-shadow:
        inset 0 0 72px rgba(255, 209, 102, 0.1),
        0 0 34px rgba(88, 215, 255, 0.12);
}

#kanji-stage.bump {
    animation: stage-bump 0.24s ease;
}

#kanji-stage.flash {
    box-shadow:
        inset 0 0 80px rgba(120, 180, 255, 0.16),
        0 0 40px rgba(88, 215, 255, 0.14);
}

@keyframes stage-bump {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }

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

#kanji {
    /* 主役の文字なので、かなり大きく見せます。 */
    font-size: clamp(120px, 26vw, 240px);
    color: #f7fbff;
    position: relative;
    z-index: 2;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.6s ease, color 0.3s ease, filter 0.3s ease;
    text-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
}

#kanji.effect-unlocked {
    text-shadow:
        0 0 14px rgba(255, 208, 102, 0.8),
        0 20px 30px rgba(0, 0, 0, 0.28);
    filter: drop-shadow(0 0 24px rgba(116, 199, 255, 0.45));
}

#kanji.awakening-active {
    color: #fff3c2;
    text-shadow:
        0 0 18px rgba(255, 244, 191, 0.95),
        0 0 42px rgba(255, 209, 102, 0.72),
        0 0 76px rgba(88, 215, 255, 0.4);
    filter: drop-shadow(0 0 30px rgba(255, 209, 102, 0.58));
}

#kanji.surge {
    animation: kanji-surge 0.34s ease;
}

@keyframes kanji-surge {
    0% {
        filter: brightness(1);
        text-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
    }

    35% {
        filter: brightness(1.95);
        text-shadow:
            0 0 18px rgba(255, 255, 255, 0.8),
            0 0 38px rgba(88, 215, 255, 0.45),
            0 14px 30px rgba(0, 0, 0, 0.28);
    }

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

#effect-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.ring-effect {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: ring-expand 0.55s ease-out forwards;
}

.ring-effect.special {
    border-color: rgba(255, 209, 102, 0.95);
    box-shadow: 0 0 18px rgba(255, 209, 102, 0.5);
}

@keyframes ring-expand {
    0% {
        opacity: 0.95;
        transform: translate(-50%, -50%) scale(0.4);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(8.4);
    }
}

.particle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #58d7ff;
    transform: translate(-50%, -50%);
    opacity: 0;
    animation: particle-burst 0.72s ease-out forwards;
}

.particle.special {
    background: #ffd166;
    box-shadow: 0 0 12px rgba(255, 209, 102, 0.5);
}

@keyframes particle-burst {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.4);
    }

    20% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform:
            translate(
                calc(-50% + var(--move-x, 0px)),
                calc(-50% + var(--move-y, 0px))
            )
            scale(0.2);
    }
}

#progress-panel {
    padding: 18px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-head h2 {
    margin: 0;
    font-size: 18px;
}

#awakening-panel {
    margin-bottom: 22px;
    padding: 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(170, 200, 255, 0.12);
}

#awakening-state {
    font-size: 13px;
    font-weight: 700;
    color: #9eb7ff;
}

#awakening-state.active {
    color: #ffe28a;
}

#awakening-track {
    height: 18px;
    margin-top: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

#awakening-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #7fe2ff 0%, #ffd166 55%, #ff9eb5 100%);
    box-shadow: 0 0 18px rgba(255, 209, 102, 0.24);
    transition: width 0.18s linear;
}

#awakening-text {
    margin: 6px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: #cfe0ff;
}

#badge-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    max-height: 360px;
    overflow-y: auto;
    padding-right: 6px;
}

#badge-list::-webkit-scrollbar {
    width: 8px;
}

#badge-list::-webkit-scrollbar-thumb {
    background: rgba(170, 200, 255, 0.26);
    border-radius: 999px;
}

#badge-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 999px;
}

.badge-item {
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(170, 200, 255, 0.18);
}

.badge-item.locked {
    background: rgba(255, 255, 255, 0.05);
    color: #7e91b8;
}

.badge-item.unlocked {
    background: linear-gradient(135deg, rgba(255, 209, 102, 0.24), rgba(255, 143, 171, 0.18));
    color: #fff8de;
    box-shadow: inset 0 0 24px rgba(255, 209, 102, 0.08);
}

.badge-name {
    display: block;
    font-size: 14px;
    font-weight: 700;
}

.badge-detail {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.5;
}

#control-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 14px;
    margin-bottom: env(safe-area-inset-bottom);
}

#auto-rotate-button,
#reset-data-button {
    padding: 14px 18px;
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

#auto-rotate-button,
#reset-data-button {
    background: rgba(255, 255, 255, 0.1);
    color: #f5f7ff;
}

#reset-data-button {
    background: rgba(255, 120, 120, 0.16);
}

#auto-rotate-button[aria-pressed="true"] {
    background: linear-gradient(180deg, #58d7ff 0%, #3ba7ff 100%);
    color: #08111f;
}

#auto-rotate-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

#auto-rotate-button:hover,
#reset-data-button:hover {
    transform: translateY(-2px);
}

#unlock-toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 14px 18px;
    border-radius: 14px;
    background: rgba(255, 214, 102, 0.95);
    color: #2c2100;
    font-weight: 700;
    white-space: pre-line;
    text-align: center;
    line-height: 1.6;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.25);
    z-index: 20;
}

#unlock-toast.badge-toast {
    background: linear-gradient(180deg, rgba(255, 240, 192, 0.98), rgba(255, 211, 120, 0.94));
    color: #3f2d00;
    border: 1px solid rgba(255, 244, 201, 0.8);
    box-shadow:
        0 0 24px rgba(255, 209, 102, 0.3),
        0 16px 32px rgba(0, 0, 0, 0.25);
}

#level-up-overlay {
    position: fixed;
    top: 18%;
    left: 50%;
    display: grid;
    gap: 8px;
    justify-items: center;
    transform: translateX(-50%);
    padding: 22px 28px;
    border-radius: 22px;
    background: rgba(255, 209, 102, 0.18);
    border: 1px solid rgba(255, 209, 102, 0.42);
    color: #fff6d1;
    box-shadow: 0 22px 44px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    pointer-events: none;
    z-index: 25;
}

#level-up-overlay.show {
    animation: level-up-pop 1.3s ease forwards;
}

#awakening-overlay {
    position: fixed;
    top: 30%;
    left: 50%;
    display: grid;
    gap: 6px;
    justify-items: center;
    transform: translateX(-50%);
    padding: 22px 30px;
    border-radius: 24px;
    background: rgba(88, 215, 255, 0.12);
    border: 1px solid rgba(255, 225, 138, 0.45);
    color: #fff7dc;
    box-shadow:
        0 0 40px rgba(88, 215, 255, 0.2),
        0 20px 44px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(12px);
    pointer-events: none;
    z-index: 26;
}

#awakening-overlay.show {
    animation: awakening-pop 1.6s ease forwards;
}

.awakening-title {
    font-size: clamp(26px, 4.4vw, 42px);
    font-weight: 800;
    letter-spacing: 0.14em;
}

.awakening-value {
    font-size: clamp(22px, 3.2vw, 32px);
    font-weight: 700;
}

.level-up-title {
    font-size: clamp(24px, 4vw, 38px);
    font-weight: 800;
    letter-spacing: 0.12em;
}

#level-up-value {
    font-size: clamp(20px, 3vw, 30px);
    font-weight: 700;
}

@keyframes level-up-pop {
    0% {
        opacity: 0;
        transform: translateX(-50%) scale(0.78);
    }

    18% {
        opacity: 1;
        transform: translateX(-50%) scale(1.1);
    }

    65% {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) scale(1.08);
    }
}

@keyframes awakening-pop {
    0% {
        opacity: 0;
        transform: translateX(-50%) scale(0.72);
    }

    16% {
        opacity: 1;
        transform: translateX(-50%) scale(1.12);
    }

    58% {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) scale(1.08);
    }
}

@media (max-width: 900px) {
    #game-screen {
        grid-template-columns: 1fr;
    }

    #kanji-stage {
        min-height: 320px;
    }
}

@media (max-width: 720px) {
    #app {
        padding: 16px;
        gap: 16px;
    }

    #status-bar {
        grid-template-columns: 1fr;
    }

    #control-bar {
        grid-template-columns: 1fr;
    }

    #kanji-stage {
        min-height: 260px;
    }

    #level-up-overlay {
        top: 12%;
        width: min(320px, calc(100vw - 32px));
        padding: 18px 20px;
    }

    #awakening-overlay {
        top: 24%;
        width: min(320px, calc(100vw - 32px));
        padding: 18px 20px;
    }
}
