/* JEV SPEED — UI レイヤー。3D キャンバスの上に重ねる HUD とオーバーレイ。 */

:root {
  --bg: #05070f;
  --panel: rgba(13, 19, 36, 0.78);
  --panel-line: rgba(94, 234, 212, 0.18);
  --ink: #e6edf7;
  --dim: #8fa3c0;
  --teal: #5eead4;
  --pink: #f472b6;
  --amber: #fbbf24;
  --red: #f87171;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

/* display を指定した要素でも hidden 属性を効かせる（UA の [hidden] は簡単に上書きされてしまう） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: 100dvh;
}

/* ------------------------------------------------------------------ stage */

#stage { position: relative; overflow: hidden; }

#table-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#table-canvas.miss { animation: miss-shake 0.32s cubic-bezier(.36,.07,.19,.97); }

@keyframes miss-shake {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

#scoreboard {
  position: absolute;
  inset: 16px 16px auto 16px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  backdrop-filter: blur(12px);
}

.score-name { font: 700 12px/1 var(--mono); letter-spacing: 0.16em; }
.score-cpu .score-name { color: var(--pink); }
.score-human .score-name { color: var(--teal); }
.score-num { font: 700 24px/1 var(--mono); font-variant-numeric: tabular-nums; }
.score-unit { font-size: 10px; color: var(--dim); letter-spacing: 0.1em; }

/* ---------------------------------------------------------------- コンボ */

#combo {
  --combo-hue: #fbbf24;
  --combo-glow: rgba(251, 191, 36, 0.75);
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  font: 900 44px/1 var(--mono);
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: var(--combo-hue);
  text-shadow: 0 0 24px var(--combo-glow), 0 4px 0 rgba(0, 0, 0, 0.4);
  pointer-events: none;
  opacity: 0;
}

/* 段階ごとの色と字の太さ。上がるほど大きく・眩しく */
#combo[data-tier="aqua"]  { --combo-hue: #67e8f9; --combo-glow: rgba(56, 189, 248, 0.9);  font-size: 50px; }
#combo[data-tier="flame"] { --combo-hue: #ffb054; --combo-glow: rgba(255, 110, 20, 0.95); font-size: 58px; }
#combo[data-tier="storm"] { --combo-hue: #e0f2ff; --combo-glow: rgba(125, 211, 252, 1);   font-size: 66px; }
#combo[data-tier="god"] {
  --combo-hue: #fff;
  --combo-glow: rgba(255, 214, 122, 1);
  font-size: 78px;
  background: linear-gradient(95deg, #fff2a8, #ff7a1e 35%, #ff2f6a 55%, #7dd3fc 85%, #fff);
  background-size: 260% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: combo-pop 0.7s cubic-bezier(.17,.89,.32,1.28) forwards, god-shift 1.1s linear infinite;
  filter: drop-shadow(0 0 26px rgba(255, 190, 80, 0.95));
}
#combo[data-tier="break"] {
  --combo-hue: #94a3b8;
  --combo-glow: rgba(148, 163, 184, 0.55);
  font-size: 34px;
  letter-spacing: 0.22em;
}
#combo[data-owner="cpu"] { text-shadow: 0 0 26px var(--combo-glow), 0 0 60px rgba(255, 47, 106, 0.55), 0 4px 0 rgba(0, 0, 0, 0.5); }

#combo.pop { animation: combo-pop 0.7s cubic-bezier(.17,.89,.32,1.28) forwards; }
#combo[data-tier="storm"].pop,
#combo[data-tier="god"].pop { animation-duration: 0.95s; }

@keyframes combo-pop {
  0%   { opacity: 0; transform: translateX(-50%) scale(2.2) rotate(-6deg); }
  18%  { opacity: 1; transform: translateX(-50%) scale(1) rotate(2deg); }
  70%  { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(1.15) translateY(-16px); }
}

@keyframes god-shift {
  from { background-position: 0% 50%; }
  to   { background-position: 260% 50%; }
}

/* ------------------------------------------------------------------ 煽り */

