:root {
    --bg-color: #0d1117;
    --panel-bg: rgba(22, 27, 34, 0.95);
    --border: #30363d;
    --text: #c9d1d9;
    --muted: #8b949e;
    --accent-blue: #58a6ff;
    --accent-cyan: #00ffcc;
    --correct-green: #39ff14;
    --error-red: #ff4444;
    --gold: #ffd700;

    /* コースごとの色 */
    --c-basics: #00ff00;
    --c-stdlib: #f1e05a;
    --c-features: #58c7ff;
    --c-advanced: #d39bff;
    --c-ecosystem: #ffb347;
}

[data-course="basics"] { --course: var(--c-basics); }
[data-course="stdlib"] { --course: var(--c-stdlib); }
[data-course="features"] { --course: var(--c-features); }
[data-course="advanced"] { --course: var(--c-advanced); }
[data-course="ecosystem"] { --course: var(--c-ecosystem); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    background-color: var(--bg-color);
    color: var(--text);
    font-family: 'Fira Code', 'Consolas', 'Menlo', monospace;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    padding: 16px;
}

#game-container {
    position: relative;
    text-align: center;
    border: 1px solid var(--border);
    padding: 22px 40px 14px;
    background: var(--panel-bg);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    border-radius: 12px;
    width: min(960px, 100%);
}

h1 { color: var(--accent-blue); letter-spacing: 8px; margin: 0 0 2px; font-size: 2rem; }

kbd {
    display: inline-block;
    padding: 1px 6px;
    margin: 0 2px;
    border: 1px solid #484f58;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #161b22;
    color: var(--text);
    font-family: inherit;
    font-size: 0.75em;
}

