@charset "UTF-8";

/* ==========================================================================
   0. 共通リセット & 変数定義
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-color: #f4f7f6;
    --panel-bg: #ffffff;
    --text-main: #2c3e50;
    --text-muted: #95a5a6;
    --primary-color: #3498db;
    --primary-hover: #2980b9;
    --success-color: #2ecc71;
    --success-hover: #27ae60;
    --danger-color: #e74c3c;
    --secondary-color: #7f8c8d;
    --secondary-hover: #718093;
    --map-fill: #bdc3c7;
    --border-color: #dcdde1;
}

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden; /* 全画面アプリケーションとしてブラウザ自体のスクロールを抑制 */
    height: 100vh;
    width: 100vw;
}

/* PC専用制限ガード */
#pc-guard {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #2c3e50;
    color: white;
    z-index: 99999;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}
#pc-guard .guard-message h2 { font-size: 24px; margin-bottom: 10px; }

@media (max-width: 1023px) {
    #pc-guard { display: flex; }
}

/* アプリケーション外枠固定 */
#app-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px;
}

/* 画面共通定義 */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    animation: fadeIn 0.3s ease-in-out forwards;
}
.screen.active {
    display: flex;
    flex-direction: column;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.99); }
    to { opacity: 1; transform: scale(1); }
}

/* 汎用ボタン装飾 */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    transition: all 0.2s ease;
}
button:disabled {
    background-color: var(--border-color) !important;
    color: var(--text-muted) !important;
    cursor: not-allowed !important;
    transform: none !important;
    box-shadow: none !important;
}

.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-success { background-color: var(--success-color); color: white; }
.btn-success:hover { background-color: var(--success-hover); }
.btn-secondary { background-color: var(--secondary-color); color: white; }
.btn-secondary:hover { background-color: var(--secondary-hover); }

/* ==========================================================================
   1. スタート画面 (Start Screen)
   ========================================================================== */
.main-title {
    text-align: center;
    font-size: 32px;
    margin-bottom: 30px;
    color: var(--text-main);
    font-weight: 800;
    letter-spacing: 1px;
}

.mode-selection-container {
    display: flex;
    gap: 24px;
    flex: 1;
    height: calc(100% - 80px);
}

.mode-panel {
    flex: 1;
    background-color: var(--panel-bg);
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
}

.mode-panel h2 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text-main);
    border-left: 5px solid var(--primary-color);
    padding-left: 10px;
}
.mode-panel:first-child h2 {
    border-left-color: var(--success-color);
}

.mode-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* 100問プリセットボタン垂直スタック */
.button-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
    padding-right: 5px;
}

.btn-preset-select {
    width: 100%;
    padding: 14px 15px;
    font-size: 15px;
    text-align: left;
    background-color: #f8f9fa;
    color: var(--text-main);
    border: 2px solid var(--border-color);
    border-radius: 8px;
}
.btn-preset-select:hover {
    background-color: #edf2f7;
    border-color: var(--text-muted);
}
.btn-preset-select.active {
    background-color: #ebf8ff;
    border-color: var(--primary-color);
    color: var(--primary-hover);
    box-shadow: 0 0 0 1px var(--primary-color);
}

/* 九九選択用チェックボックスグリッド */
.lines-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    flex: 1;
    align-content: start;
    margin-bottom: 20px;
}

.lines-checkbox-grid label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background-color: #f8f9fa;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 18px 10px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}
.lines-checkbox-grid label:hover {
    background-color: #edf2f7;
    border-color: var(--text-muted);
}
.lines-checkbox-grid input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
.lines-checkbox-grid label:has(input:checked) {
    background-color: #ebf8ff;
    border-color: var(--primary-color);
    color: var(--primary-hover);
}

.btn-start-trigger {
    width: 100%;
    padding: 18px;
    font-size: 18px;
    letter-spacing: 1px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.btn-start-trigger:not(:disabled):active {
    transform: translateY(2px);
    box-shadow: none;
}

/* ==========================================================================
   2. ゲーム画面 (Game Screen)
   ========================================================================== */

/* カウントダウン演出レイヤー */
#countdown-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(244, 247, 246, 0.95);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
}
#countdown-text {
    font-size: 120px;
    font-weight: 900;
    color: var(--text-main);
    transform: scale(0.5);
    opacity: 0;
}
#countdown-text.count-animate {
    animation: countPop 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes countPop {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.1); opacity: 1; }
    80% { transform: scale(1.0); opacity: 1; }
    100% { transform: scale(1.3); opacity: 0; }
}

/* 上段：メインエリアと右上のテンキーを分割 */
.top-play-area {
    display: flex;
    gap: 20px;
    height: 60%;
    margin-bottom: 20px;
}