#taunt {
  position: absolute;
  top: calc(18% + 76px);
  left: 50%;
  transform: translateX(-50%);
  font: 700 19px/1.2 var(--sans);
  letter-spacing: 0.08em;
  color: #e6edf7;
  text-shadow: 0 0 18px rgba(0, 0, 0, 0.9), 0 2px 0 rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

#taunt[data-owner="cpu"] { color: #ffb4cf; text-shadow: 0 0 20px rgba(255, 47, 106, 0.85); }
#taunt[data-owner="human"] { color: #9ef7e2; text-shadow: 0 0 20px rgba(45, 212, 191, 0.75); }
#taunt.pop { animation: taunt-pop 2.2s ease-out forwards; }

@keyframes taunt-pop {
  0%   { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.9); }
  10%  { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* 開始画面で属性を色分けするための小物 */
.el-aqua  { color: #67e8f9; font-weight: 700; }
.el-flame { color: #ffb054; font-weight: 700; }
.el-storm { color: #bfdbfe; font-weight: 700; }
.el-god   { color: #fff3b0; font-weight: 900; text-shadow: 0 0 14px rgba(255, 200, 80, 0.8); }

/* -------------------------------------------------------- コンボ帯の画面演出 */

/* 盤面の縁が段階の色で脈打つ。3D 側の演出と合わせて「熱」を作る */
#stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  box-shadow: inset 0 0 90px 10px var(--rage, transparent), inset 0 0 220px 40px var(--rage, transparent);
  z-index: 3;
}

#stage[data-rage="aqua"],  #stage[data-rage="aqua-cpu"]  { --rage: rgba(56, 189, 248, 0.30); }
#stage[data-rage="flame"], #stage[data-rage="flame-cpu"] { --rage: rgba(255, 110, 20, 0.36); }
#stage[data-rage="storm"], #stage[data-rage="storm-cpu"] { --rage: rgba(147, 197, 253, 0.42); }
#stage[data-rage="god"]     { --rage: rgba(94, 234, 212, 0.55); }
#stage[data-rage="god-cpu"] { --rage: rgba(255, 47, 106, 0.55); }
#stage[data-rage="spark"]   { --rage: rgba(251, 191, 36, 0.22); }
#stage[data-rage="spark-cpu"] { --rage: rgba(255, 47, 106, 0.22); }

/* 文字類は縁の発光より前に出す */
#combo, #taunt, #foul-banner, #status-line, #scoreboard, #toggles { z-index: 4; }

#stage[data-rage]:not([data-rage=""])::after { opacity: 1; animation: rage-pulse 1.1s ease-in-out infinite; }
#stage[data-rage="storm"]::after, #stage[data-rage="storm-cpu"]::after { animation-duration: 0.7s; }
#stage[data-rage="god"]::after, #stage[data-rage="god-cpu"]::after { animation-duration: 0.45s; }

@keyframes rage-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

/* ------------------------------------------------------- スピード宣言ボタン */

#speed-call {
  position: absolute;
  inset: auto 0 27%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 5;
  pointer-events: none;
  animation: sc-in 0.32s cubic-bezier(.17,.89,.32,1.28);
}

/* 盤面の上に重なるので、文字は暗い下地を敷いて必ず読めるようにする */
.sc-lead, .sc-hint {
  margin: 0;
  padding: 5px 14px;
  background: rgba(5, 8, 16, 0.72);
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.sc-lead {
  font: 700 13px/1 var(--mono);
  letter-spacing: 0.3em;
  color: var(--amber);
  text-shadow: 0 0 16px rgba(251, 191, 36, 0.8);
}

#speed-btn {
  pointer-events: auto;
  padding: 16px 52px;
  font: 900 40px/1 var(--mono);
  letter-spacing: 0.12em;
  color: #1a1204;
  background: linear-gradient(180deg, #ffe89a, #fbbf24 55%, #e08b0a);
  border: 3px solid #fff3c4;
  border-radius: 14px;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  box-shadow:
    0 0 0 3px rgba(251, 191, 36, 0.28),
    0 0 46px rgba(251, 191, 36, 0.75),
    0 10px 0 #8a5a04,
    0 14px 26px rgba(0, 0, 0, 0.55);
  animation: sc-throb 0.85s ease-in-out infinite;
  transition: transform 0.06s, box-shadow 0.12s;
}

#speed-btn:hover { filter: brightness(1.08); }

#speed-btn:active {
  transform: translateY(8px);
  box-shadow:
    0 0 0 3px rgba(251, 191, 36, 0.28),
    0 0 60px rgba(251, 191, 36, 0.95),
    0 2px 0 #8a5a04,
    0 4px 12px rgba(0, 0, 0, 0.55);
  animation: none;
}

.sc-hint {
  font-size: 11px;
  color: #b9c8de;
  letter-spacing: 0.06em;
}

.sc-hint kbd {
  padding: 1px 6px;
  font: 600 10px/1.6 var(--mono);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
}

@keyframes sc-in {
  from { opacity: 0; transform: translateY(26px) scale(0.88); }
}

@keyframes sc-throb {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.055); }
}

/* ------------------------------------------------- 残り枚数の緊張（死にかけ） */

/* 心拍。残りが減るほど速く、視界が締まっていく */
#stage::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 2;
  box-shadow:
    inset 0 0 110px 20px var(--ten, transparent),
    inset 0 0 300px 80px var(--ten, transparent);
}

