/* =========================================================
   計算ページ共通のスタイル
   モードごとの違い（背景・ボタンの色など）は各モードの CSS で上書きする
   ========================================================= */

/* ブラウザのデフォルトのマージンとパディングをリセット */
html,
body {
    margin: 0;
    padding: 0;
    overflow: hidden; /* スクロールバーが出ないように設定 */
    height: 100%;
}

h1 {
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    font-size: 24px;
}

.unselectable {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}


/* ---------- オープニング（レベル選択）画面 ---------- */

#openingScreen {
    position: relative;
    /* レイヤー1：トップ画面と同じ宇宙のキラキラ背景を使い回し！ */
    background-image: url('../img/bg_space.svg') !important;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    height: 100vh;
    width: 100vw;
    display: block;
    overflow: hidden;
}

/* レイヤー2：トップ画面と同じ水面ボードを使い回し！ */
#openingScreen .opening-board {
    position: absolute;
    top: 14vh;
    left: 1.5vw;
    right: 1.5vw;
    bottom: 2.5vh;
    border: 14px solid #57c1e8; /* たしざん・百マスは水色の枠 */
    background-image: url('../img/board_water.svg');
    background-size: 100% 100%;
    box-sizing: border-box;
    z-index: 0;
}

/* ひきざん・かけざんモードのときは、原画どおり枠の色をピンク（#ff8e99）に自動変更！ */
html[data-mode="sub"] #openingScreen .opening-board,
html[data-mode="multi"] #openingScreen .opening-board {
    border-color: #ff8e99;
}

/* レイヤー3：タマとモード別タイトルのヘッダー（枠の上辺にタマの手がピタッと乗る） */
#openingScreen .opening-header-logo {
    position: absolute;
    top: calc(14vh - clamp(52px, 8.2vw, 96px));
    left: 48%; /* 右上の「にがてちょうせん！」ボタンと重なりにくいよう少しだけ左寄り中央に */
    transform: translateX(-50%);
    width: clamp(540px, 86vw, 1020px);
    z-index: 2;
    pointer-events: none;
}

#openingScreen .opening-header-logo svg {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
}

/* モードごとのタイトル文字の自動出し分け */
#openingScreen .mode-title {
    display: none;
}
html[data-mode="add"] #openingScreen .title-add,
html[data-mode="sub"] #openingScreen .title-sub,
html[data-mode="multi"] #openingScreen .title-multi,
html[data-mode="hundredgrid"] #openingScreen .title-hundredgrid {
    display: inline;
}

.select-level-buttons {
    position: absolute;
    top: 24%;
    left: 50%;
    transform: translateX(-50%); /* 中央揃え */
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3列のグリッド */
    gap: 10px;
    width: calc(100% - 40px);
    margin: 0 auto;
}

.level-pair {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* ← center から flex-start に変更（ボタンの頭をピタッと揃える） */
}

.level-pair.empty {
    visibility: hidden; /* 拡張用空欄は非表示に */
}

.coin-container {
    margin-top: 5px; /* コインコンテナとボタンの間隔 */
    font-size: 14px;
}

.select-level-buttons button {
    width: 18vw;
    height: 7vh;
    padding: 10px 20px;
    border-radius: 20px;
    background-color: #FFC0CB; /* ピンク色 */
    color: Purple;
    border: 2px solid #8B0000; /* 濃い赤色の外枠 */
    font-size: 20px;
    font-weight: bold;
    box-shadow: 4px 4px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s, box-shadow 0.3s;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.select-level-buttons button:hover {
    transform: scale(1.1);
    box-shadow: 6px 6px 7px rgba(0, 0, 0, 0.3);
}

.select-level-buttons button:active {
    transform: scale(0.9);
}

.comment {
    font-weight: bold;
}


footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
    padding: 8px 0;
    background-color: rgba(248, 248, 248, 0.8);
}

footer p {
    margin: 0;
    color: gray;
    font-size: 0.8em;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}


/* ---------- テンキー ---------- */

.keypad {
    position: fixed;
    bottom: 0px;
    right: 0px;
    background-color: #f0f0f0;
    padding: 5px;
    border-radius: 10px;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
}

.key-row {
    display: flex;
    justify-content: center;
    margin-bottom: 5px;
}

