/* 12ヶ月カードバトル（apps/12vs） */
:root {
    --blue: #64b5f6;
    --blue-dark: #1e88e5;
    --orange: #ffb74d;
    --orange-dark: #f57c00;
    --bg: #fffbf0;
    --table: #fcedda;
    --text: #5d4037;
    --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;
}

* { 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;
    touch-action: manipulation;
}

button, select { 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;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    overflow: hidden;
}

/* プレイヤーの じんち */
.player-area {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    margin: 4px 6px;
    border-radius: 16px;
    background: var(--table);
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
/* 上の人は さかさま（むかいあって あそぶ） */
.player-area.flipped { transform: rotate(180deg); }

.area-top {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 12px 0;
    min-height: 50px;
}
.star-tracker {
    min-width: 120px;
    font-size: 22px;
    color: #f1c40f;
    text-shadow: 1px 1px 0 #c79a00;
    letter-spacing: 2px;
    white-space: nowrap;
    overflow: hidden;
}
.rule-display {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    color: var(--blue-dark);
    background: rgba(255, 255, 255, 0.85);
    border: 2px solid var(--blue);
    border-radius: 12px;
    padding: 4px 12px;
    line-height: 1.35;
}
.hint-btn {
    min-width: 120px;
    min-height: 44px;
    padding: 0 14px;
    border: 3px solid #fdcb6e;
    border-radius: 14px;
    background: #ffeaa7;
    color: #c0392b;
    font-size: 17px;
    font-weight: 800;
    box-shadow: 0 3px 0 #f0b74a;
    cursor: pointer;
}
.hint-btn:active { transform: translateY(3px); box-shadow: none; }

.area-main {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 6px 150px 8px;
}

/* うらがえしの カード */
.deck {
    display: grid;
    grid-template-columns: repeat(6, 76px);
    gap: 8px;
}
.deck-card {
    width: 76px;
    aspect-ratio: 4 / 3;
    border: none;
    border-radius: 8px;
    background: var(--blue) repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.18) 0 6px, transparent 6px 12px);
    box-shadow: 0 4px 0 var(--blue-dark);
    color: rgba(255, 255, 255, 0.8);
    font-size: 20px;
    cursor: pointer;
}
.deck-card:active { transform: translateY(4px); box-shadow: none; }
.deck-card.taken { visibility: hidden; }

/* ひいた カード */
.field {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 200px;
    min-height: 84px;
    padding: 8px;
    border: 3px dashed #d7ccc8;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.6);
}
.field-card {
    width: 100px;
    aspect-ratio: 4 / 3;
    border-radius: 8px;
    background: var(--blue) repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.18) 0 6px, transparent 6px 12px);
    box-shadow: 0 3px 0 var(--blue-dark);
}
.field-card.open { background: none; box-shadow: none; }
.field-card .dm-card { width: 100%; border: 3px solid var(--orange); }
.field.open-field .field-card { width: 128px; }

