html {
    height: 100%;
    overflow: hidden;
}

/* フォントウェイトの統一 */
h1, h2, h3, h4, h5, h6, strong, b {
    font-weight: 500;
}

/* ボタンとフォーム要素のフォント統一 */
button, input, select, textarea, .action-btn, .control-btn, .dpad-btn {
    font-family: "Barlow Condensed", sans-serif;
    font-weight: 500;
}

body {
    margin: 0;
    padding: 0;
    font-family: "Barlow Condensed", sans-serif;
    font-weight: 400;
    background-color: #2a2620;
    background-image: url('../assets/images/bg.svg');
    background-repeat: repeat;
    background-position: 0 0;
    background-size: 200px 200px;
    background-attachment: fixed;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
    letter-spacing: 0.05em;
    /* ダブルタップによるズームを防止 */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* スプラッシュオーバーレイ */
.splash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000000;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease;
}

.splash-overlay.splash-active {
    opacity: 0.8;
}

/* ページロード時のスプラッシュアニメーション */
.page-splash {
    opacity: 1;
}

.page-splash.splash-fadeout {
    animation: pageSplash 0.6s ease-out forwards;
}

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

/* ロゴ表示 */
.logo-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10001;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.logo-overlay.logo-show {
    opacity: 1;
    animation: logoShow 1.2s ease-in;
}

.logo-overlay.logo-fadeout {
    animation: logoFadeout 1s ease-out forwards;
}

.logo-overlay img {
    width: 340px;
    height: auto;
}

/* PC用のロゴサイズ調整 */
@media (min-width: 1025px) {
    .logo-overlay img {
        width: 500px; /* PC時は少し大きめ */
        height: auto;
    }
}

/* Glitch effect control */
.logo-glitch {
    transition: filter 0.3s ease;
}

/* Glitch is disabled by default - enable only during specific animations */
.logo-glitch #glitch-filter animate {
    animation-play-state: paused;
}

.logo-overlay.glitch-active .logo-glitch #glitch-filter animate {
    animation-play-state: running;
}

/* Alternative approach using CSS variables for more control */
.logo-glitch.glitch-enabled {
    animation: glitchPulse 0.1s infinite alternate;
}

/* Intense glitch effect during fadeout */
.logo-overlay.glitch-intense .logo-glitch {
    animation: glitchIntense 0.08s infinite;
}

/* 赤い光エフェクト */
.logo-overlay.red-glow {
    filter: drop-shadow(0 0 8px #ff0000) drop-shadow(0 0 16px #ff0000);
    animation: redGlowPulse 2s ease-in-out infinite alternate;
}

@keyframes redGlowPulse {
    0% {
        filter: drop-shadow(0 0 5px #ff0000) drop-shadow(0 0 10px #ff0000);
    }
    100% {
        filter: drop-shadow(0 0 12px #ff0000) drop-shadow(0 0 24px #ff0000);
    }
}

@keyframes glitchPulse {
    0% { opacity: 1; }
    100% { opacity: 0.95; }
}

@keyframes glitchIntense {
    0% {
        opacity: 1;
        transform: translateX(0);
    }
    20% {
        opacity: 0.8;
        transform: translateX(-2px);
    }
    40% {
        opacity: 1;
        transform: translateX(2px);
    }
    60% {
        opacity: 0.9;
        transform: translateX(-1px);
    }
    80% {
        opacity: 0.95;
        transform: translateX(1px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes logoShow {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scaleY(0.003);
        transform-origin: center center;
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scaleY(1);
    }
}

@keyframes logoFadeout {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1);
    }
}

#game-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    max-width: 100%;
    position: relative;
    width: 100%;
    max-height: 100vh;
    justify-content: center;
    flex-wrap: wrap;
    overflow: hidden;
}

#container {
    width: 100%;
    max-width: 800px;
    aspect-ratio: 1;
    border: 2px solid #00D9FF;
    position: relative;
    /* タッチ操作の制御 */
    touch-action: manipulation;
}

#container canvas.game-over-blur,
#container canvas.rankings-blur {
    filter: blur(3px);
    transition: filter 0.2s ease;
}

