/* Typing of the Data Science — ゲームの見た目
   外部のフォントや画像は読み込まない（初回の読み込み後はオフラインで動く）． */

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --line: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --done: #5c6672;
  --accent: #56d4c8;
  --accent-strong: #a5f3ec;
  --warn: #f2b84b;
  --miss: #ff7b72;
  --font-sans: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.05em 0.45em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85em;
  line-height: 1.5;
  text-align: center;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---- 全体の配置 ---- */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 48px);
}

.screen {
  width: min(100%, 880px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.help { margin: 0; color: var(--muted); font-size: 0.9rem; }

.notice {
  margin: 0;
  padding: 10px 16px;
  border: 1px solid var(--warn);
  border-radius: 8px;
  color: var(--warn);
  font-size: 0.95rem;
}
.notice::before { content: "！ "; font-weight: 700; }
.notice-error { border-color: var(--miss); color: var(--miss); }
.notice-floating {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: max-content;
  max-width: calc(100% - 32px);
  background: var(--bg);
}

/* ---- タイトル画面 ---- */

.game-title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(2rem, 6.4vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--accent-strong);
  text-wrap: balance;
}

.lead { margin: 0; font-size: 1.05rem; }
.lead strong { color: var(--accent); }

.difficulties {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  margin-top: 8px;
}

.difficulty {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 12px 16px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.difficulty:hover:not(:disabled) { border-color: var(--muted); }

.difficulty-marker {
  position: absolute;
  top: 8px;
  left: 12px;
  color: var(--accent);
  visibility: hidden;
}
.difficulty.is-selected { border-color: var(--accent); }
.difficulty.is-selected .difficulty-marker { visibility: visible; }

.difficulty-name { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; letter-spacing: 0.06em; }
.difficulty-desc { font-size: 0.95rem; }
.difficulty-detail { color: var(--muted); font-size: 0.82rem; }
.difficulty-best { margin-top: 6px; color: var(--muted); font-family: var(--font-mono); font-size: 0.85rem; }
.difficulty-reason { color: var(--miss); font-size: 0.82rem; }

.difficulty:disabled { cursor: not-allowed; opacity: 0.6; }
.difficulty:disabled .difficulty-name { text-decoration: line-through; }

.settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}
.setting {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
}
.setting:hover { color: var(--text); border-color: var(--muted); }
.setting-value { color: var(--text); font-weight: 600; }

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

.countdown-label { margin: 0; color: var(--muted); font-family: var(--font-mono); font-size: 1.2rem; letter-spacing: 0.1em; }
.countdown-number {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(6rem, 24vw, 12rem);
  font-weight: 800;
  line-height: 1;
  color: var(--accent-strong);
}

/* ---- プレイ画面 ---- */

.screen-play { gap: 28px; }

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}
.hud-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 6px 10px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.hud-label { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.12em; }
.hud-value {
  font-family: var(--font-mono);
  font-size: clamp(1.3rem, 4vw, 2rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}
.hud-sub { color: var(--muted); font-size: 0.72rem; }

/* 残り時間の警告: 色に加えて，数字を大きくし，枠を太くする */
.hud-time.is-warning { border-color: var(--warn); border-width: 3px; }
.hud-time.is-warning .hud-value { color: var(--warn); font-size: clamp(1.7rem, 5.4vw, 2.7rem); }
.hud-time.is-warning .hud-label::after { content: " ！"; color: var(--warn); }

.hud-float {
  position: absolute;
  top: 6px;
  right: 8px;
  color: var(--miss);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
}

.hud-multiplier .hud-value { color: var(--accent); }
.hud-multiplier.is-max .hud-value { color: var(--accent-strong); }

.gauge {
  display: block;
  width: 80%;
  height: 6px;
  margin: 4px 0 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.gauge-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform: scaleX(var(--progress, 0));
  transform-origin: left center;
}

.prompt {
  position: relative;
  width: 100%;
  min-height: 15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}
.prompt p { margin: 0; max-width: 100%; overflow-wrap: anywhere; }
.prompt-romaji { padding-top: 0.5em; }

.prompt-display { font-size: clamp(1.5rem, 4.4vw, 2.4rem); font-weight: 700; line-height: 1.35; text-wrap: balance; }
.prompt-reading { color: var(--muted); font-size: clamp(0.95rem, 2.4vw, 1.15rem); letter-spacing: 0.04em; }
.prompt-romaji {
  position: relative;
  font-family: var(--font-mono);
  font-size: clamp(1.25rem, 3.6vw, 1.9rem);
  letter-spacing: 0.06em;
  line-height: 1.5;
  word-break: break-all;
}

/* 打った部分と残りの部分: 色に加えて，打った部分を薄くし，現在位置に下線を置く */
.prompt .done { color: var(--done); }
.prompt-reading .rest { color: var(--text); }
.prompt-romaji .rest { color: var(--text); }
.prompt-romaji .cursor {
  color: var(--accent-strong);
  font-weight: 700;
  border-bottom: 3px solid var(--accent);
}

/* ミスの印は，現在の入力位置の真上に出す（文字の並びは動かさない） */
.cursor-wrap { position: relative; display: inline-block; }
.miss-mark {
  position: absolute;
  left: -1em;
  right: -1em;
  bottom: 100%;
  color: var(--miss);
  font-size: 0.8em;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  letter-spacing: 0;
  opacity: 0;
  pointer-events: none;
}

.popup {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
}

.play-status {
  min-height: 1.6em;
  margin: 0;
  font-weight: 700;
  color: var(--accent);
}
.play-status.is-lost { color: var(--miss); }

/* ---- 一時停止 ---- */

.paused-title { margin: 0; font-size: clamp(1.8rem, 5vw, 2.6rem); }

/* ---- 結果画面 ---- */

.screen-result { gap: 12px; }
.result-difficulty { margin: 0; color: var(--muted); font-family: var(--font-mono); letter-spacing: 0.1em; }
.result-caption { margin: 8px 0 0; color: var(--muted); font-size: 0.85rem; letter-spacing: 0.2em; }
.result-title {
  margin: 0;
  font-size: clamp(1.8rem, 5.6vw, 3rem);
  font-weight: 800;
  line-height: 1.25;
  color: var(--accent-strong);
  text-wrap: balance;
}
.result-score { display: flex; flex-direction: column; align-items: center; margin: 8px 0 0; }
.result-score-value {
  font-family: var(--font-mono);
  font-size: clamp(2.4rem, 8vw, 4rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.badge {
  margin: 0;
  padding: 4px 14px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 700;
}
.badge-best { border-color: var(--warn); color: var(--warn); }

.result-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  margin: 12px 0 4px;
}
.result-stats div {
  padding: 10px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.result-stats dt { color: var(--muted); font-size: 0.75rem; }
.result-stats dd {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }
.action {
  padding: 10px 18px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.action:hover:not(:disabled) { border-color: var(--muted); }
.action-primary { border-color: var(--accent); }
.is-locked .action { opacity: 0.5; }

/* ---- 遅延の表示（?debug のときだけ） ---- */

.debug-overlay {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 20;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 17, 23, 0.92);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  text-align: left;
  white-space: pre;
  pointer-events: none;
}

/* ---- 狭い画面 ---- */

@media (max-width: 640px) {
  .difficulties { grid-template-columns: 1fr; }
  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .prompt { min-height: 13rem; }
}
