:root {
  --bg: #0d1b2a;
  --ink: #ffffff;
  --ink-dim: rgba(255,255,255,.72);
  --panel: rgba(13,27,42,.86);
  --accent: #ffd23f;
  --out: #ff4d4d;
  --safe: #4dc3ff;
  --huh: #ffb84d;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0d1b2a; color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
#c { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }

/* HUD */
#hud {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  pointer-events: none; font-weight: 800; text-shadow: 0 2px 4px rgba(0,0,0,.6);
}
#hud > div { background: rgba(0,0,0,.35); border-radius: 10px; padding: 4px 12px; font-size: 18px; }
#hud .sub { font-size: 13px; color: var(--ink-dim); margin-left: 4px; }
#hud .lbl { font-size: 12px; color: var(--accent); margin-right: 6px; letter-spacing: .1em; }

#prompt {
  position: fixed; left: 0; right: 0; bottom: 14%; text-align: center;
  font-size: clamp(16px, 3.6vmin, 24px); font-weight: 800; pointer-events: none;
  text-shadow: 0 2px 6px rgba(0,0,0,.8);
}
#flash {
  position: fixed; left: 0; right: 0; top: 38%; text-align: center; pointer-events: none;
  font-size: clamp(28px, 9vmin, 64px); font-weight: 900; color: var(--accent);
  text-shadow: 0 3px 0 #7a5200, 0 6px 14px rgba(0,0,0,.6); opacity: 0;
}
#flash.show { animation: flash .7s ease-out forwards; }
@keyframes flash { 0%{opacity:1;transform:scale(1.4)} 60%{opacity:1;transform:scale(1)} 100%{opacity:0;transform:scale(1)} }

#call {
  position: fixed; left: 0; right: 0; top: 12%; text-align: center; pointer-events: none;
  font-size: clamp(44px, 14vmin, 120px); font-weight: 900; font-style: italic; opacity: 0;
  letter-spacing: .02em;
}
#call.show { animation: stamp .45s cubic-bezier(.2,1.6,.4,1) forwards; }
#call.out  { color: var(--out);  text-shadow: 0 4px 0 #6b0000, 0 8px 20px rgba(0,0,0,.6); }
#call.safe { color: var(--safe); text-shadow: 0 4px 0 #00456b, 0 8px 20px rgba(0,0,0,.6); }
@keyframes stamp { 0%{opacity:0;transform:scale(2.4) rotate(-8deg)} 100%{opacity:1;transform:scale(1) rotate(-4deg)} }

#bubble {
  position: fixed; left: 50%; top: 20%; transform: translate(-50%, -100%);
  background: #fff; color: #222; font-weight: 900; font-size: clamp(30px, 9vmin, 64px);
  padding: .15em .6em; border-radius: 1em; opacity: 0; pointer-events: none;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
#bubble::after {
  content: ""; position: absolute; left: 30%; bottom: -16px;
  border: 10px solid transparent; border-top: 16px solid #fff; border-bottom: 0;
}
#bubble.show { animation: pop .35s cubic-bezier(.2,1.8,.4,1) forwards; }
@keyframes pop { 0%{opacity:0;transform:translate(-50%,-100%) scale(.3)} 100%{opacity:1;transform:translate(-50%,-100%) scale(1)} }

#toast {
  position: fixed; left: 50%; top: 30%; transform: translateX(-50%);
  background: var(--panel); border-radius: 12px; padding: 10px 18px;
  font-weight: 800; font-size: 18px; opacity: 0; transition: opacity .25s; pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

#tapBtn {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  width: 120px; height: 120px; border-radius: 50%; border: 4px solid #fff;
  background: rgba(139,74,34,.85); color: #fff; font-size: 22px; font-weight: 900;
  box-shadow: 0 6px 16px rgba(0,0,0,.45);
}
#tapBtn:active { transform: scale(.94); }

