/* =========================================================
   オリジナルタウン（apps/town）
   GIGA端末（iPad 横）が いちばん。スマホでも 最後まで 進める（rules md 2-9）
   ========================================================= */
:root {
    --bg: #FBF6EC;
    --ink: #4E3D31;
    --sub: #8A7766;
    --main: #E9852B;
    --main-dark: #C76A17;
    --ok: #3FA66B;
    --ok-dark: #2E8152;
    --line: #E3D7C3;
    --card: #FFFFFF;
    --sel: #3B86D1;
    --danger: #D9534F;
    --font: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --left-safe: calc(140px + env(safe-area-inset-left, 0px));
}

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

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    -webkit-user-select: none;
    user-select: none;
}

/* UI要塞化（引っ越しの型 3-4） */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
}

#app {
    position: relative;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
}

.screen {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- ボタン --- */
.ui-btn {
    font-family: var(--font);
    font-weight: 800;
    font-size: 18px;
    min-height: 48px;
    padding: 8px 18px;
    border-radius: 16px;
    border: 3px solid transparent;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .08s;
}
.ui-btn:active { transform: scale(.96); }
.ui-btn:disabled { opacity: .45; cursor: default; transform: none; }
.primary-btn { background: var(--main); color: #fff; border-color: var(--main-dark); }
.success-btn { background: var(--ok); color: #fff; border-color: var(--ok-dark); }
.sub-btn { background: #fff; color: var(--ink); border-color: var(--line); }
.danger-btn { background: #fff; color: var(--danger); border-color: #F0C4C2; }
.danger-btn.armed { background: var(--danger); color: #fff; border-color: #B23C38; }
.big-btn { min-height: 64px; font-size: 22px; padding: 10px 28px; }
.small-btn { min-height: 44px; font-size: 16px; padding: 6px 12px; }

/* --- いちばん上の 行（左は 🏠 もどる の ばしょ） --- */
.topbar {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    min-height: 68px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) calc(340px + env(safe-area-inset-right, 0px)) 6px var(--left-safe);
}
.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;
}
.top-title { margin: 0; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.title-en { font-size: 30px; font-weight: 900; color: var(--main-dark); letter-spacing: .02em; }
.title-sub { font-size: 18px; font-weight: 700; color: var(--sub); }
html:not([lang="ja"]) .title-sub { display: none; }
.step-title { margin: 0; display: flex; align-items: center; gap: 10px; font-size: 26px; font-weight: 900; }
.step-title.small { font-size: 22px; }
.step-no {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--main); color: #fff; font-size: 22px; flex: 0 0 auto;
}

/* --- 0. はじめの画面 --- */
.home-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 24px 24px;
    -webkit-overflow-scrolling: touch;
}
.home-hero {
    display: flex; align-items: center; gap: 22px;
    background: #fff; border: 3px solid var(--line); border-radius: 24px;
    padding: 14px 22px; max-width: 980px; margin: 0 auto;
}
.hero-gem { width: 120px; height: 120px; object-fit: contain; flex: 0 0 auto; }
.hero-text { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.hero-lead { margin: 0; font-size: 26px; font-weight: 900; }
.hero-steps { margin: 0 0 4px; font-size: 16px; font-weight: 700; color: var(--sub); }
.list-head { display: flex; align-items: baseline; gap: 12px; max-width: 980px; margin: 18px auto 8px; }
.list-title { margin: 0; font-size: 22px; font-weight: 900; }
.list-count { margin: 0; color: var(--sub); font-weight: 700; }
.town-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 14px;
    max-width: 980px;
    margin: 0 auto;
}
.town-card {
    background: #fff; border: 3px solid var(--line); border-radius: 20px;
    padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.town-thumb { border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; background: #E6F0D2; }
.town-thumb svg { display: block; width: 100%; height: 100%; }
.town-info { padding: 0 4px; }
.town-name { margin: 0; font-size: 20px; font-weight: 900; word-break: break-all; }
.town-meta { margin: 2px 0 0; font-size: 14px; font-weight: 700; color: var(--sub); }
.town-btns { display: flex; gap: 8px; }
.town-btns .ui-btn { flex: 1 1 0; }
.list-empty { text-align: center; color: var(--sub); font-weight: 700; font-size: 18px; margin: 16px; }
.lock-note { text-align: center; color: var(--sub); font-size: 14px; font-weight: 700; margin: 18px auto 0; max-width: 980px; }

/* --- 下の 行（ひとつ まえへ・つぎへ） --- */
.step-foot {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 14px;
    padding: 8px 20px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, .7);
    border-top: 2px solid var(--line);
}
.foot-note { flex: 1 1 auto; margin: 0; text-align: center; font-weight: 800; font-size: 18px; }
.step-foot .primary-btn { min-width: 160px; min-height: 60px; font-size: 20px; }

/* --- 1. まちを えらぶ --- */
.map-grid {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    padding: 6px 20px 14px;
    align-content: start;
}
.map-card {
    font-family: var(--font);
    background: #fff; border: 4px solid var(--line); border-radius: 20px;
    padding: 8px 8px 6px; cursor: pointer; color: var(--ink);
    display: flex; flex-direction: column; align-items: stretch; gap: 2px;
    touch-action: manipulation;
}
.map-card.sel { border-color: var(--sel); box-shadow: 0 0 0 4px rgba(59, 134, 209, .25); }
.map-thumb { border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; }
.map-thumb svg { display: block; width: 100%; height: 100%; }
.map-name { margin: 4px 0 0; font-size: 19px; font-weight: 900; }
.map-lots { margin: 0; font-size: 14px; font-weight: 700; color: var(--sub); }

/* --- 2. しせつを えらぶ --- */
.fac-tools {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 0 20px 6px;
}
.fac-count { margin: 0 auto 0 0; font-size: 20px; font-weight: 900; }
.fac-grid {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    padding: 4px 20px 12px;
    align-content: start;
}
.fac-card {
    position: relative;
    font-family: var(--font);
    background: #fff; border: 4px solid var(--line); border-radius: 18px;
    padding: 6px 4px; min-height: 112px; cursor: pointer; color: var(--ink);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    touch-action: manipulation;
}
.fac-card.sel { border-color: var(--ok); background: #F0FAF3; }
.fac-card.full { opacity: .5; }
.fac-card .fac-en { font-size: 15px; font-weight: 900; line-height: 1.15; text-align: center; }
.fac-card .fac-ja { font-size: 12px; font-weight: 700; color: var(--sub); }
.fac-check {
    position: absolute; top: 4px; right: 6px;
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--ok); color: #fff; font-weight: 900; font-size: 18px;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transform: scale(.6); transition: opacity .12s, transform .12s;
}
.fac-card.sel .fac-check { opacity: 1; transform: scale(1); }
.fac-pic {
    display: inline-flex; align-items: center; justify-content: center;
    width: 76px; height: 66px; border-radius: 14px; flex: 0 0 auto;
}
.fac-pic img { width: 66px; height: 60px; object-fit: contain; pointer-events: none; }
.fac-pic.small { width: 54px; height: 46px; border-radius: 10px; }
.fac-pic.small img { width: 46px; height: 42px; }
.cat-legend { display: flex; flex-wrap: wrap; gap: 4px; }
.cat-chip { font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; border: 2px solid; }

/* --- 3. おく（左に パネル・右に 地図） --- */
#sc-place, #sc-play { flex-direction: row; }
.place-panel {
    position: relative;
    flex: 0 0 300px;
    display: flex; flex-direction: column; gap: 10px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px calc(10px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
    background: #fff;
    border-right: 3px solid var(--line);
    overflow: hidden;
}
.panel-top { min-height: 50px; display: flex; align-items: center; padding-left: 128px; }
.place-panel .step-title.small { font-size: 20px; }
.mode-row { display: flex; gap: 6px; }
.mode-btn {
    flex: 1 1 0;
    font-family: var(--font); font-weight: 900; font-size: 17px;
    min-height: 54px; border-radius: 14px; cursor: pointer;
    background: #F4EEE3; color: var(--sub); border: 3px solid var(--line);
    touch-action: manipulation;
}
.mode-btn.on { background: var(--sel); color: #fff; border-color: #2B69A8; }
.mode-box { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.mode-help { margin: 0; font-size: 15px; font-weight: 800; line-height: 1.45; min-height: 44px; }
.tray {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; align-content: start;
    background: #FBF6EC; border-radius: 14px; padding: 6px;
}
.tray-item {
    font-family: var(--font);
    background: #fff; border: 3px solid var(--line); border-radius: 12px;
    min-height: 76px; padding: 4px 2px; cursor: pointer; color: var(--ink);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    touch-action: manipulation;
}
.tray-item.sel { border-color: var(--sel); background: #EAF3FC; box-shadow: 0 0 0 3px rgba(59, 134, 209, .3); }
.tray-en { font-size: 12px; font-weight: 800; line-height: 1.1; text-align: center; }
.row-2 { display: flex; gap: 8px; }
.row-2 .ui-btn { flex: 1 1 0; font-size: 14px; padding: 6px 4px; }
.panel-bottom { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; }
.place-status { margin: 0; text-align: center; font-weight: 900; font-size: 17px; }
#btn-save { min-height: 60px; font-size: 20px; }

.place-stage {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    display: flex; flex-direction: column;
    padding: 0 calc(10px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) 10px;
}
.place-top { position: relative; flex: 0 0 auto; height: 66px; }
.town-svg-box {
    position: relative;
    flex: 1 1 auto; min-height: 0;
    border-radius: 18px; overflow: hidden;
    background: #E6F0D2;
    border: 3px solid var(--line);
}
.town-svg-box svg { display: block; width: 100%; height: 100%; }

/* SVG の 中の 文字・場所 */
.town-svg text { font-family: var(--font); text-anchor: middle; }
.town-svg .fac-en { font-weight: 900; fill: #4E3D31; paint-order: stroke; stroke: rgba(255, 255, 255, .9); stroke-width: 8px; stroke-linejoin: round; }
.town-svg .fac-ja { font-weight: 700; fill: #7A6655; paint-order: stroke; stroke: rgba(255, 255, 255, .9); stroke-width: 6px; }
.town-svg .ph-emoji { text-anchor: middle; }
.town-svg .lot .hit { fill: transparent; stroke: transparent; stroke-width: 6; }
.town-svg .lot.tappable { cursor: pointer; }
.town-svg .lot.tappable.empty .hit { fill: rgba(255, 255, 255, .35); stroke: #fff; stroke-dasharray: 16 12; }
.picking .town-svg .lot.tappable.empty .hit { fill: rgba(59, 134, 209, .18); stroke: #3B86D1; }
.town-svg .lot-plus { font-size: 64px; font-weight: 900; fill: rgba(78, 61, 49, .35); }
.picking .town-svg .lot-plus { fill: #3B86D1; }


/* --- 0. 一覧の あそぶ ボタン --- */
.play-btn { width: 100%; min-height: 56px; font-size: 20px; }

/* --- 4. あそぶ --- */
.play-town-name { margin: -4px 0 0; font-size: 16px; font-weight: 900; color: var(--sub); text-align: center; word-break: break-all; }
.play-box { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.play-box > * { flex-shrink: 0; }
.mode-big {
    font-family: var(--font); color: var(--ink);
    display: flex; align-items: center; gap: 10px;
    min-height: 74px; padding: 8px 12px;
    background: #fff; border: 3px solid var(--line); border-radius: 18px;
    cursor: pointer; text-align: left; touch-action: manipulation;
}
.mode-big:active { transform: scale(.97); }
.mb-icon { font-size: 34px; flex: 0 0 auto; }
.mb-text { display: flex; flex-direction: column; gap: 2px; }
.mb-text b { font-size: 19px; font-weight: 900; }
.mb-text small { font-size: 13px; font-weight: 700; color: var(--sub); }
.sound-note { margin: 2px 0 0; font-size: 13px; font-weight: 700; color: var(--sub); text-align: center; }
.play-score { margin: 0; font-size: 16px; font-weight: 900; text-align: center; min-height: 1.2em; }
.cmd-box {
    display: flex; flex-wrap: wrap; gap: 5px;
    background: #FBF6EC; border-radius: 14px; padding: 8px;
    max-height: 150px; overflow-y: auto;
}
.cmd-box .cmd {
    font-size: 14px; font-weight: 800; padding: 4px 9px; border-radius: 999px;
    background: #fff; border: 2px solid var(--line); white-space: nowrap;
}
.cmd-box .cmd.now { background: #FFF4D6; border-color: var(--main); color: var(--main-dark); }
.cmd-box .cmd.did { color: var(--sub); }
.cmd-box .cmd.q { background: #EAF3FC; border-color: #9CC3EA; }
.play-msg { margin: 0; font-size: 15px; font-weight: 800; line-height: 1.45; min-height: 44px; }
.pair-say { background: #F4EEE3; border-radius: 14px; padding: 6px 10px; }
.pair-say-title { margin: 0; font-size: 12px; font-weight: 800; color: var(--sub); }
.pair-say-en { margin: 2px 0 0; font-size: 14px; font-weight: 900; line-height: 1.4; }
.ctrl-box { display: flex; flex-direction: column; gap: 6px; }
.ctrl-row { display: flex; gap: 6px; }
.ctrl-btn {
    font-family: var(--font); color: #fff;
    flex: 1 1 0; display: flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 60px; border-radius: 16px; cursor: pointer; touch-action: manipulation;
    border: 3px solid transparent; font-weight: 900; font-size: 16px; line-height: 1.15;
}
.ctrl-btn:active { transform: scale(.96); }
.ctrl-btn .ci { font-size: 24px; }
.ctrl-btn.go { background: var(--ok); border-color: var(--ok-dark); }
.ctrl-btn.turn { background: var(--sel); border-color: #2B69A8; }
.ctrl-btn.hint { box-shadow: 0 0 0 5px #FFD54A; animation: hintPulse 0.9s ease-in-out infinite; }
@keyframes hintPulse { 50% { box-shadow: 0 0 0 9px rgba(255, 213, 74, .5); } }
#btn-arrive, #btn-next-q { min-height: 58px; font-size: 17px; }
.dot-note { margin: 0; font-size: 13px; font-weight: 800; color: var(--sub); text-align: center; }
.town-svg .start-lab { font-size: 34px; font-weight: 900; fill: #C0392B; paint-order: stroke; stroke: #fff; stroke-width: 8px; }
.town-svg .lr-text { font-size: 30px; font-weight: 900; text-anchor: middle; }
.town-svg .lot.pickable { cursor: pointer; }
.town-svg #tgem, .town-svg #tlr, .town-svg .start-lab { pointer-events: none; }
.picking .town-svg .lot.pickable .hit { fill: rgba(255, 255, 255, .25); stroke: #E9852B; stroke-dasharray: 16 12; }
.town-svg .lot.correct .hit { fill: rgba(63, 166, 107, .25); stroke: #3FA66B; stroke-width: 10; stroke-dasharray: none; }
.town-svg .lot.wrong .hit { fill: rgba(217, 83, 79, .18); stroke: #D9534F; stroke-width: 8; stroke-dasharray: none; }
@media (max-width: 760px), (max-height: 560px) {
    .play-box { flex: 0 0 auto; overflow: visible; }
}
@media (prefers-reduced-motion: reduce) {
    .ctrl-btn.hint { animation: none; }
}


/* --- 4. ペア（ジェム・ナビと 同じ しくみ） --- */
.pair-lead { margin: 4px 0 0; font-size: 17px; font-weight: 900; text-align: center; line-height: 1.4; }
.role-btn { min-height: 64px; font-size: 18px; }
.pair-note { margin: 4px 0 0; font-size: 13px; font-weight: 700; color: var(--sub); line-height: 1.45; }
.pw-box {
    font-size: 40px; font-weight: 900; letter-spacing: .3em; text-align: center;
    background: #fff; border: 3px solid var(--line); border-radius: 14px; padding: 4px 0 4px .3em;
}
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.num-btn {
    font-family: var(--font); font-size: 26px; font-weight: 900; color: var(--ink);
    min-height: 54px; border-radius: 14px; background: #fff; border: 3px solid var(--line);
    cursor: pointer; touch-action: manipulation;
}
.num-btn:active { transform: scale(.95); }
.num-btn.num-del { font-size: 16px; color: var(--danger); border-color: #F0C4C2; }
.num-space { display: block; }
.role-box { display: flex; flex-direction: column; gap: 6px; background: #FBF6EC; border-radius: 14px; padding: 8px; }
.role-label { margin: 0; font-size: 13px; font-weight: 900; color: var(--sub); }
.seed-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.seed-txt { font-size: 15px; font-weight: 800; }
.seed-txt b { font-size: 26px; letter-spacing: .08em; color: var(--main-dark); }
.mark-emojis { font-size: 24px; letter-spacing: .05em; background: #fff; border: 2px solid var(--line); border-radius: 10px; padding: 0 6px; }
.target-box { font-size: 14px; font-weight: 800; }
.target-box b { font-size: 18px; color: #C0392B; }
.say-box { background: #fff; border: 2px dashed #E9C38F; border-radius: 12px; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.say-title { margin: 0; font-size: 12px; font-weight: 800; color: var(--sub); }
.say-en { margin: 0; font-size: 18px; font-weight: 900; }
.say-model-btn {
    align-self: flex-start; font-family: var(--font); font-size: 14px; font-weight: 800;
    min-height: 36px; padding: 2px 10px; border-radius: 999px; background: #FFF4D6; border: 2px solid #E9C38F; color: var(--ink);
    cursor: pointer; touch-action: manipulation;
}
#btn-check, #btn-replay { min-height: 54px; font-size: 16px; }
.modal-mark { margin: 0; font-size: 44px; text-align: center; letter-spacing: .1em; }
.modal-btn-danger { background: var(--danger); color: #fff; border-color: #B23C38; }
.town-svg #tgem.ghost { opacity: .55; }
.town-svg .lot.goal .hit { fill: rgba(231, 76, 60, .12); stroke: #E74C3C; stroke-width: 8; stroke-dasharray: 18 10; }

/* --- 小窓 --- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 8000;
    background: rgba(40, 30, 20, .45);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-box {
    background: #fff; border-radius: 24px; border: 4px solid var(--line);
    padding: 22px 24px; width: min(520px, 100%);
    display: flex; flex-direction: column; gap: 14px;
}
.modal-msg { margin: 0; font-size: 21px; font-weight: 900; text-align: center; line-height: 1.5; }
.modal-input-wrap { position: relative; display: flex; flex-direction: column; gap: 6px; }
.modal-input {
    font-family: var(--font); font-size: 24px; font-weight: 800;
    padding: 10px 14px; border-radius: 14px; border: 3px solid var(--line);
    width: 100%; color: var(--ink); -webkit-user-select: text; user-select: text;
}
.modal-hint { margin: 0; font-size: 14px; font-weight: 700; color: var(--sub); text-align: center; }
.modal-btns { display: flex; gap: 10px; }
.modal-btns .ui-btn { flex: 1 1 0; min-height: 56px; }
.modal-btn-main { background: var(--main); color: #fff; border-color: var(--main-dark); }
.modal-btn-sub { background: #fff; color: var(--ink); border-color: var(--line); }

.modal-preview { position: relative; border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; }
.modal-preview svg { display: block; width: 100%; height: 100%; }
.qr-box { align-items: center; }
.qr-wrap { background: #fff; padding: 6px; border-radius: 12px; border: 3px solid var(--line); line-height: 0; }
.qr-box .modal-btns { width: 100%; }

/* --- 小さな お知らせ --- */
.toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 8500;
    background: rgba(78, 61, 49, .92); color: #fff;
    font-weight: 800; font-size: 18px;
    padding: 12px 22px; border-radius: 999px;
    max-width: 90vw; text-align: center;
    pointer-events: none;
}

/* --- たてむき（iPad） --- */
.rotate-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 8800;
    background: var(--bg);
    align-items: center; justify-content: center; text-align: center;
    font-size: 26px; font-weight: 900;
}
@media (orientation: portrait) and (min-width: 700px) and (max-width: 1100px) {
    .rotate-overlay { display: flex; }
}

/* --- 小さい 画面の 高さ --- */
@media (max-height: 760px) {
    .topbar { min-height: 60px; }
    .map-name { font-size: 17px; }
    .fac-card { min-height: 104px; }
    .fac-pic { width: 64px; height: 56px; }
    .fac-pic img { width: 56px; height: 50px; }
    .hero-gem { width: 96px; height: 96px; }
}

/* --- スマホ・せまい 画面（rules md 2-9：パネル全体を スクロール） --- */
@media (max-width: 1100px) {
    .fac-grid { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 900px) {
    .map-grid { grid-template-columns: repeat(2, 1fr); }
    .fac-grid { grid-template-columns: repeat(4, 1fr); }
    .topbar { padding-right: calc(10px + env(safe-area-inset-right, 0px)); padding-top: calc(66px + env(safe-area-inset-top, 0px)); }
    .lang-slot { top: calc(10px + env(safe-area-inset-top, 0px)); }
}
@media (max-width: 760px), (max-height: 560px) {
    .screen { overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .map-grid, .fac-grid, .home-body { flex: 0 0 auto; overflow: visible; }
    .fac-grid { grid-template-columns: repeat(3, 1fr); }
    .home-hero { flex-direction: column; text-align: center; }
    .hero-text { align-items: center; }
    #sc-place, #sc-play { flex-direction: column; }
    .place-panel { flex: 0 0 auto; border-right: none; border-bottom: 3px solid var(--line); overflow: visible; }
    .mode-box { flex: 0 0 auto; }
    .tray { flex: 0 0 auto; overflow: visible; }
    .place-stage { flex: 0 0 auto; padding: 0 10px 10px; }
    .place-top { height: 66px; }
    .town-svg-box { flex: 0 0 auto; aspect-ratio: 16 / 9; }
    .step-foot { position: sticky; bottom: 0; }
}
@media (max-width: 560px) {
    .map-grid { grid-template-columns: 1fr; }
    .step-foot .primary-btn { min-width: 110px; }
    .foot-note { font-size: 15px; }
}

/* --- あそぶ：左の パネルを スクロール なしで おさめる（iPad 横 1024×700 でも） --- */
.play-panel { gap: 6px; }
.play-panel .panel-top { min-height: 46px; }
.play-town-name { font-size: 14px; margin: 0; line-height: 1.2; }
.play-box { gap: 6px; }
.play-msg { min-height: 0; font-size: 14px; }
.play-msg:empty { display: none; }
.play-score:empty { display: none; }
.role-box { gap: 4px; padding: 6px 8px; }
.role-label { font-size: 12px; }
.seed-row { flex-wrap: nowrap; }
.seed-txt { font-size: 13px; white-space: nowrap; }
.seed-txt b { font-size: 22px; }
.mark-emojis { font-size: 19px; padding: 0 4px; white-space: nowrap; }
.target-box { font-size: 13px; line-height: 1.3; }
.target-box b { font-size: 16px; }
.say-box { padding: 4px 8px; gap: 0; }
.say-title { font-size: 11px; }
.say-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.say-en { font-size: 16px; }
.say-model-btn { flex: 0 0 auto; min-height: 34px; font-size: 13px; padding: 2px 8px; }
.mini-row .ui-btn { min-height: 38px; font-size: 12px; padding: 2px 4px; line-height: 1.2; }
.ctrl-box { gap: 5px; }
.ctrl-btn { min-height: 52px; }
.play-panel .row-2 .ui-btn { min-height: 42px; }
#btn-check, #btn-replay, #btn-next-q { min-height: 48px; font-size: 15px; }
.play-panel .dot-note { font-size: 11px; line-height: 1.3; }
.play-panel .panel-bottom .ui-btn { min-height: 44px; font-size: 13px; }
.cmd-box { padding: 6px; gap: 4px; max-height: 120px; }
.cmd-box .cmd { font-size: 13px; padding: 3px 8px; }
/* ひくい 画面（iPad 横の Safari など）：ヒントの 文の わくを 小さく して、中だけ スクロール */
@media (max-height: 760px) {
    .play-panel .cmd-box { max-height: 58px; overflow-y: auto; }
    .play-panel .panel-top { min-height: 42px; }
}

/* 言語ボタン（deji_nav.js が ない WP 版 だけ） */
.town-lang { display: flex; gap: 2px; background: #fff; border: 3px solid #3B86D1; border-radius: 999px; padding: 3px; }
.town-lang-btn {
    font-family: var(--font); font-size: 15px; font-weight: 800; color: #3B86D1;
    min-height: 40px; padding: 4px 12px; border-radius: 999px; border: none; background: transparent;
    cursor: pointer; touch-action: manipulation;
}
.town-lang-btn.on { background: #3B86D1; color: #fff; }

/* P1 スマホの よこ（844×340 など）：おく・あそぶ は 上下に ならべず「パネル 左（スクロール）・地図 右」。
   上下だと、⬆ を おして いる あいだ ジェムえもん（地図）が 画面の 外に いた。地図の 絵は preserveAspectRatio meet なので 箱の 高さに あわせて ちぢむ */
@media (max-height: 560px) and (orientation: landscape) {
    #sc-place, #sc-play { flex-direction: row; overflow: hidden; }
    .place-panel {
        flex: 0 0 clamp(250px, 36vw, 320px); min-height: 0;
        overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
        border-right: 3px solid var(--line); border-bottom: none;
    }
    .place-stage { flex: 1 1 auto; min-width: 0; min-height: 0; padding: 0 calc(8px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) 8px; }
    .place-top { height: 60px; }
    .town-svg-box { flex: 1 1 auto; min-height: 0; aspect-ratio: auto; }
    /* 小窓：高さが たりない ときは 中を スクロール・QR を 小さく */
    .modal-overlay { padding: 8px; }
    .modal-box { max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 18px; gap: 8px; }
    .modal-msg { font-size: 17px; }
    #qr-canvas { width: 150px !important; height: 150px !important; }
}

/* P1（相棒が (A) に 決めた 10/25）：よこの スマホだけ「たてむきが おすすめ」の お知らせ（main.js の initPhoneNote）。
   右下（地図の すみ）に 出す＝左の パネルの ボタンに かさならない。たて・iPad では 出さない */
.phone-note { display: none; }
@media (orientation: landscape) and (max-height: 560px) {
    .phone-note {
        display: flex; align-items: center; gap: 8px;
        position: fixed; z-index: 7000;
        right: calc(10px + env(safe-area-inset-right, 0px)); bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        width: max-content; max-width: calc(100% - 300px); box-sizing: border-box;
        padding: 6px 6px 6px 14px; border-radius: 999px;
        background: #fff7d6; border: 2px solid #f59e0b; color: #78350f;
        font-size: 0.9rem; font-weight: 800; line-height: 1.4;
        word-break: keep-all; overflow-wrap: anywhere;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    .phone-note-x {
        flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
        border: none; background: #f59e0b; color: #fff; font-size: 1rem; font-weight: 900;
        cursor: pointer; font-family: inherit;
    }
}
