/* =================================================================
 * つみきかぞえ（空間認識・見えない積み木を数える）固有スタイル
 * すべてのセレクタを #app-kids-tsumiki でスコープ
 * ================================================================= */

#app-kids-tsumiki {
    --ts-accent: #f0a500;
    --ts-accent-text: var(--kids-warm-text, #a06a00);   /* 文字に使うとき（白背景で読める濃さ） */
}

/* ---------- がんばりきろく ---------- */
#app-kids-tsumiki .ts-record-box {
    background: var(--bs-body-bg);
    border: 2px solid var(--bs-border-color);
    border-radius: 1rem;
    padding: 0.75rem 0.5rem;
}

#app-kids-tsumiki .ts-record-num {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--bs-body-color);
    /* 2けたでも おりかえさない（「10もん」が「10も／ん」に なって いた） */
    white-space: nowrap;
}

/* たんいは 小さく。**数が 主役**で、2けたでも 1行に 収まる */
#app-kids-tsumiki .ts-record-unit {
    font-size: 0.55em;
    font-weight: 700;
    margin-left: 0.08em;
}

/* ---------- しんちょくバー ---------- */
#app-kids-tsumiki .ts-progress {
    border-radius: 0;
}

#app-kids-tsumiki .ts-progress .progress-bar {
    transition: width 0.35s ease;
}

/* ---------- しつもん文 ---------- */
#app-kids-tsumiki .ts-prompt {
    font-size: clamp(1.15rem, 4.5vw, 1.5rem);
    font-weight: 800;
    line-height: 1.3;
    color: var(--bs-body-color);
}

#app-kids-tsumiki .ts-prompt .ts-prompt-em {
    color: var(--kids-accent-text, var(--bs-primary));
}

/* ---------- つみきの え（等角投影 SVG） ---------- */
#app-kids-tsumiki .ts-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    padding: 0.5rem;
}

#app-kids-tsumiki .ts-stage svg {
    width: auto;
    max-width: 100%;
    max-height: 260px;
    height: auto;
    overflow: visible;
}

#app-kids-tsumiki .ts-stage svg.is-drop {
    animation: ts-drop 0.4s ease;
}

@keyframes ts-drop {
    0% { transform: translateY(-14px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* 積み木の面（塗り分け） */
#app-kids-tsumiki .ts-face { stroke: #7a5320; stroke-width: 1.4; stroke-linejoin: round; }
/* **3つの 面の 明暗を はっきり 分ける**（2026-09-03「明暗が わかりにくくて
   どちらの 面か まよう」）。上＝いちばん 明るい／みぎ＝中／ひだり＝いちばん 暗い */
#app-kids-tsumiki .ts-face-top { fill: #fbdf8b; }
#app-kids-tsumiki .ts-face-left { fill: #b07615; }
#app-kids-tsumiki .ts-face-right { fill: #eec25c; }

/* 聞かれて いる 面 */
#app-kids-tsumiki .ts-face.is-target { stroke: #1f6feb; stroke-width: 2; }

/* どこから 見るかの 案内 */
#app-kids-tsumiki .ts-mark-line { stroke: #1f6feb; stroke-width: 3; stroke-linecap: round; }
#app-kids-tsumiki .ts-mark-head { fill: #1f6feb; }
#app-kids-tsumiki .ts-mark-text {
    fill: #1f6feb;
    font-size: 21px;
    font-weight: 800;
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 4;
}
/* うらがわ（ひだり）は 破線で「まわりこむ」ことを 示す */
#app-kids-tsumiki .ts-mark-line.is-back { stroke-dasharray: 6 5; }
#app-kids-tsumiki .ts-mark-head.is-back { opacity: 0.85; }
/* たしかめ用ハイライト段 */
#app-kids-tsumiki .ts-face.is-dim { opacity: 0.28; }
#app-kids-tsumiki .ts-face.is-hi { stroke: var(--bs-primary); stroke-width: 2.4; }
/* box: たりない立方体（ゴースト表示） */
/* たりない ところ。**うすいと 何も 読めない**ので はっきり 出す（2026-09-03 指摘） */
#app-kids-tsumiki .ts-face.is-ghost {
    fill: var(--bs-primary);
    fill-opacity: 0.3;
    stroke: var(--bs-primary);
    stroke-opacity: 1;
    stroke-width: 1.6;
    stroke-dasharray: 5 3;
}
#app-kids-tsumiki .ts-face.is-ghost.is-ghost-hi {
    fill-opacity: 0.55;
    stroke-opacity: 1;
    stroke-dasharray: none;
    stroke-width: 2.6;
}
/* 目ざす はこの わく */
#app-kids-tsumiki .ts-frame {
    fill: var(--bs-primary);
    fill-opacity: 0.06;
    stroke: var(--bs-primary);
    stroke-opacity: 0.75;
    stroke-width: 1.6;
    stroke-dasharray: 5 4;
}

