/* =========================================
   1. Root Variables & Base Styles
   ========================================= */
:root {
    --primary-color: #6c5ce7;
    --secondary-color: #a29bfe;
    --bg-color: #f0f3f7;
    --panel-bg: #fdfaf0;
    --text-color: #2d3436;
    --accent-color: #fdcb6e;
    --danger-color: #d63031;
    --easy-color: #00b894;
    --normal-color: #0984e3;
    --hard-color: #d63031;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000;
    color: var(--text-color);
    margin: 0;
    padding: 0;
    touch-action: manipulation;
    overflow: hidden;
    width: 100vw;
    height: 100dvh;
    box-sizing: border-box;
}

#app-container {
    aspect-ratio: 3 / 4;
    width: 100%;
    max-width: calc(100dvh * 3 / 4);
    height: 100%;
    background-image: url('assets/images/BG.jpg');
    padding: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center; 
    box-sizing: border-box;
}

h1 {
    margin: 5px 0;
    font-size: 22px;
    color: var(--primary-color);
}

/* =========================================
   2. Layout & Containers
   ========================================= */
#game-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    flex: 1;
    width: 100%;
    overflow: visible; 
}

#main-area-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: visible;
    width: 100%; 
}

#main-area {
    display: flex;
    flex-direction: column;
    align-items: center; 
    width: 100%;
}

#stats-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
    background: var(--panel-bg);
    padding: 10px 30px;
    border-radius: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    font-weight: bold;
    align-items: center;
}

.stats-row {
    display: flex;
    gap: 30px;
    align-items: center;
    justify-content: center;
}

.time-plus-popup {
    position: absolute;
    top: 0;
    color: #d63031;
    font-weight: 900;
    font-size: 1.4em;
    text-shadow: 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff;
    pointer-events: none;
    animation: popFade 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    z-index: 100;
}

@keyframes popFade {
    0% { transform: scale(0.5); opacity: 0; }
    20% { transform: scale(1.2); opacity: 1; }
    80% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

#stats-container span {
    color: #f28d35;
    font-size: 1.2em;
    text-shadow: 1px 1px 0px rgba(0,0,0,0.1);
}

.lamp-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

.lamp {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: #dfe6e9;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid #b2bec3;
}

.lamp.on {
    background-color: #fdcb6e;
    border-color: #f28d35;
    box-shadow: 0 0 12px #fdcb6e, inset 0 1px 3px rgba(255,255,255,0.8);
    transform: scale(1.1);
}

.lamp.power-on {
    background-color: #d63031;
    border-color: #a40000;
    box-shadow: 0 0 15px #d63031, inset 0 1px 3px rgba(255,255,255,0.5);
    transform: scale(1.15);
}

#side-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 100px;
}

#controls {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

/* =========================================
   3. UI Components (Buttons, Modals, Title)
   ========================================= */
button {
    padding: 10px 20px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-sizing: border-box;
    background-color: #f28d35;
    border-style: solid;
    border-width: 6px;
    border-top-color: #fdb863;
    border-left-color: #f49f47;
    border-right-color: #d97325;
    border-bottom-color: #b85b17;
    border-radius: 10px;
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
    transition: transform 0.1s, filter 0.1s;
}

button:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

button:active {
    transform: translateY(1px);
    border-width: 4px 6px 6px 6px;
}

button#settings-btn, button#history-btn, .title-settings-btn {
    width: 60px;
    height: 60px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent;
    border: none;
    box-shadow: none;
    position: absolute;
    z-index: 100;
}

button#settings-btn, button#history-btn {
    top: 10px;
}

.title-settings-btn {
    bottom: 10px;
}

button#settings-btn, .title-settings-btn {
    right: 10px;
    background-image: url('assets/images/Y_Block.png');
}

button#settings-btn img, .title-settings-btn img {
    width: 35px;
    height: 35px;
}

button#history-btn {
    left: 10px;
    background-image: url('assets/images/Y_Block.png');
    color: #4e342e;
    text-shadow: 1px 1px 0 rgba(255,255,255,0.7);
    padding-bottom: 4px;
}

button#settings-btn:active, button#history-btn:active, .title-settings-btn:active {
    transform: scale(0.95);
    background-color: transparent;
}

