/* タイピングゲーム（/typing/）。ゲームの画面（.tg-stage）は、いつも同じ色（夜の色）で出す。
   あそんでいる間（body.tg-on）は、上のメニューなどをかくして、画面いっぱいをゲームと画面のキーボードに使う。 */
.page-typing { --accent: var(--blue); --accent-soft: var(--blue-soft); --ok: var(--green); --ok-soft: #e6f6ee; --no: var(--red); --no-soft: #fdecec; }
.tg-app {
  margin-top: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; scroll-margin-top: 72px;
}
.tg-app button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* はじめの画面 */
.tg-sec + .tg-sec { margin-top: 22px; }
.tg-h { font-size: 1.15rem; margin: 0; }
.tg-gh { font-size: .88rem; color: var(--muted); font-weight: 700; margin: 12px 0 0; }
.tg-opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tg-opt {
  min-height: 48px; padding: 6px 16px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 700; font-size: 1rem; cursor: pointer; text-align: left;
}
.tg-opt:hover { border-color: var(--accent); }
.tg-opt[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.tg-toggle::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px; border: 2px solid var(--muted); border-radius: 4px; vertical-align: -2px; }
.tg-toggle[aria-pressed="true"]::before { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent-soft); }
.tg-rules ul { margin: 8px 0 0; padding-left: 1.2em; color: var(--ink-2); font-size: .95rem; }
.tg-go { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; margin-top: 26px; }
.tg-start { min-width: 220px; min-height: 56px; font-size: 1.3rem; }
.tg-best { margin: 0 0 0 auto; font-size: .9rem; color: var(--muted); font-weight: 700; }