/* ---------- たしかめ（段ごと） ---------- */
#app-kids-tsumiki .ts-check-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem;
    border: 2px dashed var(--bs-border-color);
    border-radius: 1rem;
    animation: ts-pop 0.35s ease;
}

#app-kids-tsumiki .ts-check-rows {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
}

#app-kids-tsumiki .ts-check-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.7rem;
    border: 2px solid var(--bs-border-color);
    border-radius: 0.7rem;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    font-weight: 700;
    font-size: 1rem;
}

#app-kids-tsumiki .ts-check-chip .ts-check-n {
    color: var(--ts-accent-text);
    font-weight: 800;
}

#app-kids-tsumiki .ts-check-sum {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--bs-body-color);
}

#app-kids-tsumiki .ts-check-sum .ts-check-total {
    color: var(--kids-accent-text, var(--bs-primary));
    font-size: 1.5rem;
}

/* 走らせる ごうけい */
#app-kids-tsumiki .ts-check-run {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--bs-secondary-color);
}

#app-kids-tsumiki .ts-check-run .ts-check-runnum {
    color: var(--ts-accent-text);
    font-size: 1.3rem;
    font-weight: 800;
}

/* ハイライト中の段チップ */
#app-kids-tsumiki .ts-check-chip.is-lit {
    border-color: var(--bs-primary);
    background: rgba(124, 90, 195, 0.14);
    transform: scale(1.06);
    transition: transform 0.15s ease;
}

/* ---------- はんてい メッセージ ---------- */
#app-kids-tsumiki .ts-feedback {
    text-align: center; /* 演出は画面の中央に出す */
    min-height: 2.4rem;
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0.4rem 0;
    line-height: 1.2;
}

#app-kids-tsumiki .ts-feedback.is-correct { color: var(--bs-success); }
#app-kids-tsumiki .ts-feedback.is-wrong { color: var(--bs-danger); }
#app-kids-tsumiki .ts-feedback.is-answer { color: var(--kids-accent-text, var(--bs-primary)); }
#app-kids-tsumiki .ts-feedback.is-animate { animation: ts-pop 0.4s ease; }

/* ---------- こたえ（テンキー） ---------- */
#app-kids-tsumiki .ts-answer-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-weight: 800;
}

#app-kids-tsumiki .ts-answer-label {
    font-size: 1.1rem;
    color: var(--bs-secondary-color);
}

#app-kids-tsumiki .ts-answer-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.4em;
    padding: 0.1em 0.3em;
    font-size: 2rem;
    border-radius: 0.6rem;
    border: 4px dashed var(--ts-accent);
    color: var(--ts-accent-text);
    line-height: 1.1;
}

#app-kids-tsumiki .ts-answer-box.is-empty { opacity: 0.85; }

#app-kids-tsumiki .ts-answer-box.is-correct {
    border-style: solid;
    border-color: var(--bs-success);
    color: var(--bs-success);
}

#app-kids-tsumiki .ts-answer-box.is-reveal {
    border-style: solid;
    border-color: var(--bs-primary);
    color: var(--kids-accent-text, var(--bs-primary));
}

#app-kids-tsumiki .ts-answer-unit {
    font-size: 1.3rem;
    color: var(--bs-body-color);
}