/* panels */
.panel {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(400px, calc(100vw - 32px)); background: var(--panel); border-radius: 16px;
  padding: 10px 16px 12px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.card-title { font-size: 24px; font-weight: 900; }
.card-title.out { color: var(--out); } .card-title.safe { color: var(--safe); } .card-title.huh { color: var(--huh); }
.card-detail { font-size: 13px; color: var(--ink-dim); margin: 4px 0; line-height: 1.5; }
.pitch-note { font-size: 12px; opacity: .85; }
.card-points { font-size: 20px; font-weight: 900; color: var(--accent); margin-bottom: 8px; }

.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px 10px;
  font-size: 17px; font-weight: 800; color: #1a1a1a; background: var(--accent); cursor: pointer;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); filter: brightness(.95); }
.btn-sub { background: rgba(255,255,255,.16); color: #fff; margin-top: 8px; font-size: 14px; }
.btn-main { margin-top: 12px; }

/* screens */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(13,27,42,.55), rgba(13,27,42,.92));
  overflow-y: auto; padding: 16px;
}
.title-box { width: min(440px, 100%); text-align: center; margin: auto; }
.logo-sub { font-size: 14px; color: var(--accent); font-weight: 800; letter-spacing: .2em; }
.logo {
  margin: 4px 0 10px; font-size: clamp(40px, 11vmin, 64px); line-height: 1.05; font-weight: 900;
  font-style: italic; text-shadow: 0 4px 0 #8b4a22, 0 8px 24px rgba(0,0,0,.5);
}
.howto { text-align: left; font-size: 14px; line-height: 1.7; padding-left: 1.4em; margin: 8px 0; color: var(--ink-dim); }
.howto b { color: #fff; }
.opts { display: block; font-size: 12px; color: var(--ink-dim); margin: 12px 0 0; }
.lead { font-size: 15px; margin: 10px 0 6px; color: var(--ink-dim); }
.lead b { color: #fff; }
.opts select { font-size: 12px; padding: 3px 6px; border-radius: 8px; margin-left: 6px; font-family: inherit; }
.note { font-size: 12px; color: var(--ink-dim); margin-top: 12px; line-height: 1.6; }
.note b { color: #fff; }
.best { margin-top: 10px; font-size: 13px; color: var(--accent); font-weight: 700; }
.rank { font-size: clamp(30px, 8vmin, 46px); font-weight: 900; margin: 6px 0; }
.over-score { font-size: 40px; font-weight: 900; color: var(--accent); }
.stats { margin: 10px auto; border-collapse: collapse; font-size: 15px; }
.stats td { padding: 3px 12px; }
.stats td:first-child { color: var(--ink-dim); text-align: left; }
.stats td:last-child { font-weight: 800; text-align: right; }

#sensorWarn {
  position: fixed; left: 50%; top: 56px; transform: translateX(-50%); background: var(--panel);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; width: max-content; max-width: calc(100vw - 32px);
}
#debug {
  position: fixed; left: 8px; bottom: 8px; background: rgba(0,0,0,.7); color: #0f0;
  font: 11px/1.4 ui-monospace, Menlo, monospace; padding: 6px 8px; border-radius: 6px; white-space: pre;
  pointer-events: auto; max-width: calc(100vw - 16px);
}
#debug input { width: 120px; vertical-align: middle; pointer-events: auto; }
#debug { pointer-events: none; }   /* デバッグ表示は「タッチ！」ボタンへのタップを邪魔しない（スライダーだけ操作できる） */

#card .btn { padding: 10px; }

/* スマホへの誘導 */
.disclaimer { font-size: 11px; color: var(--ink-dim); margin-top: 14px; line-height: 1.6; text-align: center;
  background: rgba(255,255,255,.06); border-radius: 8px; padding: 8px 10px; }
.rotate-hint { display: none; margin-top: 10px; font-size: 13px; color: var(--accent); font-weight: 700; }
.rotate-hint b { color: #fff; }
@media (orientation: landscape) { body.mobile .rotate-hint { display: block; } }
body.mobile .pc-only { display: none; }
.pc-logo { font-size: clamp(34px, 8vmin, 52px); }
.pc-lead { text-wrap: balance; font-size: 14px; line-height: 1.7; color: var(--ink-dim); margin: 6px 0 14px; }
.qr-box { background: #fff; padding: 10px; border-radius: 12px; line-height: 0; width: max-content; margin: 0 auto; }
.qr-box svg { display: block; width: 180px; height: 180px; }
.pc-url { font: 12px/1.4 ui-monospace, Menlo, monospace; background: rgba(255,255,255,.08); border-radius: 8px;
  padding: 8px 12px; margin: 12px auto 0; word-break: break-all; width: max-content; max-width: 100%; }
.share-status { font-size: 12px; color: var(--accent); min-height: 1em; margin-top: 4px; }

/* 反応の秒数（タッチした瞬間に大きく） */
#bigTime {
  position: fixed; left: 0; right: 0; top: 40%; text-align: center; pointer-events: none;
  font: 900 clamp(48px, 16vmin, 110px)/1 ui-monospace, "SF Mono", Menlo, monospace; color: #fff; opacity: 0;
  text-shadow: 0 4px 0 #8b4a22, 0 8px 20px rgba(0,0,0,.6); letter-spacing: -.02em;
}
#bigTime.show { animation: bigtime 1.6s ease-out forwards; }
@keyframes bigtime { 0%{opacity:0;transform:scale(1.8)} 12%{opacity:1;transform:scale(1)} 75%{opacity:1} 100%{opacity:0;transform:translateY(-30px)} }

/* 隠し球のときの「シェイク！」（フェードインで出す） */
#hint { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 20; pointer-events: none;
  font-size: 64px; font-weight: 900; color: #ffd23f; letter-spacing: .04em; white-space: nowrap;
  text-shadow: 0 3px 0 #7a3c12, 0 6px 18px rgba(0,0,0,.55); opacity: 0; transition: opacity .9s ease; }
#hint.show { opacity: 1; animation: hintPulse 1.2s ease-in-out .9s infinite; }
@keyframes hintPulse { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.07); } }

