/* typing.css - タイピング練習画面 */
/* 既存の style.css（body/main/.hidden/.tab-btn 等）に乗せる形で、この画面固有の分だけ書く */

#typing-container {
    padding: 20px 24px 28px;
    position: relative;
}

#typing-container h2 {
    margin: 0 0 4px;
    color: #00796b;
}

.typing-lead {
    margin: 0 0 20px;
    color: #666;
    font-size: 0.9rem;
}

/* --- おまかせ（spec §13） -------------------------------------- */
/* 初心者・低学年が最初に見るところ。選択欄より先に、大きく1つだけ置く。
   「じぶんで えらぶ」以下は、打てる子が見にいくもの */

#typing-omakase {
    margin-bottom: 18px;
}

.typing-omakase-button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    width: 100%;
    max-width: 520px;
    padding: 16px 22px;
    background-color: #00796b;
    color: #fff;
    border: none;
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.typing-omakase-button:hover {
    background-color: #00695c;
}
.typing-omakase-button:disabled {
    background-color: #b0bec5;
    cursor: default;
}

.typing-omakase-name {
    font-size: 1.35rem;
    font-weight: bold;
}

.typing-omakase-lead {
    font-size: 0.85rem;
    opacity: 0.85;
}

/* にがてキーにちょうせん。おまかせより一段控えめにする。
   毎日これを押す入り口ではなく、苦手が出たときの寄り道なので */
#typing-weak {
    margin-bottom: 18px;
}

.typing-weak-button {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
    max-width: 520px;
    padding: 12px 20px;
    background-color: #fff;
    color: #00695c;
    border: 2px solid #00796b;
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.typing-weak-button:hover {
    background-color: #e0f2f1;
}
.typing-weak-button:disabled {
    border-color: #b0bec5;
    color: #90a4ae;
    cursor: default;
}

.typing-weak-name {
    font-size: 1.05rem;
    font-weight: bold;
}

/* 「きょうは Q と Y」。押す前に何をやるか分かるようにする */
.typing-weak-keys {
    font-size: 0.9rem;
    letter-spacing: 0.08em;
}

/* あつまるごほうび。**選ぶ作業から切り離して画面のいちばん下に置く**（spec §13.1）。
   選択欄とスタートの間に挟むと、押すべきボタンが遠くなる */
.typing-badge-block {
    margin: 24px 0 0;
    padding-top: 16px;
    border-top: 1px solid #eee;
}

.typing-badge-heading {
    margin: 0 0 10px;
    color: #00695c;
    font-size: 0.95rem;
    font-weight: bold;
}

/* まだ1つも無い子に出す1行。**「0／16」とは書かない。**
   足りない数を数えさせず、これから増えるものだと伝えるだけにする */
.typing-badges-empty {
    margin: 0 0 12px;
    color: #999;
    font-size: 0.85rem;
}

/* 棚に並んでいるのが見えることに意味があるので、
   数を主役にせず、アイコンと短い名前だけを置く */
.typing-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 18px;
}

.typing-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    background-color: #f1f8f7;
    border: 1px solid #b2dfdb;
    color: #00695c;
    font-size: 0.85rem;
    white-space: nowrap;
}

.typing-badge-icon {
    font-size: 1rem;
}

/* バッジのぼう。生徒が自分から開くコレクション。
   **取った枠と取っていない枠の差が、色と濃さだけで分かること**が眼目。
   未取得の枠も同じ大きさで場所を確保しておく（枠の位置が動くと
   「あそこが空いている」という覚え方ができない） */
.typing-shelf-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 12px;
}

.typing-shelf-button {
    padding: 6px 16px;
    border-radius: 999px;
    border: 1px solid #b2dfdb;
    background-color: #fff;
    color: #00695c;
    font-size: 0.9rem;
    cursor: pointer;
}

.typing-shelf-button:hover {
    background-color: #f1f8f7;
}

.typing-shelf {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 10px;
    margin: 0 0 18px;
    padding: 14px;
    border-radius: 12px;
    background-color: #fafafa;
    border: 1px solid #e0e0e0;
}

.typing-shelf-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 72px;
    padding: 8px 4px;
    border-radius: 10px;
    text-align: center;
    font-size: 0.75rem;
    line-height: 1.3;
}