#history-overlay, #collection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#history-modal {
    width: 80%;
    max-width: 500px;
    height: 70%;
    background-color: #fdfaf0;
    background-image: 
        linear-gradient(rgba(253, 250, 240, 0.55), rgba(253, 250, 240, 0.55)),
        url('assets/images/BG.jpg'),
        radial-gradient(#eac88b 0.6px, transparent 0.6px);
    background-size: cover, cover, 15px 15px;
    background-position: center;
    border: 8px solid #b85b17;
    outline: 4px solid #eac88b;
    outline-offset: -12px;
    border-radius: 10px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    color: #4e342e;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    position: relative;
}

#history-modal h2 {
    text-align: center;
    margin-top: 0;
    color: #b85b17;
    border-bottom: 3px double #eac88b;
    padding-bottom: 15px;
    font-size: 32px;
    text-shadow: 1px 1px 0px #fff;
}

#history-list, #collection-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.history-item {
    background: white;
    padding: 15px;
    border-radius: 10px;
    border-left: 8px solid #f28d35;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    background-image: linear-gradient(to right, #fff, #fdfaf0);
    margin-bottom: 15px;
}

.history-word {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 5px;
    color: #b85b17;
}

.history-reading {
    font-size: 14px;
    color: #636e72;
    margin-bottom: 5px;
}

.history-meaning {
    font-size: 16px;
    line-height: 1.4;
}

/* =========================================
   これくしょん画面用スタイル
   ========================================= */
.collection-group {
    background: white;
    border: 2px solid #d1e0b8;
    border-radius: 8px;
    padding: 10px;
    position: relative;
    overflow: visible; /* スタンプを見せるため */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}
.collection-group.completed {
    background: #f8fbf2;
    border-color: #8ab04c;
}
.collection-title {
    font-weight: bold;
    color: #6d8c3b;
    margin-bottom: 8px;
    font-size: 18px;
}
.collection-words {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.collection-word {
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: bold;
    transition: all 0.2s;
    font-size: 18px;
    min-width: 40px;
    text-align: center;
}
.collection-word.acquired {
    background: #8ab04c;
    color: white;
    cursor: pointer;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}
.collection-word.acquired:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}
.collection-word.unacquired {
    background: #e2e2e2;
    color: #7f8c8d;
    opacity: 0.3; /* 半透明 */
}

.complete-stamp {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%) rotate(-15deg);
    color: #d63031;
    border: 4px solid #d63031;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 26px;
    font-weight: bold;
    opacity: 0.8;
    z-index: 10;
    background-color: rgba(255, 255, 255, 0.8);
}

.stamp-animate {
    animation: stampDrop 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes stampDrop {
    0% { transform: translateY(-50%) rotate(0deg) scale(10); opacity: 0; filter: blur(5px); }
    30% { transform: translateY(-50%) rotate(10deg) scale(1.5); opacity: 1; filter: blur(0px); }
    100% { transform: translateY(-50%) rotate(-15deg) scale(1); opacity: 0.8; }
}

.newly-completed {
    animation: flashGroup 1.5s ease-out forwards;
}
@keyframes flashGroup {
    0% { background: #ffffff; box-shadow: 0 0 20px #f28d35; }
    20% { background: #ffdcae; box-shadow: 0 0 50px #d63031; transform: scale(1.02); }
    100% { background: #fff8e1; box-shadow: none; transform: scale(1); }
}

#collection-detail {
    margin: 10px 0;
    padding: 15px;
    background: #fff;
    border-left: 5px solid #8ab04c;
    border-radius: 5px;
    display: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.col-detail-word { font-size: 20px; font-weight: bold; color: #8ab04c; }
.col-detail-reading { font-size: 14px; color: #666; margin-left: 10px; }
.col-detail-meaning { font-size: 14px; margin-top: 8px; line-height: 1.4; }
.pop { animation: popIn 0.3s ease-out; }

/* コレクション画面を緑ベースにする上書き設定 */
#collection-overlay #history-modal {
    background-color: #f8fbf2;
    background-image: 
        linear-gradient(rgba(248, 251, 242, 0.55), rgba(248, 251, 242, 0.55)),
        url('assets/images/BG2.jpg'),
        radial-gradient(#d1e0b8 0.6px, transparent 0.6px);
    border: 8px solid #8ab04c;
    outline: 4px solid #d1e0b8;
}

#collection-overlay #history-modal h2 {
    color: #8ab04c;
    border-bottom: 3px double #d1e0b8;
    text-shadow: 1px 1px 0px #fff;
    margin-bottom: 10px;
}

.collection-description {
    text-align: center;
    font-size: 18px;
    color: #6d8c3b;
    margin-bottom: 15px;
    line-height: 1.4;
    font-weight: bold;
}

#collection-rank-container {
    background: #fff;
    border: 3px solid #8ab04c;
    border-radius: 8px;
    padding: 10px 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
}

.rank-title-row {
    font-weight: bold;
    margin-bottom: 5px;
}

.rank-label {
    font-size: 16px;
    color: #6d8c3b;
}

#rank-name {
    font-size: 24px;
    color: #f28d35;
    text-shadow: 1px 1px 0 #fff;
}

#rank-progress {
    font-size: 14px;
    color: #7f8c8d;
    margin-left: 5px;
}

#rank-desc {
    font-size: 14px;
    color: #636e72;
    font-weight: bold;
}

.menu-btn {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    border: none;
    border-radius: 12px;
    background-color: #f28d35;
    border-top: 4px solid #fdb863;
    border-left: 4px solid #f49f47;
    border-right: 4px solid #d97325;
    border-bottom: 4px solid #b85b17;
    color: white;
    font-weight: bold;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0,0,0,0.2);
    transition: all 0.1s;
}

