:root {
    --bg-color: #2E3440;
    --text-color: #ECEFF4;
    --cell-bg: #434C5E;
    --cell-text: #E5E9F0;
    --cell-hover: #81A1C1;
    --highlight-bg: #BF616A;
    --cell-size: 56px;
    --font-family: "Noto Sans JP", sans-serif;
}

body {
    font-family: var(--font-family);
    text-align: center;
    background: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    transition: background 0.3s, color 0.3s;

    /* ▼ ここから追加：画面全体を縦並びのフレックスボックスにする */
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* 画面の高さの最低値を100%にする */
    box-sizing: border-box; /* paddingを含めて100vhに収める */
    align-items: center; /* ▼ 横方向を真ん中に固定する */
    /* ▲ ここまで追加 */
}

footer, #footer {
    margin-top: auto; 
    padding-top: 20px; /* 上の要素との間に最低限の余白を持たせる */
}

h1 {
    color: #88C0D0;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
    margin-bottom: 5px;
    cursor: pointer;
}

a {
    color: var(--text-color);
}

#error-container {
    color: #EBCB8B;
    margin: 5px;
    font-weight: bold;
}

.screen-container {
    margin-bottom: 15px;
    background: var(--cell-bg);
    padding: 20px;
    border-radius: 8px;
    display: inline-block;
    max-width: 600px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: background 0.3s;
}

#controls {
    margin-bottom: 15px;
}

button {
    background: var(--bg-color);
    color: var(--text-color);
    border: none;
    padding: 10px 20px;
    margin: 0 5px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s, color 0.2s;
    font-family: var(--font-family);
}

button:hover {
    background: var(--cell-hover);
    color: #2E3440;
}

button.active {
    background: #A3BE8C;
    color: #2E3440;
    font-weight: bold;
}

.btn-start {
    background: #88C0D0;
    color: #2E3440;
    font-weight: bold;
    font-size: 1.2rem;
    padding: 12px 30px;

    /* ▼ ここから追加：ボタンの幅を統一 */
    width: 240px; 
    box-sizing: border-box; /* paddingを含めて240pxに収める */
    /* ▲ ここまで追加 */
}

.btn-start:hover {
    background: #8FBCBB;
}

.btn-share {
    background: #000000;
    color: #FFFFFF;
    font-weight: bold;
    margin-bottom: 15px;
}

.btn-share:hover {
    background: #333333;
    color: #FFFFFF;
}

.btn-action {
    background: #EBCB8B;
    color: #2E3440;
    font-weight: bold;
    border: none;
    border-radius: 4px;
    padding: 8px 15px;
    cursor: pointer;

    /* ▼ ここから追加：ボタンの幅を統一 */
    width: 240px; 
    box-sizing: border-box; /* paddingを含めて240pxに収める */
    /* ▲ ここまで追加 */
}

.btn-action:hover {
    background: #D08770;
}

.btn-hint {
    background: #A3BE8C;
    color: #2E3440;
    font-weight: bold;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-hint:hover {
    background: #8FBCBB;
}

#hint-text {
    color: var(--text-color); /* 変更：#EBCB8B を削除 */
    font-weight: bold;
    font-size: 1.1rem;
}

#game-info {
    display: none;
    justify-content: space-between;
    align-items: center;
    max-width: 500px;
    margin: 0 auto 15px auto;
    font-size: 1.5rem;
    background: var(--cell-bg);
    padding: 10px 20px;
    border-radius: 8px;
    transition: background 0.3s;
    
    /* ▼ 追加：盤面と同じ幅まで広げつつ、paddingのハミ出しを防ぐ */
    width: 100%;
    box-sizing: border-box;
}

.time-warning {
    color: var(--highlight-bg);
    font-weight: bold;
    animation: blink 1s infinite;
}

@keyframes blink {
    50% { opacity: 0.5; }
}

#result-score {
    font-size: 3rem;
    color: var(--text-color); /* 変更：#A3BE8C を削除 */
    margin: 10px 0;
}

#ad-container {
    margin-top: 30px;
    padding: 15px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    border: 2px dashed #EBCB8B;
}