.typing-shelf-slot-earned {
    background-color: #f1f8f7;
    border: 1px solid #b2dfdb;
    color: #00695c;
}

/* 未取得。**枠があることだけ伝えて、中身は伏せる。**
   薄いグレーで「まだ」を表す。バツや鍵は「失敗」に見えるので使わない */
.typing-shelf-slot-locked {
    background-color: #f5f5f5;
    border: 1px dashed #d5d5d5;
    color: #bdbdbd;
}

.typing-shelf-icon {
    font-size: 1.5rem;
    line-height: 1;
}

/* 結果画面で「いま取った」ぶん。ここだけは目立たせる */
.typing-new-badges {
    margin: 14px 0 0;
    padding: 12px 16px;
    border-radius: 12px;
    background-color: #fff8e1;
    border: 1px solid #ffe082;
}

.typing-new-badges .typing-new-lead {
    margin: 0 0 8px;
    font-weight: bold;
    color: #8d6e00;
}

.typing-new-badges .typing-badge {
    background-color: #fff;
    border-color: #ffca28;
    color: #8d6e00;
    font-size: 0.95rem;
}

/* じぶんで えらぶ。**選ぶ3つとスタートを1つの枠に閉じる**（spec §13.1）。
   おまかせ・にがてキーは「押せば始まる」ボタンだが、ここは「選んでから押す」場所。
   枠で囲わないと、どこまでが1つの操作なのかが見た目から分からない */
.typing-choose-card {
    margin: 0 0 20px;
    padding: 16px 18px 4px;
    border: 1px solid #d8e6e4;
    border-radius: 12px;
    background-color: #fcfefe;
}

.typing-choose-lead {
    margin: 0 0 10px;
    color: #888;
    font-size: 0.85rem;
    font-weight: bold;
}

/* スタートは選択欄と同じ枠の中、いちばん下に置く。
   **選択欄との間に他のものを挟まない。** 挟むと、押すべきボタンが遠くなる */
.typing-choose-start {
    margin-top: 4px;
    padding-top: 12px;
    border-top: 1px dashed #e0eceb;
}

/* --- セット選択 ------------------------------------------------ */

.typing-form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.typing-form-row label {
    font-weight: bold;
    color: #444;
    min-width: 8em;
}

.typing-form-row select {
    padding: 8px 10px;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    background-color: #fff;
}

#typing-set-info {
    color: #777;
    font-size: 0.85rem;
}

.typing-primary-button {
    background-color: #00796b;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 32px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.typing-primary-button:hover {
    background-color: #00695c;
}

.typing-secondary-button {
    background-color: #eceff1;
    color: #455a64;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 0.95rem;
    cursor: pointer;
}

.typing-secondary-button:hover {
    background-color: #cfd8dc;
}

/* --- 練習中 ---------------------------------------------------- */

.typing-status-bar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    color: #455a64;
    font-weight: bold;
}

.typing-status-bar .typing-spacer {
    flex: 1;
}

/* コンボ（連続正解）。伸びたときだけ出て、ミスでそっと消える。
   消えたことを強調しない（設計書 U4「ミスを目立たせない」）ため、
   0 の表示も、消えるときのアニメーションも持たせない。 */
#typing-combo {
    color: #ef6c00;
    white-space: nowrap;
}

.typing-combo-pop {
    animation: typing-combo-pop 180ms ease-out;
}

@keyframes typing-combo-pop {
    from { transform: scale(1.35); }
    to   { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .typing-combo-pop { animation: none; }
}

#typing-display {
    font-family: "Consolas", "Menlo", "Courier New", monospace;
    font-size: clamp(1.8rem, 5vw, 3rem);
    letter-spacing: 0.06em;
    text-align: center;
    padding: 36px 10px 14px;
    word-break: break-all;
}

.typing-char {
    color: #b0bec5;
    /* 空白でも枠が潰れないように */
    display: inline-block;
    min-width: 0.4em;
}

.typing-char.done {
    color: #00796b;
}

.typing-char.current {
    color: #263238;
    border-bottom: 4px solid #00796b;
}