#stage[data-tension^="danger"] { --ten: rgba(255, 36, 54, 0.50); }
#stage[data-tension^="chance"] { --ten: rgba(54, 240, 196, 0.40); }
#stage[data-tension$="-1"] { --beat: 1.40s; }
#stage[data-tension$="-2"] { --beat: 0.95s; }
#stage[data-tension$="-3"] { --beat: 0.60s; }

#stage[data-tension^="danger"]::before,
#stage[data-tension^="chance"]::before {
  animation: heartbeat var(--beat, 1.4s) cubic-bezier(.2,.8,.3,1) infinite;
}

/* ドクン…ドクン の二拍 */
@keyframes heartbeat {
  0%          { opacity: 0.14; }
  6%          { opacity: 1; }
  17%         { opacity: 0.26; }
  24%         { opacity: 0.74; }
  38%, 100%   { opacity: 0.14; }
}

/* 残り 5 枚を切ったスコアだけ警告表示 */
.score.low { animation: score-alarm 0.9s ease-in-out infinite; }
.score-cpu.low {
  border-color: #ff2436;
  box-shadow: 0 0 28px rgba(255, 36, 54, 0.6);
}
.score-cpu.low .score-num { color: #ff6b7a; }
.score-human.low {
  border-color: #36f0c4;
  box-shadow: 0 0 28px rgba(54, 240, 196, 0.55);
}
.score-human.low .score-num { color: #7ef7dc; }

@keyframes score-alarm {
  50% { transform: scale(1.07); }
}

/* ----------------------------------------------------------- フィニッシュ */

#finish {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  place-items: center;
  gap: 10px;
  pointer-events: none;
  z-index: 6;
  overflow: hidden;
}

/* 集中線 */
.finish-rays {
  position: absolute;
  inset: -40%;
  background: repeating-conic-gradient(
    from 0deg at 50% 50%,
    rgba(255, 255, 255, 0.55) 0deg 1.1deg,
    transparent 1.1deg 4.2deg
  );
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 14%, #000 46%, #000 100%);
  mask-image: radial-gradient(circle at 50% 50%, transparent 14%, #000 46%, #000 100%);
  opacity: 0;
  mix-blend-mode: screen;
}

/* 画面を殴る白 */
.finish-slam {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
}

#finish-word {
  position: relative;
  font: 900 clamp(48px, 11vw, 148px)/0.94 var(--mono);
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: #fff;
  opacity: 0;
  text-shadow:
    0 0 10px #fff,
    0 0 40px var(--finish-glow, #ffd76a),
    0 0 90px var(--finish-glow, #ffd76a),
    0 8px 0 rgba(0, 0, 0, 0.55);
}

#finish-sub {
  position: relative;
  font: 900 clamp(20px, 3.4vw, 46px)/1 var(--mono);
  letter-spacing: 0.34em;
  color: var(--finish-ink, #ffd76a);
  opacity: 0;
  text-shadow: 0 0 26px var(--finish-glow, #ffd76a), 0 4px 0 rgba(0, 0, 0, 0.5);
}

#finish[data-result="win"]  { --finish-glow: rgba(94, 234, 212, 0.95);  --finish-ink: #5eead4; }
#finish[data-result="lose"] { --finish-glow: rgba(244, 114, 182, 0.95); --finish-ink: #f472b6; }
#finish[data-result="draw"] { --finish-glow: rgba(251, 191, 36, 0.95);  --finish-ink: #fbbf24; }

#finish.go .finish-slam { animation: slam-flash 0.9s cubic-bezier(.2,.8,.2,1) forwards; }
#finish.go .finish-rays { animation: rays-in 3.2s cubic-bezier(.12,.9,.3,1) forwards; }
#finish.go #finish-word { animation: word-slam 3.2s cubic-bezier(.12,.9,.3,1) forwards; }
#finish.go #finish-sub  { animation: sub-in 3.2s cubic-bezier(.2,.9,.3,1) forwards; }

@keyframes slam-flash {
  0%  { opacity: 0.95; }
  12% { opacity: 0.85; }
  100%{ opacity: 0; }
}

@keyframes rays-in {
  0%   { opacity: 0; transform: scale(0.4) rotate(0deg); }
  6%   { opacity: 0.9; transform: scale(1) rotate(3deg); }
  40%  { opacity: 0.4; transform: scale(1.08) rotate(14deg); }
  100% { opacity: 0; transform: scale(1.3) rotate(34deg); }
}

/* 「バチコーン!!」: 画面外から叩きつけて、揺らして、居座る */
@keyframes word-slam {
  0%   { opacity: 0; transform: scale(5.5) rotate(-12deg); filter: blur(14px); }
  5%   { opacity: 1; transform: scale(1) rotate(-3deg); filter: blur(0); }
  8%   { transform: scale(1.14) rotate(2deg); }
  11%  { transform: scale(0.97) rotate(-1.5deg); }
  14%  { transform: scale(1.05) rotate(1deg); }
  18%  { transform: scale(1) rotate(0deg); }
  22%  { transform: scale(1) translateX(-6px); }
  25%  { transform: scale(1) translateX(6px); }
  28%  { transform: scale(1) translateX(0); }
  85%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.1) translateY(-22px); }
}

@keyframes sub-in {
  0%, 8% { opacity: 0; transform: translateY(26px) scale(0.85); letter-spacing: 0.02em; }
  16%    { opacity: 1; transform: translateY(0) scale(1); letter-spacing: 0.34em; }
  85%    { opacity: 1; }
  100%   { opacity: 0; transform: translateY(-14px); }
}

@media (prefers-reduced-motion: reduce) {
  #finish.go .finish-rays,
  #finish.go #finish-word,
  #finish.go #finish-sub { animation-duration: 0.4s; }
  #stage::after, #stage::before, .score.low, #speed-btn { animation: none !important; }
}

#foul-banner {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 28px;
  font: 900 40px/1 var(--mono);
  letter-spacing: 0.1em;
  color: #fff;
  background: rgba(185, 28, 28, 0.35);
  border: 2px solid var(--red);
  border-radius: 12px;
  text-shadow: 0 0 22px rgba(248, 113, 113, 0.9), 0 3px 0 rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 40px rgba(248, 113, 113, 0.45);
  pointer-events: none;
  white-space: nowrap;
}

#foul-banner[data-by="cpu"] {
  background: rgba(190, 24, 93, 0.35);
  border-color: var(--pink);
  text-shadow: 0 0 22px rgba(244, 114, 182, 0.9), 0 3px 0 rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 40px rgba(244, 114, 182, 0.45);
}