.menu-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.menu-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

#title-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('assets/images/title-bg.jpg');
    background-size: cover;
    background-position: center;
    z-index: 1000;
    display: none; /* 初期は非表示 */
    flex-direction: column;
    color: #4e342e;
}

#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    color: white;
    font-size: 24px;
    font-weight: bold;
    flex-direction: column;
    gap: 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.title-logo {
    position: absolute;
    right: 10px;
    top: 40%;
    transform: translateY(-50%);
    width: 50%;
    max-width: 450px;
    height: auto;
    filter: drop-shadow(0 0 20px rgba(0,0,0,0.5));
}

.difficulty-selection {
    position: absolute;
    left: 60px;
    bottom: 80px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 220px;
}

.diff-btn {
    padding: 12px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    background-color: #f28d35;
    border-style: solid;
    border-width: 4px;
    border-top-color: #fdb863;
    border-left-color: #f49f47;
    border-right-color: #d97325;
    border-bottom-color: #b85b17;
    border-radius: 12px;
    color: white;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
    transition: all 0.2s;
}

.diff-btn.easy { /* Orange default */ }
.diff-btn.hard { filter: hue-rotate(330deg); }
.diff-btn.tutorial {
    background-color: #d84b4b;
    border-top-color: #ef8080;
    border-left-color: #de5c5c;
    border-right-color: #a93131;
    border-bottom-color: #852121;
}

.diff-btn:hover {
    filter: brightness(1.2);
    transform: scale(1.05);
}

#tutorial-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('assets/images/BG.jpg');
    background-size: cover;
    background-position: center;
    z-index: 1000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    color: #4e342e;
    padding: 14px 4px 18px;
    box-sizing: border-box;
    touch-action: none;
}

#tutorial-stats-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
    background: var(--panel-bg);
    padding: 10px 24px;
    border-radius: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    font-weight: bold;
    align-items: center;
}

#tutorial-stats-container span {
    color: #f28d35;
    font-size: 1.2em;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

#tutorial-main-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.tutorial-stage-shell {
    width: 100%;
    height: 0;
    display: flex;
    justify-content: center;
    overflow: visible;
}

.tutorial-stage-scale {
    width: 630px;
    height: 836px;
    transform-origin: top center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tutorial-game-window {
    width: 630px;
    height: 630px;
    flex: 0 0 auto;
    border: none;
    border-radius: 15px;
    position: relative;
    background-image: url('assets/images/banmen.png');
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent;
}

#tutorial-grid-container {
    position: absolute;
    top: 75px;
    left: 75px;
    width: 480px;
    height: 480px;
    display: grid;
    grid-template-columns: repeat(8, 60px);
    grid-template-rows: repeat(8, 60px);
    background-color: transparent;
    box-shadow: none;
}

#tutorial-grid-container .cell {
    border: none;
    background: transparent;
}

#tutorial-launcher,
#tutorial-shot-tile {
    position: absolute;
    width: 60px;
    height: 60px;
    box-sizing: border-box;
    z-index: 25;
    pointer-events: none;
}

#tutorial-shot-tile {
    transition: left 0.55s linear, top 0.55s linear;
}

#tutorial-guide-line {
    position: absolute;
    border: 1px dashed #d63031;
    opacity: 0.45;
    pointer-events: none;
    z-index: 15;
}