/*
 * かなモードでは、かな側の下線を消して色だけで位置を示す。
 * 下線はローマ字の段（実際に押すキー）が持つ。
 * 消すのに transparent を使うのは、border を外すと行の高さが変わって
 * 打つたびにお題が上下に揺れるため。
 */
.typing-mode-kana .typing-char.current {
    border-bottom-color: transparent;
}

.typing-char-space {
    color: #cfd8dc;
}

.typing-char.miss {
    animation: typing-miss-flash 0.35s ease-out;
}

@keyframes typing-miss-flash {
    0% { color: #e53935; background-color: #ffcdd2; }
    100% { color: #263238; background-color: transparent; }
}

/* かなモードのローマ字（お手本）。かなより一回り小さくして主役を奪わない */
#typing-romaji {
    font-family: "Consolas", "Menlo", "Courier New", monospace;
    font-size: clamp(1.1rem, 3vw, 1.6rem);
    letter-spacing: 0.08em;
    text-align: center;
    padding-bottom: 10px;
    word-break: break-all;
}

.typing-romaji-done {
    color: #00796b;
}

/*
 * 次に押す1キー。下線はここにだけ引く。
 * 実際に指が押すのはローマ字のほうなので、一番強い目印はこちらに置く
 * （かな側にも下線があると、画面に2つ出てどちらを打つのか迷わせる）。
 */
.typing-romaji-current {
    color: #263238;
    display: inline-block;
    border-bottom: 4px solid #00796b;
}

.typing-romaji-rest {
    color: #b0bec5;
}

/*
 * かなモードだけ「次のお題」を日本語ヒントより上（お題のすぐ下）に出す。
 * かな＋ローマ字の2段でお題の縦幅が増え、先読みが遠くなるため（typing-spec.md 5.1）。
 * 英字モードは DOM の順（お題 → 日本語ヒント → 次のお題）のまま。
 */
#typing-stage {
    display: flex;
    flex-direction: column;
}

.typing-mode-kana #typing-next {
    order: 1;
}

.typing-mode-kana #typing-hint-text {
    order: 2;
}

#typing-hint-text {
    text-align: center;
    color: #78909c;
    min-height: 1.4em;
    margin-bottom: 6px;
}

/* 次のお題の先読み。いま打っている語より明らかに弱く見せて、視線が移らないようにする */
#typing-next {
    text-align: center;
    color: #b0bec5;
    font-family: "Consolas", "Menlo", "Courier New", monospace;
    font-size: 0.95rem;
    min-height: 1.4em;
    margin-bottom: 18px;
    border-top: 1px dashed #eceff1;
    padding-top: 8px;
}

/* --- キーボード ------------------------------------------------ */

#typing-keyboard {
    background-color: #eceff1;
    border-radius: 10px;
    padding: 8px;
    user-select: none;
}

