:root {
    --bg-color: #0f0f1b;
    /* パネルの消灯時と発光時の色定義（サイバーネオン風） */
    --p0-off: #4a0010; --p0-on: #ff1053; /* 赤 */
    --p1-off: #001a4a; --p1-on: #00d2ff; /* 青 */
    --p2-off: #4a3c00; --p2-on: #ffdf00; /* 黄 */
    --p3-off: #004a15; --p3-on: #00ff66; /* 緑 */
    --p4-off: #3a004a; --p4-on: #b200ff; /* 紫 */
    --p5-off: #003a4a; --p5-on: #00e5ff; /* 水色 */
    --p6-off: #4a2a00; --p6-on: #ff8800; /* オレンジ */
    --p7-off: #4a002a; --p7-on: #ff00aa; /* ピンク */
    --p8-off: #2a2a2a; --p8-on: #ffffff; /* 白 */
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: #fff;
    font-family: 'Arial Rounded MT Bold', 'Helvetica Rounded', Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
    touch-action: none; /* スマホのデフォルトジェスチャーを無効化 */
    -webkit-user-select: none;
    user-select: none;
    transition: background-color 0.3s ease;
}

/* 画面全体のノイズエフェクト（ミス時） */
.noise {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 998;
    opacity: 0;
    background-image: url('data:image/svg+xml;utf8,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noiseFilter"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="3" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noiseFilter)"/%3E%3C/svg%3E');
    transition: opacity 0.1s;
}
.noise-active { opacity: 0.3; }

/* フラッシュエフェクト（クリア時） */
#flash-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: white;
    opacity: 0;
    pointer-events: none;
    z-index: 999;
    transition: opacity 0.3s ease-out;
}
.flash-active {
    opacity: 1 !important;
    transition: opacity 0s !important;
}

#game-container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    position: relative;
    z-index: 10;
}

/* ミス時のシェイクアニメーション */
.shake { animation: shake-anim 0.4s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake-anim {
    0%, 100% { transform: translate3d(0, 0, 0); }
    10%, 30%, 50%, 70%, 90% { transform: translate3d(-15px, 15px, 0); }
    20%, 40%, 60%, 80% { transform: translate3d(15px, -15px, 0); }
}

.header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box;
    font-size: 1.2rem;
    letter-spacing: 1px;
    margin-bottom: 10px;
    color: #aaa;
}
.header span { color: #fff; font-size: 1.5rem; }

#message-area {
    font-size: 2rem;
    height: 2.5rem;
    margin-bottom: 20px;
    text-align: center;
    font-weight: bold;
    letter-spacing: 3px;
    text-shadow: 0 0 10px currentColor;
    transition: color 0.3s;
}

/* 2x2のゲームボード */
/* モード選択UI */
.mode-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    z-index: 10;
}
.mode-btn {
    background: transparent;
    border: 1px solid #555;
    color: #888;
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    text-transform: uppercase;
    transition: all 0.2s;
}
.mode-btn:hover:not(.locked) {
    border-color: #fff;
    color: #fff;
    box-shadow: 0 0 10px rgba(255,255,255,0.2);
}
.mode-btn.active {
    border-color: #00d2ff;
    color: #00d2ff;
    box-shadow: 0 0 15px rgba(0,210,255,0.4);
    background: rgba(0,210,255,0.1);
}
.mode-btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
    position: relative;
    padding-right: 25px;
}
.mode-btn.locked::after {
    content: "🔒";
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
}

#board {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 15px;
    width: 90vw;
    max-width: 380px;
    aspect-ratio: 1 / 1;
    position: relative;
}

#board.grid-3x3 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;
}

/* 褒め言葉ポップアップ */
#popup-message {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    font-size: 3.5rem;
    font-weight: bold;
    font-style: italic;
    color: #fff;
    text-shadow: 0 0 20px #ff00ff, 0 0 40px #00ffff;
    opacity: 0;
    pointer-events: none;
    z-index: 100;
}
.popup-anim { animation: popup-effect 1.2s ease-out forwards; }
@keyframes popup-effect {
    0% { transform: translate(-50%, -50%) scale(0.5) rotate(-10deg); opacity: 0; }
    15% { transform: translate(-50%, -50%) scale(1.2) rotate(5deg); opacity: 1; }
    30% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
    80% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; filter: blur(10px); }
}

/* パネルの基本スタイル */
.panel {
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.8), 0 5px 15px rgba(0,0,0,0.5);
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

/* タップ時の波紋エフェクト */
.panel::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 0; height: 0;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
}
.panel.ripple::after { animation: ripple-effect 0.4s ease-out; }
@keyframes ripple-effect {
    0% { width: 0; height: 0; opacity: 1; }
    100% { width: 200%; padding-bottom: 200%; opacity: 0; }
}

/* 各パネルの通常色 */
#panel-0 { background-color: var(--p0-off); border: 2px solid rgba(255,16,83,0.3); }
#panel-1 { background-color: var(--p1-off); border: 2px solid rgba(0,210,255,0.3); }
#panel-2 { background-color: var(--p2-off); border: 2px solid rgba(255,223,0,0.3); }
#panel-3 { background-color: var(--p3-off); border: 2px solid rgba(0,255,102,0.3); }
#panel-4 { background-color: var(--p4-off); border: 2px solid rgba(178,0,255,0.3); }
#panel-5 { background-color: var(--p5-off); border: 2px solid rgba(0,229,255,0.3); }
#panel-6 { background-color: var(--p6-off); border: 2px solid rgba(255,136,0,0.3); }
#panel-7 { background-color: var(--p7-off); border: 2px solid rgba(255,0,170,0.3); }
#panel-8 { background-color: var(--p8-off); border: 2px solid rgba(255,255,255,0.3); }

