/* ==========================================================
 * 九九忍者 ジェムのすけ  共通の見た目  (math/kuku_ninja.css)  v1.0
 * ・各ページの style.css の「あと」に読みこむ（同じ名前は こちらが勝つ）
 * ・UI要塞化の .hidden、🗺 マップへ、言語ボタンの場所、結果画面、数字パッドの「けす」
 * ・🏠 もどる（deji_nav.js・左上・z-index 9000・白い丸ボタン）と まざらないように、
 *   🗺 マップへ は「緑の 角丸四角」にする
 * ========================================================== */

:root {
    --nj-font: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --nj-brush: 'Klee One', 'M PLUS Rounded 1c', 'Gowun Dodum', 'UD Digi Kyokasho N-R', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --nj-map: #27ae60;
    --nj-map-dark: #1e8449;
    --nj-blue: #4A90E2;
    --nj-blue-dark: #2a5d96;
    --nj-orange: #e67e22;
    --nj-orange-dark: #b9611a;
    --nj-safe-left: calc(140px + env(safe-area-inset-left, 0px));
    --nj-safe-top: calc(68px + env(safe-area-inset-top, 0px));
}

body {
    font-family: var(--nj-font);
}

/* UI要塞化（出し入れは classList の add/remove('hidden') だけ） */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
}

/* ふりがな・絵文字の上の文字がタップのじゃまをしない */
button * {
    pointer-events: none;
}

/* ---------- 言語の切りかえ（にほんご・English・한국어） ---------- */
.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% - 330px);
}
.lang-slot .deji-lang-btn {
    transition: none;
}

/* ---------- 🗺 マップへ（緑の 角丸四角） ---------- */
.nj-map-btn {
    font-family: var(--nj-font);
    font-size: 17px;
    font-weight: 700;
    line-height: 1.4;
    min-height: 52px;
    padding: 6px 18px;
    color: #fff;
    background: var(--nj-map);
    border: 3px solid #fff;
    border-radius: 12px;
    box-shadow: 0 4px 0 var(--nj-map-dark), 0 6px 10px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.nj-map-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--nj-map-dark);
}
.nj-map-btn:focus-visible {
    outline: 3px solid #145a32;
    outline-offset: 2px;
}
/* はじめの画面では、左上の 🏠 もどる の右どなりに置く */
.nj-map-corner {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: var(--nj-safe-left);
    z-index: 100;
}

/* ---------- オープニングの訳（日本語いがいのとき、絵巻の上にかさねる） ---------- */
.nj-story {
    position: absolute;
    top: 50%;
    right: 7%;
    transform: translateY(-50%);
    width: min(52%, 620px);
    max-height: 70%;
    overflow-y: auto;
    z-index: 4;
    padding: 18px 22px;
    background: rgba(255, 249, 235, 0.96);
    border: 3px solid #8b5a2b;
    border-radius: 14px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
    font-family: var(--nj-font);
    font-size: clamp(1.05rem, 2.1vw, 1.5rem);
    font-weight: 700;
    line-height: 1.7;
    color: #3b2414;
}

/* ---------- 数字パッドの「けす」（英語でも はみ出さない） ---------- */
.num-btn[data-val="del"] {
    font-family: var(--nj-font);
    white-space: nowrap;
}