/* --- メニュー --- */
.portal-link { position: absolute; top: 14px; left: 14px; padding: 6px 12px; font-size: 0.75rem; }
.howto-link { position: absolute; top: 14px; right: 14px; padding: 6px 12px; font-size: 0.75rem; letter-spacing: 1px; }
.menu-message { min-height: 1.2em; margin: 0 0 6px; font-size: 0.8rem; color: var(--error-red); }
.selection-group { margin-bottom: 14px; }
.label { font-size: 0.75rem; color: var(--muted); margin: 0 0 6px; letter-spacing: 2px; }
.label span { color: #6e7681; letter-spacing: 0; }
.desc { min-height: 1.3em; margin: 5px 0 0; font-size: 0.75rem; color: var(--muted); }

.lang-group {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 4px;
    text-align: left;
}
.group-label {
    flex: 0 0 150px;
    font-size: 0.68rem;
    letter-spacing: 1px;
    color: #6e7681;
    text-align: right;
    padding-right: 6px;
}
/* 注意書きがないときは、その行の高さも取らない */
#lang-note:empty { display: none; }
.lang-locked .chip:not(.active) { opacity: 0.35; }
.chip.picked { border-color: var(--accent-cyan); color: #fff; background: rgba(0, 255, 204, 0.12); }
.chip.picked::before { content: '\2713'; margin-right: 6px; color: var(--accent-cyan); }
.review-lang { color: var(--accent-blue); }
.group-chips, .chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
/* モードは 7 つを 1 行に並べるので、ボタンを少し詰める（幅が足りない画面では折り返す） */
#mode-selector { gap: 4px; }
#mode-selector .chip { padding: 4px 7px; font-size: 0.75rem; }
#mode-selector .chip[data-course]::before { margin-right: 5px; }
.chip-row { justify-content: center; }

.chip {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #161b22;
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.chip small { margin-left: 6px; color: #6e7681; font-weight: normal; font-size: 0.7rem; }
.chip:hover { border-color: var(--accent-blue); }
.chip:focus-visible, .btn-ghost:focus-visible, .btn-gradient:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}
.chip.active {
    border-color: var(--correct-green);
    background: linear-gradient(to right, rgba(112, 218, 250, 0.25), rgba(147, 125, 247, 0.25));
    color: #fff;
    box-shadow: 0 0 12px rgba(57, 255, 20, 0.45);
}
.chip.active small { color: var(--text); }
.chip[data-course] { border-color: color-mix(in srgb, var(--course) 45%, var(--border)); }
.chip[data-course]:hover { border-color: var(--course); }
.chip[data-course].active {
    border-color: var(--course);
    background: color-mix(in srgb, var(--course) 16%, #161b22);
    box-shadow: 0 0 12px color-mix(in srgb, var(--course) 55%, transparent);
}
.chip[data-course]::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 7px;
    border-radius: 50%;
    background: var(--course);
}

.custom-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 16px;
    width: min(520px, 100%);
    margin: 12px auto 0;
    padding: 14px 16px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    text-align: left;
}
.custom-panel label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.8rem; color: var(--text); }
.custom-panel input {
    width: 76px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #0d1117;
    color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
    text-align: right;
}
.custom-panel input:focus { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
.custom-help, .custom-summary { grid-column: 1 / -1; margin: 2px 0 0; font-size: 0.75rem; color: var(--muted); }
.custom-summary { color: var(--accent-cyan); letter-spacing: 1px; }

.best-display { min-height: 1.3em; margin: 0; font-size: 0.85rem; color: var(--gold); letter-spacing: 1px; }
.key-hint { margin: 8px 0 0; font-size: 0.7rem; color: #6e7681; }

/* --- ボタン --- */
.btn-gradient {
    display: inline-block;
    padding: 12px 25px;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.4);
    background-image: linear-gradient(to right, #70dafa 0%, #937df7 100%);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: 0.3s;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    text-transform: uppercase;
}
.btn-gradient:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(57, 255, 20, 0.3);
    filter: brightness(1.1);
    border-color: #fff;
}
#start-btn.btn-gradient {
    background-image: linear-gradient(to right, #00f3ff 10%, #39ff14 90%);
    color: #06210a;
    width: min(480px, 100%);
    padding: 8px 25px;
    font-size: 1.25rem;
    margin-top: 8px;
}
#start-btn:disabled { filter: grayscale(1); opacity: 0.2; cursor: not-allowed; }

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.85rem;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-ghost:hover { color: #fff; border-color: var(--accent-blue); background: rgba(88, 166, 255, 0.1); }

/* --- ゲーム画面 --- */
#game-screen { position: relative; padding-bottom: 8px; }
/* 一時停止の間だけ、メニューが収まる高さを確保する */
#game-screen.paused { min-height: 300px; }
.game-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }

.course-tag {
    display: inline-block;
    min-height: 1.2em;
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--course, var(--muted));
}
#course-tag { display: block; margin-bottom: 6px; font-size: 1rem; }

/* 区切りの知らせ。タイマーのすぐ下に出す。知らせのあるモードでは、そのぶんの場所を先に空けておくので、
   出たり消えたりしてもほかの表示は動かない */
#game-screen.has-toast { padding-bottom: 60px; }
.toast {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 20px;
    border: 2px solid var(--accent-cyan);
    border-radius: 9999px;
    background: #0d1117;
    color: var(--accent-cyan);
    font-size: 1.05rem;
    font-weight: bold;
    letter-spacing: 1px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 2;
}
.toast.show { animation: toast 2.6s ease-out forwards, toast-glow 0.5s ease-in-out 0.3s 3; }
.toast.warn { border-color: var(--error-red); color: #ff9a9a; }
.toast.warn.show { animation: toast 2.6s ease-out forwards, toast-glow-warn 0.5s ease-in-out 0.3s 3; }
/* 小さく現れて一度大きく弾み、しばらく光ってから、上へ消える */
@keyframes toast {
    0% { opacity: 0; transform: translate(-50%, 14px) scale(0.6); }
    10% { opacity: 1; transform: translate(-50%, 0) scale(1.14); }
    18% { transform: translate(-50%, 0) scale(1); }
    82% { opacity: 1; transform: translate(-50%, 0) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -12px) scale(0.96); }
}
@keyframes toast-glow {
    0%, 100% { box-shadow: 0 0 0 rgba(0, 255, 204, 0); }
    50% { box-shadow: 0 0 22px rgba(0, 255, 204, 0.75); }
}
@keyframes toast-glow-warn {
    0%, 100% { box-shadow: 0 0 0 rgba(255, 68, 68, 0); }
    50% { box-shadow: 0 0 22px rgba(255, 68, 68, 0.8); }
}
}
#game-info { font-size: 1rem; color: var(--accent-blue); text-align: left; }
.pause-icon {
    width: 10px;
    height: 12px;
    border-left: 3px solid currentColor;
    border-right: 3px solid currentColor;
}