.top-play-area .main-area {
    flex: 3;
    background-color: var(--panel-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.display-box {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ==========================================================================
   ★究極改修：イコール不動原点・左右分離レイアウト構造
   ========================================================================== */
.game-display-zone {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto 1fr; /* 左・中央（＝）・右 を完璧な3等分または対称配置 */
    align-items: baseline;                /* フォントの下部基準線を一糸乱れぬ位置にシンクロ */
    height: 72px;                         /* 縦ブレ完全シャットアウト */
}

/* ①【左セクション】出題エリア（右詰め） */
.zone-left {
    text-align: right;
    padding-right: 15px;
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
}
.layer-question {
    font-size: 72px;
    font-weight: 800;
    color: var(--text-main);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    user-select: none;
}

/* ②【中央セクション】不動の「＝」配置 */
.zone-center {
    display: flex;
    justify-content: center;
    align-items: baseline;
    user-select: none;
}
.equal-mark {
    font-size: 72px;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
}

/* ③【右セクション】解答＆演出エリア（左詰め・絶対座標の原点化） */
.zone-right {
    position: relative; /* 子要素の演出レイヤーに対して絶対的な(0, 0)を提供するベース */
    padding-left: 15px;  /* イコールとの綺麗な余白 */
    display: flex;
    justify-content: flex-start;
    align-items: baseline;
}

/* 解答（実体文字 / ？） */
.layer-input {
    font-size: 72px;
    font-weight: 800;
    color: var(--primary-color);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    min-width: 120px; /* 3桁まで耐えられる安心幅 */
    text-align: left;
}
/* 未入力状態の「？」マーカー */
.layer-input.empty::before {
    content: "？";
    color: #cbd5e0;
}

/* 演出専用：完全にイコールの右横（zone-rightの左端）を絶対原点（0, 0）としてロック */
.layer-effect {
    position: absolute;
    top: 0;
    left: 15px; /* zone-rightのpadding-leftと完全に一致させ、文字の開始位置をガチガチにシンクロ */
    width: 100%;
    height: 100%;
    pointer-events: none; /* 入力イベントをすべてスルー */
    z-index: 10;
}

/* 動的に生成される視認性特化型・上昇フェードアウト残像 */
.input-residual-text {
    position: absolute;
    top: 0;
    left: 0; /* JSでの動的計算不要、常にCSSで原点固定 */
    font-size: 72px;
    font-weight: 800;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    white-space: nowrap;
    display: inline-block;
    transform-origin: left center; /* 左詰め文字に準拠 */
    
    /* 調整点：時間を 0.45秒 に延長し、脳への認識猶予を確保 */
    animation: textFadeOutZoom 0.45s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes textFadeOutZoom {
    0% { 
        /* 調整点：開始時不透明度を 1 にし、打ち込んだ瞬間の文字情報を網膜に確実に残す */
        transform: scale(1) translateY(0); 
        opacity: 1; 
        filter: blur(0px); 
    }
    30% {
        /* 前半の100〜130ミリ秒ほどは完全不透明を維持し、文字としての輪郭を認識させる */
        opacity: 1;
    }
    100% { 
        /* 調整点：1.8倍に拡大しつつ、真上(-20px)へスライドさせて次の入力文字と分離、ぼかしは輪郭が残るよう2pxに制限 */
        transform: scale(1.8) translateY(-20px); 
        opacity: 0; 
        filter: blur(2px); 
    }
}

/* ==========================================================================
   テンキー ＆ ダッシュボード周辺（従前仕様を完全維持）
   ========================================================================== */
.top-play-area .side-area {
    flex: 1;
    background-color: var(--panel-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    padding: 15px;
}

#tenkey-container {
    width: 100%;
    height: 100%;
}

.tenkey-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    height: 100%;
}

.btn-key {
    background-color: #e2e8f0;
    color: var(--text-main);
    font-size: 26px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 3px 0 #cbd5e0;
}
.btn-key:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #cbd5e0;
}

.btn-clear {
    background-color: #fbd38d;
    color: #dd6b20;
    box-shadow: 0 3px 0 #e2e8f0;
    font-weight: 900;
}
.btn-clear:active {
    box-shadow: 0 1px 0 #e2e8f0;
}
.btn-key[data-key="0"] {
    grid-column: span 2;
}

/* 下段インフォエリア */
.bottom-info-area {
    display: flex;
    gap: 20px;
    height: calc(40% - 40px);
}

.info-panel {
    background-color: var(--panel-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 15px;
    display: flex;
    flex-direction: column;
}
.info-panel h4 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: bold;
    border-bottom: 1px solid var(--bg-color);
    padding-bottom: 5px;
}

#minimap-container { flex: 1.8; }
#game-log-container { flex: 1.2; }

.grid-map {
    display: grid;
    gap: 3px;
    width: 100%;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.map-cell {
    background-color: #eaeded;
    border-radius: 2px;
    transition: background-color 0.15s ease;
}
.map-cell.filled {
    background-color: #95a5a6;
}

#game-log-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow: hidden;
}

.log-placeholder {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    margin-top: 20px;
    font-style: italic;
}

.log-item {
    background-color: #f8f9fa;
    border-left: 4px solid var(--secondary-color);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 15px;
    font-weight: bold;
    color: #555;
    animation: slideInLog 0.2s ease-out forwards;
    font-variant-numeric: tabular-nums;
}

@keyframes slideInLog {
    from { transform: translateY(-5px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ==========================================================================
   3. リザルト画面 (Result Screen)
   ========================================================================== */
.result-layout {
    display: flex;
    gap: 24px;
    height: 100%;
}

.result-layout .main-area {
    flex: 1.8;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.capture-wrapper {
    background-color: white;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow: hidden; 
}

.result-title {
    font-size: 24px;
    color: #2c3e50;
    font-weight: 900;
    letter-spacing: 2px;
    text-align: center;
}

.result-divider {
    border: none;
    border-top: 2px dashed var(--border-color);
    margin: 2px 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.stat-item {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 12px 8px;
    text-align: center;
    border: 1px solid #edf2f7;
}

.stat-label {
    display: block;
    font-size: 11px;
    font-weight: bold;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.result-main-grid {
    display: flex;
    gap: 20px;
    flex: 1;
    align-items: stretch;
    overflow: hidden;
}

.result-map-wrapper {
    flex: 1.1;
    display: flex;
    flex-direction: column;
}
.result-map-wrapper h3, .result-pickup-wrapper h3 {
    font-size: 13px;
    color: var(--text-main);
    font-weight: bold;
    margin-bottom: 8px;
}

.result-map {
    width: 100%;
    max-width: 420px;
    height: 280px;
}

.map-cell.correct { background-color: var(--success-color); }
.map-cell.incorrect { background-color: var(--danger-color); }

.result-pickup-wrapper {
    flex: 0.9;
    display: flex;
    flex-direction: column;
}

#result-pickup-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: hidden;
}

.pickup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #fff5f5;
    border-left: 4px solid var(--danger-color);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: bold;
    color: #c0392b;
    font-variant-numeric: tabular-nums;
}

.pickup-more-badge {
    background-color: #edf2f7;
    color: var(--text-main);
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
    border: 1px dashed var(--text-muted);
    margin-top: 4px;
}

.result-actions {
    display: flex;
    gap: 12px;
    margin-top: 15px;
}
.result-actions button {
    flex: 1;
    padding: 14px;
    font-size: 14px;
}

.result-layout .side-area.history-area {
    flex: 1.2;
    background-color: var(--panel-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.history-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.history-controls h3 { font-size: 16px; font-weight: bold; }

.toggle-buttons {
    display: flex;
    background-color: var(--bg-color);
    padding: 3px;
    border-radius: 6px;
}

.btn-toggle {
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 4px;
    background-color: transparent;
    color: var(--text-muted);
}
.btn-toggle.active {
    background-color: white;
    color: var(--text-main);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

#btn-skip-animation {
    width: 100%;
    padding: 8px;
    font-size: 13px;
    margin-bottom: 10px;
}

.history-list-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid #edf2f7;
    border-radius: 6px;
    padding: 5px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 8px;
    border-bottom: 1px solid #f8f9fa;
    font-size: 14px;
}
.history-item:last-child { border-bottom: none; }

.history-item.is-correct { border-left: 4px solid var(--success-color); background-color: #f4fbf7; }
.history-item.is-incorrect { border-left: 4px solid var(--danger-color); background-color: #fff5f5; }

.history-formula { font-weight: bold; font-variant-numeric: tabular-nums; }
.history-answers {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 12px;
    gap: 2px;
    font-variant-numeric: tabular-nums;
}
.user-ans { color: #555; }
.correct-ans { font-weight: bold; color: var(--success-color); }
.history-item.is-incorrect .correct-ans { color: #c0392b; }

/* ==========================================================================
   5. 【裏面】問題・解答入り詳細グリッド用の装飾CSS（画像書き出し専用）
   ========================================================================== */
.grid-capture-cell {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    padding: 6px 4px;
    color: white;
    font-family: sans-serif;
    text-align: center;
}

.grid-cell-no {
    font-size: 10px;
    opacity: 0.85;
    margin-bottom: 2px;
}

.grid-cell-formula {
    font-size: 14px;
    font-weight: bold;
    letter-spacing: -0.5px;
    margin-bottom: 2px;
}

.grid-cell-answer {
    font-size: 11px;
    font-weight: bold;
    background-color: rgba(0, 0, 0, 0.15);
    padding: 1px 4px;
    border-radius: 3px;
    width: 90%;
    text-align: center;
}