.kb-row {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

.kb-row:last-child {
    margin-bottom: 0;
}

.kb-key {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    padding: 10px 0;
    border-radius: 6px;
    background-color: #fff;
    border-bottom: 2px solid #cfd8dc;
    font-size: 0.8rem;
    color: #37474f;
    overflow: hidden;
    white-space: nowrap;
}

.kb-key.kb-func {
    color: #90a4ae;
    font-size: 0.7rem;
}

/* ホームポジション（F・J）の突起 */
.kb-key.kb-home {
    box-shadow: inset 0 -6px 0 -4px #78909c;
}

/* 指ごとの色分け。人差し指2本だけで打つ癖を防ぐためのもの */
.kb-key.f-lp { background-color: #ffe0e6; }
.kb-key.f-lr { background-color: #ffeccf; }
.kb-key.f-lm { background-color: #fff9c4; }
.kb-key.f-li { background-color: #dcedc8; }
.kb-key.f-ri { background-color: #c8e6c9; }
.kb-key.f-rm { background-color: #b3e5fc; }
.kb-key.f-rr { background-color: #d1c4e9; }
.kb-key.f-rp { background-color: #f8bbd0; }
.kb-key.f-th { background-color: #eceff1; }

.kb-key.kb-active {
    background-color: #00796b;
    color: #fff;
    font-weight: bold;
    transform: translateY(1px);
}

.kb-key.kb-active-shift {
    background-color: #4db6ac;
    color: #fff;
    font-weight: bold;
}

.kb-key.kb-miss {
    animation: typing-key-miss 0.35s ease-out;
}

@keyframes typing-key-miss {
    0% { background-color: #e53935; color: #fff; }
    100% { background-color: #00796b; color: #fff; }
}

/* --- カウントダウン --------------------------------------------- */

/* スタート直後の 3・2・1。お題は下に見えたままにして、数えている間に読ませる */
#typing-countdown {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.72);
    border-radius: 8px;
    z-index: 15;
    pointer-events: none;
}

#typing-countdown-number {
    font-family: "Consolas", "Menlo", "Courier New", monospace;
    font-size: clamp(3.5rem, 14vw, 7rem);
    font-weight: bold;
    color: #00796b;
    text-shadow: 0 2px 12px rgba(255, 255, 255, 0.9);
}

.typing-countdown-pop {
    animation: typing-countdown-pop 0.45s ease-out;
}

@keyframes typing-countdown-pop {
    0% { transform: scale(1.6); opacity: 0; }
    40% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* 動きを減らす設定の端末では拡大アニメーションを出さない */
@media (prefers-reduced-motion: reduce) {
    .typing-countdown-pop {
        animation: none;
    }
}

/* --- IME警告 --------------------------------------------------- */

#typing-ime-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(38, 50, 56, 0.92);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-radius: 8px;
    z-index: 20;
    padding: 20px;
}

#typing-ime-overlay .typing-ime-title {
    font-size: 1.8rem;
    font-weight: bold;
    margin-bottom: 12px;
}

#typing-ime-overlay .typing-ime-body {
    font-size: 1.1rem;
    line-height: 1.7;
}

#typing-ime-overlay kbd {
    background-color: #fff;
    color: #263238;
    border-radius: 6px;
    padding: 4px 10px;
    font-weight: bold;
    margin: 0 4px;
}

/* 入力を受けるだけの隠しinput。画面には出さないがフォーカスは持たせる */
#typing-key-catcher {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    border: none;
    padding: 0;
    top: 0;
    left: 0;
}

/* --- 結果 ------------------------------------------------------ */

.typing-result-headline {
    font-size: 1.3rem;
    font-weight: bold;
    color: #00796b;
    text-align: center;
}

.typing-score {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin: 20px 0 28px;
}

.typing-score-item {
    background-color: #f4f7f6;
    border-radius: 8px;
    padding: 14px 22px;
    text-align: center;
    min-width: 120px;
}

.typing-score-label {
    display: block;
    font-size: 0.8rem;
    color: #78909c;
    margin-bottom: 6px;
}

.typing-score-value {
    display: block;
    font-size: 1.6rem;
    font-weight: bold;
    color: #263238;
}

.typing-key-table {
    width: 100%;
    max-width: 460px;
    border-collapse: collapse;
    margin: 8px 0 20px;
}

.typing-key-table th,
.typing-key-table td {
    border-bottom: 1px solid #eee;
    padding: 8px 10px;
    text-align: left;
    font-size: 0.9rem;
}

.typing-key-table th {
    color: #78909c;
    font-weight: normal;
}

.typing-result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* 読み込み中・保存結果などの短いメッセージ */
.typing-status-text {
    color: #78909c;
    font-size: 0.9rem;
    text-align: center;
    min-height: 1.4em;
    margin: 12px 0 0;
}

.typing-primary-button:disabled {
    background-color: #b0bec5;
    cursor: default;
}

/* 自己ベスト。更新した回だけ色を付ける。
   更新できなかった回は「いまのベスト」を淡く置くだけにして、
   届かなかったことを責めない（設計書 U5） */
#typing-best {
    margin: 6px 0 18px;
    font-weight: bold;
    color: #90a4ae;
}

#typing-best.typing-best-hit {
    color: #ef6c00;
    font-size: 1.15rem;
}

/* 累計打鍵数。減らない数字だけを置く場所。
   他人との比較も順位も出さない（spec §5.7） */
#typing-my-total {
    margin: -4px 0 16px;
    color: #00796b;
    font-weight: bold;
}