/* Modal Overlay Styles */
.modal-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(26, 26, 62, 0.95);
    border: 2px solid #00D9FF;
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    z-index: 1000;
}

.modal-overlay.show {
    backdrop-filter: blur(5px);
}


#game-over {
    display: none;
}

/* Game Title Styles */
.game-title {
    margin: 0 0 50px 0;
}

#gameover-block-title {
    margin: 0 0 40px 0;
}

/* Action Button Styles */
.action-btn {
    background: linear-gradient(135deg, #00D9FF, #0099CC);
    color: white;
    border: none;
    border-radius: 5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0, 217, 255, 0.3);
    letter-spacing: 0.1em;
}

.action-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 8px rgba(0, 217, 255, 0.5);
}

.action-btn-primary {
    padding: 20px 60px;
    font-size: 24px;
}

.action-btn-secondary {
    padding: 15px 40px;
    font-size: 20px;
}

/* Score Summary Styles */
.score-summary {
    color: white;
    margin-bottom: 40px;
}

.score-item {
    font-size: 20px;
    margin: 10px 0;
    display: flex;
    justify-content: center;
    gap: 15px;
}

.score-label {
    text-align: right;
    width: 70px;
}

.score-value {
    font-weight: 500;
    text-align: left;
    width: 80px;
}

.score-gold {
    color: #FFD700;
}

.score-green {
    color: #50E3C2;
}

.score-red {
    color: #FF6B6B;
}

.score-blue {
    color: #00D9FF;
}

.score-purple {
    color: #B794F4;
}

/* Ghost Toggle Icon */
.ghost-toggle-icon {
    display: block;
    margin: auto;
}

#info-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
    z-index: 1;
}

.info-box {
    background-color: #1a1a3e;
    padding: 15px;
    border-radius: 5px;
    border: 1px solid #00D9FF;
    box-sizing: border-box;
    text-align: center;
}

.info-box h3 {
    margin: 0 0 10px 0;
    color: #00D9FF;
    letter-spacing: 0.1em;
    font-weight: 500;
}

#next-piece {
    width: 100px;
    height: 100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#score {
    font-size: 24px;
    font-weight: 500;
    color: #FFD700;
}

#lines {
    font-size: 24px;
    font-weight: 500;
    color: #50E3C2;
}

#level {
    font-size: 24px;
    font-weight: 500;
    color: #FF6B6B;
}

.controls {
    font-size: 12px;
    line-height: 1.5;
}

#continue-btn:hover, #start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 12px rgba(0, 217, 255, 0.5);
}

#container canvas.game-not-started {
    filter: blur(2px);
    opacity: 0.9;
}

#container.game-not-started {
    background-color: #000000;
}

/* ゴーストピース切り替えボタン */
.ghost-toggle-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(26, 26, 62, 0.8);
    border: 1px solid #00D9FF;
    color: #00D9FF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    z-index: 100;
    padding: 0;
    outline: none;
}

.ghost-toggle-btn:focus {
    outline: none;
}

.ghost-toggle-btn:hover {
    background: rgba(0, 217, 255, 0.2);
    transform: scale(1.1);
}

.ghost-toggle-btn.active {
    background: rgba(0, 217, 255, 0.4);
    color: #ffffff;
}

/* モバイルコントロール */
.mobile-controls {
    display: none;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    padding: 0px;
    order: 3;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 10px 0;
}

.control-row:last-child {
    margin-top: 20px;
}

.control-btn {
    width: 60px;
    height: 60px;
    font-size: 28px;
    background: rgba(26, 26, 62, 0.95);
    color: #00D9FF;
    border: 2px solid #00D9FF;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* 左右のボタンを横長に */
#left-btn, #right-btn {
    width: 100px;
}

.control-btn:active {
    background: #00D9FF;
    color: #1a1a3e;
    transform: scale(0.95);
}