#tutorial-solo-hand-area {
    width: 500px;
    aspect-ratio: 1080 / 379;
    margin-top: 10px;
    padding: 22px 36px 18px;
    background-image: url('assets/images/tehuda.png');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    flex: 0 0 auto;
}

#tutorial-hand-container {
    width: 320px;
    transform: translateY(-42px);
}

#tutorial-text-panel {
    width: min(92%, 540px);
    min-height: 104px;
    background-color: rgba(253, 250, 240, 0.96);
    background-image:
        linear-gradient(rgba(253, 250, 240, 0.88), rgba(253, 250, 240, 0.88)),
        url('assets/images/和紙.png');
    background-size: cover;
    background-position: center;
    border: 6px solid #b85b17;
    outline: 3px solid #eac88b;
    outline-offset: -10px;
    border-radius: 12px;
    padding: 14px 18px;
    box-sizing: border-box;
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

#tutorial-step-title {
    display: none;
}

#tutorial-step-text {
    font-size: 17px;
    line-height: 1.5;
    font-weight: 700;
    white-space: pre-line;
}

#tutorial-controls {
    width: min(92%, 540px);
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

#tutorial-controls .menu-btn {
    width: 100%;
    margin-top: 0 !important;
}

#tutorial-controls .menu-btn:disabled {
    opacity: 0.45;
    cursor: default;
    filter: none;
    transform: none;
    box-shadow: 0 4px 0 rgba(0,0,0,0.12);
}

#tutorial-controls .menu-btn:disabled:hover {
    filter: none;
    transform: none;
}

#tutorial-close-btn {
    background-color: #7a858b;
    border-top-color: #c4cdd1;
    border-left-color: #7a858b;
    border-right-color: #4d5960;
    border-bottom-color: #2f383d;
}

.tutorial-emphasis {
    animation: tutorialPulse 0.8s ease-in-out 2;
}

.hand-tile.tutorial-hand-pop {
    animation: tutorialPulse 0.8s ease-in-out 2;
}

#settings-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#settings-modal {
    width: 320px;
    background-color: #fdfaf0;
    background-image: 
        linear-gradient(rgba(253, 250, 240, 0.55), rgba(253, 250, 240, 0.55)),
        url('assets/images/BG.jpg'),
        radial-gradient(#eac88b 0.6px, transparent 0.6px);
    background-size: cover, cover, 15px 15px;
    background-position: center;
    border: 8px solid #b85b17;
    outline: 4px solid #eac88b;
    outline-offset: -12px;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    gap: 20px;
    color: #4e342e;
}

/* =========================================
   Media Queries
   ========================================= */
@media (max-width: 600px), (max-height: 800px) {
    .difficulty-selection {
        width: 140px;
        left: 15px;
        bottom: 40px;
        gap: 8px;
    }
    .diff-btn {
        padding: 6px;
        font-size: 14px;
        border-width: 3px;
        border-radius: 8px;
    }
    .menu-btn {
        padding: 6px !important;
        font-size: 14px !important;
        margin-top: 10px !important;
    }
    #tutorial-screen {
        padding: 10px 4px 12px;
    }
    #tutorial-stats-container {
        padding: 8px 14px;
        margin-bottom: 4px;
    }
    #tutorial-stats-container .stats-row {
        gap: 14px;
        font-size: 13px;
    }
    #tutorial-solo-hand-area {
        width: 500px;
        margin-top: 10px;
        padding: 22px 36px 18px;
    }
    #tutorial-text-panel {
        width: 96%;
        min-height: 108px;
        padding: 14px;
    }
    #tutorial-step-title {
        font-size: 18px;
        margin-bottom: 6px;
    }
    #tutorial-step-text {
        font-size: 14px;
        line-height: 1.55;
    }
    #tutorial-controls {
        width: 96%;
        gap: 8px;
    }
    .title-logo {
        width: 55%;
        max-width: 250px;
    }
    .title-settings-btn {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }
    .title-settings-btn img {
        width: 26px;
        height: 26px;
    }

    /* コレクション画面のスマホ最適化 */
    #collection-overlay #history-modal h2 {
        font-size: 18px;
    }
    .collection-description {
        font-size: 13px;
        margin-bottom: 10px;
    }
    #collection-rank-container {
        padding: 8px 10px;
        margin-bottom: 10px;
    }
    .rank-label {
        font-size: 14px;
    }
    #rank-name {
        font-size: 18px;
    }
    #rank-progress, #rank-desc {
        font-size: 12px;
    }
    .collection-group {
        padding: 6px;
        margin-bottom: 8px;
    }
    .collection-title {
        font-size: 15px;
        margin-bottom: 4px;
    }
    .collection-words {
        gap: 4px;
    }
    .collection-word {
        font-size: 14px;
        padding: 4px 6px;
        min-width: 32px;
    }
}