/* ▼ 広告エリアのテキスト */
#ad-container p {
    margin: 0 0 10px 0;
    color: var(--text-color); /* 変更：#EBCB8B を削除 */
    font-weight: bold;
}

/* ▼ 広告エリアのリンク */
#ad-container a {
    color: var(--text-color); /* 変更：#88C0D0 を削除 */
    text-decoration: underline; /* 色を変えたので、常に下線を引いてリンクだと分かるようにする */
    font-size: 0.9rem;
    display: block;
    margin-bottom: 5px;
}

#ad-container a:hover {
    text-decoration: underline;
}

#board {
    display: none;
    gap: 4px;
    justify-content: center;
    margin: 0 auto;
    max-width: min(90vw, 65vh, 600px);
    width: 100%;
}

.cell {
    background: var(--cell-bg);
    color: var(--cell-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: all 0.1s;
    user-select: none;
    /* widthとheightのピクセル指定を削除し、100%にする */
    width: 100%;
    height: 100%;
    /* 幅と高さを1:1に保つ */
    aspect-ratio: 1 / 1;
    font-size: calc(var(--cell-size) * 0.65);

    /* ▼ ここから追加：中身によるサイズ変動を強制的に殺す */
    line-height: 1;       /* 行の高さを文字サイズと完全に一致させる */
    min-width: 0;         /* 最小幅の自動拡張を禁止 */
    min-height: 0;        /* 最小高さの自動拡張を禁止 */
    overflow: hidden;     /* 万が一はみ出しても絶対に外に影響を出さない */
    /* ▲ ここまで追加 */
}

.cell:hover {
    background: var(--cell-hover);
    color: var(--bg-color);
}

.cell.wrong-click {
    background: var(--highlight-bg) !important;
    color: #ECEFF4 !important;
    animation: shake 0.3s;
}

.cell.revealed {
    background: var(--highlight-bg) !important;
    color: #ECEFF4 !important;
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(0,0,0,0.6);
    z-index: 10;
    position: relative;
}

@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    50% { transform: translateX(3px); }
    75% { transform: translateX(-3px); }
    100% { transform: translateX(0); }
}

/* 設定画面用スタイル */
.config-group {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.config-group label {
    font-weight: bold;
}
.config-group select, .config-group input[type="color"] {
    padding: 5px;
    font-size: 1rem;
    border-radius: 4px;
    border: 1px solid var(--text-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
}

/* 戦績タブ用スタイル */
.tab-btn {
    flex: 1;
    padding: 8px 0;
    font-size: 0.9rem;
    background: var(--bg-color);
    border-radius: 4px 4px 0 0;
    opacity: 0.7;
}
.tab-btn.active {
    background: var(--highlight-bg);
    color: #ECEFF4;
    opacity: 1;
    font-weight: bold;
}
.tab-content {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 0 4px 4px 4px;
}
.daily-record-item {
    padding: 8px;
    border-bottom: 1px dashed var(--cell-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.daily-record-item:last-child {
    border-bottom: none;
}

/* ▼ 追加：図鑑・モーダル用スタイル */
.collection-tile {
    background: var(--cell-bg);
    color: var(--cell-text);
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    border-radius: 4px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
}
.collection-tile:hover {
    background: var(--cell-hover);
    color: var(--bg-color);
}
.collection-tile.locked {
    opacity: 0.3;
    filter: grayscale(100%);
}
.similar-pair-item {
    background: var(--cell-bg);
    padding: 8px 15px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
}

#time-left {
    font-variant-numeric: tabular-nums;
    display: inline-block;
    min-width: 2.0em; /* 桁数が増えても枠の幅を固定する */
    text-align: right;
}

/* ▼ スマホの図鑑はみ出し・巨大化問題を解決するCSS */
@media screen and (max-width: 600px) {
    /* コンテナが中身に引っ張られて際限なく膨張するのを防ぐ */
    #stats-screen {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 10列固定を上書きし、画面幅に合わせて自動で列数を調整する */
    #collection-grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)) !important;
    }

    /* 文字サイズに引っ張られてタイルが巨大化するのを防ぐ */
    .collection-tile {
        min-width: 0 !important;
        min-height: 0 !important;
        font-size: 1rem !important; /* スマホ用に文字を少し小さく */
    }
}