#foul-banner.pop { animation: foul-pop 0.5s cubic-bezier(.17,.89,.32,1.28); }

@keyframes foul-pop {
  0%   { opacity: 0; transform: translateX(-50%) scale(1.8) rotate(-4deg); }
  35%  { opacity: 1; transform: translateX(-50%) scale(1) rotate(1.5deg); }
  100% { opacity: 1; transform: translateX(-50%) scale(1) rotate(0); }
}

#status-line {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--dim);
  letter-spacing: 0.04em;
  text-shadow: 0 2px 8px #000;
  pointer-events: none;
  white-space: nowrap;
}

#toggles {
  position: absolute;
  right: 16px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--dim);
  cursor: pointer;
  user-select: none;
}

.toggle input { accent-color: var(--teal); }

/* -------------------------------------------------------------------- HUD */

#hud {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  background: linear-gradient(180deg, #080c18, #05070f);
  border-left: 1px solid var(--panel-line);
}

.hud-panel {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  transition: box-shadow 0.2s;
}

.hud-panel.pulse { animation: panel-pulse 0.45s ease-out; }

@keyframes panel-pulse {
  0% { box-shadow: 0 0 0 0 rgba(94, 234, 212, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(94, 234, 212, 0); }
}

.hud-title {
  margin: 0 0 8px;
  font: 700 10px/1 var(--mono);
  letter-spacing: 0.22em;
  color: var(--teal);
}

.hud-hint { margin: -4px 0 10px; font-size: 10px; color: var(--dim); line-height: 1.5; }

/* --- mood: Jev の顔 --- */

.hud-mood { --mood-c: var(--dim); --mood-glow: rgba(143, 163, 192, 0); }
.hud-mood[data-mood="relaxed"]   { --mood-c: var(--teal);  --mood-glow: rgba(94, 234, 212, 0.35); }
.hud-mood[data-mood="steady"]    { --mood-c: #a3e635;      --mood-glow: rgba(163, 230, 53, 0.30); }
.hud-mood[data-mood="strained"]  { --mood-c: var(--amber); --mood-glow: rgba(251, 191, 36, 0.35); }
.hud-mood[data-mood="cornered"]  { --mood-c: #fb7185;      --mood-glow: rgba(251, 113, 133, 0.45); }
.hud-mood[data-mood="checkmate"] { --mood-c: var(--red);   --mood-glow: rgba(248, 113, 113, 0.30); }

.hud-mood .hud-title { color: var(--mood-c); transition: color 0.3s; }
.hud-mood[data-mood="cornered"] { animation: mood-alarm 0.7s ease-in-out infinite; }

@keyframes mood-alarm {
  0%, 100% { box-shadow: 0 0 0 0 var(--mood-glow); }
  50%      { box-shadow: 0 0 22px 2px var(--mood-glow); }
}

.mood-body { display: grid; grid-template-columns: 78px 1fr; gap: 12px; align-items: center; }

.mood-face {
  width: 78px;
  height: 78px;
  color: var(--mood-c);
  filter: drop-shadow(0 0 10px var(--mood-glow));
  transition: color 0.3s, filter 0.3s;
}
.mood-face svg { width: 100%; height: 100%; overflow: visible; }
.mood-face.pop { animation: mood-pop 0.55s cubic-bezier(.17,.89,.32,1.28); }

@keyframes mood-pop {
  0%   { transform: scale(0.7) rotate(-10deg); }
  60%  { transform: scale(1.18) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}

/* 顔のパーツ。線は現在色、頭はパネルよりわずかに明るい */
.f-head { fill: rgba(255, 255, 255, 0.05); stroke: currentColor; stroke-width: 3; transition: fill 0.3s; }
.f-features { transform-origin: 50px 52px; transition: transform 0.25s; }
.f-line { fill: none; stroke: currentColor; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.f-open { fill: rgba(0, 0, 0, 0.45); }
.f-eye { fill: currentColor; }
.f-eye-ring { fill: #fff; stroke: currentColor; stroke-width: 2.5; }
.f-spark { fill: #fff8c2; animation: mood-spark 1.6s ease-in-out infinite; transform-origin: 82px 30px; }
.f-sweat { fill: #7dd3fc; animation: mood-sweat 1.1s ease-in infinite; }
.f-sweat.late { animation-delay: 0.55s; }

@keyframes mood-spark {
  0%, 100% { transform: scale(0.6) rotate(0); opacity: 0.4; }
  50%      { transform: scale(1.15) rotate(30deg); opacity: 1; }
}
@keyframes mood-sweat {
  0%   { transform: translateY(-6px); opacity: 0; }
  30%  { opacity: 1; }
  100% { transform: translateY(10px); opacity: 0; }
}

/* 気分ごとの仕草 */
.hud-mood[data-mood="relaxed"] .f-features { animation: mood-bob 2.2s ease-in-out infinite; }
.hud-mood[data-mood="cornered"] .f-features { animation: mood-shiver 0.14s linear infinite; }
.hud-mood[data-mood="checkmate"] .mood-face { filter: grayscale(0.55) drop-shadow(0 0 8px var(--mood-glow)); }
.hud-mood[data-mood="checkmate"] .f-features { transform: rotate(-7deg) translateY(2px); }
.hud-mood.is-thinking .f-features { transform: translate(2px, -2px); }

@keyframes mood-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2.5px) rotate(2deg); }
}
@keyframes mood-shiver {
  0%   { transform: translate(-1.2px, 0.4px); }
  50%  { transform: translate(1.2px, -0.4px); }
  100% { transform: translate(-1.2px, 0.4px); }
}

.mood-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.mood-label {
  font: 900 30px/1 var(--sans);
  letter-spacing: 0.06em;
  color: var(--mood-c);
  text-shadow: 0 0 16px var(--mood-glow);
  transition: color 0.3s, text-shadow 0.3s;
}
.hud-mood[data-mood="idle"] .mood-label { font-weight: 700; font-size: 20px; }

.mood-bubble {
  position: relative;
  padding: 6px 9px;
  font: 600 11px/1.45 var(--sans);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mood-bubble::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 50%;
  width: 9px;
  height: 9px;
  transform: translateY(-50%) rotate(45deg);
  background: inherit;
  border-left: 1px solid rgba(255, 255, 255, 0.10);
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}
.hud-mood.is-thinking .mood-bubble { color: var(--dim); }
.hud-mood.is-thinking .mood-bubble::after { content: ' …'; animation: mood-dots 0.9s steps(3) infinite; }
.hud-mood[data-mood="checkmate"] .mood-bubble { color: var(--dim); }

@keyframes mood-dots { from { opacity: 0.2; } to { opacity: 1; } }

/* 圧力ゲージ。左=選択肢が多い(余裕) … 右=出せる手が無い */
.mood-gauge { margin-top: 10px; }
.mood-track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg,
    rgba(94, 234, 212, 0.18), rgba(163, 230, 53, 0.18), rgba(251, 191, 36, 0.18), rgba(248, 113, 113, 0.18));
  overflow: visible;
}
.mood-fill {
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--teal), var(--mood-c));
  transition: width 0.35s cubic-bezier(.2,.8,.3,1), background 0.3s;
}
.mood-marker {
  position: absolute;
  top: 50%;
  left: 0;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--mood-c);
  box-shadow: 0 0 0 3px rgba(5, 7, 15, 0.9), 0 0 12px var(--mood-glow);
  transition: left 0.35s cubic-bezier(.2,.8,.3,1), background 0.3s;
}
.hud-mood[data-mood="idle"] .mood-marker { opacity: 0.35; }