#settings-modal h2 {
    margin: 0;
    text-align: center;
    font-size: 28px;
    color: #b85b17;
    border-bottom: 2px solid #eac88b;
    padding-bottom: 10px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
}

.setting-item select {
    padding: 5px;
    border-radius: 5px;
    border: 2px solid #b85b17;
    background: #fdfaf0;
    font-weight: bold;
}

#close-settings-btn {
    align-self: center;
    margin-top: 10px;
}

#stage-clear-overlay, #game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#stage-clear-modal {
    width: 420px;
    background-color: #fdfaf0;
    background-image: 
        linear-gradient(rgba(253, 250, 240, 0.55), rgba(253, 250, 240, 0.55)),
        url('assets/images/BG.jpg'),
        radial-gradient(#eac88b 0.6px, transparent 0.6px);
    background-size: cover, cover, 15px 15px;
    background-position: center;
    border: 12px solid #b85b17;
    outline: 6px solid #eac88b;
    outline-offset: -18px;
    border-radius: 15px;
    padding: 40px 30px;
    box-shadow: 0 0 60px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    animation: modalPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#clear-title {
    width: 100%;
    display: flex;
    justify-content: center;
    font-size: 48px;
    margin: 0;
    color: #f28d35;
    text-shadow: 2px 2px 0 #b85b17;
    letter-spacing: 4px;
    text-align: center;
    line-height: 1.3;
    font-weight: 900;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    justify-content: center;
}

.clear-btn {
    width: 100%;
    padding: 20px;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    background-color: #f28d35;
    border-style: solid;
    border-width: 6px;
    border-top-color: #fdb863;
    border-left-color: #f49f47;
    border-right-color: #d97325;
    border-bottom-color: #b85b17;
    border-radius: 15px;
    color: white;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
    transition: all 0.2s;
}

.clear-btn.next {
    filter: hue-rotate(0deg); 
    background-color: #f28d35;
}

.clear-btn.title {
    background-color: #7a858b;
    border-top-color: #c4cdd1;
    border-left-color: #7a858b;
    border-right-color: #4d5960;
    border-bottom-color: #2f383d;
}

.clear-btn:hover {
    filter: brightness(1.2);
    transform: scale(1.05);
}

@keyframes modalPop {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

#status-message {
    height: 20px;
    color: var(--danger-color);
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 5px;
}

/* =========================================
   4. Game Board (Grid & Cells)
   ========================================= */
#game-window {
    width: 630px;
    height: 630px;
    border: none; 
    border-radius: 15px;
    position: relative;
    background-image: url('assets/images/banmen.png');
    background-size: cover;
    background-position: center;
    background-color: transparent; 
    transform-origin: top left;
}

#grid-container {
    position: absolute;
    top: 75px;
    left: 75px;
    width: 480px;
    height: 480px;
    display: grid;
    grid-template-columns: repeat(8, 60px);
    grid-template-rows: repeat(8, 60px);
    background-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

.cell {
    width: 60px;
    height: 60px;
    box-sizing: border-box;
    border: 1px solid rgba(139, 69, 19, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    font-weight: bold;
    position: relative;
    transition: background-color 0.6s ease-out, border-color 0.6s ease-out, box-shadow 0.6s ease-out;
}

/* =========================================
   5. Game States & Elements
   ========================================= */

.cell.occupied, .hand-tile, #shooting-tile, #launcher {
    background-size: 100% 100% !important;
    background-color: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    color: white;
    text-shadow: 
        -2px -2px 0 #4d1b18,    
         2px -2px 0 #4d1b18,  
        -2px  2px 0 #4d1b18,  
         2px  2px 0 #4d1b18;

    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    font-weight: bold;
}

.cell.occupied, .hand-tile, #shooting-tile, #launcher {
    background-image: url('assets/images/Block.png') !important;
}

.cell.occupied.g-block, .hand-tile.g-block, #shooting-tile.g-block, #launcher.g-block {
    background-image: url('assets/images/G_Block.png') !important;
}