.control-btn.wide {
    width: 155px;  /* 上の行の合計幅に合わせる (100+60+100+10*2=280, 280/2+5=145) */
}

/* メディアクエリ - タブレット対応 */
@media (max-width: 1024px) {
    #game-wrapper {
        flex-direction: column;
        align-items: center;
    }
    
    #container {
        max-width: 600px;
    }
    
    #info-panel {
        flex-direction: row;
        width: 100%;
        max-width: 600px;
        justify-content: space-between;
    }
    
    .info-box {
        flex: 1;
    }
}

/* メディアクエリ - タブレット・スマートフォン対応 */
@media (max-width: 1024px) {
    body {
        padding: 10px;
        padding-top: 10px;
        align-items: center;
        justify-content: center;
        height: 100vh;
        overflow: hidden;
    }
    
    #game-wrapper {
        gap: 10px; /* 間隔を調整 */
        flex-direction: column; /* 通常の縦並び（info-panelが先、containerが後） */
        align-items: center;
        justify-content: center;
        margin-top: 0;
    }
    
    .mobile-controls {
        display: block !important;
    }
    
    #controls-info {
        display: none !important; /* PCコントロール説明を非表示 */
    }
    
    /* スタート画面とゲームオーバー画面のサイズ調整 */
    #game-start, #game-over {
        width: 80% !important;
        max-width: 400px !important;
        padding: 25px 35px !important;
        box-sizing: border-box !important;
    }
    
    #block-title, #gameover-block-title {
        margin: 0 0 25px 0 !important;
        transform: scale(0.9);
    }
    
    #start-btn, #continue-btn {
        padding: 18px 50px !important;
        font-size: 22px !important;
    }
    
    #container {
        width: calc(100vw - 20px);
        height: calc((100vw - 20px) * 1.15); /* 1:1.15 ratio (15%縦長) */
        max-width: 500px;
        max-height: 575px; /* 500 * 1.15 */
        order: 2; /* containerを2番目に */
        flex-shrink: 0; /* 縮小を防ぐ */
        margin: 0 auto;
    }
    
    #info-panel {
        flex-direction: row;
        width: calc(100vw - 20px);
        max-width: 500px;
        justify-content: space-between;
        align-items: stretch; /* 高さを揃える */
        gap: 10px;
        order: 1; /* info-panelを1番目に */
        height: 80px; /* NEXTピースに合わせた高さ */
        flex-shrink: 0; /* 縮小を防ぐ */
        box-sizing: border-box;
        margin: 0 auto;
    }
    
    .info-box {
        padding: 5px 10px;
        flex: 1;
        text-align: center;
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 100%;
    }
    
    /* スマホ時はNEXTを一番右に配置 */
    .score-box {
        order: 1;
    }
    
    .lines-box {
        order: 2;
    }
    
    .level-box {
        order: 3;
    }
    
    .next-box {
        order: 4; /* 一番右 */
    }
    
    .info-box h3 {
        font-size: 12px;
        margin: 0 0 5px 0;
    }
    
    #score, #lines, #level {
        font-size: 18px;
    }
    
    #next-piece {
        width: 80px;  /* スマホ時は横長 */
        height: 50px; /* 縦を短く */
        margin: 0 auto;
    }
    
    .controls {
        display: none;
    }
}

/* タブレット用の追加調整（iPadなど） */
@media (min-width: 768px) and (max-width: 1024px) {
    #container {
        width: 450px;
        height: 450px;
    }
    
    #info-panel {
        width: 450px;
        height: 90px;
    }
    
    #game-wrapper {
        padding-top: 20px;
    }
}

/* スマートフォン用の追加調整 */
@media (max-width: 767px) {
    #container {
        width: calc(100vw - 20px);
        height: calc((100vw - 20px) * 1.2); /* 1:1.2 ratio (20%縦長) */
        max-width: 450px;
        max-height: 540px; /* 450 * 1.2 */
    }
    
    #info-panel {
        flex-direction: row;
        width: calc(100vw - 20px);
        max-width: 500px;
        justify-content: space-between;
        align-items: stretch;
        gap: 10px;
        order: 1;
        height: 80px;
    }
}