/* ---------- 結果画面（全ページ共通。z-index は 🏠 もどる の 9000 より下） ---------- */
.nj-result {
    position: fixed;
    inset: 0;
    z-index: 8000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(70px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
    background: rgba(0, 0, 0, 0.7);
    font-family: var(--nj-font);
}
.nj-result-card {
    width: min(92vw, 640px);
    max-height: 100%;
    overflow-y: auto;
    background: #fff;
    border: 5px solid var(--nj-blue);
    border-radius: 20px;
    padding: 24px 24px 28px;
    text-align: center;
    animation: njPop 0.35s ease;
}
@keyframes njPop {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}
.nj-result-title {
    margin: 0 0 6px;
    font-size: clamp(1.8rem, 4.5vw, 2.8rem);
    color: #ff6b6b;
    line-height: 1.5;
}
.nj-result-medal {
    font-size: clamp(4rem, 10vh, 6rem);
    line-height: 1.1;
    margin: 4px 0 8px;
}
.nj-medal-img {
    width: 1em;
    height: 1em;
    object-fit: contain;
    vertical-align: middle;
}
.nj-result-msg {
    margin: 0 0 16px;
    font-family: var(--nj-brush);
    font-size: clamp(1.1rem, 2.6vw, 1.5rem);
    font-weight: 600;
    line-height: 1.8;
    color: #333;
}
.nj-result-extra {
    margin: 0 0 16px;
}
.nj-result-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
}
.nj-btn {
    font-family: var(--nj-font);
    font-size: clamp(1rem, 2.2vw, 1.3rem);
    font-weight: 700;
    line-height: 1.4;
    min-height: 60px;
    padding: 8px 22px;
    color: #fff;
    background: var(--nj-blue);
    border: none;
    border-radius: 30px;
    box-shadow: 0 6px 0 var(--nj-blue-dark);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.nj-btn:active {
    transform: translateY(6px);
    box-shadow: none;
}
.nj-btn-cert {
    background: var(--nj-orange);
    box-shadow: 0 6px 0 var(--nj-orange-dark);
}
.nj-btn-cert:active {
    box-shadow: none;
}
.nj-map-btn-inline {
    min-height: 60px;
    font-size: clamp(1rem, 2.2vw, 1.3rem);
}

/* ---------- 小さなお知らせ（遊びを止めない） ---------- */
.nj-toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 8500;
    max-width: 90vw;
    padding: 12px 22px;
    background: rgba(30, 30, 30, 0.88);
    color: #fff;
    border-radius: 30px;
    font-family: var(--nj-font);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.6;
    text-align: center;
    pointer-events: none;
}

/* ---------- せまい画面・低い画面 ---------- */
@media (max-width: 700px) {
    .lang-slot {
        top: calc(66px + env(safe-area-inset-top, 0px));
        max-width: calc(100% - 20px);
    }
}
@media (max-height: 640px) {
    .nj-result-card { padding: 14px 16px 18px; }
    .nj-result-medal { font-size: 3.5rem; }
    .nj-btn, .nj-map-btn-inline { min-height: 50px; }
}

/* サバイバルの「🏆 ランキングに とうろく」 */
.nj-btn-rank {
    background: #f39c12;
    box-shadow: 0 6px 0 #b9770e;
}
.nj-btn-rank:active {
    box-shadow: none;
}

/* さいごの たたかいの「📜 まきものを よむ」 */
.nj-btn-scroll {
    background: #8e44ad;
    box-shadow: 0 6px 0 #5e2d73;
}
.nj-btn-scroll:active {
    box-shadow: none;
}

/* コースの ボタン（しっかり学ぶ・力をためす）は どのステージでも 大きく押しやすく */
.course-buttons-container .ui-btn {
    min-height: 64px;
    min-width: 220px;
}
.btn-main-text {
    display: block;
    font-size: clamp(1.1rem, 2.2vw, 1.6rem);
    font-weight: bold;
    line-height: 1.3;
}

/* ===== P1（スマホ点検・2026/10/25）：スマホの たて（はば 600px 以下）は
   遊び場を 上・テンキーを 下に ならべる。10ステージ 共通
   （右 30% の まま だと テンキーの 右の 列〔9・6・3・＝〕が 画面の 外に 切れて とどかなかった） ===== */
@media (max-width: 600px) and (orientation: portrait) {
  #game-screen { flex-direction: column; }
  #game-area { width: 100%; height: auto; flex: 1 1 auto; min-height: 0; }
  #ui-area {
    width: 100%; height: auto; flex: 0 0 auto; box-sizing: border-box;
    border-left: none; border-top: 4px solid #000;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  #answer-display { height: 52px; min-height: 52px; margin-bottom: 8px; font-size: 2.4rem; }
  #numpad { flex-grow: 0; gap: 8px; }
  #numpad .num-btn { min-height: 50px; font-size: 2rem; }
  #numpad .wide-btn { font-size: 1.5rem; }
  /* 問題の 箱が せまくて 2行に 折れないように */
  #problem-display { white-space: nowrap; font-size: 2.6rem; padding: 6px 18px; }
}