.cell.occupied.y-block, .hand-tile.y-block, #shooting-tile.y-block, #launcher.y-block {
    background-image: url('assets/images/Y_Block.png') !important;
}

.cell.occupied.obstacle {
    background-image: url('assets/images/J_Block.png') !important;
    background-size: 100% 100% !important;
    background-color: transparent !important;
    border: none !important;
    color: transparent !important; 
    text-shadow: none !important;
}
.cell.occupied.obstacle-j2 {
    background-image: url('assets/images/J_Block2.png') !important;
    background-size: 100% 100% !important;
    background-color: transparent !important;
    border: none !important;
    color: transparent !important;
    text-shadow: none !important;
}

.cell.occupied.obstacle-hard {
    background-image: url('assets/images/J_Block2.png') !important;
    background-size: 100% 100% !important;
    background-color: transparent !important;
    border: none !important;
    color: transparent !important;
    text-shadow: none !important;
}

.cell.occupied {
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition: none;
}

.cell.enemy {
    background: none !important;
    background-image: url('assets/images/toge.png') !important;
    background-size: 90% !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    border: none !important;
    animation: 
        popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards,
        enemyBreathe 0.4s ease-in-out infinite alternate 0.5s;
    z-index: 5;
}

.cell.enemy-i {
    background: none !important;
    background-image: url('assets/images/toge_I.png') !important;
    background-size: 90% !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    border: none !important;
    animation: 
        popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards,
        enemyBreathe 0.4s ease-in-out infinite alternate 0.5s;
    z-index: 5;
}

.cell.boss-dai-root {
    z-index: 10;
}
.cell.boss-dai-root::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 200%; 
    height: 200%;
    background-image: url('assets/images/toge_dai.png');
    background-size: 95%; 
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    transform-origin: 50% 50% !important;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    animation: bossBreathe 1s ease-in-out infinite alternate;
}

.cell.boss-toku-root {
    z-index: 10;
}
.cell.boss-toku-root::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 300%; 
    height: 300%;
    background-image: url('assets/images/toge_toku.png');
    background-size: 95%;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    transform-origin: 50% 50% !important;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    animation: bossBreathe 1.2s ease-in-out infinite alternate;
}

@keyframes bossBreathe {
    0% { transform: scale(1) translateZ(0); }
    100% { transform: scale(1.04) translateZ(0); }
}

.cell.boss-part {
    background-image: none !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

@keyframes enemyBreathe {
    0% { transform: scale(1); }
    100% { transform: scale(1.08); }
}

#launcher {
    position: absolute;
    width: 60px;
    height: 60px;
    box-sizing: border-box;
    z-index: 20;
    pointer-events: none;
}

#guide-line {
    position: absolute;
    border: 1px dashed var(--primary-color);
    opacity: 0.3;
    pointer-events: none;
    z-index: 15;
}

#shooting-tile {
    position: absolute;
    width: 60px;
    height: 60px;
    box-sizing: border-box;
    z-index: 25;
    transition: transform 0.1s linear;
}

.particle {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: var(--accent-color);
    border-radius: 50%;
    pointer-events: none;
    z-index: 100;
}

#word-overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.huge-word {
    font-size: 280px;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 30px #f28d35, 0 0 60px #d97325, 0 0 90px #b85b17;
    opacity: 0;
    transform: scale(0.5);
    position: absolute;
    writing-mode: vertical-rl;
    -webkit-writing-mode: vertical-rl;
    text-orientation: upright;
    -webkit-text-orientation: upright;
    letter-spacing: 10px;
    z-index: 1100;
}

.meaning-box {
    position: absolute;
    left: 40px;
    bottom: 40px;
    width: auto;
    max-width: 500px;
    max-height: 500px;
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
    color: white;
    font-size: 24px;
    font-weight: 900;
    line-height: 1.5;
    text-shadow: 0 0 15px #f28d35, 0 0 30px #d97325;
    opacity: 0;
    pointer-events: none;
    z-index: 1001;
    writing-mode: vertical-rl;
    -webkit-writing-mode: vertical-rl;
    text-orientation: upright;
    -webkit-text-orientation: upright;
}

.meaning-box.animate {
    animation: wordReveal 1.5s ease-out forwards;
}

.meaning-label {
    display: inline-block;
    font-size: 16px;
    color: #ffdcae;
    font-weight: bold;
    margin-left: 10px;
    border-left: 2px solid rgba(255, 255, 255, 0.5);
    padding-left: 6px;
    line-height: 1;
    text-shadow: 0 0 10px #b85b17;
}