/* さらに小さい画面用 */
@media (max-width: 480px) {
    body {
        padding: 0;
        padding-top: 5px;
        align-items: flex-start;
        height: 100vh;
        overflow: hidden;
    }
    
    .ghost-toggle-btn {
        width: 35px;
        height: 35px;
        top: 5px;
        right: 5px;
    }
    
    .ghost-toggle-btn svg {
        width: 25px;
        height: 25px;
    }
    
    #game-wrapper {
        gap: 7px; /* 間隔を確保 */
        align-items: center;
    }
    
    /* ゲームオーバー画面を適度に大きく */
    #game-over {
        width: 95% !important;
        max-width: 350px !important;
        padding: 25px 30px !important;
    }
    
    /* ランキング画面は幅確保だが画面内に収める */
    #rankings {
        width: 85% !important;
        max-width: 330px !important;
        padding: 30px 20px !important;
    }
    
    /* 名前入力画面も適度なサイズ */
    #name-input {
        width: 85% !important;
        max-width: 330px !important;
        padding: 30px 20px !important;
    }
    
    #block-title, #gameover-block-title {
        transform: scale(0.7);
        margin: 0 0 30px 0 !important;
    }
    
    #start-btn, #continue-btn, #submit-name-btn, #close-rankings-btn, #view-rankings-btn {
        padding: 12px 30px !important;
        font-size: 18px !important;
    }
    
    #container {
        width: calc(100vw - 10px);
        height: calc((100vw - 10px) * 1.1); /* 1:1.1 ratio (少し縦長) */
        max-width: 400px;
        max-height: 440px; /* 400 * 1.1 */
        border-width: 1px;
        flex-shrink: 0; /* 縮小を防ぐ */
        margin: 0 auto;
    }
    
    #info-panel {
        width: calc(100vw - 10px);
        max-width: 400px;
        gap: 5px;
        height: 60px; /* 小画面では60pxに */
        flex-shrink: 0; /* 縮小を防ぐ */
        margin: 0 auto;
    }
    
    .info-box {
        padding: 5px;
    }
    
    .info-box h3 {
        font-size: 10px;
        margin: 0 0 3px 0;
    }
    
    #score, #lines, #level {
        font-size: 18px;
    }
    
    #next-piece {
        width: 65px;  /* 横長に変更 */
        height: 40px; /* 縦を短く */
    }
}

/* ランキングシステムのスタイル */

/* 名前入力モーダル */
#name-input {
    display: none;
}

#name-input.show {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.name-input-title {
    font-size: 28px;
    font-weight: 500;
    color: #FFD700;
    text-align: center;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.1em;
}

.name-input-subtitle {
    font-size: 18px;
    color: #00D9FF;
    text-align: center;
    margin: 0;
    letter-spacing: 0.05em;
}

.name-input-container {
    margin: 0;
}