/* ---- 盗塁スタート用 ---- */
#hud .hud-r { font-size: 13px; color: var(--ink-dim); }
.dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.dots i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; }
.dots i.on { background: var(--out); border-color: var(--out); }
#btnBack {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(24px, env(safe-area-inset-bottom));
  width: 128px; height: 128px; border-radius: 50%; border: 4px solid #fff;
  background: rgba(13,27,42,.78); color: #fff; font: inherit; font-size: 26px; font-weight: 900; cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,.45);
}
#btnBack:active { transform: translateX(-50%) scale(.94); }
#btnGo {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom));
  width: 88px; height: 88px; border-radius: 50%; border: 0; background: var(--accent); color: #1a1a1a;
  font: inherit; font-size: 16px; font-weight: 900; cursor: pointer;
}
#btnGo:active { transform: scale(.94); }
#prompt { bottom: calc(max(24px, env(safe-area-inset-bottom)) + 140px); }
.card-detail .nums { font-variant-numeric: tabular-nums; }
#toast { white-space: pre-line; width: max-content; max-width: calc(100vw - 32px); text-align: center; line-height: 1.5; font-size: 16px; }
#bigTime { font-family: inherit; font-variant-numeric: tabular-nums; letter-spacing: 0; top: 28%; }
#bigTime .bt-label { display: block; font-size: 16px; line-height: 1.5; font-weight: 800; color: var(--ink-dim); text-shadow: 0 2px 4px rgba(0,0,0,.8); margin-bottom: 4px; }
#bigTime .bt-main { display: block; }
#bigTime.read .bt-main { color: var(--accent); }   /* 動きを盗んだ（見分ける前にスタート）ときだけアクセント色 */