/* 発光状態のスタイル */
.panel.active-0 { background-color: var(--p0-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p0-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }
.panel.active-1 { background-color: var(--p1-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p1-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }
.panel.active-2 { background-color: var(--p2-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p2-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }
.panel.active-3 { background-color: var(--p3-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p3-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }
.panel.active-4 { background-color: var(--p4-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p4-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }
.panel.active-5 { background-color: var(--p5-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p5-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }
.panel.active-6 { background-color: var(--p6-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p6-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }
.panel.active-7 { background-color: var(--p7-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p7-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }
.panel.active-8 { background-color: var(--p8-on) !important; border-color: #fff !important; box-shadow: 0 0 40px var(--p8-on), inset 0 0 20px rgba(255,255,255,0.8) !important; transform: scale(0.98); }

#start-btn {
    margin-top: 30px;
    padding: 15px 50px;
    font-size: 1.5rem;
    font-weight: bold;
    background-color: transparent;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 40px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 3px;
    transition: all 0.2s;
    box-shadow: 0 0 15px rgba(255,255,255,0.3), inset 0 0 10px rgba(255,255,255,0.1);
    position: absolute;
    bottom: -80px;
}
#start-btn:active {
    background-color: #fff;
    color: var(--bg-color);
    box-shadow: 0 0 30px rgba(255,255,255,0.8);
    transform: scale(0.95);
}

/* 連続正解時の背景フィーバー演出 */
.fever-bg { animation: fever-colors 4s infinite alternate; }
@keyframes fever-colors {
    0% { background-color: #0f0f1b; }
    33% { background-color: #2a102a; }
    100% { background-color: #2a2a10; }
}

/* Portal Header */
.portal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(10, 10, 15, 0.9);
    border-bottom: 2px solid var(--p1-on);
    color: #fff;
    width: 100%;
    position: fixed;
    top: 0; left: 0;
    z-index: 100;
    box-sizing: border-box;
}
.portal-header h1 {
    font-size: 1.5rem;
    margin: 0;
    color: var(--p1-on);
    text-shadow: 0 0 10px var(--p1-on);
}
.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}
.auth-status {
    font-size: 0.9rem;
    color: #fff;
}
.nav-btn, .back-link {
    background: transparent;
    border: 1px solid var(--p1-on);
    color: var(--p1-on);
    padding: 5px 10px;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: 4px;
    transition: 0.3s;
}
.nav-btn:hover, .back-link:hover {
    background: var(--p1-on);
    color: #000;
}

/* Leaderboard Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.hidden { display: none !important; }

.ranking-modal-content {
    background: var(--bg-color);
    border: 2px solid var(--p1-on);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(0, 210, 255, 0.3);
    color: #fff;
    overflow: hidden;
    animation: modal-fade-in 0.3s ease-out;
}
@keyframes modal-fade-in {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(0, 210, 255, 0.1);
    border-bottom: 1px solid var(--p1-on);
}
.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--p1-on);
    text-shadow: 0 0 10px var(--p1-on);
    letter-spacing: 2px;
}
.close-btn {
    background: none; border: none;
    color: #fff; font-size: 1.8rem;
    cursor: pointer; transition: 0.2s;
}
.close-btn:hover { color: var(--p0-on); }

/* Tabs */
.ranking-tabs {
    display: flex;
    border-bottom: 1px solid rgba(0, 210, 255, 0.3);
}
.ranking-tab {
    flex: 1;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: #888;
    padding: 12px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}
.ranking-tab.active {
    background: rgba(0, 210, 255, 0.1);
    color: var(--p1-on);
    border-bottom: 2px solid var(--p1-on);
}
.ranking-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.ranking-personal {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    font-size: 1.1rem;
    font-weight: bold;
}
.highlight-score {
    color: var(--p2-on);
    font-size: 1.4rem;
    text-shadow: 0 0 8px var(--p2-on);
}

.ranking-list-container {
    padding: 0;
    overflow-y: auto;
    flex: 1;
}
.ranking-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}
.ranking-table th {
    position: sticky; top: 0;
    background: rgba(10, 10, 15, 0.95);
    padding: 12px 15px;
    font-size: 0.9rem;
    color: #aaa;
    border-bottom: 1px solid rgba(0, 210, 255, 0.3);
    z-index: 10;
}
.ranking-table td {
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.95rem;
}
.ranking-table tbody tr:hover {
    background: rgba(0, 210, 255, 0.05);
}
.rank-1 { color: #FFD700; font-weight: bold; }
.rank-2 { color: #C0C0C0; font-weight: bold; }
.rank-3 { color: #cd7f32; font-weight: bold; }
.my-rank-row { background: rgba(0, 255, 102, 0.1) !important; }
.error-text { color: var(--p0-on); padding: 20px; text-align: center; }
#ranking-loading { text-align: center; padding: 20px; color: var(--p1-on); }

/* デバッグヒントの強調スタイル（開発者・内部テスト用） */
.debug-hint {
    border: 4px solid #fff !important;
    box-shadow: 0 0 20px #fff, inset 0 0 10px rgba(255,255,255,0.5) !important;
    animation: hint-pulse 1s infinite alternate;
    z-index: 100;
}
@keyframes hint-pulse {
    from { transform: scale(1.0); opacity: 1; border-color: #fff; }
    to { transform: scale(1.02); opacity: 0.8; border-color: #aaa; }
}
/* ヒント：コーナーに小さなドットを追加 */
.debug-hint::before {
    content: '';
    position: absolute;
    top: 10px; right: 10px;
    width: 15px; height: 15px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 10px #fff;
    z-index: 101;
}