/* 月の テンキー（5れつ） */
.numpad {
    display: grid;
    grid-template-columns: repeat(5, 62px);
    gap: 6px;
    padding: 8px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
}
.numpad-display {
    grid-column: span 5;
    min-height: 40px;
    padding: 4px 10px;
    border: 2px solid #eee;
    border-radius: 8px;
    background: #fafafa;
    font-size: 19px;
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    color: var(--text);
}
.num-btn {
    min-height: 46px;
    border: 2px solid #efe7e2;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font-size: 17px;
    font-weight: 800;
    box-shadow: 0 3px 0 #e6dcd5;
    cursor: pointer;
    padding: 0 2px;
}
.num-btn:active { transform: translateY(3px); box-shadow: none; }
.num-btn.op-clear { color: #d63031; }
.num-btn.op-plus { color: #0984e3; font-size: 22px; }
.num-btn.enter { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; box-shadow: 0 3px 0 #1565c0; }

.total-display {
    min-width: 110px;
    padding: 6px 22px;
    font-size: 52px;
    font-weight: 900;
    color: var(--blue-dark);
    background: rgba(255, 255, 255, 0.92);
    border: 5px solid var(--blue);
    border-radius: 16px;
    text-align: center;
    line-height: 1.1;
}
.result-text {
    position: static !important;
    font-size: 44px;
    font-weight: 900;
    line-height: 1.1;
    min-width: 120px;
    text-align: center;
}
.result-text.hidden { position: absolute !important; }
.result-text.win { color: #ff5252; }
.result-text.lose { color: #8d6e63; }
.result-text.draw { color: #ffa502; }

/* けいさんが ちがうときの お知らせ（じんちの 中・向きも そのまま。ルールの らんに かさねて、テンキーを かくさない） */
.calc-msg {
    position: absolute;
    left: 50%;
    top: 4px;
    transform: translateX(-50%);
    z-index: 30;
    width: min(92%, 620px);
    padding: 10px 16px;
    background: #fff3e0;
    border: 3px solid var(--orange-dark);
    border-radius: 14px;
    font-size: 17px;
    font-weight: 800;
    color: #8d4b00;
    text-align: center;
    line-height: 1.5;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
    pointer-events: none;
}

/* こっそり ヒント（じんちの 中） */
.hint-overlay {
    position: absolute;
    top: 56px;
    right: 10px;
    bottom: 10px;
    z-index: 40;
    width: 300px;
    padding: 8px 10px;
    background: rgba(253, 246, 227, 0.98);
    border: 3px solid var(--orange);
    border-radius: 12px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.hint-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 10px;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.5;
    align-content: start;
}
.hint-close {
    min-height: 44px;
    border: none;
    border-radius: 12px;
    background: var(--orange);
    color: #fff;
    font-size: 16px;
    font-weight: 800;
    box-shadow: 0 3px 0 var(--orange-dark);
    cursor: pointer;
}

/* まんなか */
#center-area {
    flex-shrink: 0;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 12px;
}
.progress {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.35;
}
.center-btns { flex-shrink: 0; display: flex; gap: 10px; }
.btn {
    min-height: 50px;
    padding: 0 22px;
    border: none;
    border-radius: 25px;
    background: var(--orange);
    color: #fff;
    font-size: 19px;
    font-weight: 800;
    box-shadow: 0 4px 0 var(--orange-dark);
    cursor: pointer;
    white-space: nowrap;
}
.btn:active { transform: translateY(4px); box-shadow: none; }
.btn-open { background: #ef6c00; box-shadow: 0 4px 0 #bf360c; font-size: 22px; }
.btn-next { background: var(--blue-dark); box-shadow: 0 4px 0 #1565c0; }
.btn-rule { flex: 1; max-width: 220px; margin-left: auto; background: var(--blue); box-shadow: 0 4px 0 var(--blue-dark); font-size: 16px; }
.center-btns:empty + .btn-rule { margin-left: auto; }

/* はじめの画面・けっか（z-index は 🏠 もどる より下） */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 8000;
    background: rgba(255, 251, 240, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(64px + env(safe-area-inset-top, 0px)) 12px 12px;
    overflow-y: auto;
}
.setup-box, .result-card {
    position: relative;
    width: 94%;
    max-width: 640px;
    max-height: 100%;
    overflow-y: auto;
    background: #fff;
    border: 4px solid var(--blue);
    border-radius: 22px;
    padding: 16px 22px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.setup-box .lang-slot { align-self: flex-end; }
.setup-box h1 { margin: 0; font-size: clamp(1.5rem, 3.2vw, 2.1rem); font-weight: 900; color: var(--blue-dark); }
.setup-how { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.6; }
.select-label { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 520px; font-weight: 800; font-size: 17px; }
.select-label span { flex-shrink: 0; min-width: 110px; text-align: right; }
.select-label select {
    flex: 1;
    min-width: 0;
    min-height: 50px;
    padding: 4px 10px;
    border: 3px solid var(--blue);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font-size: 17px;
    font-weight: 700;
}
.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.55;
}
.medal-guide p { margin: 0; }
.medal-guide-title { color: #b8860b; }
.guide-small { font-size: 13px; color: #8a6d1e; }

.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;
}
.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: 19px; }

.result-card h2 { margin: 0; font-size: 30px; color: #ef6c00; }
.result-medal { font-size: 72px; line-height: 1.2; }
.result-score { margin: 0; font-size: 22px; font-weight: 800; }
.result-stars { margin: 0; font-size: 17px; font-weight: 700; color: #8d6e63; }
.result-note { margin: 0; font-size: 16px; font-weight: 700; color: #7a5a00; background: #fffbea; border-radius: 10px; padding: 6px 10px; }
.result-buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

@media (max-width: 1100px) {
    .area-main { padding-left: 140px; padding-right: 140px; gap: 12px; }
    .deck { grid-template-columns: repeat(6, 64px); gap: 6px; }
    .deck-card { width: 64px; }
    .field-card { width: 84px; }
    .field.open-field .field-card { width: 104px; }
    .numpad { grid-template-columns: repeat(5, 56px); }
}

@media (max-height: 760px) {
    .area-top { min-height: 46px; }
    .num-btn { min-height: 44px; font-size: 16px; }
    .numpad { gap: 4px; padding: 6px; }
    .numpad-display { min-height: 34px; font-size: 17px; }
    .total-display { font-size: 42px; }
    .setup-how { font-size: 14px; }
    .medal-guide { font-size: 13px; }
    .start-btn { min-height: 54px; font-size: 21px; }
}

@media (max-width: 900px) {
    .area-main { padding: 6px 10px 8px; flex-wrap: wrap; gap: 8px; }
    .star-tracker, .hint-btn { min-width: 0; }
    .rule-display { font-size: 13px; }
}

/* ===== P1（スマホ点検）：スマホでも 5回 勝負を 最後まで =====
   いままで：せまい 画面（max-width 900px）で area-main の 左右の すきま（150px）を 10px に して いたため、
   上の人（さかさま）の テンキーが 画面の 左上に きて 🏠 もどる の 下に もぐった。
   スマホでは カードの 山・テンキーが 高さに 入りきらず、まんなかの 文字も たてに つぶれていた。
   iPad（1180×820・1024×700）には 効かない。 */
@media (max-height: 560px) and (orientation: landscape) {
    /* よこ（844×340 など）：2人の じんちは 上下の まま、中を ちいさく 1〜2だんに */
    #center-area { min-height: 40px; padding: 0 8px; gap: 8px; }
    .progress { font-size: 12px; line-height: 1.3; }
    .center-btns { gap: 6px; }
    .btn { min-height: 38px; padding: 0 14px; font-size: 15px; box-shadow: 0 3px 0 var(--orange-dark); }
    .btn-open { font-size: 16px; box-shadow: 0 3px 0 #bf360c; }
    .btn-next { box-shadow: 0 3px 0 #1565c0; }
    .btn-rule { max-width: 170px; font-size: 13px; box-shadow: 0 3px 0 var(--blue-dark); }
    .player-area { margin: 2px 4px; border-radius: 12px; }
    .area-top { min-height: 30px; padding: 2px 8px 0; gap: 6px; }
    .star-tracker { min-width: 0; font-size: 16px; }
    .rule-display { font-size: 12px; padding: 1px 8px; border-radius: 9px; }
    .hint-btn { min-width: 0; min-height: 30px; padding: 0 10px; font-size: 13px; border-width: 2px; border-radius: 10px; box-shadow: 0 2px 0 #f0b74a; }
    .area-main { padding: 2px 8px 4px; gap: 8px; flex-wrap: nowrap; }
    /* 上の人は さかさま：じんちの 右は 画面の 左。🏠 もどる（左上 110px）を よける */
    #p2-area .area-main { padding-right: 112px; }
    .deck { grid-template-columns: repeat(6, min(52px, 6.4vw)); gap: 4px; }
    .deck-card { width: min(52px, 6.4vw); font-size: 14px; box-shadow: 0 3px 0 var(--blue-dark); }
    .field { flex-wrap: wrap; gap: 4px; min-width: 0; min-height: 0; max-width: calc(2 * min(60px, 7.2vw) + 26px); padding: 4px; border-width: 2px; }
    .field-card, .field.open-field .field-card { width: min(60px, 7.2vw); }
    .numpad { grid-template-columns: repeat(9, min(42px, 5.2vw)); gap: 4px; padding: 5px; border-radius: 10px; }
    .numpad-display { grid-column: span 3; min-height: 0; padding: 2px 6px; font-size: 14px; display: flex; align-items: center; justify-content: flex-end; }
    .num-btn { min-height: 36px; font-size: 13px; border-radius: 8px; padding: 0; }
    .num-btn.op-plus { font-size: 18px; }
    .total-display { min-width: 70px; padding: 2px 12px; font-size: 30px; border-width: 3px; }
    .result-text { font-size: 28px; min-width: 70px; }
    .calc-msg { font-size: 13px; padding: 6px 10px; }
    .hint-overlay { top: 4px; bottom: 4px; width: 280px; }
    #p2-hint { right: 112px; }
    .hint-list { font-size: 13px; line-height: 1.35; }
    .hint-close { min-height: 34px; font-size: 14px; }
    .overlay { padding: calc(60px + env(safe-area-inset-top, 0px)) 10px 8px; align-items: flex-start; }
    .setup-box, .result-card { padding: 10px 16px 14px; gap: 6px; margin: 0 auto; }
    .result-medal { font-size: 44px; }
    .result-card h2 { font-size: 22px; }
    .start-btn { min-height: 48px; padding: 6px 28px; font-size: 18px; box-shadow: 0 5px 0 #388e3c; }
    .cert-btn { box-shadow: 0 5px 0 #b94a00; }
    .btn-sub { box-shadow: 0 5px 0 var(--blue-dark); font-size: 16px; }
}
@media (max-width: 600px) and (orientation: portrait) {
    /* たて（390×655 など）：まんなかは 文字の 行と ボタンの 行に。じんちの 中は 2だんに */
    #center-area { flex-wrap: wrap; min-height: 0; padding: 2px 8px; gap: 4px 6px; }
    .progress { flex: 1 1 100%; font-size: 12px; line-height: 1.3; text-align: center; }
    .center-btns { gap: 6px; }
    .btn { min-height: 38px; padding: 0 14px; font-size: 15px; box-shadow: 0 3px 0 var(--orange-dark); }
    .btn-open { font-size: 16px; box-shadow: 0 3px 0 #bf360c; }
    .btn-next { box-shadow: 0 3px 0 #1565c0; }
    .btn-rule { max-width: 170px; font-size: 13px; box-shadow: 0 3px 0 var(--blue-dark); }
    .player-area { margin: 2px 4px; border-radius: 12px; }
    .area-top { min-height: 32px; padding: 3px 6px 0; gap: 6px; }
    .star-tracker { min-width: 0; font-size: 15px; letter-spacing: 0; }
    .rule-display { font-size: 11px; padding: 2px 6px; border-radius: 9px; }
    .hint-btn { min-width: 0; min-height: 32px; padding: 0 8px; font-size: 13px; border-width: 2px; border-radius: 10px; box-shadow: 0 2px 0 #f0b74a; }
    .area-main { padding: 4px 6px; gap: 6px; flex-wrap: wrap; align-content: center; }
    /* 上の人は さかさま：じんちの 下は 画面の 上。🏠 もどる（上 58px）を よける */
    #p2-area .area-main { padding-bottom: 50px; }
    .deck { grid-template-columns: repeat(6, min(52px, 13vw)); gap: 5px; }
    .deck-card { width: min(52px, 13vw); font-size: 14px; box-shadow: 0 3px 0 var(--blue-dark); }
    .field { gap: 4px; min-width: 120px; min-height: 0; padding: 4px; border-width: 2px; }
    .field-card, .field.open-field .field-card { width: min(72px, 18vw); }
    .numpad { grid-template-columns: repeat(9, min(38px, 9.4vw)); gap: 4px; padding: 5px; border-radius: 10px; }
    .numpad-display { grid-column: span 3; min-height: 0; padding: 2px 6px; font-size: 14px; display: flex; align-items: center; justify-content: flex-end; }
    .num-btn { min-height: 38px; font-size: 12px; border-radius: 8px; padding: 0; }
    .num-btn.op-plus { font-size: 18px; }
    .total-display { min-width: 70px; padding: 2px 12px; font-size: 32px; border-width: 3px; }
    .result-text { font-size: 30px; min-width: 70px; }
    .calc-msg { font-size: 13px; padding: 6px 10px; }
    .hint-overlay { top: 36px; bottom: 6px; right: 6px; left: 6px; width: auto; }
    #p2-hint { bottom: 52px; }
    .hint-list { font-size: 13px; line-height: 1.35; }
    .hint-close { min-height: 36px; font-size: 14px; }
    .result-medal { font-size: 52px; }
    .start-btn { min-height: 52px; padding: 8px 28px; font-size: 19px; }
}
