/* 大文字さんと小文字くん（apps/alpha） */
:root {
    --brown: #5d4037;
    --brown-mid: #8d6e63;
    --brown-light: #d7ccc8;
    --bg: #fff9f0;
    --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;
    width: 100vw;
    height: 100dvh;
    background-color: var(--bg);
    font-family: var(--font-maru);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

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

/* 確実な非表示（UI要塞化） */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
}

#app-container {
    position: relative;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
}

#canvas-container {
    position: absolute;
    inset: 0;
    z-index: 1;
}

canvas {
    display: block;
    touch-action: none;
}

/* 左上の「🏠 もどる」は deji_nav.js が自動で付ける（z-index 9000） */

#rule-box {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: var(--safe-left);
    z-index: 30;
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 14px;
    border-radius: 12px;
    border: 3px solid var(--brown-mid);
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15);
    font-size: 15px;
    color: var(--brown);
    font-weight: 700;
    max-width: 280px;
    line-height: 1.5;
    pointer-events: none;
}

#quit-btn {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    z-index: 30;
    min-width: 88px;
    min-height: 50px;
    padding: 0 16px;
    border-radius: 25px;
    background: #ef5350;
    border: 3px solid #c62828;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    box-shadow: 0 4px 0 #b71c1c;
    cursor: pointer;
}
#quit-btn:active { transform: translateY(4px); box-shadow: none; }

#credit-box {
    position: absolute;
    bottom: calc(5px + env(safe-area-inset-bottom, 0px));
    right: 10px;
    z-index: 2;
    font-size: 12px;
    color: var(--brown-mid);
    opacity: 0.7;
    pointer-events: none;
}

/* 言語の切りかえ。はじめの画面の右上 */
.lang-slot {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    z-index: 100;
    max-width: calc(100% - 170px);
}

.overlay-screen {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: rgba(255, 249, 240, 0.98);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 70px 12px 12px;
}

.start-panel {
    width: 92%;
    max-width: 760px;
    max-height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

h1 {
    color: var(--brown);
    margin: 0 0 6px;
    font-size: clamp(1.7rem, 3.6vw, 2.3rem);
    font-weight: 900;
    text-shadow: 2px 2px 0 var(--brown-light);
}

.setting-group { margin-bottom: 6px; width: 100%; }
.setting-label { font-weight: 700; color: var(--brown); margin-bottom: 6px; display: block; font-size: 18px; }
.btn-group { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.choice-btn {
    min-height: 52px;
    padding: 8px 20px;
    border: 3px solid var(--brown-mid);
    background: #fff;
    color: var(--brown);
    border-radius: 12px;
    font-weight: 700;
    font-size: 17px;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--brown-light);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.3;
}
.choice-btn small { font-size: 12px; font-weight: 400; }
.choice-btn.selected { background: var(--brown-mid); color: #fff; box-shadow: 0 4px 0 var(--brown); }
.choice-btn:active { transform: translateY(4px); box-shadow: none; }

.medal-guide {
    background: #fffbea;
    border: 2px dashed #f1c40f;
    border-radius: 12px;
    padding: 6px 14px;
    font-size: 15px;
    font-weight: 700;
    color: #7a5a00;
    line-height: 1.5;
    margin: 4px 0;
}
.medal-guide p { margin: 0; }
.medal-guide-title { color: #b8860b; }

.start-btn {
    margin-top: 8px;
    min-height: 60px;
    padding: 10px 44px;
    font-size: 24px;
    background: #66bb6a;
    color: #fff;
    border: none;
    border-radius: 60px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 0 #388e3c;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.start-btn:active { transform: translateY(8px); box-shadow: none; }
.cert-btn { background: linear-gradient(180deg, #f1c40f, #d35400); box-shadow: 0 8px 0 #b94a00; }

.result-card {
    background: #fff;
    border: 5px solid var(--brown-mid);
    border-radius: 24px;
    padding: 18px 28px;
    width: 92%;
    max-width: 600px;
    max-height: 100%;
    overflow-y: auto;
}
.result-card h2 { color: var(--brown); margin: 0 0 4px; font-size: 34px; }
.result-medal { font-size: 72px; line-height: 1.2; }
.result-score { font-size: 24px; font-weight: 800; color: var(--brown); margin: 4px 0; }
.result-time { font-size: 20px; font-weight: 700; color: #e53935; margin: 4px 0; }
.result-note { font-size: 16px; font-weight: 700; color: #7a5a00; background: #fffbea; border-radius: 10px; padding: 6px 10px; margin: 6px 0; }
.result-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

@media (max-height: 800px) {
    .overlay-screen { padding-top: 64px; }
    h1 { font-size: 1.6rem; margin-bottom: 2px; }
    .setting-label { font-size: 16px; margin-bottom: 4px; }
    .choice-btn { min-height: 46px; padding: 4px 16px; font-size: 16px; }
    .medal-guide { font-size: 13px; padding: 4px 12px; }
    .start-btn { min-height: 54px; font-size: 21px; margin-top: 4px; }
}

@media (max-width: 700px) {
    .lang-slot { left: var(--safe-left); right: 10px; max-width: none; display: flex; justify-content: flex-end; }
    .overlay-screen { padding-top: 120px; }
    #rule-box { top: 70px; left: 10px; }
}

/* ===== P1（スマホ点検） =====
   たての スマホ：上の 帯（canvas の 高さの 35%）の まんなかに かく お題の 文字に、
   「あそびかた」の 箱（top 70px）が 重なって、何を さがすか 見えなかった。
   箱を 帯の 線の すぐ 下へ うつし、文字を ドラッグする 指は とおす（rules md 2-9：飾りの 箱は pointer-events: none）。 */
@media (max-width: 600px) and (orientation: portrait) {
    #rule-box {
        top: calc(35vh + 8px);
        top: calc(35dvh + 8px);
        left: 10px;
        max-width: calc(100% - 20px);
        padding: 4px 10px;
        font-size: 13px;
        border-width: 2px;
        background: rgba(255, 255, 255, 0.88);
        pointer-events: none;
    }
}
