/* ============================================================
 * ことばシューティング（Word Shooter）
 * iPad 横（1180×820・1024×700）が 基本。左に そら、右に そうさパネル。
 * 色は オリジナルタウンと そろえた（青 #3B86D1・なかまの 色）。
 * ============================================================ */

:root {
    --ink: #1F3A5F;
    --ink-soft: #4F6B8C;
    --blue: #3B86D1;
    --blue-dark: #2A69A8;
    --panel: #FFFFFF;
    --panel-bg: #EAF4FD;
    --line: #C9DDF0;
    --ok: #2FA866;
    --ok-dark: #1F7D4A;
    --ng: #E2574C;
    --ng-dark: #A9372E;
    --sun: #FFD34D;
    --font: '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;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: var(--panel-bg);
    color: var(--ink);
    font-family: var(--font);
    font-weight: 700;
    overscroll-behavior: none;
}

button { font-family: var(--font); color: inherit; }

/* === UI要塞化 === */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
}

/* === 全体（横長：左に そら・右に パネル） === */
#app {
    position: relative;
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
}
#stage {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    background: #9ED6F5;
}
#game {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

#loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--ink);
    background: #CDEBFB;
    z-index: 50;
}

/* === 数（ひこうき・うちぬいた）：パネルの いちばん上 === */
#hud-top {
    display: flex;
    gap: 8px;
    justify-content: center;
    pointer-events: none;
}
.hud-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 4px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    border: 3px solid var(--blue);
    font-size: 20px;
    color: var(--ink);
    white-space: nowrap;
}
.hud-hit { border-color: var(--sun); }
.hud-icon { font-size: 18px; }

/* === そうさパネル === */
#cockpit {
    flex: 0 0 36%;
    min-width: 300px;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    padding: calc(16px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) 16px;
    background: var(--panel-bg);
    border-left: 4px solid var(--blue);
    z-index: 10;
    overflow: hidden;
}