#word-display {
    font-size: 4rem;
    line-height: 1.3;
    min-height: 1.3em;
    margin-bottom: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
/* プレイ中の文字サイズは、問題文の長さと幅に合わせて script.js が決める */
#word-display.countdown { font-size: 4rem; color: #fff; }

#word-display span { color: #888; border-bottom: 3px solid transparent; }
#word-display span.current { color: #fff; border-bottom-color: var(--accent-cyan); }
#word-display span.cleared { color: var(--course, #00ff00); }
/* エディタモードで自動で入った閉じ側（まだ通り過ぎていないものは薄く、通り過ぎたら少し薄いまま） */
#word-display span.auto { color: var(--course, #00ff00); opacity: 0.45; }
#word-display span.cleared.auto { opacity: 0.7; }
#word-display span.miss {
    display: inline-block;
    background-color: #ff0000;
    color: #fff;
    animation: shake 0.12s;
}

#note-display { min-height: 1.5em; margin-bottom: 22px; font-size: 1rem; color: var(--muted); }
#note-display.warn { color: var(--error-red); }
#timer-display { font-size: 1.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
#timer-display.bonus { color: var(--correct-green); }
#timer-display.penalty { color: var(--error-red); }
/* 終了時の表示（FINISH! / TIME UP! / TERMINATED） */
#timer-display.ending {
    font-size: 2.6rem;
    font-weight: bold;
    letter-spacing: 8px;
}
#timer-display.ending.finish { color: var(--correct-green); text-shadow: 0 0 18px rgba(57, 255, 20, 0.6); }
#timer-display.ending.timeup { color: var(--gold); text-shadow: 0 0 18px rgba(255, 215, 0, 0.6); }
#timer-display.ending.dead {
    color: var(--error-red);
    text-shadow: 0 0 18px rgba(255, 68, 68, 0.7);
    animation: shake 0.12s 3;
}
#note-display.ending-note { color: var(--text); }

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

/* --- 一時停止 --- */
#pause-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #0d1117; /* 問題文が透けて読めないよう、完全に隠す */
    border: 1px dashed var(--border);
    border-radius: 8px;
}
.pause-title { font-size: 2.2rem; letter-spacing: 6px; color: var(--gold); animation: blink 1.4s infinite; }
.pause-sub { margin: 0 0 18px; font-size: 0.85rem; color: var(--muted); }
.pause-actions { display: flex; flex-direction: column; gap: 10px; width: min(320px, 90%); }
.pause-actions .btn-ghost { justify-content: space-between; color: var(--text); padding: 11px 16px; }