.name-input-field {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.name-char {
    position: relative;
    width: 40px;
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.char-display {
    font-size: 32px;
    font-weight: 500;
    color: white;
    line-height: 1;
    margin-bottom: 10px;
    min-height: 40px;
    display: flex;
    align-items: center;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.char-underline {
    width: 100%;
    height: 3px;
    background-color: #00D9FF;
    position: relative;
}

.name-char.active .char-underline {
    background-color: #FFD700;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.char-selector {
    margin: 0;
}

.char-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 12px;
    max-width: 440px;
    margin: 0 auto;
    justify-items: center;
}

.char-option {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 500;
    color: #888;
    border: 1px solid #333;
    background-color: rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.char-option.current {
    color: #FFD700;
    border-color: #FFD700;
    background-color: rgba(255, 215, 0, 0.1);
    transform: scale(1.1);
}

.char-option:hover {
    color: white;
    border-color: #00D9FF;
}


/* ランキング表示モーダル */
#rankings {
    display: none;
}


#rankings.show {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.rankings-title {
    font-size: 36px;
    font-weight: 500;
    color: #FFD700;
    text-align: center;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.1em;
}

.player-info-display {
    text-align: center;
    margin-bottom: 20px;
}

.player-score-display {
    font-size: 18px;
    color: #FFD700;
    font-weight: 500;
    margin-bottom: 5px;
}

.player-rank-display {
    font-size: 18px;
    color: #00D9FF;
    font-weight: 500;
}

.player-rank-display.highlight {
    color: #FFD700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.rankings-table {
    width: 100%;
    max-width: 600px;
    margin-bottom: 30px;
}

.rankings-header {
    display: grid;
    grid-template-columns: 60px 140px 120px;
    gap: 15px;
    padding: 10px 0;
    border-bottom: 2px solid #00D9FF;
    color: #00D9FF;
    font-weight: 500;
    font-size: 18px;
    text-align: center;
}

.rankings-list {
    max-height: 220px;
    overflow-y: auto;
    position: relative;
}

.ranking-row {
    display: grid;
    grid-template-columns: 60px 140px 120px;
    gap: 15px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 18px;
    text-align: center;
    transition: all 0.3s ease-in-out;
}


.ranking-row.highlight {
    background-color: rgba(255, 215, 0, 0.2);
    color: #FFD700;
}

.rank-col { color: #CCCCCC; font-weight: 500; }
.name-col { color: #00D9FF; font-weight: 500; }
.score-col { color: #FFD700; }
.lines-col { color: #90EE90; }
.level-col { color: #FF6B6B; }

/* 追加ボタンスタイル */
.action-btn-tertiary {
    background: linear-gradient(145deg, #4a4a4a, #2a2a2a);
    border: 2px solid #666;
    color: #ccc;
    margin-top: 10px;
    padding: 15px 40px;
    font-size: 20px;
}

.action-btn-tertiary:hover {
    background: linear-gradient(145deg, #5a5a5a, #3a3a3a);
    border-color: #888;
    color: white;
}

/* ゲームオーバー画面のボタン配置 */
#game-over {
    text-align: center;
}

#game-over .action-btn {
    display: block;
    margin: 20px auto 0px;
}

#game-over .action-btn-secondary,
#rankings .action-btn-secondary {
    padding: 15px 40px !important;
    font-size: 20px !important;
}



/* モバイル対応 */
@media (max-width: 768px) {
    .name-input-title {
        font-size: 28px;
    }
    
    .name-input-subtitle {
        font-size: 18px;
    }
    
    .name-input-field {
        gap: 15px;
    }
    
    .name-char {
        width: 35px;
        height: 50px;
    }
    
    .char-display {
        font-size: 24px;
        min-height: 30px;
    }
    
    .char-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 10px;
        max-width: 350px;
    }
    
    .char-option {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }
    
    .rankings-title {
        font-size: 28px;
    }
    
    .rankings-header,
    .ranking-row {
        grid-template-columns: 50px 110px 100px;
        gap: 12px;
        font-size: 18px;
    }
    
    .rankings-table {
        max-width: 350px;
    }
}

@media (max-width: 480px) {
    .name-input-title {
        font-size: 24px;
    }
    
    .name-input-field {
        gap: 12px;
    }
    
    .name-char {
        width: 30px;
        height: 45px;
    }
    
    .char-display {
        font-size: 20px;
        min-height: 25px;
    }
    
    .char-grid {
        grid-template-columns: repeat(7, 1fr);
        max-width: 310px;
        gap: 8px;
    }
    
    .char-option {
        width: 34px;
        height: 34px;
        font-size: 18px;
    }
    
    .rankings-header,
    .ranking-row {
        grid-template-columns: 50px 110px 95px;
        font-size: 18px;
    }
    
    .rankings-table {
        max-width: 280px;
    }
}