.keypad button {
    background: none;
    border: none;
    padding: 5px;
    margin: 5px;
    cursor: pointer;
    transition: transform 0.1s ease;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
}

/* キーを押したとき（:active はマウス、.active はタッチ・物理キー）に縮小 */
.keypad button:active,
.keypad button:active .key-digit,
.keypad button.active,
.keypad button.active .key-digit {
    transform: scale(0.9);
}

/* キーの数字（高さは画面の 1/9、40px～70px） */
.keypad button .key-digit {
    --key-height: clamp(40px, 11vh, 70px);
    display: block;
    height: var(--key-height);
    width: calc(var(--key-height) * 250 / 330);
    transition: transform 0.1s ease;
    will-change: transform;
}


/* ---------- 問題画面：式 ---------- */

.calculation-container {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: 58%;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

/* 数字・記号・ひらがなの字形（js/glyphs.js。線の色は color） */
.glyph {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.digit,
.digit-card,
.symbol,
.key-digit {
    color: #000;
}

/* 式の数字（数字の枠いっぱい） */
.digit {
    display: block;
    flex: none;
    width: 12vh;
    height: 16vh;
}

/* 記号（＋ − × ＝、「5 は 2 と ？」の は・と） */
.symbol {
    display: block;
    width: 11.4vh;
    height: 15vh;
}

.symbol.kana-ha {
    color: #3333ff;
}

/* 正解するまで、答えの数字はかくしておく（「？」カードの角のすき間から見えないように） */
.digit.hidden-answer {
    visibility: hidden;
}

/* 答えをかくす「？」のカード */
.q-card {
    width: 100%;
    height: 100%;
    background-color: #fff;
    border-radius: 1.6vh;
    color: #ff2929;
}

.calculation-symbol {
    align-self: flex-end; /* 底面を揃える */
    margin-bottom: 4%;
}

.number-set {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    border: 1px solid grey;
    border-radius: 10px;
    vertical-align: bottom;
    padding: 10px;
    margin: 10px;
}

.num-container {
    position: relative;
    width: 12vh;
    height: 16vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* 十の位がないときは幅0にして、数字ごとかくす */
}

.cover-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: none;
}

/* おたすけだんご */
.dot-set {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.num-big-container {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    padding: 10px;
    margin: 10px;
}

.dots {
    font-size: 130%;
    margin: 3px;
}

.help-checkbox {
    position: absolute;
    top: 5px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* おたすけだんご・けんばんの よみかた：おすと ON／OFF が かわる スイッチ */
.help-checkbox input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    flex: none;
    width: 46px;
    height: 26px;
    margin: 0;
    border-radius: 13px;
    background: #c8ccd2;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    transition: background 0.2s ease;
    vertical-align: middle;
}

.help-checkbox input[type="checkbox"]::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s ease;
}

.help-checkbox input[type="checkbox"]:checked {
    background: #ff7eb6;
}

.help-checkbox input[type="checkbox"]:checked::before {
    transform: translateX(20px);
}

.help-checkbox input[type="checkbox"]:focus-visible {
    outline: 3px solid #74b9ff;
    outline-offset: 2px;
}

.help-checkbox label {
    cursor: pointer;
    user-select: none;
}

.remaining-problems {
    position: fixed;
    top: 30px;
    left: 3px;
    color: #2c3e50;
    padding: 0;
    border-radius: 5px;
    font-size: 20px;
}


/* ---------- ボタン ---------- */

.returnButton,
.universalButton {
    padding: 5px 10px;
    border-radius: 20px;
    background-color: #FFC0CB; /* ピンク色 */
    color: Purple;
    font-size: 20px;
    transition: transform 0.3s, box-shadow 0.3s;
}

.returnButton {
    position: absolute;
    bottom: 5px;
    left: 10px;
}

.returnButton:hover,
.universalButton:hover {
    transform: scale(1.1);
    box-shadow: 6px 6px 7px rgba(0, 0, 0, 0.3);
}

.returnButton:active,
.universalButton:active {
    transform: scale(0.9);
}

#masterButton {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    font-size: 16px;
    background-color: #007BFF;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}


/* ---------- 入力した数字のアニメーション ---------- */

/* 正解：上から落ちてきて縮む */
@keyframes dropAndShrink {
    0% {
        transform: translateY(-50px) scale(3);
        opacity: 0;
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.falling-and-shrinking-image {
    animation: dropAndShrink 0.1s ease-out;
    width: 12vh;
    height: 16vh;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 不正解：回転しながらはじかれる（移動量は JS で --random-x/y に設定） */
@keyframes spin-and-bounce {
    0% {
        transform: translate(0, 0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translate(var(--random-x, 0), var(--random-y, 0)) rotate(720deg);
        opacity: 0;
    }
}

.bouncing-and-spinning-image {
    animation: spin-and-bounce 0.2s ease-out forwards;
    transform-origin: center;
}

/* 「？」カバーが広がって消える */
@keyframes expand-and-fade {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

.expand-and-fade {
    animation: expand-and-fade 0.8s forwards;
}


/* ---------- ドロップ ---------- */

.coin {
    position: fixed;
    width: 50px;
    z-index: 1;
    will-change: transform;
}

.reward-coin {
    z-index: 1;
}


/* ---------- 通知・モーダル ---------- */

.notification {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #4caf50; /* 緑色 */
    color: white;
    padding: 10px;
    border-radius: 5px;
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: 3;
    pointer-events: none; /* 見えない ときも 画面の まんなかに あるので、下の ボタンを おせなく しない */
}

#deleteModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 2;
}

#rescueModal {
    z-index: 5; /* こするエリア（くろねこ）より上に */
}

#rescueModal input[type="range"] {
    width: 100%;
}


/* ---------- タマのおしゃべり ---------- */

/* こするとタマがしゃべるエリア（SVGのくろねこタマ自身が当たり判定！） */
#touchArea {
    pointer-events: auto; /* タマのイラスト部分だけタッチ・マウスイベントを受け取る */
    touch-action: none;   /* 指でこすっても画面がスクロールしない */
    cursor: grab;
    transition: filter 0.2s ease;
}

#touchArea:hover {
    filter: drop-shadow(0 0 8px rgba(255, 255, 200, 0.7)); /* 触れるとほんのり光って分かりやすい */
}

#touchArea:active {
    cursor: grabbing;
}