ruby {
    ruby-position: over;
}

rt {
    font-size: 80px;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 20px #f28d35, 0 0 40px #d97325;
    letter-spacing: normal;
    text-orientation: upright;
}

@keyframes wordReveal {
    0% { transform: scale(0.8); opacity: 0; filter: blur(10px); }
    15% { transform: scale(1); opacity: 1; filter: blur(0px); }
    85% { transform: scale(1.1); opacity: 1; filter: blur(0px); }
    100% { transform: scale(1.2); opacity: 0; filter: blur(10px); }
}

.cell.hint-highlight {
    animation: blink 0.8s infinite;
    z-index: 5;
}

.cell.hint-specific {
    border: 4px solid #d63031 !important;
}

.cell.clearing-highlight {
    animation: highlight-glow 0.5s ease-in-out 2;
    z-index: 10;
    border-color: var(--accent-color) !important;
}

.cell.success-flash {
    animation: success-flash 0.4s ease-out;
    z-index: 15;
    border-color: var(--primary-color) !important;
}

.cell.power-range-highlight {
    border: 2px solid rgba(214, 48, 49, 0.5) !important;
    background-color: rgba(214, 48, 49, 0.15) !important;
    box-shadow: 0 0 10px rgba(214, 48, 49, 0.2);
}

.cell.exploding {
    animation: countdown-flash 0.6s infinite !important;
    z-index: 10;
}
.cell.exploding.fast {
    animation-duration: 0.3s !important;
}
.cell.exploding.faster {
    animation-duration: 0.1s !important;
}

.shake {
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

/* =========================================
   6. Player Hand Area
   ========================================= */
#solo-hand-area {
    margin-top: 20px;
    background-image: url('assets/images/tehuda.png');
    background-size: 100% 100%;
    background-color: transparent;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    box-sizing: border-box;
}

.hand-container {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center; 
    align-items: center;
    width: 100%;
    gap: 2px; 
}

.hand-tile {
    width: 60px;
    height: 60px;
    flex: 0 0 60px; 
    box-sizing: border-box;
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s, width 0.6s, opacity 0.6s, margin-top 0.2s;
}

.hand-tile.removing, .hand-tile.adding {
    width: 0;
    flex: 0 0 0;
    opacity: 0;
    transform: scale(0.5);
    margin: 0;
}

.hand-tile:hover {
    filter: brightness(1.1);
}

.hand-tile.selected {
    margin-top: -15px;
    filter: drop-shadow(0 10px 10px rgba(0,0,0,0.3));
}
.shuffle-btn {
    width: 300px;
    height: 60px;
    font-size: 24px;
    background-image: url('assets/images/S_Block.png');
    background-size: 100% 100%;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: white;
    text-shadow: 
        -2px -2px 0 #4d1b18,    
         2px -2px 0 #4d1b18,  
        -2px  2px 0 #4d1b18,  
         2px  2px 0 #4d1b18 !important;
}

.shuffle-btn:active {
    border-width: 0 !important;
}

/* =========================================
   7. Animations (@keyframes)
   ========================================= */
@keyframes titlePulse {
    from { transform: translateY(-50%) scale(1); }
    to { transform: translateY(-50%) scale(1.05); }
}

