/* アルファベットハンター（apps/abc）  Tailwind をやめて 素の CSS に（B9） */
:root {
    --indigo: #4f46e5;
    --indigo-dark: #4338ca;
    --indigo-light: #c7d2fe;
    --slate: #334155;
    --slate-mid: #64748b;
    --slate-light: #e2e8f0;
    --font-maru: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --safe-left: calc(140px + env(safe-area-inset-left, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
    margin: 0;
    padding: 0 8px 8px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: var(--font-maru);
    color: #1e293b;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    background-color: #e2e8f0;
    background-image: url('images/bg-sky.webp');
    background-size: cover;
    background-position: center;
    position: relative;
}

button, input { font-family: var(--font-maru); }

.bg-veil { position: fixed; inset: 0; background: rgba(255, 255, 255, 0.2); z-index: -1; pointer-events: none; }

/* 確実な非表示（UI要塞化） */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
    /* P1：かくした 言語ボタンなどが 横に のびない（rules md 2-10 の 8つの 指定に そろえる） */
    max-width: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
}

.file-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* 左上の「🏠 もどる」は deji_nav.js が自動で付ける（z-index 9000） */
.app-header {
    width: 100%;
    max-width: 1100px;
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 0 4px var(--safe-left);
    z-index: 20;
    flex-shrink: 0;
}
.app-name {
    margin: 0;
    font-size: clamp(1.05rem, 2.2vw, 1.35rem);
    font-weight: 900;
    color: var(--indigo-dark);
    background: rgba(255, 255, 255, 0.92);
    padding: 6px 16px;
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    border: 1px solid #e0e7ff;
    white-space: nowrap;
}
.header-right { display: flex; align-items: center; gap: 8px; position: relative; }
.lang-slot { position: relative; }

.teacher-btn {
    min-height: 44px;
    padding: 0 14px;
    border: none;
    border-radius: 10px;
    background: #facc15;
    color: #713f12;
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}
.teacher-btn.on { background: #3b82f6; color: #fff; }

.screen-stack {
    display: grid;
    grid-template-areas: "stack";
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 1100px;
    justify-items: center;
    align-items: center;
    position: relative;
}
.screen-layer {
    grid-area: stack;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* --- はじめの画面 --- */
.start-card {
    background: rgba(255, 255, 255, 0.95);
    padding: 18px 24px;
    border-radius: 24px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
    border: 4px solid var(--indigo-light);
    text-align: center;
    width: 95%;
    max-width: 680px;
    max-height: 100%;
    overflow-y: auto;
}
.start-title { margin: 0; font-size: 1.9rem; font-weight: 900; color: var(--indigo); }
.start-sub { margin: 2px 0 12px; color: var(--slate-mid); font-weight: 700; font-size: 0.95rem; }
.mode-box { margin-bottom: 12px; }
.mode-head {
    margin: 0 0 8px;
    padding: 6px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: clamp(1.15rem, 2.4vw, 1.45rem);
    font-weight: 900;
}
.mode-head small { font-size: 0.75rem; font-weight: 700; margin-top: 2px; }
.mode-head.auto { color: var(--indigo); background: #eef2ff; border-bottom: 4px solid var(--indigo-light); }
.mode-head.auto small { color: #818cf8; }
.mode-head.img { color: var(--slate); background: #f8fafc; border-bottom: 4px solid var(--slate-light); }
.mode-head.img small { color: #94a3b8; }
.count-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.count-btn {
    min-height: 54px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    border: 2px solid;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.count-btn:active { transform: scale(0.95); }
.count-btn.green { background: #dcfce7; color: #15803d; border-color: #86efac; }
.count-btn.blue { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.count-btn.purple { background: #f3e8ff; color: #7e22ce; border-color: #d8b4fe; }
.count-btn.gray { background: #f1f5f9; color: var(--slate); border-color: #cbd5e1; }

.medal-guide {
    background: #fffbea;
    border: 2px dashed #f1c40f;
    border-radius: 12px;
    padding: 6px 12px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #7a5a00;
    line-height: 1.5;
}
.medal-guide p { margin: 0; }
.medal-guide-title { color: #b8860b; }
.data-status { margin: 8px 0 0; font-size: 11px; color: #94a3b8; font-weight: 700; }

/* --- あそぶ画面 --- */
.game-layer { justify-content: flex-start; width: 98%; max-width: 860px; }
.status-bar {
    width: 100%;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 999px;
    padding: 6px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-weight: 700;
    color: #475569;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}
.status-num { color: var(--indigo); font-size: 1.25rem; }
.game-area { position: relative; width: 100%; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 4px solid rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.6);
}
#game-canvas { display: block; touch-action: none; }
.feedback-layer { position: absolute; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.countdown-layer { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 30; }
.countdown-text { font-size: 8rem; font-weight: 900; color: #fff; text-shadow: 0 5px 10px rgba(0, 0, 0, 0.5); }

.mark {
    position: absolute;
    font-size: 4.5rem;
    font-weight: 900;
    line-height: 1;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    animation: popMark 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
.mark.ok { color: #ef4444; }
.mark.ng { color: #3b82f6; opacity: 0.8; }
@keyframes popMark { 0% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.2); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

.question-panel {
    width: 100%;
    background: #fff;
    padding: 8px;
    border-radius: 16px;
    border-bottom: 8px solid var(--indigo-light);
    text-align: center;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    margin-top: 6px;
    flex-shrink: 0;
}
.target-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    width: 100%;
    min-height: 60px;
    border: none;
    background: transparent;
    cursor: pointer;
}
.target-display:active { transform: scale(0.95); }
.find-word { font-size: 1.9rem; color: #475569; font-weight: 900; }
.target-char { font-size: 3.6rem; font-weight: 900; color: #ef4444; border-bottom: 4px solid #ef4444; padding: 0 16px 4px; line-height: 1; }
.speaker { font-size: 1.6rem; opacity: 0.6; }

/* --- 先生モード --- */
/* 絵の上に重ねず、絵の下に ならべる（B9 の なおし：前は 絵の下のほうの 文字が 道具に かくれて とうろくしにくかった）。
   先生モードの あいだは 絵のほうが 小さくなる（createResponsiveCanvas が のこりの 高さで 計算する） */
.teacher-ui {
    position: relative;
    flex-shrink: 0;
    width: 100%;
    max-width: 760px;
    margin-top: 6px;
    background: #fefce8;
    padding: 8px 10px;
    border-radius: 12px;
    border: 2px solid #fde047;
    z-index: 50;
    box-shadow: 0 10px 20px -8px rgba(0, 0, 0, 0.25);
}
.teacher-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.teacher-row.card { background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--slate-light); margin-bottom: 0; }
.teacher-row-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.teacher-title { font-size: 13px; font-weight: 700; color: #854d0e; }
.t-btn {
    min-height: 40px;
    padding: 0 12px;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    position: relative;
}
.t-btn.green { background: #10b981; }
.t-btn.blue { background: #3b82f6; }
.t-btn.red { background: #ef4444; }
.t-btn.gray { background: #64748b; }
.t-btn.armed { background: #b91c1c; outline: 3px solid #fecaca; }
.t-file {
    display: block;
    min-height: 40px;
    line-height: 40px;
    margin-bottom: 6px;
    padding: 0 12px;
    background: #fff;
    border: 1px dashed #94a3b8;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--slate);
    cursor: pointer;
    position: relative;
}
.input-char {
    width: 64px;
    height: 48px;
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    font-size: 1.6rem;
    font-weight: 900;
    text-align: center;
    text-transform: uppercase;
    color: var(--indigo);
}
/* G3：先生の 写真の 注意（rules 3-14・3-23） */
.t-note { margin: -2px 0 6px; font-size: 12px; font-weight: 700; line-height: 1.45; color: #854d0e; }
.t-help { font-size: 12px; font-weight: 700; color: var(--slate-mid); line-height: 1.4; flex: 1; }
.t-count { color: var(--indigo); }

/* --- けっか画面 --- */
.result-card {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    padding: 26px 24px 20px;
    border-radius: 24px;
    text-align: center;
    width: 90%;
    max-width: 420px;
    border: 8px solid #a5b4fc;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-height: 100%;
    overflow-y: auto;
}
.result-party { position: absolute; top: -8px; left: 0; right: 0; font-size: 2.6rem; }
.result-title { margin: 8px 0 0; font-size: 2.2rem; font-weight: 900; color: var(--indigo); }
.result-medal { font-size: 3.6rem; line-height: 1.2; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 10px; }
.result-cell { background: #f8fafc; padding: 8px 4px; border-radius: 12px; border: 1px solid var(--slate-light); }
.result-label { font-size: 12px; color: #94a3b8; font-weight: 700; }
.result-value { font-size: 1.7rem; font-weight: 900; color: var(--slate); }
.result-note { font-size: 14px; font-weight: 700; color: #7a5a00; background: #fffbea; border-radius: 10px; padding: 6px 10px; margin: 0 0 10px; }
.big-btn {
    width: 100%;
    min-height: 60px;
    border: none;
    border-radius: 999px;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    background: #6366f1;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    margin-bottom: 10px;
}
.big-btn:active { transform: scale(0.95); }
.big-btn.cert { background: #eab308; }

/* 小さな お知らせ（z-index は 🏠 もどる の 9000 より下） */
.notice {
    position: fixed;
    left: 50%;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 8000;
    max-width: calc(100% - 24px);
    padding: 10px 22px;
    border-radius: 999px;
    background: #fff;
    border: 3px solid #f59e0b;
    box-shadow: 0 8px 24px -8px rgba(15, 23, 42, 0.45);
    font-size: 16px;
    font-weight: 700;
    color: #333;
    text-align: center;
    white-space: pre-line;
}

@media (max-height: 800px) {
    .start-card { padding: 12px 20px; }
    .start-title { font-size: 1.6rem; }
    .start-sub { margin-bottom: 8px; }
    .mode-box { margin-bottom: 8px; }
    .count-btn { min-height: 48px; }
    .target-char { font-size: 3rem; }
}

@media (max-width: 760px) {
    .app-header { flex-wrap: wrap; }
    .lang-slot { order: 2; }
}

/* ===== P1（スマホ点検） =====
   「Find ○」の 枠は カウントダウンの あとに 出る。いままでは かくして いる あいだ 場所を とらず、
   canvas が その 分まで 大きく なって、枠に 重なっていた（1024×700 で 60px・スマホ よこで 39px・iPad 1180×820 で 7px）。
   かくして いる ときも 場所だけは とっておく（見えない・さわれない は そのまま）。 */
.question-panel.hidden {
    position: relative !important;
    max-width: none !important;
    max-height: none !important;
}
/* スマホの よこ（高さ 560 以下）：上下に ならべると canvas が 140px ほどに なるので、
   「canvas 左・じかんと Find ○ 右」に ならべる（rules md 2-9） */
@media (max-height: 560px) and (orientation: landscape) {
    .app-header { min-height: 54px; padding-top: calc(4px + env(safe-area-inset-top, 0px)); padding-bottom: 2px; }
    .app-name { font-size: 1rem; padding: 4px 12px; }
    .game-layer {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 168px;
        grid-template-rows: auto minmax(0, 1fr);
        gap: 6px 10px;
        width: 98%;
        max-width: none;
        padding-bottom: 6px;
    }
    .game-layer .status-bar { grid-column: 2; grid-row: 1; flex-direction: column; align-items: stretch; gap: 2px; margin: 0; padding: 6px 12px; border-radius: 16px; font-size: 13px; }
    .game-layer .status-num { font-size: 1.1rem; }
    .game-layer .game-area { grid-column: 1; grid-row: 1 / 3; height: 100%; }
    .game-layer .question-panel { grid-column: 2; grid-row: 2; align-self: start; margin: 0; padding: 6px; }
    .target-display { flex-wrap: wrap; gap: 4px 8px; min-height: 0; }
    .find-word { font-size: 1.3rem; }
    .target-char { font-size: 2.6rem; padding: 0 10px 4px; }
    .speaker { font-size: 1.3rem; }
    .countdown-text { font-size: 5rem; }
    .mark { font-size: 3rem; }
}
/* P1：たての スマホ（はば 420 以下）で 題名が 右に 5px はみ出していた */
@media (max-width: 420px) {
    .app-name { font-size: 0.95rem; padding: 5px 10px; }
}