/* --- 結果画面 --- */
.result-title { font-size: 1.1rem; color: #aaa; letter-spacing: 3px; }
.result-context { margin-top: 4px; font-size: 0.8rem; color: var(--muted); }
.result-score { margin-top: 6px; font-size: 3rem; font-weight: bold; color: var(--gold); }
.result-best { min-height: 1.4em; font-size: 0.95rem; font-weight: bold; color: #ff5cf4; }
.result-best.new { animation: blink 1s 3; }

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    width: min(520px, 100%);
    margin: 18px auto;
}
.stat { padding: 12px 8px; border: 1px solid var(--border); border-radius: 8px; background: #0d1117; }
.stat-value { font-size: 1.5rem; color: #fff; font-variant-numeric: tabular-nums; }
.stat-label { margin-top: 2px; font-size: 0.7rem; color: var(--muted); letter-spacing: 2px; }

.result-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.result-actions .btn-gradient { min-width: 190px; }
.result-actions .btn-gradient kbd { background: rgba(0, 0, 0, 0.35); border-color: rgba(255, 255, 255, 0.4); color: #fff; }
.btn-secondary { background-image: none; background-color: #21262d; }

.result-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

/* 振り返り */
.review { margin-top: 22px; text-align: left; }
.review-title { margin-bottom: 8px; font-size: 0.75rem; letter-spacing: 3px; color: var(--muted); text-align: center; }
.review-list {
    max-height: 260px;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #0d1117;
}
.review-list li { padding: 9px 14px; border-left: 3px solid var(--course); }
.review-list li + li { border-top: 1px solid #21262d; }
.review-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.review-head .course-tag { flex: 0 0 76px; }
.review-head code { font-family: inherit; font-size: 0.9rem; color: var(--course); overflow-wrap: anywhere; }
.review-flag { font-size: 0.7rem; color: var(--muted); }
.review-flag.miss { color: var(--error-red); }
.review-note { margin: 3px 0 0 86px; font-size: 0.8rem; color: var(--text); }

/* X でシェアするボタン */
.share-x {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 22px 10px 18px;
    border: 1px solid #536471;
    border-radius: 9999px;
    background: #000;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.share-x svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.share-x:hover {
    background: #fff;
    color: #000;
    border-color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(255, 255, 255, 0.18);
}
.share-x:active { transform: translateY(0); }

/* --- HOW TO PLAY ページ --- */
.doc-page { align-items: flex-start; }
.howto { text-align: left; font-size: 0.9rem; line-height: 1.8; }
.howto section { margin-top: 28px; }
.howto h2 { margin: 0 0 10px; font-size: 0.85rem; font-weight: normal; letter-spacing: 2px; color: var(--accent-blue); }
.howto h3 { margin: 18px 0 6px; font-size: 0.85rem; font-weight: normal; color: var(--text); }
.howto p { margin: 8px 0; }
.howto ol, .howto ul { margin: 0; padding-left: 1.6em; }
.howto li { margin: 4px 0; }
.howto table { width: 100%; margin: 8px 0; border-collapse: collapse; }
.howto th, .howto td { padding: 7px 10px; border: 1px solid var(--border); vertical-align: top; }
.howto th { background: #0d1117; font-size: 0.75rem; font-weight: normal; letter-spacing: 1px; color: var(--muted); text-align: left; }
.howto code { padding: 1px 5px; border-radius: 4px; background: #0d1117; font-family: inherit; color: var(--accent-cyan); }
.howto .course-tag { font-size: 0.8rem; font-weight: bold; }
.howto-back { margin-top: 32px; text-align: center; }
.howto-back .btn-gradient { text-decoration: none; }

/* --- 背景（theme.js が body の data-bg を切り替える） --- */
/* 模様は .bg-layer に描く。MARATHON と SUDDEN DEATH では、theme.js が区切りごとに下の変数を変えて、
   ワープしたように次の見た目へ移す。模様は画面の中央を基準に拡大・縮小する。
     --scale : 模様の細かさ   --hue : 色相の回転   --glow : 明るさ */
.bg-layer, .bg-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}
.bg-layer {
    --scale: 1;
    --hue: 0deg;
    --glow: 1;
    filter: hue-rotate(var(--hue)) brightness(var(--glow));
}

/* GRID: サイバー調の方眼 */
body[data-bg="grid"] .bg-layer {
    background-image:
        radial-gradient(ellipse at 50% -10%, rgba(88, 166, 255, 0.22), transparent 60%),
        radial-gradient(ellipse at 50% 110%, rgba(147, 125, 247, 0.18), transparent 55%),
        linear-gradient(rgba(88, 166, 255, 0.11) 1px, transparent 1px),
        linear-gradient(90deg, rgba(88, 166, 255, 0.11) 1px, transparent 1px);
    background-size: 100% 100%, 100% 100%, calc(44px * var(--scale)) calc(44px * var(--scale)), calc(44px * var(--scale)) calc(44px * var(--scale));
    background-position: 0 0, 0 0, center, center;
}

/* CIRCUIT: 基板調の配線とランド */
body[data-bg="circuit"] { background-color: #06120e; }
body[data-bg="circuit"] .bg-layer {
    background-image:
        radial-gradient(ellipse at 50% 50%, transparent 35%, rgba(3, 8, 6, 0.85) 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cg fill='none' stroke='%2324a36b' stroke-opacity='.5' stroke-width='1.5'%3E%3Cpath d='M0 50h60l20 20h50l20-20h50'/%3E%3Cpath d='M50 0v30l20 20v60l-20 20v70'/%3E%3Cpath d='M0 150h40l20 20h60l20-20h60'/%3E%3Cpath d='M150 0v50M150 80v40l-20 20v60'/%3E%3Cpath d='M100 0v20l20 20M100 200v-20l-20-20v-40'/%3E%3Cpath d='M0 100h20M180 100h20'/%3E%3C/g%3E%3Cg fill='%2339ff14' fill-opacity='.55'%3E%3Ccircle cx='60' cy='50' r='3.5'/%3E%3Ccircle cx='150' cy='50' r='3.5'/%3E%3Ccircle cx='150' cy='80' r='3.5'/%3E%3Ccircle cx='50' cy='130' r='3.5'/%3E%3Ccircle cx='120' cy='40' r='3.5'/%3E%3Ccircle cx='80' cy='120' r='3.5'/%3E%3Ccircle cx='20' cy='100' r='3.5'/%3E%3Ccircle cx='180' cy='100' r='3.5'/%3E%3Ccircle cx='40' cy='150' r='3.5'/%3E%3C/g%3E%3Cg fill='none' stroke='%2324a36b' stroke-opacity='.45'%3E%3Crect x='92' y='84' width='36' height='24' rx='2'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 100% 100%, calc(200px * var(--scale)) calc(200px * var(--scale));
    background-position: 0 0, center;
}

/* CRT: ブラウン管の走査線 */
body[data-bg="crt"] { background-color: #050a08; }
body[data-bg="crt"] .bg-layer {
    background-image:
        radial-gradient(ellipse at 50% 50%, rgba(0, 255, 204, 0.10), transparent 70%),
        repeating-linear-gradient(0deg, rgba(0, 255, 204, 0.07) 0, rgba(0, 255, 204, 0.07) 1px, transparent 1px, transparent 4px);
    background-size: 100% 100%, 100% calc(4px * var(--scale));
    background-position: 0 0, center;
}

/* --- 警告と、システムが止まる演出（script.js が body のクラスを切り替える） --- */
/* 画面の縁を染める層。背景より手前、ゲームの枠より奥に置く */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0;
}

/* 持ち時間が残り少ない: 縁が橙に脈打ち、タイマーの色が変わり、背景がゆっくり鼓動する */
body.danger::after {
    background: radial-gradient(ellipse at center, transparent 45%, rgba(255, 140, 0, 0.55) 100%);
    animation: alert-pulse 1s ease-in-out infinite;
}
body.danger #game-container { border-color: #ff9f1a; animation: alert-border 1s ease-in-out infinite; }
body.danger #timer-display:not(.bonus):not(.penalty):not(.ending) { color: #ffb347; font-weight: bold; }
body.danger .bg-layer { animation: bg-throb 1s ease-in-out infinite; }

/* さらに少ない: 赤くなり、速く脈打ち、タイマーが点滅し、背景が小刻みに揺れる */
body.critical::after {
    background: radial-gradient(ellipse at center, transparent 35%, rgba(255, 30, 30, 0.7) 100%);
    animation-duration: 0.45s;
}
body.critical #game-container { border-color: var(--error-red); animation-duration: 0.45s; --alert-color: rgba(255, 68, 68, 0.75); }
body.critical #timer-display:not(.bonus):not(.penalty):not(.ending) {
    color: var(--error-red);
    text-shadow: 0 0 14px rgba(255, 68, 68, 0.8);
    animation: blink 0.45s steps(2, start) infinite;
}
body.critical .bg-layer { animation: bg-quake 0.3s linear infinite; }

@keyframes alert-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@keyframes alert-border {
    0%, 100% { box-shadow: 0 0 40px rgba(0, 0, 0, 0.8); }
    50% { box-shadow: 0 0 34px var(--alert-color, rgba(255, 159, 26, 0.7)); }
}
@keyframes bg-throb { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@keyframes bg-quake {
    0% { transform: translate(0, 0) scale(1.03); }
    25% { transform: translate(-5px, 3px) scale(1.05); }
    50% { transform: translate(4px, -4px) scale(1.03); }
    75% { transform: translate(-3px, -2px) scale(1.06); }
    100% { transform: translate(0, 0) scale(1.03); }
}

/* 時間切れ・ミスの上限: 画面が赤く明滅して、システムが止まる */
body.system-halt::after {
    background:
        repeating-linear-gradient(0deg, rgba(255, 0, 0, 0.16) 0, rgba(255, 0, 0, 0.16) 2px, transparent 2px, transparent 5px),
        radial-gradient(ellipse at center, rgba(120, 0, 0, 0.35) 0%, rgba(255, 0, 0, 0.75) 100%);
    animation: halt-flash 1.2s steps(1, end) forwards;
}
body.system-halt .bg-layer,
body.system-down .bg-layer {
    /* 模様の色を落として、暗い赤に沈める */
    filter: grayscale(1) sepia(1) hue-rotate(-50deg) saturate(5) brightness(0.55);
}
body.system-halt .bg-canvas { opacity: 0; }
body.system-halt #game-container {
    border-color: #ff2222;
    box-shadow: 0 0 60px rgba(255, 0, 0, 0.75);
    animation: halt-glitch 0.5s steps(1, end) 2;
}
body.system-halt #word-display { animation: halt-fade 1s ease-out forwards; }
body.system-halt #game-info { color: var(--error-red); }

/* 結果画面: 止まったあとの、赤く沈んだ状態 */
body.system-down::after {
    background: radial-gradient(ellipse at center, transparent 40%, rgba(160, 0, 0, 0.5) 100%);
    opacity: 1;
}
body.system-down #game-container { border-color: #8b1a1a; box-shadow: 0 0 40px rgba(180, 0, 0, 0.45); }

@keyframes halt-flash {
    0% { opacity: 1; }
    8% { opacity: 0.15; }
    16% { opacity: 0.95; }
    26% { opacity: 0.3; }
    38% { opacity: 1; }
    50% { opacity: 0.45; }
    62% { opacity: 0.9; }
    100% { opacity: 0.7; }
}
@keyframes halt-glitch {
    0% { transform: translate(0, 0) skewX(0); }
    15% { transform: translate(-7px, 2px) skewX(-2deg); }
    30% { transform: translate(6px, -2px) skewX(1.5deg); }
    45% { transform: translate(-3px, 1px) skewX(0); }
    60% { transform: translate(4px, 0) skewX(-1deg); }
    80% { transform: translate(-1px, 0) skewX(0); }
    100% { transform: translate(0, 0) skewX(0); }
}
@keyframes halt-fade {
    0% { opacity: 1; filter: none; }
    30% { opacity: 0.5; filter: blur(1px) saturate(0); }
    100% { opacity: 0.25; filter: saturate(0); }
}

.bg-btn {
    margin-right: auto;
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: #6e7681;
    font-family: inherit;
    font-size: 0.7rem;
    letter-spacing: 1px;
    cursor: pointer;
}
.bg-btn:hover { color: var(--accent-blue); border-color: var(--accent-blue); }

/* --- フッター --- */
#app-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    margin-top: 14px;
    font-size: 0.72rem;
    color: #6e7681;
}
#app-footer a { color: #6e7681; }
#app-footer a:hover { color: var(--accent-blue); }

@media (max-width: 720px) {
    #game-container { padding: 24px 16px 16px; }
    h1 { font-size: 1.8rem; letter-spacing: 4px; }
    .portal-link, .howto-link { position: static; margin: 0 2px 12px; }
    .howto table { font-size: 0.8rem; }
    .lang-group { flex-direction: column; gap: 4px; }
    .group-label { flex: none; text-align: left; }
    .key-hint { display: none; }
    .custom-panel { grid-template-columns: 1fr; }
    .review-note { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
    .toast.show { opacity: 1; } /* 動きを出さない設定でも、知らせは見えるようにする */
}