.mood-ticks { display: flex; justify-content: space-between; margin-top: 5px; }
.mood-ticks span { font: 600 8px/1 var(--mono); letter-spacing: 0.08em; color: var(--dim); }

.mood-foot {
  margin-top: 8px;
  font: 500 9px/1 var(--mono);
  letter-spacing: 0.06em;
  color: var(--dim);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- latency --- */

.lat-big {
  font: 800 52px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: color 0.2s;
}
.lat-big.is-fast { color: var(--teal); }
.lat-big.is-slow { color: var(--amber); }
.lat-unit { font-size: 15px; color: var(--dim); margin-left: 6px; letter-spacing: 0.1em; }

.lat-spark { display: block; width: 100%; height: 56px; margin: 8px 0 6px; }

.lat-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.lat-stat { display: flex; flex-direction: column; gap: 2px; }
.lat-stat-k { font: 600 8px/1 var(--mono); letter-spacing: 0.14em; color: var(--dim); }
.lat-stat-v { font: 600 12px/1 var(--mono); font-variant-numeric: tabular-nums; }

.mock-badge {
  margin-top: 10px;
  padding: 4px 8px;
  font: 700 9px/1.4 var(--mono);
  letter-spacing: 0.16em;
  text-align: center;
  color: var(--amber);
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 6px;
}

/* --- judgement --- */

.hud-judge.is-thinking { box-shadow: inset 0 0 0 1px rgba(94, 234, 212, 0.4); }

.judge-list { display: flex; flex-direction: column; gap: 3px; min-height: 130px; }

.judge-row {
  display: grid;
  grid-template-columns: 74px 1fr 34px 12px;
  align-items: center;
  gap: 6px;
  padding: 3px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.025);
  animation: row-in 0.2s ease-out;
}