#commentArea {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.speech-bubble {
    position: absolute;
    transform: translate(-50%, -50%); /* top / left が吹き出しの中心 */
    width: max-content;
    max-width: 80vw;
    padding: 0.8em 1.6em;
    background-color: #fffcd2; /* クリーム色 */
    border: 3px solid #d9d2fb; /* うすいむらさきのふち */
    border-radius: 1.4em;
    filter: drop-shadow(10px 10px 10px rgba(0, 0, 0, 0.5));
    z-index: 1;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.speech-bubble p {
    margin: 0;
    color: black;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
}


/* ---------- 画面ごとに出し分ける部品 ---------- */

/* データ管理モーダル：さいしょの画面だけ／計算の画面だけ */
html[data-mode="home"] .mode-only,
html:not([data-mode="home"]) .home-only {
    display: none !important;
}

/* 百マスのクリア画面には「おめでとう！」を出さない */
html[data-mode="hundredgrid"] .drill-only {
    display: none;
}

#dataModal { z-index: 3; }
#deleteModal { z-index: 1000; }

/* ================= 右上ナビゲーション（にがて・もどる・きろく） ================= */

.top-right-nav {
    position: fixed;
    top: 10px;
    right: 14px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: stretch; /* 上のボタンの幅に合わせて下の2つのボタンもピタッと揃う */
    gap: 6px;
}

.nav-sub-row {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* 1段目：🔥 にがてちょうせん！ */
#toggleWeakMode {
    padding: 6px 16px;
    font-size: 15px;
    font-weight: 900;
    font-family: 'M PLUS Rounded 1c', sans-serif;
    color: #fff;
    background: linear-gradient(135deg, #ff7043, #e53935);
    border: 2px solid #fff;
    border-radius: 999px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
}

#toggleWeakMode:hover {
    transform: scale(1.05);
}

#toggleWeakMode.active {
    background: linear-gradient(135deg, #d32f2f, #b71c1c);
    box-shadow: 0 0 12px rgba(255, 87, 34, 0.8);
}

