/* 月をあわせよう！12ヶ月マッチング（apps/month02） */
:root {
    --blue: #4A90E2;
    --blue-dark: #357ABD;
    --lv1: #7cb342;
    --lv1-dark: #558b2f;
    --lv2: #f4511e;
    --lv2-dark: #bf360c;
    --bg: #f4f8ec;
    --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 20px;
}

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

.start-panel {
    width: 100%;
    max-width: 720px;
    background: #fff;
    border-radius: 20px;
    padding: 16px 20px 20px;
    box-shadow: 0 5px 0 #dce8c8;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}

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

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

.choice-btn {
    min-height: 56px;
    min-width: 120px;
    padding: 6px 18px;
    border: 3px solid var(--blue);
    background: #fff;
    color: var(--blue-dark);
    border-radius: 14px;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 0 #c2dcf8;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.3;
}
.choice-btn small { font-size: 13px; 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; }
#level-group .choice-btn[data-level="1"] { border-color: var(--lv1); color: var(--lv1-dark); box-shadow: 0 4px 0 #dcedc8; }
#level-group .choice-btn[data-level="1"].selected { background: var(--lv1); color: #fff; box-shadow: 0 4px 0 var(--lv1-dark); }
#level-group .choice-btn[data-level="2"] { border-color: var(--lv2); color: var(--lv2-dark); box-shadow: 0 4px 0 #ffccbc; }
#level-group .choice-btn[data-level="2"].selected { background: var(--lv2); color: #fff; box-shadow: 0 4px 0 var(--lv2-dark); }
#level-group .choice-btn.selected small { color: #fff; }

.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; }

.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; }

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

.game-head {
    width: 100%;
    min-height: 56px;
    padding-left: 130px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.timer-box, .remain-box {
    flex-shrink: 0;
    background: #fff;
    border-radius: 30px;
    padding: 8px 16px;
    font-size: 20px;
    font-weight: 800;
    box-shadow: 0 3px 0 #dce8c8;
}
#timer-display { color: var(--blue-dark); font-variant-numeric: tabular-nums; }
.game-how { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 700; color: #4e6b2a; line-height: 1.4; }
.quit-btn {
    flex-shrink: 0;
    min-height: 50px;
    padding: 0 18px;
    border: none;
    border-radius: 25px;
    background: #ef5350;
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    box-shadow: 0 4px 0 #b71c1c;
    cursor: pointer;
}
.quit-btn:active { transform: translateY(4px); box-shadow: none; }

.board {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    --cw: 120px;   /* カード1まいの はば。main.js が 画面に あわせて きめる */
}
.area {
    display: grid;
    grid-auto-rows: auto;
    gap: 10px;
    padding: 10px;
    border-radius: 16px;
    justify-content: center;
}
.target-area { background: #fff; border: 3px dashed #b7c9a0; }
.hand-area { background: #e0f2fe; }

.slot {
    position: relative;
    width: var(--cw);
    aspect-ratio: 4 / 3;
}
.slot .dm-card {
    width: 100%;
    height: 100%;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
}
.target-slot .dm-card { outline: 3px solid transparent; transition: outline-color 0.15s; }
.target-slot.drop-hover .dm-card { outline-color: var(--blue); }
.target-slot.wrong .dm-card { animation: shake 0.4s; outline-color: #2196f3; }

/* あわせた カード（目印の上に のせる） */
.target-slot .placed {
    position: absolute;
    inset: 0;
}
.target-slot .placed .dm-card { width: 100%; height: 100%; box-shadow: none; }
.target-slot .maru {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--cw) * 0.5);
    font-weight: 900;
    color: rgba(229, 57, 53, 0.85);
    line-height: 1;
    pointer-events: none;
}
.target-slot .batsu {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--cw) * 0.5);
    font-weight: 900;
    color: rgba(33, 150, 243, 0.85);
    line-height: 1;
    pointer-events: none;
}

.hand-slot .dm-card { cursor: grab; touch-action: none; }
.hand-slot.lifted .dm-card { opacity: 0.25; }
.hand-slot.used .dm-card { visibility: hidden; }

.drag-ghost {
    position: fixed;
    z-index: 7000;
    pointer-events: none;
    transform: scale(1.06);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.25);
    border-radius: 10px;
}
.drag-ghost .dm-card { width: 100%; }

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

/* けっか（z-index は 🏠 もどる より下） */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 8000;
    background: rgba(244, 248, 236, 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: 620px;
    max-height: 100%;
    overflow-y: auto;
    text-align: center;
}
.result-card h2 { margin: 0; color: #ff5722; font-size: 32px; }
.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: 0; }
    .setting-label { font-size: 16px; margin-bottom: 4px; }
    .choice-btn { min-height: 48px; font-size: 16px; }
    .medal-guide { font-size: 13px; padding: 4px 12px; }
    .start-btn { min-height: 54px; font-size: 21px; }
    .start-panel { gap: 6px; padding-top: 12px; }
}

@media (max-width: 900px) {
    .game-head { flex-wrap: wrap; }
    .game-how { order: 4; 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; }
}

@media (prefers-reduced-motion: reduce) {
    .target-slot.wrong .dm-card { animation: none; }
}

/* ===== P1（スマホ点検） ===== */
/* たての スマホ：「タイム・のこり・やめる」が 3だんに なって 場所を とっていた。
   1行め「🏠 もどる・タイム」、2行め「のこり・やめる」、3行め せつめい */
@media (max-width: 600px) and (orientation: portrait) {
    .game-head { padding-left: 0; gap: 8px; row-gap: 6px; min-height: 0; }
    .timer-box { margin-left: 130px; }
    .timer-box, .remain-box { padding: 6px 12px; font-size: 17px; }
    .quit-btn { min-height: 44px; font-size: 15px; padding: 0 14px; margin-left: auto; }
    .game-how { font-size: 14px; line-height: 1.3; }
}
/* よこの 低い スマホ：せつめいの 文を 同じ 行に（カードの 高さを かせぐ） */
@media (max-height: 560px) and (orientation: landscape) {
    .game-head { flex-wrap: nowrap; min-height: 50px; gap: 8px; }
    .game-how { order: 0; flex-basis: auto; font-size: 13px; line-height: 1.3; }
    .timer-box, .remain-box { padding: 6px 12px; font-size: 17px; }
    .quit-btn { min-height: 44px; font-size: 15px; padding: 0 14px; }
}