#app-kids-tsumiki .ts-keypad {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
    max-width: 340px;
}

#app-kids-tsumiki .ts-key {
    font-size: 1.8rem;
    font-weight: 800;
    padding: 0.5rem 0;
    border-radius: 1rem;
    min-height: 64px;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
    transition: transform 0.05s ease;
}

#app-kids-tsumiki .ts-key.btn-light {
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border: 2px solid var(--bs-border-color);
}

#app-kids-tsumiki .ts-key:active { transform: translateY(2px); box-shadow: none; }
#app-kids-tsumiki .ts-key-ok,
#app-kids-tsumiki .ts-key-del { font-size: 1.5rem; }

/* ---------- こたえ（どこから みた: 4たく） ---------- */
#app-kids-tsumiki .ts-choices {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    max-width: 420px;
    margin: 0 auto;
}

#app-kids-tsumiki .ts-choice {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.9rem;
    border: 3px solid var(--bs-border-color);
    border-radius: 1rem;
    background: var(--bs-body-bg);
    cursor: pointer;
    transition: transform 0.06s ease, border-color 0.15s ease;
    min-height: 120px;
}

@media (hover: hover) { #app-kids-tsumiki .ts-choice:hover { border-color: var(--bs-primary); } }
#app-kids-tsumiki .ts-choice:active { transform: scale(0.97); }
#app-kids-tsumiki .ts-choice.is-correct { border-color: var(--bs-success); background: rgba(var(--bs-success-rgb), 0.12); }
#app-kids-tsumiki .ts-choice.is-wrong { border-color: var(--bs-danger); background: rgba(220, 53, 69, 0.10); }
#app-kids-tsumiki .ts-choice.is-locked { pointer-events: none; }

/* **引きのばさない**。svg が もつ 大きさの まま 出す ので、
   どの こうほも ます目の 大きさが そろう（2026-09-03「2列だと でかすぎる」） */
#app-kids-tsumiki .ts-choice svg {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}

/* 三面図のマス */
#app-kids-tsumiki .ts-vcell-on { fill: #e6b348; stroke: #7a5320; stroke-width: 1.4; }
#app-kids-tsumiki .ts-vcell-off { fill: none; stroke: var(--bs-border-color); stroke-width: 1.4; stroke-dasharray: 3 3; }

/* ---------- アニメーション ---------- */
@keyframes ts-pop {
    0% { transform: scale(0.4); opacity: 0; }
    60% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes ts-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-7px); }
    75% { transform: translateX(7px); }
}

#app-kids-tsumiki .ts-stage.is-shake { animation: ts-shake 0.35s ease; }

/* ---------- けっか ---------- */
#app-kids-tsumiki .ts-result-emoji {
    font-size: clamp(3.5rem, 16vw, 5rem);
    line-height: 1.25;
    margin-bottom: 0.5rem;
    animation: ts-pop 0.5s ease;
}

#app-kids-tsumiki .ts-result-box {
    background: var(--bs-body-tertiary-bg, var(--bs-tertiary-bg));
    border: 2px solid var(--bs-border-color);
    border-radius: 1rem;
    padding: 0.9rem 0.5rem;
}

#app-kids-tsumiki .ts-result-num {
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--bs-body-color);
}

#app-kids-tsumiki .ts-result-marks {
    font-size: 1.6rem;
    letter-spacing: 0.15em;
    word-break: break-word;
}

/* ---------- こども語 かいせつ ---------- */
#app-kids-tsumiki .ts-explain {
    min-height: 0;
    max-width: 460px;
    margin: 0 auto 0.4rem;
    padding: 0;
    font-size: 0.98rem;
    font-weight: 600;
    line-height: 1.45;
    color: var(--bs-secondary-color);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.25s ease, max-height 0.25s ease, padding 0.25s ease;
}

#app-kids-tsumiki .ts-explain.is-show {
    opacity: 1;
    max-height: 8rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.7rem;
    background: rgba(124, 90, 195, 0.08);
}

/* ---------- どっちが おおい？（くらべる） ---------- */
#app-kids-tsumiki .ts-compare {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    flex-wrap: nowrap;
}