/* あそぶ画面 */
.tg-on .site-header, .tg-on .site-footer, .tg-on .breadcrumb, .tg-on .tg-intro, .tg-on .tg-below { display: none; }
.tg-on .container { width: min(1120px, 100% - 12px); }
.tg-on .tg-app {
  display: flex; flex-direction: column; margin-top: 0; padding: 6px 10px max(8px, env(safe-area-inset-bottom));
  height: 100vh; height: 100dvh; border-radius: 0; border-block: 0; box-shadow: none;
}
.tg-hud { display: flex; align-items: center; gap: 16px; font-weight: 700; font-variant-numeric: tabular-nums; min-height: 40px; flex: none; }
.tg-lives i { font-style: normal; color: #e5484d; margin-right: 2px; font-size: 1.4rem; }
.tg-lives i.is-lost { color: var(--line); }
.tg-prog { color: var(--muted); font-size: 1.15rem; min-width: 3ch; }
.tg-prog.is-last { color: var(--no); }
.tg-combo { color: var(--ok); font-size: .9rem; }
.tg-score { margin-left: auto; font-size: 1.4rem; }
.tg-pause { min-height: 36px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 99px; padding: 2px 16px; font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer; }
.tg-pause:hover { border-color: var(--accent); }

.tg-stage {
  --u: 8px;
  position: relative; overflow: hidden; margin-top: 4px; border-radius: 12px; color: #fff;
  width: 100%; flex: 1 1 0; min-height: 170px; user-select: none; -webkit-user-select: none;
}
.tg-bg, .tg-fx, .tg-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.is-space > .tg-bg { background: radial-gradient(ellipse at 50% 125%, #2c3a86 0%, #0d1230 55%, #060814 100%); }
.is-obake > .tg-bg {
  background:
    radial-gradient(circle at 84% 14%, #fff3c4 0, #fff3c4 4.2%, rgba(255, 243, 196, .18) 4.4%, rgba(255, 243, 196, 0) 11%),
    linear-gradient(#151a36 0%, #2d2b5c 30%, #3d5a44 30.2%, #2c4735 62%, #223a2c 100%);
}
/* まもる線：宇宙はシールド（よこ）、おばけはフェンス（たて） */
.tg-line { position: absolute; pointer-events: none; transition: opacity .3s, filter .3s; }
.is-space .tg-line { left: 0; right: 0; top: 82%; height: 3px; background: linear-gradient(90deg, transparent, #7fe3ff 20%, #7fe3ff 80%, transparent); opacity: .55; box-shadow: 0 0 12px #7fe3ff; }
.is-obake .tg-line {
  top: 30%; bottom: 0; left: 14%; width: calc(var(--u) * 1.6);
  background: repeating-linear-gradient(180deg, #c9a56b 0, #c9a56b calc(var(--u) * 2.4), #7d6238 calc(var(--u) * 2.4), #7d6238 calc(var(--u) * 3));
  border-radius: 4px; box-shadow: 2px 0 0 rgba(0, 0, 0, .25);
}

/* 端末の キーボードを出すための、見えない入力らん。iPhone・iPad で フォーカスしたときに 画面が大きく ならないよう、字は 16px */
.tg-input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; font-size: 16px; color: transparent; caret-color: transparent; background: transparent; }
.tg-enemy, .tg-player { position: absolute; left: 0; top: 0; will-change: transform; }
.tg-enemy { display: flex; flex-direction: column; align-items: center; gap: 2px; transition: opacity .3s; }
.is-obake .tg-enemy { flex-direction: column-reverse; }
.tg-sprite, .tg-player { width: clamp(30px, calc(var(--u) * 6.6), 62px); }
.tg-sprite svg, .tg-player svg { display: block; width: 100%; height: auto; overflow: visible; }
.is-obake .tg-sprite, .is-obake .tg-player { width: clamp(26px, calc(var(--u) * 5.6), 54px); }
.tg-label {
  background: rgba(8, 12, 28, .86); border: 2px solid rgba(255, 255, 255, .28); border-radius: 10px;
  padding: 1px 10px 3px; text-align: center; white-space: nowrap; line-height: 1.35;
}
.tg-kana { font-size: clamp(17px, calc(var(--u) * 2.7), 26px); font-weight: 700; letter-spacing: .04em; }
.tg-kana .is-done { color: #6ee7a8; }
.tg-kana ruby { ruby-position: over; }
.tg-kana rt { font-size: .58em; font-weight: 700; letter-spacing: .02em; color: #fff; }
.tg-kana:has(ruby) { font-size: clamp(20px, calc(var(--u) * 3.1), 30px); line-height: 1.7; }
.tg-kana .is-cur { text-decoration: underline; text-decoration-color: #ffd84d; text-underline-offset: 4px; }
.tg-roma { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: clamp(12px, calc(var(--u) * 1.6), 16px); color: #b9c3dd; letter-spacing: .06em; }
.tg-roma b, .tg-p-roma b { color: #6ee7a8; font-weight: 700; }
.tg-enemy.is-target { z-index: 50 !important; }
.tg-enemy.is-target .tg-label { border-color: #ffd84d; box-shadow: 0 0 0 3px rgba(255, 216, 77, .28); }
.tg-enemy.is-dead, .tg-enemy.is-gone { opacity: 0; }
.tg-enemy.is-dead .tg-sprite { transform: scale(1.6); transition: transform .3s; }
.tg-enemy.is-miss .tg-label, .tg-panel.is-miss { animation: tg-shake .25s; }
.tg-stage.is-hit { animation: tg-hit .4s; }
.is-space[data-lives="2"] .tg-line { opacity: .38; }
.is-space[data-lives="1"] .tg-line { opacity: .3; background: linear-gradient(90deg, transparent, #ff6b5e 20%, #ff6b5e 80%, transparent); box-shadow: 0 0 12px #ff6b5e; }
.is-obake[data-lives="2"] .tg-line { filter: brightness(.8); }
.is-obake[data-lives="1"] .tg-line { filter: brightness(.6) sepia(1) hue-rotate(-40deg) saturate(3); }
.tg-stage[data-lives="0"] .tg-line { opacity: 0; }
@keyframes tg-shake { 25% { translate: -5px 0; } 75% { translate: 5px 0; } }
@keyframes tg-hit { 30% { box-shadow: inset 0 0 0 6px #ff6b5e, inset 0 0 60px rgba(255, 107, 94, .6); } }
@keyframes tg-bob { 50% { translate: 0 -3px; } }
@keyframes tg-flame { 50% { transform: scaleY(.6); } }
@media (prefers-reduced-motion: no-preference) {
  .tg-sprite { animation: tg-bob 1.6s ease-in-out infinite; }
  .tg-flame { animation: tg-flame .2s linear infinite; transform-origin: 50% 44px; transform-box: view-box; }
}

.tg-overlay {
  position: absolute; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 16px;
  background: rgba(6, 8, 20, .78); text-align: center;
}
.tg-overlay h2 { font-size: 1.8rem; margin: 0; }
.tg-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.tg-actions .btn { min-height: 52px; }

/* いま ねらっている ことば */
.tg-panel {
  display: flex; align-items: center; justify-content: center; gap: 4px 28px; flex-wrap: wrap; flex: none;
  min-height: 64px; margin-top: 8px; padding: 4px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
.tg-hint { margin: 0; color: var(--muted); font-size: .95rem; text-align: center; line-height: 1.5; }
.tg-p-word { font-size: 1.9rem; font-weight: 700; line-height: 1.6; white-space: nowrap; }
.tg-p-word rt { font-size: .42em; font-weight: 500; }
.tg-p-word .is-done { color: var(--ok); }
.tg-p-roma { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 1.4rem; letter-spacing: .08em; color: var(--muted); }
.tg-p-roma b { color: var(--ok); }
.tg-keys { flex: none; font-size: .82rem; color: var(--muted); margin: 8px 0 0; text-align: center; }

/* 画面のキーボード（タブレット・スマホ）。キーの高さは画面の高さに合わせる */
.tg-kb {
  flex: none; display: grid; gap: 6px; margin-top: 8px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.tg-kb-row { display: flex; justify-content: center; gap: 1%; }
.tg-key {
  position: relative; flex: 0 0 9%; height: clamp(40px, 7.4vh, 62px); padding: 0; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); box-shadow: 0 3px 0 var(--line); color: var(--ink); font: inherit; font-weight: 900;
  font-size: clamp(1rem, 2.6vw, 1.5rem); line-height: 1; cursor: pointer;
}
.tg-key-wide { flex-basis: 18%; word-break: keep-all; line-height: 1.2; font-size: clamp(.7rem, 1.7vw, 1rem); font-weight: 700; color: var(--ink-2); }
.tg-key.is-home::after { content: ""; position: absolute; left: 35%; right: 35%; bottom: 14%; height: 3px; border-radius: 2px; background: var(--muted); opacity: .5; }
.tg-key.is-next { background: #ffe48a; border-color: #e0b93a; box-shadow: 0 3px 0 #e0b93a; }
.tg-key.is-down { transform: translateY(2px); background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 1px 0 var(--accent); }
.has-kb .tg-panel { min-height: 52px; }
.has-kb .tg-p-word { font-size: 1.5rem; }
.has-kb .tg-p-roma { font-size: 1.2rem; }

/* けっか */
.tg-result { text-align: center; padding-block: 12px; }
.tg-result h2 { font-size: 1.6rem; margin: 0; }
.tg-stars { font-size: 2.75rem; line-height: 1.3; letter-spacing: 6px; }
.tg-stars i { font-style: normal; color: var(--line); }
.tg-stars i.is-on { color: #f5b90f; }
.tg-bigscore { font-size: 4rem; font-weight: 900; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tg-bigscore small { display: block; font-size: .88rem; color: var(--muted); font-weight: 700; }
.tg-newbest { display: inline-block; font-size: .82rem; font-weight: 700; color: var(--ok); background: var(--ok-soft); border-radius: 99px; padding: 2px 12px; }
.tg-msg { color: var(--ink-2); margin: 10px 0 0; }
.tg-stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 20px 0 0; }
.tg-stats div { min-width: 132px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.tg-stats dt { font-size: .82rem; color: var(--muted); }
.tg-stats dd { margin: 0; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tg-result .tg-gh { margin-top: 22px; }
.tg-words, .tg-chart { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0; }
.tg-words { justify-content: center; }
.tg-words li, .tg-chart li { display: grid; justify-items: center; min-width: 56px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.tg-words b, .tg-chart b { font-size: 1.35rem; font-weight: 700; line-height: 1.8; }
.tg-words rt { font-size: .45em; }
.tg-chart b { line-height: 1.4; }
.tg-words span, .tg-chart span { font-size: .82rem; color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.tg-result .tg-actions { margin-top: 26px; }

/* ページ */
.tg-help { margin-top: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 20px; }
.tg-help summary { cursor: pointer; font-weight: 700; }
.tg-help-notes { margin: 12px 0 0; padding-left: 1.2em; color: var(--ink-2); font-size: .95rem; }
.tg-parents ul { padding-left: 1.2em; }
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.theme-card { display: grid; grid-template-rows: auto 1fr; overflow: hidden; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; }
a.theme-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.theme-art { position: relative; height: 150px; display: flex; align-items: center; justify-content: center; gap: 28px; }
.theme-art svg { position: relative; width: 62px; height: auto; overflow: visible; }
.theme-art .tg-label { position: relative; color: #fff; font-size: 1.15rem; font-weight: 700; }
.theme-body { padding: 16px 22px 20px; }
.theme-body h3 { font-size: 1.3rem; margin: 0; }
.theme-body p { color: var(--ink-2); margin: 6px 0 0; }
.theme-go { display: inline-block; margin-top: 10px; font-weight: 700; color: var(--accent-text); }

@media (max-width: 760px) {
  .tg-app { padding: 14px 12px; }
  .theme-grid { grid-template-columns: 1fr; }
  .tg-best { margin-left: 0; }
  .tg-hud { gap: 10px; }
  .tg-on .tg-app { padding-inline: 4px; }
  .tg-kb { gap: 5px; }
  .tg-key { border-radius: 8px; }
}