/* 2段目：「もどる」「きろく」「きょくノート」共通のぷっくりカプセルデザイン */
#goToIndex,
#goToRecords,
#goToSongNote {
    position: static !important; /* records.css等の右下固定を強制解除 */
    right: auto !important;
    bottom: auto !important;
    top: auto !important;
    left: auto !important;
    flex: 1;
    padding: 5px 12px !important;
    font-size: 14px !important;
    font-weight: 900 !important;
    font-family: 'M PLUS Rounded 1c', sans-serif !important;
    color: #fff !important;
    border: 2px solid #fff !important;
    border-radius: 999px !important; /* カプセル型を強制適用 */
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.22) !important;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: transform 0.15s ease, filter 0.2s ease;
}

/* 「もどる」：枠や歯車と調和するアクアブルー */
#goToIndex {
    background: linear-gradient(135deg, #26c6da, #0097a7) !important;
}

/* 「きろく」：ドロップ感のあるオレンジ〜ゴールド */
#goToRecords {
    background: linear-gradient(135deg, #ffb74d, #f57c00) !important;
}

/* 「きょくノート」（おんぷよみ）：おんがくの へやの むらさき */
#goToSongNote {
    background: linear-gradient(135deg, #a29bfe, #6c5ce7) !important;
}

#goToIndex:hover,
#goToRecords:hover,
#goToSongNote:hover {
    transform: scale(1.06);
    filter: brightness(1.08);
}

#goToIndex:active,
#goToRecords:active,
#goToSongNote:active {
    transform: scale(0.95);
}

/* にがてモードONのときのレベル選択ボタン */
#openingScreen.weak-mode-active .select-level-buttons button {
    position: relative;
    background-color: #fff3e0 !important;
    border: 3px solid #ff7043 !important;
    color: #bf360c !important;
    transition: all 0.2s ease;
}

/* 苦手が残っているレベルのボタンは特に強調 */
#openingScreen.weak-mode-active .select-level-buttons button.has-weak {
    background: linear-gradient(180deg, #ffe0b2, #ffcc80) !important;
    border-color: #e64a19 !important;
    box-shadow: 0 4px 10px rgba(230, 74, 25, 0.3);
}

/* 苦手が0個のレベルのボタンは少し落ち着いた色に */
#openingScreen.weak-mode-active .select-level-buttons button.no-weak {
    opacity: 0.75;
    border-color: #ffb74d !important;
}

/* ボタン右上の🔥バッジ */
.weak-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 7px;
    font-size: 0.85em;
    font-weight: bold;
    color: #fff;
    background-color: #e53935;
    border-radius: 999px;
    vertical-align: middle;
}

button.no-weak .weak-badge {
    background-color: #43a047;
}

/* にがてな問題がないレベルは、にがてちょうせんでは押せない */
#openingScreen.weak-mode-active .select-level-buttons button:disabled {
    filter: grayscale(0.8);
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 👑 特訓コースボタン */
.special-course-pair {
    margin-top: 0;
}

#openingScreen.weak-mode-active button.special-course-btn {
    background: linear-gradient(135deg, #ffd54f, #ffb300) !important;
    border: 3px solid #ff6f00 !important;
    color: #4e342e !important;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(255, 111, 0, 0.4);
}

/* にがてな問題がないときは押せない */
#openingScreen.weak-mode-active button.special-course-btn:disabled {
    filter: grayscale(0.8);
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ================= 左上の歯車ボタン（セーブ・設定） ================= */

.gear-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    width: clamp(44px, 6vw, 56px);
    height: clamp(44px, 6vw, 56px);
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 10;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.2s ease;
}

.gear-btn:hover {
    transform: rotate(45deg) scale(1.1);
    filter: brightness(1.08);
}

.gear-btn:active {
    transform: rotate(90deg) scale(0.92);
}

/* 「？」カードが枠をこえて大きく広がれるようにする */
.calculation-container,
.num-big-container,
.number-set,
.num-container,
.cover-container,
.q-card,
.q-card svg {
    overflow: visible !important;
}

/* 広がっている最中の「？」が他の枠の下に隠れないよう一番手前に出す */
.expand-and-fade {
    z-index: 100;
    pointer-events: none;
}
/* ひみつの しかけ（js/music.js）：たしざんを おさえた ままに しても、iPad の メニューや 文字えらびが 出ないように */
#homeAdd,
#homeSub {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
