/* 12ヶ月タッチゲーム（apps/month01） */
:root {
    --blue: #4A90E2;
    --blue-dark: #357ABD;
    --blue-light: #e3f2fd;
    --bg: #f0f8ff;
    --text: #333333;
    --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;
    width: 100vw;
    height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-maru);
    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 {
    position: relative;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.scroll-screen {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: calc(70px + env(safe-area-inset-top, 0px)) 12px 24px;
}

#error-screen { justify-content: center; padding: 70px 12px 12px; }

/* 言語の切りかえ（右上） */
.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);
}

.panel {
    width: 100%;
    max-width: 680px;
    background: #fff;
    border-radius: 18px;
    padding: 18px 20px 22px;
    box-shadow: 0 4px 0 #d6e6f7;
    text-align: center;
    margin: 0 auto;
}

.panel-kids {
    max-width: 640px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

h1 {
    margin: 0 0 8px;
    color: var(--blue-dark);
    font-size: clamp(1.5rem, 3.2vw, 2.1rem);
    font-weight: 900;
}

.lead { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.6; }

.step { font-weight: 700; font-size: 17px; margin: 8px 0; }

.btn {
    min-height: 48px;
    padding: 8px 16px;
    border: none;
    border-radius: 12px;
    background: var(--blue);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--blue-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    line-height: 1.4;
}
.btn:active { transform: translateY(4px); box-shadow: none; }
.btn:disabled { background: #c8ccd2; box-shadow: 0 4px 0 #a9aeb5; cursor: not-allowed; }
.btn:disabled:active { transform: none; }
.btn-green { background: #4caf50; box-shadow: 0 4px 0 #388e3c; }
.btn-orange { background: #ff9800; box-shadow: 0 4px 0 #e67e00; }
.btn-red { background: #f44336; box-shadow: 0 4px 0 #c62828; }
.btn-blue { background: var(--blue); box-shadow: 0 4px 0 var(--blue-dark); }
.btn-gray { background: #78909c; box-shadow: 0 4px 0 #546e7a; }

.row-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }

.sequence-display {
    background: var(--blue-light);
    border-radius: 10px;
    padding: 10px 12px;
    min-height: 48px;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.6;
    margin-bottom: 12px;
}

.month-btns { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.month-btns .btn { padding: 6px 4px; font-size: 17px; }
.month-btns .btn.used { background: #b0bec5; box-shadow: 0 4px 0 #90a4ae; }

.cheat-sheet {
    background: #fff9c4;
    border: 2px dashed #fbc02d;
    border-radius: 10px;
    padding: 10px 12px;
    text-align: left;
    margin-top: 6px;
}
.cheat-sheet summary { font-weight: 700; cursor: pointer; font-size: 16px; min-height: 32px; }
.cheat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; margin-top: 8px; font-size: 15px; }

.divider { border: 0; border-top: 2px dashed #d8e2ec; margin: 22px 0 10px; }

.mode-list { display: flex; flex-direction: column; gap: 12px; max-width: 480px; margin: 0 auto; }
.mode-list .btn { min-height: 56px; }

.qr-container {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    background: #f5f5f5;
    border-radius: 12px;
    padding: 16px;
}
.qr-instruction { font-weight: 700; color: #d84315; margin: 0; }
#qr-code { background: #fff; border-radius: 8px; }
.qr-mode-label { margin: 0; font-weight: 700; }
.magic-link { color: #555; font-size: 14px; word-break: break-all; }

/* ひとりで あそぶ・はじめの画面 */
.choice-list { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 460px; }
.choice-btn {
    min-height: 60px;
    padding: 8px 16px;
    border: 3px solid var(--blue);
    background: #fff;
    color: var(--blue-dark);
    border-radius: 14px;
    font-size: 19px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 0 #c2dcf8;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.3;
}
.choice-btn small { font-size: 14px; font-weight: 700; color: #5f7a96; }
.choice-btn.selected { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-dark); }
.choice-btn.selected small { color: #eaf4ff; }
.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.6;
}
.medal-guide p { margin: 0; }
.medal-guide-title { color: #b8860b; }

.sound-note { margin: 0; font-size: 14px; color: #5f7a96; font-weight: 700; }

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

.link-btn {
    min-height: 48px;
    border: none;
    background: transparent;
    color: var(--blue-dark);
    font-size: 16px;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

.error-text { font-size: 19px; font-weight: 700; line-height: 1.7; margin: 0 0 10px; }

/* あそぶ画面 */
#play-screen {
    padding: calc(10px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
    gap: 10px;
}

.play-head {
    width: 100%;
    min-height: 60px;
    padding-left: 130px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.q-count {
    flex-shrink: 0;
    background: var(--blue);
    color: #fff;
    font-weight: 800;
    font-size: 20px;
    border-radius: 30px;
    padding: 8px 16px;
}
.prompt {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    font-weight: 800;
    color: var(--blue-dark);
}
.prompt-text { font-size: 20px; line-height: 1.4; }
.prompt-word {
    font-size: 30px;
    color: #d84315;
    background: #fff3e0;
    border-radius: 12px;
    padding: 2px 16px;
}
.head-btns { display: flex; gap: 8px; flex-shrink: 0; }
.small-btn { min-height: 48px; padding: 6px 14px; font-size: 16px; }

.card-grid {
    /* カード1まいの はば：横はば と 高さ（2だん）の 小さいほう */
    --cw: min(calc((100vw - 24px - 60px) / 6), calc((100dvh - 110px - 12px) / 1.5));
    flex: 1;
    min-height: 0;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(6, var(--cw));
    grid-auto-rows: auto;
    gap: 12px;
    justify-content: center;
    align-content: center;
}
.card-slot {
    position: relative;
    aspect-ratio: 4 / 3;
    display: block;
    border: none;
    padding: 0;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
}
.card-slot .dm-card {
    width: 100%;
    height: 100%;
    box-shadow: 0 5px 0 #b9cde3;
    transition: transform 0.1s ease, opacity 0.3s ease;
}
.card-slot:active .dm-card { transform: scale(0.96); }
.card-slot.done { cursor: default; }
.card-slot.done .dm-card { opacity: 0.28; box-shadow: none; }
.card-slot.shake .dm-card { animation: shake 0.4s; }

@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    50% { transform: translateX(8px); }
    75% { transform: translateX(-8px); }
    100% { transform: translateX(0); }
}

/* ○・✕ */
.mark {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 7000;
    font-size: 40vmin;
    font-weight: 900;
    line-height: 1;
    pointer-events: none;
    text-shadow: 0 0 30px #fff;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.mark.show { transform: translate(-50%, -50%) scale(1); }
.mark-circle { color: #ff4081; }
.mark-cross { color: #2196f3; }

/* けっか（z-index は 🏠 もどる より下） */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 8000;
    background: rgba(240, 248, 255, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 70px 12px 12px;
}
.result-card {
    background: #fff;
    border: 5px solid var(--blue);
    border-radius: 24px;
    padding: 18px 28px;
    width: 92%;
    max-width: 600px;
    max-height: 100%;
    overflow-y: auto;
    text-align: center;
}
.result-card h2 { margin: 0; color: #ff9800; font-size: 34px; }
.result-medal { font-size: 72px; line-height: 1.2; }
.result-score { font-size: 23px; font-weight: 800; margin: 4px 0; }
.result-time { font-size: 19px; 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: 10px; }

@media (max-height: 800px) {
    .scroll-screen { padding-top: calc(64px + env(safe-area-inset-top, 0px)); }
    h1 { font-size: 1.5rem; margin-bottom: 2px; }
    .lead { font-size: 16px; }
    .choice-btn { min-height: 52px; font-size: 17px; }
    .medal-guide { font-size: 13px; }
    .start-btn { min-height: 54px; font-size: 21px; }
}

@media (max-width: 900px) {
    .card-grid {
        --cw: min(calc((100vw - 24px - 36px) / 4), calc((100dvh - 170px - 24px) / 2.25));
        grid-template-columns: repeat(4, var(--cw));
    }
    .play-head { flex-wrap: wrap; }
    .prompt { order: 3; flex-basis: 100%; }
}

@media (max-width: 700px) {
    .lang-slot { left: var(--safe-left); right: 10px; max-width: none; display: flex; justify-content: flex-end; }
    .scroll-screen { padding-top: 120px; }
    .month-btns { grid-template-columns: repeat(4, 1fr); }
    .cheat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    .mark, .card-slot .dm-card { transition: none; }
    .card-slot.shake .dm-card { animation: none; }
}

/* P1（スマホ点検）：たての スマホで「🔊 もういちど・👀 もじで みる・おわる」が 1行に ならび、
   「おわる」が 画面の 右の 外（はば 390 で 429〜505px）に 出ていた。ボタンの 列を 折り返す */
@media (max-width: 600px) {
    /* 1行め「🏠 もどる・1/12」、2行め「ボタン 3つ」（2行めは 左はしから） */
    .play-head { padding-left: 0; gap: 6px; row-gap: 8px; }
    .q-count { margin-left: 130px; }
    .head-btns { order: 2; flex: 1 0 100%; justify-content: center; flex-wrap: nowrap; gap: 6px; }
    .head-btns .small-btn { padding: 6px 10px; font-size: 14px; white-space: nowrap; }
}