#app-kids-tsumiki .ts-cmp-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    flex: 1 1 0;
    min-width: 0;
}

#app-kids-tsumiki .ts-cmp-svg {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 120px;
}

#app-kids-tsumiki .ts-cmp-svg svg {
    width: auto;
    max-width: 100%;
    max-height: 160px;
    height: auto;
    overflow: visible;
}

#app-kids-tsumiki .ts-cmp-label {
    font-weight: 800;
    font-size: 1.05rem;
    color: var(--bs-body-color);
}

#app-kids-tsumiki .ts-cmp-vs {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--bs-secondary-color);
    flex: 0 0 auto;
    padding: 0 0.15rem;
}

/* ---------- テキスト3択（くらべる） ---------- */
#app-kids-tsumiki .ts-choices-text {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-width: 360px;
}

#app-kids-tsumiki .ts-choice-text {
    padding: 0.9rem 1rem;
    border: 3px solid var(--bs-border-color);
    border-radius: 1rem;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.06s ease, border-color 0.15s ease, background 0.15s ease;
}

#app-kids-tsumiki .ts-choice-text.is-same { border-style: dashed; }
@media (hover: hover) { #app-kids-tsumiki .ts-choice-text:hover { border-color: var(--bs-primary); } }
#app-kids-tsumiki .ts-choice-text:active { transform: scale(0.97); }
#app-kids-tsumiki .ts-choice-text.is-correct { border-color: var(--bs-success); background: rgba(var(--bs-success-rgb), 0.12); }
#app-kids-tsumiki .ts-choice-text.is-wrong { border-color: var(--bs-danger); background: rgba(220, 53, 69, 0.10); }
#app-kids-tsumiki .ts-choice-text.is-locked { pointer-events: none; }

/* ---------- けっか: じこベスト ---------- */
#app-kids-tsumiki .ts-result-best {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--bs-secondary-color);
}

#app-kids-tsumiki .ts-result-best .ts-best-num {
    color: var(--kids-accent-text, var(--bs-primary));
    font-size: 1.3rem;
    font-weight: 800;
}

#app-kids-tsumiki .ts-result-best .ts-newrec {
    color: var(--bs-warning);
    font-weight: 800;
    animation: ts-pop 0.5s ease;
}

/* ---------- モバイル微調整 ---------- */
@media (max-width: 575.98px) {
    #app-kids-tsumiki .ts-keypad { gap: 0.5rem; max-width: 300px; }
    #app-kids-tsumiki .ts-key { min-height: 58px; font-size: 1.6rem; }
    #app-kids-tsumiki .ts-stage svg { max-height: 210px; }
    #app-kids-tsumiki .ts-choice { min-height: 100px; padding: 0.6rem; }
    #app-kids-tsumiki .ts-cmp-svg svg { max-height: 130px; }
    #app-kids-tsumiki .ts-cmp-label { font-size: 0.95rem; }
    #app-kids-tsumiki .ts-choice-text { font-size: 1.05rem; padding: 0.75rem; }
}

/* 402x703 でテンキーが画面外に出ていたので、つみきの面とキーを詰める（2026-08-07） */
@media (max-width: 575.98px) {
    #app-kids-tsumiki .ts-stage { min-height: 150px; padding: 0.25rem; }
    #app-kids-tsumiki .ts-stage svg { max-height: 196px; }
    #app-kids-tsumiki .ts-feedback { margin: 0.2rem 0; min-height: 2rem; }
    #app-kids-tsumiki .ts-keypad { gap: 0.4rem; }
    #app-kids-tsumiki .ts-key { min-height: 50px; font-size: 1.5rem; padding: 0.35rem 0; }
}

/* たしかめの ボタン（まわす／だんごとに）は 1行に ならべる */
#app-kids-tsumiki .ts-tools {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
}

#app-kids-tsumiki .ts-tools .btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

/* つぶれた あと、こたえの ます目と 同じ 色に なる（見くらべられる ように） */
#app-kids-tsumiki .ts-face.is-flat { fill: #e6b348; }