/* デバッグモードのパネル */
#dbg {
  position: fixed; top: calc(max(8px, env(safe-area-inset-top)) + 40px); left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right));
  background: rgba(8,16,26,.86); border-radius: 12px; padding: 8px; font-size: 12px; color: #fff; z-index: 30;
  max-height: 44vh; overflow-y: auto;
}
#dbg.hidden { display: none; }
.dbg-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dbg-head b { color: var(--accent); margin-right: auto; }
.dbg-head button { font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 8px; border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.12); color: #fff; }
#dbgBody { display: grid; gap: 4px; margin-top: 8px; }
#dbgBody label { display: flex; align-items: center; gap: 8px; color: var(--ink-dim); }
#dbgBody select { font-size: 16px; flex: 1; min-width: 0; padding: 2px 4px; border-radius: 6px; font-family: inherit; }
#dbgBody input[type=range] { flex: 1; min-width: 0; }
#dbgInfo { margin: 4px 0 0; font: 11px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; color: #bfe7c4; }
body:has(#dbg:not(.hidden)) #flash { top: 62%; }

/* お邪魔: スマホの通知 */
#notif {
  position: fixed; left: 50%; top: max(8px, env(safe-area-inset-top)); width: min(360px, calc(100vw - 24px)); z-index: 25;
  transform: translate(-50%, -140%); background: rgba(245,245,247,.97); color: #111; border-radius: 16px; padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); pointer-events: none; text-align: left;
}
#notif { z-index: 40; }
/* 出ていないときは確実に見えないようにする（上の安全領域が広い端末では、上にずらすだけだと下端がのぞく） */
#notif { visibility: hidden; opacity: 0; }
#notif.show { animation: notif 3s ease forwards; }
@keyframes notif {
  0%   { transform: translate(-50%, -140%); opacity: 0; visibility: visible; }
  10%, 82% { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
  100% { transform: translate(-50%, -140%); opacity: 0; visibility: hidden; }
}
#notif .n-app { font-size: 11px; color: #666; }
#notif .n-from { font-size: 15px; font-weight: 800; margin-top: 2px; }
#notif .n-body { font-size: 15px; }
.rank { text-wrap: balance; line-height: 1.25; }
.rank { word-break: keep-all; }
.dbg-checks { display: flex; gap: 16px; flex-wrap: wrap; }
.dbg-checks label { gap: 4px; }
.dbg-checks input { width: 20px; height: 20px; }

/* 称号の段階（絵文字）: 大きいアイコンと、6段階の並び（いまの段階だけ明るく） */
.rank-icon { font-size: 56px; line-height: 1; margin-top: 8px; }
.rank-ladder { display: flex; justify-content: center; align-items: center; gap: 8px; margin: 4px auto 8px; font-size: 24px;
  width: max-content; padding: 4px 16px; border-radius: 16px; background: rgba(0,0,0,.45); }
.rank-ladder span { opacity: .55; filter: grayscale(.85); }
.rank-ladder span.on { opacity: 1; filter: none; font-size: 32px; }

/* ボークのアピール: かかとフェイクのときだけ、画面の右に浮かぶボタン */
#btnBalk {
  position: fixed; right: max(16px, env(safe-area-inset-right)); top: 48%; z-index: 20;
  padding: 12px 16px; border-radius: 16px; border: 3px solid #fff; background: var(--out); color: #fff;
  font: inherit; font-size: 16px; font-weight: 900; line-height: 1.25; cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,.45); animation: balkIn .18s ease-out;
}
#btnBalk:active { transform: scale(.95); }
@keyframes balkIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
/* コイントス */
#coin { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 30; text-align: center; pointer-events: none; }
#coin .coin-face {
  width: 96px; height: 96px; margin: 0 auto 8px; border-radius: 50%; background: var(--accent); border: 4px solid #b8860b;
  color: #5a3d00; font-size: 40px; font-weight: 900; line-height: 88px; box-shadow: 0 6px 16px rgba(0,0,0,.45);
}
#coin .coin-label { font-size: 24px; font-weight: 900; text-shadow: 0 2px 6px rgba(0,0,0,.8); }
#coin.flip .coin-face { animation: coinFlip .35s linear infinite; }
@keyframes coinFlip { from { transform: rotateX(0); } to { transform: rotateX(360deg); } }
#coin.done.yes .coin-label { color: var(--safe); }
#coin.done.no .coin-label { color: var(--out); }
#coin .coin-label { white-space: nowrap; }