@keyframes shuffleBlink {
    0% { background-color: #f28d35; filter: brightness(1); }
    100% { background-color: #ffffff; filter: brightness(1.2); box-shadow: 0 0 15px #fff; color: #f28d35; text-shadow: none; }
}

.shuffle-btn.hint-blink {
    animation: shuffleBlink 0.6s infinite alternate !important;
}

@keyframes popIn { 
    0% { transform: scale(0); opacity: 0.5; } 
    60% { transform: scale(1.15); opacity: 1; } 
    100% { transform: scale(1); opacity: 1; } 
}

@keyframes countdown-flash {
    0%, 100% { background-color: #ff9f43; color: white; }
    50% { background-color: var(--accent-color); color: var(--text-color); }
}

@keyframes highlight-glow {
    0% { background-color: var(--accent-color); box-shadow: 0 0 5px var(--accent-color); }
    50% { background-color: #fff176; box-shadow: 0 0 20px #fff176; }
    100% { background-color: var(--accent-color); box-shadow: 0 0 5px var(--accent-color); }
}

@keyframes success-flash {
    0% { background-color: white; transform: scale(1.1); box-shadow: 0 0 20px white; color: var(--primary-color); }
    100% { background-color: var(--panel-bg); transform: scale(1); box-shadow: none; color: var(--text-color); }
}

@keyframes blink {
    0%, 100% { background-color: rgba(255, 245, 157, 0.3); }
    50% { background-color: rgba(255, 245, 157, 0.8); }
}

@keyframes shake {
    0% { transform: translate(0, 0); }
    10% { transform: translate(-5px, -5px); }
    20% { transform: translate(5px, -2px); }
    30% { transform: translate(-5px, 2px); }
    40% { transform: translate(5px, 5px); }
    50% { transform: translate(-2px, -5px); }
    60% { transform: translate(2px, 5px); }
    70% { transform: translate(-5px, 2px); }
    80% { transform: translate(5px, -2px); }
    90% { transform: translate(-2px, 5px); }
    100% { transform: translate(0, 0); }
}

@keyframes tutorialPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Roulette Styles */
#roulette-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 4000;
}

#roulette-container {
    width: 420px;
    background-color: #fdfaf0;
    background-image: 
        linear-gradient(rgba(253, 250, 240, 0.55), rgba(253, 250, 240, 0.55)),
        url('assets/images/BG.jpg'),
        radial-gradient(#eac88b 0.6px, transparent 0.6px);
    background-size: cover, cover, 15px 15px;
    background-position: center;
    border: 12px solid #b85b17;
    outline: 6px solid #eac88b;
    outline-offset: -18px;
    border-radius: 15px;
    padding: 40px 30px;
    box-shadow: 0 0 60px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    animation: modalPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-sizing: border-box;
}

#roulette-container h2 {
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 0;
}

#roulette-container h2 img {
    width: 100%;
    max-width: 320px;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
}

.roulette-description {
    color: #4e342e;
    font-size: 16px;
    font-weight: 900;
    line-height: 1.5;
    margin: 0 0 22px;
    text-shadow: 1px 1px 0 rgba(255,255,255,0.8);
}

.roulette-description strong {
    color: #d63031; /* 強調用の色（赤系） */
    font-size: 1.1em; /* 少し大きくする */
}
.slots {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 30px;
    align-items: center;
}

.slot {
    width: 340px;
    height: 100px;
    background: white;
    border: 4px solid #b85b17;
    border-radius: 15px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.2);
    display: flex;
    justify-content: center;
    align-items: center;
}

.slot-strip {
    display: flex;
    flex-direction: row;
    position: absolute;
    left: 0;
    height: 100%;
    will-change: transform;
}

.slot-char {
    min-width: 100px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 60px;
    font-weight: 900;
    color: white;
    text-shadow: 
        -2px -2px 0 #4d1b18,    
         2px -2px 0 #4d1b18,  
        -2px  2px 0 #4d1b18,  
         2px  2px 0 #4d1b18;
    transition: transform 0.2s, opacity 0.2s;
}

.slot::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    width: 100px;
    height: 100%;
    transform: translateX(-50%);
    background: rgba(242, 141, 53, 0.1);
    border-left: 2px dashed #f28d35;
    border-right: 2px dashed #f28d35;
    z-index: 10;
    pointer-events: none;
}

.slot.stopped {
    background-color: #ffdcae;
    border-color: #f28d35;
    box-shadow: 0 0 20px rgba(242, 141, 53, 0.5);
}

.roulette-guide {
    font-weight: bold;
    color: #d63031;
    font-size: 18px;
    margin-top: 15px;
    animation: rouletteGuideBlink 0.8s infinite;
}

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

/* Debug Button */
#debug-skip-btn {
    position: absolute;
    bottom: 5px;
    right: 80px; 
    padding: 2px 8px;
    font-size: 10px;
    opacity: 0.3;
    z-index: 9999;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: 1px solid #fff;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.2s;
}

#debug-explode-btn {
    position: absolute;
    bottom: 5px;
    right: 5px;
    padding: 2px 8px;
    font-size: 10px;
    opacity: 0.3;
    z-index: 9999;
    background: rgba(214, 48, 49, 0.5); 
    color: #fff;
    border: 1px solid #fff;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.2s;
}

#debug-skip-btn:hover, #debug-explode-btn:hover {
    opacity: 1;
    background: rgba(0,0,0,0.8);
}
#debug-explode-btn:hover {
    background: rgba(214, 48, 49, 0.8);
}