@keyframes row-in { from { opacity: 0; transform: translateX(8px); } }

.judge-row.picked {
  background: rgba(94, 234, 212, 0.14);
  box-shadow: inset 0 0 0 1px rgba(94, 234, 212, 0.4);
}

.jr-label { display: flex; align-items: center; gap: 3px; font: 600 11px/1 var(--mono); }
.jr-card.red { color: #ff7a8a; }
.jr-card.black { color: #cbd5e1; }
.jr-arrow { color: var(--dim); font-size: 9px; }

.jr-bar { height: 6px; background: rgba(255, 255, 255, 0.07); border-radius: 3px; overflow: hidden; }
.jr-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, #0ea5a0, var(--teal)); transition: width 0.25s ease-out; }
.judge-row.ng .jr-fill { background: linear-gradient(90deg, #b91c1c, var(--red)); }

.jr-noul { font: 600 10px/1 var(--mono); color: var(--dim); font-variant-numeric: tabular-nums; text-align: right; }
.jr-mark { font-size: 10px; text-align: center; }
.judge-row.ok .jr-mark { color: var(--teal); }
.judge-row.ng .jr-mark { color: var(--red); }

.judge-foot { margin-top: 8px; font: 500 10px/1.5 var(--mono); color: var(--dim); }

/* --- validator --- */

.acc-wrap { display: flex; align-items: baseline; gap: 8px; }
.acc-big { font: 800 34px/1 var(--mono); font-variant-numeric: tabular-nums; }
.acc-big.is-perfect { color: var(--teal); text-shadow: 0 0 18px rgba(94, 234, 212, 0.5); }
.acc-label { font: 600 8px/1 var(--mono); letter-spacing: 0.18em; color: var(--dim); }

.verify-counters { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 10px; }
.verify-counter {
  display: flex;
  justify-content: space-between;
  padding: 4px 7px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 5px;
}
.vc-k { font-size: 9px; color: var(--dim); }
.vc-v { font: 700 11px/1 var(--mono); font-variant-numeric: tabular-nums; }

.usage-line {
  margin-top: 9px;
  font: 500 9px/1 var(--mono);
  letter-spacing: 0.06em;
  color: var(--dim);
  text-align: right;
}

/* --- foul --- */

.hud-foul .hud-title { color: var(--red); }
.hud-foul.is-off { opacity: 0.5; }

.foul-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.foul-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 6px;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 8px;
}
.foul-cell.is-off { opacity: 0.35; border-style: dashed; }
.foul-cpu { background: rgba(244, 114, 182, 0.08); border-color: rgba(244, 114, 182, 0.25); }

.foul-k { font: 700 9px/1 var(--mono); letter-spacing: 0.18em; color: var(--dim); }
.foul-human .foul-k { color: var(--teal); }
.foul-cpu .foul-k { color: var(--pink); }
.foul-v { font: 800 22px/1 var(--mono); font-variant-numeric: tabular-nums; }
.foul-v.bump { animation: foul-bump 0.4s cubic-bezier(.17,.89,.32,1.28); }

@keyframes foul-bump {
  0% { transform: scale(2); color: var(--red); }
  100% { transform: scale(1); }
}

/* --- start screen options --- */

.overlay-options {
  margin-top: 22px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  text-align: left;
}

.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.opt-label { font: 700 11px/1 var(--mono); letter-spacing: 0.14em; color: var(--teal); }

#foul-select {
  flex: 0 0 auto;
  padding: 7px 12px;
  font: 600 12px/1 var(--sans);
  color: var(--ink);
  background: rgba(10, 16, 32, 0.9);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  cursor: pointer;
}
#foul-select:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.opt-note { margin: 10px 0 0; font-size: 10px; line-height: 1.7; color: var(--dim); }
.opt-note strong { color: var(--red); }

/* --------------------------------------------------------------- overlay */

#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(8, 12, 24, 0.86), rgba(2, 3, 8, 0.97));
  backdrop-filter: blur(6px);
  z-index: 20;
  animation: fade-in 0.3s ease-out;
}

@keyframes fade-in { from { opacity: 0; } }

.overlay-card {
  max-width: 520px;
  padding: 36px 44px 30px;
  text-align: center;
  background: linear-gradient(160deg, rgba(20, 28, 50, 0.95), rgba(10, 14, 28, 0.95));
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: card-in 0.45s cubic-bezier(.17,.89,.32,1.28);
}

@keyframes card-in { from { opacity: 0; transform: translateY(24px) scale(0.94); } }

#overlay-title {
  margin: 0 0 16px;
  font: 900 46px/1 var(--mono);
  letter-spacing: 0.1em;
  background: linear-gradient(120deg, var(--teal), #a78bfa, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#overlay-body { font-size: 13px; line-height: 1.85; color: var(--dim); }
#overlay-body strong { color: var(--ink); }
#overlay-body pre { text-align: left; font-size: 10px; white-space: pre-wrap; color: var(--red); }

.ok-dot, .warn-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 5px;
}
.ok-dot { background: var(--teal); box-shadow: 0 0 8px var(--teal); }
.warn-dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); }