/* コイントスの表示は文字だけ（コインは3Dで主審が投げる）。画面の上の方に出して、主審とコインにかぶせない */
#coin { top: 18%; }
#coin .coin-face { display: none; }
#coin .coin-label { background: rgba(13,27,42,.78); border-radius: 12px; padding: 8px 16px; }

/* コイントスで裏が出たときの「抗議する」「諦める」 */
#protestBox {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(24px, env(safe-area-inset-bottom)); z-index: 30;
  width: min(360px, calc(100vw - 32px)); display: grid; gap: 8px;
}
#protestBox .btn { margin: 0; }
#protestBox .btn-main { background: var(--out); color: #fff; }
#coin .coin-label { white-space: pre-line; max-width: calc(100vw - 32px); margin: 0 auto; line-height: 1.4; }
#coin { width: max-content; max-width: calc(100vw - 32px); }

/* 「コイントスをする」 */
#btnToss {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(24px, env(safe-area-inset-bottom)); z-index: 30;
  width: min(360px, calc(100vw - 32px)); margin: 0;
}

/* ランキング（リザルト画面の上に重ねる） */
#rankPanel {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(0,0,0,.55);
}
.rank-box {
  width: min(400px, 100%); max-height: calc(100% - 16px); overflow-y: auto;
  background: var(--bg); border: 1px solid rgba(255,255,255,.12); border-radius: 16px; padding: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); text-align: left;
}
.rank-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rank-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
#rankClose {
  border: 0; border-radius: 8px; padding: 8px 12px; background: rgba(255,255,255,.16); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 800; cursor: pointer;
}
.rank-note { margin: 4px 0 8px; font-size: 12px; color: var(--ink-dim); }
#rankList { list-style: none; margin: 0; padding: 0; }
#rankList li {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 8px;
  padding: 8px; border-radius: 8px; font-size: 16px; font-variant-numeric: tabular-nums;
}
#rankList li:nth-child(odd) { background: rgba(255,255,255,.05); }
#rankList li.me { background: rgba(255,210,63,.18); outline: 1px solid var(--accent); }
#rankList .r-no { font-weight: 900; color: var(--ink-dim); text-align: right; }
#rankList li:nth-child(-n+3) .r-no { color: var(--accent); }
#rankList .r-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rankList .r-score { font-weight: 900; }
#rankList .r-empty { grid-column: 1 / -1; color: var(--ink-dim); font-size: 14px; text-align: center; padding: 8px; }
.rank-status { min-height: 20px; margin: 8px 0 0; font-size: 14px; color: var(--accent); text-align: center; }
.rank-status.err { color: var(--out); }
.rank-status.you { font-size: 20px; font-weight: 900; margin-top: 12px; }
#rankList li.out .r-no { color: var(--ink-dim); }   /* 上位の外の自分の行は、上位3位の色にしない */
#rankList li.gap { display: block; background: none; padding: 0; text-align: center; color: var(--ink-dim); line-height: 1; }
#rankForm { margin-top: 8px; border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; }
#rankForm label { display: block; font-size: 12px; color: var(--ink-dim); margin: 8px 0 4px; }
.rank-mine { font-size: 14px; }
.rank-mine b { font-size: 20px; color: var(--accent); margin-left: 4px; }
.rank-row { display: flex; gap: 8px; }
#rankName {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 12px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.08); color: var(--ink);
  -webkit-user-select: text; user-select: text;
}
#rankName:focus { outline: 2px solid var(--accent); outline-offset: 0; }
#rankSubmit { width: auto; padding: 12px 16px; margin: 0; }
#rankSubmit:disabled { opacity: .5; }