.target-card {
    position: relative;
    min-height: 156px;
    padding: 14px 14px 12px;
    border-radius: 20px;
    background: var(--panel);
    border: 3px solid var(--line);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
}
.target-card.is-locked { border-color: var(--ng); box-shadow: 0 0 0 4px rgba(226, 87, 76, 0.18); }
.target-card.is-ok { border-color: var(--ok); box-shadow: 0 0 0 4px rgba(47, 168, 102, 0.2); }
.target-msg {
    margin: 0;
    word-break: keep-all;
    font-size: 20px;
    line-height: 1.5;
    color: var(--ink-soft);
}
.target-word {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.target-img {
    width: 92px;
    height: 92px;
    object-fit: contain;
}
.target-text {
    font-size: 34px;
    line-height: 1.2;
    color: var(--ink);
    word-break: keep-all;
    overflow-wrap: anywhere;
}
.target-text.is-small { font-size: 26px; }
.say-btn {
    min-height: 44px;
    padding: 4px 18px;
    border-radius: 999px;
    border: 3px solid var(--blue);
    background: #fff;
    color: var(--blue-dark);
    font-size: 17px;
    font-weight: 800;
    cursor: pointer;
}
.say-btn:active { transform: translateY(2px); }

/* 4つの こたえ */
.choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.choice {
    min-height: 62px;
    padding: 6px 14px;
    border-radius: 16px;
    border: 3px solid var(--line);
    background: #fff;
    box-shadow: 0 5px 0 var(--line);
    color: var(--ink);
    font-size: 25px;
    font-weight: 800;
    line-height: 1.2;
    cursor: pointer;
    transition: transform 0.08s;
}
.choice:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.choice.is-wait {
    opacity: 0.35;
    pointer-events: none;
    color: var(--ink-soft);
}
.choice.is-off { pointer-events: none; }
.choice.is-ok {
    background: var(--ok);
    border-color: var(--ok-dark);
    box-shadow: 0 5px 0 var(--ok-dark);
    color: #fff;
}
.choice.is-ng {
    background: var(--ng);
    border-color: var(--ng-dark);
    box-shadow: 0 5px 0 var(--ng-dark);
    color: #fff;
    animation: shake 0.35s;
}
.choice.is-dim { opacity: 0.45; }

.feedback {
    margin: 0;
    min-height: 74px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    word-break: keep-all;
    font-size: 19px;
    line-height: 1.35;
    color: var(--ink);
}
.feedback .fb-line { display: block; }
.feedback .fb-pair { font-size: 1.15em; }
.feedback .fb-small { font-size: 0.85em; opacity: 0.9; }
.feedback.is-ok { color: var(--ok-dark); }
.feedback.is-ng { color: var(--ng-dark); }

#sub-controls {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
#speed-controls {
    flex: 1 1 auto;
    display: flex;
    gap: 6px;
}
.speed-btn, .quit-btn {
    min-height: 50px;
    padding: 4px 4px;
    white-space: nowrap;
    border-radius: 12px;
    border: 3px solid var(--line);
    background: #fff;
    color: var(--ink-soft);
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    line-height: 1.15;
}
.speed-btn { flex: 1 1 0; min-width: 0; }
.speed-btn.on { background: var(--blue); border-color: var(--blue-dark); color: #fff; }
.quit-btn { flex: 0 0 auto; min-width: 78px; }
.quit-btn.is-confirm { background: var(--ng); border-color: var(--ng-dark); color: #fff; font-size: 12px; white-space: normal; max-width: 96px; }

/* === 重ねる 画面（はじめ・おわり） === */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 左は 🏠 もどる（140px）を よける */
    padding: calc(14px + env(safe-area-inset-top, 0px)) 14px calc(14px + env(safe-area-inset-bottom, 0px)) calc(140px + env(safe-area-inset-left, 0px));
    background: rgba(31, 58, 95, 0.45);
    overflow-y: auto;
}
.start-box, .result-box {
    width: 100%;
    max-width: 780px;
    max-height: 100%;
    overflow-y: auto;
    border-radius: 26px;
    background: #fff;
    border: 5px solid var(--blue);
    padding: 18px 24px 20px;
    box-shadow: 0 14px 0 rgba(31, 58, 95, 0.25);
}

.start-head {
    display: flex;
    align-items: center;
    gap: 14px;
}
.start-gem {
    width: 76px;
    height: 76px;
    object-fit: contain;
    flex: 0 0 auto;
}
.start-title-box { flex: 1 1 auto; min-width: 0; }
.start-title {
    margin: 0;
    font-size: 32px;
    line-height: 1.15;
    color: var(--ink);
}
.start-sub {
    margin: 2px 0 0;
    font-size: 16px;
    color: var(--blue);
    letter-spacing: 0.04em;
}
.start-lead {
    word-break: keep-all;
    margin: 10px 0 8px;
    font-size: 18px;
    line-height: 1.5;
    color: var(--ink-soft);
}

/* 言語の 切りかえ（deji_nav.js が 中身を 入れる。はじめの 画面だけ） */
.lang-slot {
    flex: 0 0 auto;
    align-self: flex-start;
    max-width: 100%;
}

.opt-row {
    margin: 10px 0 0;
    padding: 10px 14px 10px;
    border-radius: 18px;
    background: var(--panel-bg);
}
.opt-title {
    margin: 0 0 8px;
    font-size: 17px;
    color: var(--ink);
}
.seg {
    display: flex;
    gap: 8px;
}
.seg-btn {
    flex: 1 1 0;
    min-height: 54px;
    padding: 4px 10px;
    border-radius: 14px;
    border: 3px solid var(--line);
    background: #fff;
    box-shadow: 0 4px 0 var(--line);
    color: var(--ink);
    font-size: 20px;
    font-weight: 800;
    cursor: pointer;
}
.seg-btn.on {
    background: var(--blue);
    border-color: var(--blue-dark);
    box-shadow: 0 4px 0 var(--blue-dark);
    color: #fff;
}
.opt-note {
    word-break: keep-all;
    margin: 8px 0 0;
    min-height: 1.4em;
    font-size: 15px;
    color: var(--ink-soft);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.chip {
    min-height: 48px;
    padding: 4px 14px;
    border-radius: 999px;
    border: 3px solid var(--chip-edge, var(--line));
    background: var(--chip-bg, #fff);
    color: var(--ink);
    font-size: 17px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}
.chip .chip-n {
    font-size: 13px;
    color: var(--ink-soft);
}
.chip.on {
    outline: 4px solid var(--ink);
    outline-offset: 1px;
}
.chip.on::before {
    content: '✓';
    color: var(--ink);
}

.start-foot {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.voice-btn {
    flex: 0 0 auto;
    min-height: 54px;
    padding: 4px 16px;
    border-radius: 14px;
    border: 3px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-size: 17px;
    font-weight: 800;
    cursor: pointer;
}
.voice-btn.is-off { color: var(--ink-soft); background: #F1F4F8; }
.sound-note {
    flex: 1 1 auto;
    margin: 0;
    font-size: 15px;
    color: var(--ink-soft);
}
.start-btn {
    flex: 0 0 auto;
    min-height: 64px;
    min-width: 220px;
    padding: 6px 26px;
    border-radius: 18px;
    border: 3px solid var(--ok-dark);
    background: var(--ok);
    box-shadow: 0 6px 0 var(--ok-dark);
    color: #fff;
    font-size: 26px;
    font-weight: 900;
    cursor: pointer;
}
.start-btn:active, .seg-btn:active, .res-btn:active { transform: translateY(4px); box-shadow: none; }
.novoice-note {
    margin: 10px 0 0;
    font-size: 14px;
    color: var(--ng-dark);
}

/* おわりの 画面 */
.result-head {
    display: flex;
    align-items: center;
    gap: 16px;
}
.result-gem {
    width: 92px;
    height: 92px;
    object-fit: contain;
    flex: 0 0 auto;
}
.result-title {
    margin: 0;
    font-size: 30px;
    color: var(--ink);
}
.result-score {
    margin: 4px 0 0;
    font-size: 26px;
    color: var(--blue-dark);
}
.result-msg {
    word-break: keep-all;
    margin: 4px 0 0;
    font-size: 17px;
    line-height: 1.5;
    color: var(--ink-soft);
}
.weak-title {
    margin: 14px 0 8px;
    font-size: 18px;
    color: var(--ink);
}
.weak-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.weak-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 64px;
    padding: 6px 10px;
    border-radius: 14px;
    background: var(--panel-bg);
    border: 3px solid var(--line);
    cursor: pointer;
    text-align: left;
    font-family: var(--font);
    font-weight: 800;
    color: var(--ink);
}
.weak-item img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    flex: 0 0 auto;
}
.weak-words {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.weak-en { font-size: 20px; color: var(--ink); }
.weak-ja { font-size: 15px; color: var(--ink-soft); }
.weak-say { font-size: 22px; flex: 0 0 auto; }
.weak-none {
    margin: 0;
    font-size: 18px;
    color: var(--ok-dark);
}
.result-btns {
    margin-top: 16px;
    display: flex;
    gap: 10px;
}
.res-btn {
    flex: 1 1 0;
    min-height: 60px;
    padding: 6px 10px;
    border-radius: 16px;
    border: 3px solid var(--line);
    background: #fff;
    box-shadow: 0 5px 0 var(--line);
    color: var(--ink);
    font-size: 17px;
    font-weight: 900;
    cursor: pointer;
    word-break: keep-all;
    line-height: 1.2;
}
.res-weak { flex-grow: 1.3; background: var(--ng); border-color: var(--ng-dark); box-shadow: 0 5px 0 var(--ng-dark); color: #fff; }
.res-retry { background: var(--ok); border-color: var(--ok-dark); box-shadow: 0 5px 0 var(--ok-dark); color: #fff; }

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

/* === ひくい 横画面（1024×700 など） === */
@media (orientation: landscape) and (max-height: 740px) {
    #cockpit { gap: 9px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
    .target-card { min-height: 132px; padding: 10px; }
    .target-img { width: 74px; height: 74px; }
    .target-text { font-size: 30px; }
    .choice { min-height: 54px; font-size: 23px; }
    .feedback { min-height: 66px; font-size: 16px; }
    .hud-pill { min-height: 36px; font-size: 18px; }
    .speed-btn, .quit-btn { min-height: 46px; }
    .start-box, .result-box { padding: 14px 20px 16px; }
    .opt-row { margin-top: 8px; padding: 8px 12px; }
    .seg-btn { min-height: 48px; font-size: 19px; }
    .chip { min-height: 44px; }
    .start-btn { min-height: 58px; }
    .start-lead { margin: 6px 0 4px; }
}

/* === たて長・せまい 画面：上に そら・下に パネル === */
@media (max-width: 899px) and (orientation: portrait) {
    #app { flex-direction: column; }
    #stage { flex: 1 1 auto; min-height: 0; }
    #cockpit {
        flex: 0 0 auto;
        min-width: 0;
        max-width: none;
        border-left: none;
        border-top: 4px solid var(--blue);
        gap: 8px;
        padding: 10px calc(12px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
    }
    .target-card { min-height: 92px; flex-direction: row; padding: 8px 10px; }
    .target-word { flex-direction: row; gap: 10px; }
    .target-img { width: 56px; height: 56px; }
    .target-text { font-size: 26px; }
    .target-msg { font-size: 17px; }
    .choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .choice { min-height: 52px; font-size: 19px; }
    .feedback { min-height: 58px; font-size: 15px; }
    .seg { flex-wrap: wrap; }
    .start-foot { flex-wrap: wrap; }
    .start-btn { width: 100%; }
    .weak-list { grid-template-columns: 1fr; }
    .result-btns { flex-direction: column; }
    .start-title { font-size: 26px; }
    /* たて長は 🏠 の 下から（左は あけない） */
    .overlay { padding-top: calc(70px + env(safe-area-inset-top, 0px)); padding-left: calc(14px + env(safe-area-inset-left, 0px)); }
    .lang-slot { position: absolute; top: 10px; right: 10px; }
    .start-box, .result-box { position: relative; padding-top: 66px; }
}

@media (prefers-reduced-motion: reduce) {
    .choice.is-ng { animation: none; }
}

/* =========================================================
 * B22：メダル（31「まちの ことば」）
 * ========================================================= */
.medal-note {
    margin: 12px 0 0;
    padding: 8px 12px;
    border-radius: 14px;
    background: #FFF8DC;
    border: 2px solid #F2D27A;
    font-size: 15px;
    line-height: 1.5;
    color: #7A5A00;
    white-space: pre-line;
    word-break: keep-all;
    overflow-wrap: anywhere;
}
.result-score { white-space: pre-line; }
.result-medal {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 12px 0 4px;
    padding: 10px 14px;
    border-radius: 18px;
    background: #FFF8DC;
    border: 3px solid #F2D27A;
}
.result-medal-img { width: 72px; height: 72px; object-fit: contain; flex: 0 0 auto; }
.result-medal-text { min-width: 0; }
.result-medal-name { margin: 0; font-size: 22px; color: #7A5A00; }
.result-medal-why { margin: 4px 0 0; font-size: 15px; line-height: 1.45; color: var(--ink-soft); word-break: keep-all; overflow-wrap: anywhere; }
.result-nomedal { margin: 10px 0 4px; font-size: 15px; line-height: 1.5; color: var(--ink-soft); word-break: keep-all; overflow-wrap: anywhere; }
.res-cert { background: #FFD34D; border-color: #C9A10F; box-shadow: 0 5px 0 #C9A10F; color: var(--ink); }
@media (orientation: landscape) and (max-height: 740px) {
    .medal-note { margin-top: 8px; padding: 6px 10px; font-size: 14px; }
    .result-medal-img { width: 56px; height: 56px; }
}

/* P1 スマホの よこ（844×340・667×375 など）：右の パネルに「ゆっくり・ふつう・はやい・やめる」が 入りきらず 下に 切れて いた
   → 4つの こたえを 2×2 に・ほかも つめる。それでも 入らない ときは パネルの 中を スクロール */
@media (orientation: landscape) and (max-height: 560px) {
    #cockpit {
        justify-content: flex-start; gap: 6px;
        padding: calc(6px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) 10px;
        overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    }
    .hud-pill { min-height: 30px; font-size: 15px; }
    .target-card { min-height: 68px; padding: 6px 8px; }
    .target-img { width: 50px; height: 50px; }
    .target-text { font-size: 24px; }
    .target-msg { font-size: 15px; }
    .say-btn { min-height: 36px; }
    .choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
    .choice { min-height: 46px; font-size: 17px; padding: 4px 6px; box-shadow: 0 3px 0 var(--line); }
    .feedback { min-height: 38px; font-size: 13px; }
    .speed-btn, .quit-btn { min-height: 42px; font-size: 14px; }
}