#start-btn {
  margin-top: 24px;
  padding: 13px 44px;
  font: 700 14px/1 var(--mono);
  letter-spacing: 0.16em;
  color: #04121a;
  background: linear-gradient(120deg, var(--teal), #38bdf8);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s;
  box-shadow: 0 8px 28px rgba(94, 234, 212, 0.32);
}
#start-btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 12px 36px rgba(94, 234, 212, 0.5); }
#start-btn:active { transform: translateY(0) scale(0.98); }

.overlay-keys { margin: 20px 0 0; font-size: 10px; color: #64748b; }
kbd {
  display: inline-block;
  padding: 2px 6px;
  margin: 0 1px;
  font: 600 10px/1 var(--mono);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
}

/* --------------------------------------------------------------- loading */

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--bg);
  z-index: 30;
  font-size: 12px;
  color: var(--dim);
}

.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(94, 234, 212, 0.18);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ responsive */

@media (max-width: 1080px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #hud {
    flex-direction: row;
    border-left: none;
    border-top: 1px solid var(--panel-line);
    max-height: 38dvh;
  }
  .hud-panel { flex: 1; min-width: 0; }
  .lat-big { font-size: 34px; }
}

/* --------------------------------------------------------------- Turnstile ゲート */

#gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(8, 12, 24, 0.9), rgba(2, 3, 8, 0.98));
  backdrop-filter: blur(6px);
  z-index: 30; /* #overlay(20) より手前 — 先に通すゲートなので */
  animation: fade-in 0.3s ease-out;
}

#gate[hidden] { display: none; }

.gate-card { max-width: 420px; padding: 34px 38px 28px; }

.gate-title {
  margin: 0 0 14px;
  font: 900 34px/1 var(--mono);
  letter-spacing: 0.1em;
  background: linear-gradient(120deg, var(--teal), #a78bfa, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.gate-lead { margin: 0 0 20px; font-size: 13px; color: var(--ink); }

/* Turnstile のウィジェットは iframe なので中央寄せだけ面倒を見る */
#gate-widget { display: flex; justify-content: center; min-height: 65px; }

.gate-note { margin: 18px 0 0; font-size: 10px; line-height: 1.7; color: #64748b; }

.gate-error {
  margin: 14px 0 0;
  padding: 10px 12px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--red);
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 10px;
}
