:root {
  --night: #0b0a1f;
  --ink: #23213a;
  --muted: #64607e;
  --paper: #f8f6ff;
  --line: rgba(35, 33, 58, .18);
  --red: #ff4f8b;
  --red-deep: #b01f5c;
  --gold: #ffd24a;
  --cyan: #5ff2ff;
  --green: #4dff9a;
  --violet: #b36bff;
  /* ポップ体（Dela Gothic One）は、ロゴ・一瞬の大きな演出（判定・掛け声・枚数・順位アップ・結果）・主役の数字（成功率・順位）だけに使う。
     案内・ボタン・ラベル・説明は、太いゴシック（--ui）で読みやすくする */
  --display: "Dela Gothic One", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --ui: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  --vh: 100vh;
  /* 画面の上の安全域（状態バーの高さ）。ページが状態バーの下まで広がっていないブラウザーでは、app.ts が 0 にする */
  --safe-top: env(safe-area-inset-top);
  /* 画面の下の安全域。Android のアプリの中のブラウザーでは、ページの上に重なるブラウザーの操作部分の分を、app.ts が足す */
  --safe-bottom: env(safe-area-inset-bottom);
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  color: #fff;
  background: var(--night);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body { overflow: hidden; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- 画面いっぱいの机 ---------- */
.app { position: fixed; inset: 0 0 auto; height: var(--vh); overflow: hidden; cursor: pointer; touch-action: none; }
#board { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.stage { position: absolute; inset: 0; pointer-events: none; }

/* ---------- 判定と、人を抜いた知らせ ---------- */
/* 判定は操作盤の上の端に出す（バーから目を動かさずに見える）。動きはスクリプトが時刻から決める */
.judge { position: absolute; left: 50%; bottom: calc(100% + 4px); margin: 0; display: grid; justify-items: center; opacity: 0; font-family: var(--display); white-space: nowrap; text-shadow: 0 3px 0 rgba(11, 10, 31, .85), 0 0 18px rgba(11, 10, 31, .7); pointer-events: none; will-change: transform, opacity; }
.judge b { font-size: clamp(26px, 8vw, 38px); font-weight: 400; line-height: 1.1; color: var(--cyan); }
.judge small { font: 800 14px/1.3 var(--ui); color: #fff; }
.judge[data-grade="great"] b { color: var(--green); }
.judge[data-grade="good"] b { color: var(--cyan); }
.judge[data-grade="off"] b { color: var(--gold); }
.judge[data-grade="bad"] b, .judge[data-grade="crash"] b { color: #ff4f6a; }
.judge[data-grade="redo"] b { color: #c9c4e6; }
.rankup { position: absolute; left: 50%; top: 26%; margin: 0; display: grid; justify-items: center; gap: 2px; opacity: 0; font-family: var(--display); white-space: nowrap; will-change: transform, opacity; }
.rankup b { font-size: clamp(30px, 9.5vw, 54px); font-weight: 400; line-height: 1.1; color: var(--gold); text-shadow: 0 4px 0 var(--red-deep), 0 0 24px rgba(255, 79, 139, .8); }
.rankup small { max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis; font: 700 15px/1.3 "Hiragino Sans", "Yu Gothic", system-ui, sans-serif; color: #fff; text-shadow: 0 2px 6px rgba(11, 10, 31, .9); }

/* 倒れた枚数 */
.count { position: absolute; left: 50%; top: calc(max(8px, var(--safe-top)) + 56px); display: flex; align-items: baseline; gap: 4px; margin: 0; transform: translateX(-50%); font-family: var(--display); text-shadow: 0 4px 0 rgba(11, 10, 31, .85), 0 0 22px rgba(11, 10, 31, .6); white-space: nowrap; }
/* 桁が増えたら、画面の幅に収まるように数字を小さくする（--chars は桁数。跳ねて大きくなる分の余裕も取る） */
.count b { display: inline-block; font-size: min(clamp(72px, 24vw, 112px), calc((100vw - 96px) / (0.8 * var(--chars, 1)))); font-weight: 400; line-height: 1; transform-origin: 50% 80%; will-change: transform; }
.count span { font-size: clamp(24px, 8vw, 36px); }
.count.milestone b { color: var(--gold); }
.count small { position: absolute; top: 100%; left: 50%; margin-top: 2px; transform: translateX(-50%); font-family: var(--ui); font-size: clamp(14px, 4.4vw, 18px); font-weight: 800; color: var(--gold); white-space: nowrap; }
.count small[hidden] { display: none; }
.app[data-state="result"] .count { display: none; }
.shout { position: absolute; left: 50%; top: 44%; margin: 0; opacity: 0; font: 400 clamp(30px, 10vw, 54px)/1.1 var(--display); color: var(--gold); white-space: nowrap; text-shadow: 0 4px 0 var(--red-deep), 0 0 24px rgba(255, 79, 139, .8); will-change: transform, opacity; }

/* ---------- 操作盤（順位の帯・成功率と疲労・バー・ボタンを、画面下の中央に1つにまとめる） ---------- */
.controls { position: absolute; left: 50%; bottom: max(12px, var(--safe-bottom)); width: min(calc(100% - 24px), 520px); margin-left: calc(min(calc(100% - 24px), 520px) / -2); display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.controls > * { min-width: 0; }
/* 次の目標。順位の相手（なければ自己ベスト）と、あと何枚か。人を抜いたときの光り方（--glow、0〜1）はスクリプトが決める */
.goal { --glow: 0; display: grid; gap: 5px; padding: 7px 12px 7px; border: 1.5px solid rgba(255, 210, 74, .8); border-radius: 14px; background: rgba(11, 10, 31, .8); box-shadow: 0 0 calc(10px + 26px * var(--glow)) calc(10px * var(--glow)) rgba(255, 210, 74, calc(.3 + .6 * var(--glow))); }
.goal p { margin: 0; }
.goal-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; }
.goal-line > * { will-change: transform, opacity; }
.goal-now { flex: none; font: 400 clamp(20px, 6.2vw, 26px)/1.1 var(--display); color: var(--gold); font-variant-numeric: tabular-nums; }
.goal-next { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 700; color: #e6e9f2; }
.goal-left { flex: none; margin-left: auto; font: 900 clamp(16px, 4.8vw, 20px)/1.1 var(--ui); color: var(--cyan); font-variant-numeric: tabular-nums; }
.goal-meter { position: relative; display: block; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, .14); overflow: hidden; }
.goal-meter i { position: absolute; inset: 0; background: linear-gradient(90deg, #ff9a4a, var(--gold)); transform: scaleX(0); transform-origin: 0 50%; will-change: transform; }
.goal-sub { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; font-size: 11px; font-weight: 700; line-height: 1.3; color: #b4bccb; font-variant-numeric: tabular-nums; }
.goal-sub b { font-size: 13px; color: #fff; }
.goal-sub #goalGap { margin-left: auto; }
.goal-tag { padding: 0 7px; border-radius: 999px; background: rgba(255, 255, 255, .14); color: #fff; }
.goal-sub #penaltyNote { color: #ffb27a; }
.goal[data-kind="best"] .goal-now, .goal[data-kind="best"] .goal-left { color: var(--green); }
.goal[data-kind="best"] .goal-meter i { background: linear-gradient(90deg, #37e08a, var(--green)); }
.goal[data-kind="loading"] .goal-meter, .goal[data-kind="first"] .goal-meter { opacity: .35; }
/* 案内とコンボは同じ場所に重ねる。コンボが出ている間は、案内を隠す */
.cue-line { display: grid; }
.cue-line > * { grid-area: 1 / 1; }
.cue-line:has(.combo:not([hidden])) .cue { visibility: hidden; }
/* コンボ。数字はポップ体で大きく、倍率（×2・×3）は色を変えて添える。弾み方はスクリプトが時刻から決める */
.combo { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 0; white-space: nowrap; text-shadow: 0 2px 0 rgba(11, 10, 31, .85), 0 0 14px rgba(11, 10, 31, .6); will-change: transform; }
.combo b { font: 400 clamp(20px, 6vw, 26px)/1 var(--display); color: #fff; font-variant-numeric: tabular-nums; }
.combo span { font: 900 13px/1 var(--ui); letter-spacing: .12em; color: #fff; }
.combo i { font: 900 clamp(17px, 5vw, 21px)/1 var(--ui); font-style: normal; }
.combo[data-rate="2"] b, .combo[data-rate="2"] i { color: var(--cyan); }
.combo[data-rate="3"] b, .combo[data-rate="3"] i { color: var(--gold); }
.cue { margin: 0; text-align: center; font: 900 clamp(15px, 4.6vw, 19px)/1.2 var(--ui); letter-spacing: .04em; color: #ffd9f0; text-shadow: 0 2px 0 rgba(11, 10, 31, .8), 0 0 14px rgba(255, 79, 139, .7); white-space: nowrap; }
/* バーは 0〜1000 を左から右へ。色の帯は3つに分ける：真ん中の緑（疲労が抜ける）、その外の黄（変わらない）、さらに外の赤（疲労がたまる）。
   緑の中の濃い緑（--safe-from〜--safe-to、％）は、止めても成功率が下がらない範囲（なければ幅0）。
   帯の真ん中（--good-at）と幅（--rest-half、--miss-half は％）、つまみ（--at）の位置はスクリプトが決める */
.bar { position: relative; height: 42px; border-radius: 999px; border: 2px solid rgba(255, 255, 255, .85); background: linear-gradient(90deg, var(--bar-miss) 0 calc((var(--good-at) - var(--miss-half)) * 1%), var(--bar-even) 0 calc((var(--good-at) - var(--rest-half)) * 1%), var(--bar-rest) 0 calc(var(--safe-from) * 1%), var(--bar-safe) 0 calc(var(--safe-to) * 1%), var(--bar-rest) 0 calc((var(--good-at) + var(--rest-half)) * 1%), var(--bar-even) 0 calc((var(--good-at) + var(--miss-half)) * 1%), var(--bar-miss) 0); box-shadow: 0 0 18px rgba(179, 107, 255, .7), inset 0 0 12px rgba(11, 10, 31, .45); overflow: hidden; --at: 0; --good-at: 50; --rest-half: 6; --miss-half: 12; --bar-rest: #37e08a; --bar-safe: #0a8f4a; --safe-from: 50; --safe-to: 50; --bar-even: #ffd24a; --bar-miss: #f0506e; }
.bar i { position: absolute; top: 0; bottom: 0; }
/* コンボ中は枠を光らせる。倍率が上がるほど強く、色も変える */
#bar[data-combo="1"] { border-color: #b8ffd8; box-shadow: 0 0 16px rgba(77, 255, 154, .55), inset 0 0 12px rgba(11, 10, 31, .45); }
#bar[data-combo="2"] { border-color: var(--cyan); box-shadow: 0 0 22px 2px rgba(95, 242, 255, .75), inset 0 0 12px rgba(11, 10, 31, .45); }
#bar[data-combo="3"] { border-color: var(--gold); box-shadow: 0 0 28px 4px rgba(255, 210, 74, .85), inset 0 0 12px rgba(11, 10, 31, .45); }
/* 次のターンの予告。いまのバーと同じ幅・同じ枠の太さにして、色の帯の位置をそのまま上下で見比べられるようにする。
   細く薄く出して、いまのバーと見分ける（濃い緑は、いまのターンの止め方で変わるので出さない）。
   「NEXT」の文字はバーの左端の上に小さく置く（案内の文字は真ん中なので重ならない） */
.bar.bar-next { --safe-from: var(--good-at); --safe-to: var(--good-at); height: 12px; margin: 10px 0 -2px; opacity: .5; box-shadow: none; overflow: visible; }
.bar-next span { position: absolute; left: 10px; bottom: calc(100% + 3px); font: 900 9px/1 var(--ui); letter-spacing: .1em; color: #fff; white-space: nowrap; }
.bar-mark { left: calc(var(--at) * 1%); width: 6px; margin-left: -3px; border-radius: 3px; background: #fff; box-shadow: 0 0 10px #fff, 0 0 0 1.5px rgba(11, 10, 31, .55); will-change: left; }
/* 倒れている間の速さ。倒れている間だけ出す */
.speeds { position: absolute; left: 50%; bottom: max(16px, var(--safe-bottom)); display: grid; grid-template-columns: repeat(var(--buttons, 4), 56px); gap: 6px; transform: translateX(-50%); }
.speeds button[hidden] { display: none; }
.speeds button { min-height: 44px; border: 1.5px solid rgba(255, 255, 255, .5); border-radius: 12px; background: rgba(11, 10, 31, .72); color: inherit; font: 900 16px/1 var(--ui); font-variant-numeric: tabular-nums; cursor: pointer; }
.speeds button[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 12px rgba(255, 210, 74, .55); }
.app:not([data-state="topple"]) .speeds { display: none; }
/* 倒れ終わるまで長いときのスキップ。倍速のボタンの上の真ん中に出す */
.skip { position: absolute; left: 50%; bottom: calc(max(16px, var(--safe-bottom)) + 52px); min-height: 40px; padding: 0 20px; border: 1.5px solid rgba(255, 255, 255, .7); border-radius: 999px; background: rgba(11, 10, 31, .72); color: inherit; font: 900 15px/1 var(--ui); transform: translateX(-50%); cursor: pointer; }
.app:not([data-state="topple"]) .skip { display: none; }
/* 疲労と置き失敗の確率。疲労の帯の長さ（transform）はスクリプトが決める */
.gauges { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px; }
/* 成功率（最後まで倒れきる確率）。色（--heat）は確率が下がるほど赤へ寄る */
.risk { display: flex !important; align-items: baseline; gap: 3px; --heat: var(--green); border-color: var(--heat) !important; box-shadow: 0 0 14px color-mix(in srgb, var(--heat) 50%, transparent); }
.risk span { margin-right: 3px; }
.risk b { min-width: 2.6em; font: 400 clamp(22px, 6.6vw, 28px)/1 var(--display); color: var(--heat); text-align: right; font-variant-numeric: tabular-nums; transform-origin: 50% 80%; will-change: transform; }
.risk i { font: 900 13px/1 var(--ui); font-style: normal; color: var(--heat); }
.risk[data-heat="1"] { --heat: var(--gold); }
.risk[data-heat="2"] { --heat: #ff9a4a; }
.risk[data-heat="3"] { --heat: #ff4f6a; }
.gauges p { margin: 0; display: grid; align-items: center; padding: 5px 10px 6px; border: 1.5px solid rgba(255, 255, 255, .28); border-radius: 12px; background: rgba(11, 10, 31, .72); }
.gauges span { font-size: 11px; font-weight: 700; white-space: nowrap; }
.fatigue { grid-template-columns: auto 1fr auto; column-gap: 8px; --heat: var(--green); }
/* 狭い画面では、メーターを2段目に広げる（1段目は「疲労」と置き失敗の確率） */
@media (max-width: 560px) {
  .fatigue { grid-template-columns: auto 1fr; row-gap: 3px; padding-top: 4px !important; padding-bottom: 6px !important; }
  .fatigue .slip { justify-self: end; }
  .fatigue-meter { grid-column: 1 / -1; grid-row: 2; height: 8px; }
  .gauges { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
  .risk { flex-wrap: wrap; align-content: center; column-gap: 2px; }
  .risk span { flex-basis: 100%; margin: 0; }
  .goal-left { font-size: 17px; }
}
/* とても狭い画面では、相手の名前を2行目に回す（順位とあと何枚を1行目に残す） */
@media (max-width: 360px) {
  .goal-line { flex-wrap: wrap; row-gap: 0; }
  .goal-next { order: 1; flex-basis: 100%; }
  .goal-now { font-size: 19px; }
  .goal-left { font-size: 15px; }
  .risk b { font-size: 20px; }
  .actions { gap: 6px; }
  .btn.btn-push { padding-inline: 4px; font-size: 16px; white-space: nowrap; }
  .slip b { min-width: 2em; font-size: 15px; }
  /* 疲労の見出しは省く（メーターと、置き失敗の確率の説明は残す） */
  .fatigue > span:first-child { display: none; }
  .fatigue { grid-template-columns: minmax(0, 1fr); }
  .fatigue .slip { justify-self: stretch; justify-content: space-between; }
  .levels button, .btn-undo { font-size: 13px; }
  .slip small { font-size: 9px; }
}
.fatigue[data-heat="1"] { --heat: var(--gold); }
.fatigue[data-heat="2"] { --heat: #ff9a4a; }
.fatigue[data-heat="3"] { --heat: #ff4f6a; }
.fatigue-meter { will-change: transform; position: relative; height: 10px; border-radius: 999px; background: rgba(255, 255, 255, .16); overflow: hidden; }
.fatigue-meter i { position: absolute; inset: 0; background: var(--heat); transform: scaleX(0); transform-origin: 0 50%; will-change: transform; }
/* 置き失敗の確率。説明は2行に分けて小さく、数字は大きく */
.slip { display: flex; align-items: center; gap: 6px; }
.slip small { font-size: 10px; font-weight: 700; line-height: 1.2; text-align: right; opacity: .9; }
.slip b { min-width: 2.6em; font: 900 17px/1 var(--ui); color: var(--heat); font-variant-numeric: tabular-nums; text-align: right; }
.slip i { margin-left: -2px; font: 900 12px/1 var(--ui); font-style: normal; color: var(--heat); }
.actions { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, .8fr) minmax(0, 1fr); gap: 8px; align-items: stretch; }
/* やり直し。押したときに引かれる点を下に出す。光り方（--glow、0〜1）はスクリプトが時刻から決める */
.btn-undo { display: grid; justify-items: center; align-content: center; padding: 4px 2px; border: 1.5px solid rgba(255, 255, 255, .5); border-radius: 12px; background: rgba(11, 10, 31, .72); color: inherit; font: 900 14px/1.15 var(--ui); white-space: nowrap; cursor: pointer; --glow: 0; box-shadow: 0 0 calc(22px * var(--glow)) calc(5px * var(--glow)) rgba(255, 210, 74, calc(.85 * var(--glow))); }
.btn-undo small { min-height: 13px; font: 700 11px/1.2 system-ui, sans-serif; color: #ff9a4a; font-variant-numeric: tabular-nums; }
.btn-undo:disabled { opacity: .4; cursor: default; }
.undo-hint { position: relative; justify-self: center; margin: 0 0 2px 14%; padding: 5px 10px; border-radius: 10px; background: var(--gold); color: var(--ink); font-size: 12px; font-weight: 900; white-space: nowrap; pointer-events: none; will-change: transform, opacity; }
.undo-hint::after { content: ""; position: absolute; left: 50%; top: 100%; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--gold); }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.levels button { display: grid; justify-items: center; align-content: center; padding: 4px 2px; border: 1.5px solid rgba(255, 255, 255, .5); border-radius: 12px; background: rgba(11, 10, 31, .72); font: 900 15px/1.15 var(--ui); cursor: pointer; }
.levels small { font: 700 10px/1.2 system-ui, sans-serif; }
.levels button[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 12px rgba(255, 210, 74, .55); }
.levels button:disabled { opacity: .4; cursor: default; }
/* 倒す。押し続けた分（--hold、0〜1）だけ、左から明るく満ちていく。満ち具合はスクリプトが時刻から決める */
.btn-push { position: relative; min-height: 52px; overflow: hidden; --hold: 0; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.btn-push::before { content: ""; position: absolute; inset: 0; background: rgba(255, 255, 255, .55); transform: scaleX(var(--hold)); transform-origin: 0 50%; pointer-events: none; }
.btn-push small { display: block; font: 700 10px/1.2 system-ui, sans-serif; opacity: .9; }

/* ---------- 見出し ---------- */
.head { position: absolute; inset: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: max(8px, var(--safe-top)) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); }
.title { flex: 1; min-width: 0; margin: 0; font: 400 clamp(17px, 5vw, 22px)/1.2 var(--display); white-space: nowrap; text-shadow: 0 2px 0 rgba(11, 10, 31, .7); }
.title-btn { max-width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { flex: none; padding: 6px 12px; border: 1.5px solid rgba(255, 255, 255, .85); border-radius: 8px; background: rgba(11, 10, 31, .35); font-size: 12px; font-weight: 700; cursor: pointer; }

/* ---------- 最初の画面と結果 ---------- */
.start, .result { position: absolute; left: 50%; bottom: max(14px, var(--safe-bottom)); width: min(calc(100% - 28px), 420px); margin-left: calc(min(calc(100% - 28px), 420px) / -2); text-align: center; }
.start-logo { margin: 0 0 4px; font: 400 clamp(26px, 8.4vw, 38px)/1.15 var(--display); text-shadow: 0 3px 0 var(--red-deep), 0 0 22px rgba(11, 10, 31, .7); }
.start-lead { margin: 0 0 12px; font-size: 15px; font-weight: 700; text-shadow: 0 1px 6px rgba(11, 10, 31, .9); }
.start .btn-board { margin-top: 10px; }
.stats { display: flex; justify-content: center; gap: 22px; margin: 10px 0 0; font-size: 12px; text-shadow: 0 1px 6px rgba(11, 10, 31, .9); }
.stats div { display: flex; gap: 6px; align-items: baseline; }
.stats dt { opacity: .85; }
.stats dd { margin: 0; font-weight: 700; font-size: 14px; }
.message { margin: 6px 0 0; min-height: 0; font-size: 13px; }
.message:empty { display: none; }

.btn { display: grid; justify-items: center; align-content: center; gap: 1px; width: 100%; min-height: 58px; padding: 8px 14px; border: 0; border-radius: 16px; font-size: 20px; font-weight: 900; cursor: pointer; }
.btn:active { transform: translateY(3px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn small { font-size: 11px; font-weight: 700; opacity: .9; }
.btn-main { background: linear-gradient(#ff7aa8, var(--red)); color: #fff; box-shadow: 0 5px 0 var(--red-deep), 0 10px 26px rgba(255, 79, 139, .45); letter-spacing: .04em; }
.btn-main:active { box-shadow: 0 2px 0 var(--red-deep); }
.btn-sub { min-height: 44px; border: 1.5px solid rgba(255, 255, 255, .7); background: rgba(11, 10, 31, .55); font-size: 14px; }
.panel .btn-sub { border: 2px solid var(--red); background: #fff; color: var(--red-deep); }
.btn-wide { grid-column: 1 / -1; }
.btn-x { grid-auto-flow: column; white-space: nowrap; gap: 6px; min-height: 58px; border: 1.5px solid rgba(255, 255, 255, .7); background: rgba(11, 10, 31, .55); font-size: 14px; }

.result { max-height: calc(var(--vh) - 56px - max(14px, var(--safe-bottom))); overflow-y: auto; padding: 14px 16px 16px; border: 1px solid rgba(255, 255, 255, .22); border-radius: 22px; background: rgba(14, 12, 40, .8); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 16px 50px rgba(0, 0, 0, .45); cursor: default; will-change: transform, opacity; }
.result-title { margin: 0; font: 400 clamp(20px, 6.4vw, 26px)/1.2 var(--display); color: var(--gold); }
.result-total { margin: 2px 0 0; font: 400 clamp(24px, 8vw, 32px)/1 var(--display); }
/* 数字は、桁が多いほど小さくして枠の幅に収める（--chars は表示する文字数。1文字の幅は大きさの約0.74倍） */
.result-total { --fit: calc((min(100vw - 28px, 420px) - 84px) / (0.74 * var(--chars, 5))); white-space: nowrap; }
.result-total b { font-size: min(clamp(64px, 21vw, 92px), var(--fit)); font-weight: 400; margin-right: 4px; }
.result[data-rank="high"] .result-total b { color: var(--gold); }
.result[data-rank="full"] .result-total b { color: #fff; text-shadow: 0 0 22px var(--cyan), 0 4px 0 var(--red-deep); }
.result-best { margin: 4px 0 10px; font-size: 13px; opacity: .9; }
.result-best.record { color: var(--gold); font-weight: 900; opacity: 1; }
.result-dev { margin: 0 0 8px; font-size: 12px; }
/* 内訳の計算書。項目は左、点数は右にそろえ、桁の幅を等しくして縦に読めるようにする */
.result-sheet { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; width: min(100%, 260px); margin: 0 auto; text-align: left; font-variant-numeric: tabular-nums; }
.result-sheet span { opacity: .85; }
.result-sheet .label { font-weight: 300; }
.result-sheet .value { text-align: right; }
.result-sheet hr { grid-column: 1 / -1; width: 100%; margin: 3px 0; border: 0; border-top: 1px solid rgba(255, 255, 255, .3); }
.result-sheet .minus { color: #ff9b8a; opacity: 1; }
.result-sheet .total { font-size: 14px; font-weight: 700; opacity: 1; }
.result-sheet-note { margin: 6px 0 0; font-size: 11px; opacity: .7; white-space: pre-line; }
.result-note { margin: -4px 0 8px; font-size: 10px; font-weight: 300; opacity: .7; }
.result-photo { display: block; width: 46%; margin: 0 auto 8px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .3); }
/* 背の低いスマホ（アプリの中のブラウザーなど）では、内訳と写真を横に並べて、結果の枠を短くする。
   下に重なるブラウザーの操作部分があると、枠の中のスクロールがきかないことがあるため、なるべくスクロールせずに収める */
@media (max-width: 560px) and (max-height: 760px) {
  .result-body { display: grid; grid-template-columns: minmax(0, 1fr) 34%; column-gap: 10px; align-items: start; margin-bottom: 8px; }
  .result-body > * { grid-column: 1; }
  .result-body .result-photo { grid-column: 2; grid-row: 1 / span 2; width: 100%; margin: 0; }
  .result-body .result-dev { margin-bottom: 0; }
  .result-body .result-sheet { gap: 1px 8px; }
  .result-best { margin-bottom: 6px; }
}
.panel-actions { display: grid; grid-template-columns: 1.5fr 1fr; gap: 10px; }

/* ---------- メニュー ---------- */
.overlay { position: fixed; inset: 0 0 auto; height: var(--vh); z-index: 10; display: grid; grid-template-rows: minmax(0, 1fr); place-items: center; padding: max(16px, var(--safe-top)) max(16px, env(safe-area-inset-right)) max(16px, var(--safe-bottom)) max(16px, env(safe-area-inset-left)); background: rgba(11, 10, 31, .6); overflow: hidden; }
.panel { position: relative; width: min(100%, 440px); max-height: 100%; overflow-y: auto; overscroll-behavior-y: contain; touch-action: pan-y pinch-zoom; padding: 18px 18px 16px; border-radius: 16px; background: var(--paper); color: var(--ink); box-shadow: 0 10px 40px rgba(0, 0, 0, .4); -webkit-user-select: text; user-select: text; }
.menu-close { position: absolute; top: 8px; right: 10px; width: 36px; height: 36px; border: 0; background: none; font-size: 24px; cursor: pointer; }
.menu-label { margin: 6px 0 6px; font-size: 13px; color: var(--muted); }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.menu-item { display: block; padding: 10px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); text-align: center; text-decoration: none; font-size: 13px; font-weight: 700; cursor: pointer; }
.howto { margin: 0 0 8px; padding-left: 1.3em; font-size: 12.5px; line-height: 1.65; }
.menu-links { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; }
.menu-links a { color: var(--muted); }
.menu-reset { margin-left: auto; padding: 0; border: 0; background: none; color: #b0412a; font-size: 12px; text-decoration: underline; cursor: pointer; }

/* ---------- あそびかた（横にめくるページ） ---------- */
/* 入りきらない説明は、ページの中で縦にスクロールする */
.tutorial-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 10px; width: min(100%, 420px); padding: 16px 16px 14px; }
/* 縦長のスマホでは、画面の上の空きも使って、高さいっぱいに広げる */
@media (max-width: 560px) and (orientation: portrait) {
  .tutorial-panel { height: 100%; }
}
.tutorial-title { margin: 0 32px 0 0; font: 900 18px/1.3 var(--ui); color: var(--red-deep); }
.tutorial-pages { display: grid; grid-auto-flow: column; grid-auto-columns: 100%; column-gap: 24px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; touch-action: pan-x pan-y; scrollbar-width: none; -webkit-overflow-scrolling: touch; outline: none; }
.tutorial-pages::-webkit-scrollbar { display: none; }
.tutorial-page { display: grid; align-content: start; gap: 8px; min-width: 0; overflow-y: auto; overscroll-behavior-y: contain; scroll-snap-align: start; scroll-snap-stop: always; }
.tutorial-shot { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; border-radius: 12px; background: var(--night); object-fit: cover; -webkit-user-drag: none; user-select: none; pointer-events: none; }
.tutorial-page h3 { margin: 4px 0 0; font: 900 clamp(17px, 5vw, 20px)/1.3 var(--ui); color: var(--ink); }
.tutorial-page p { margin: 0; font-size: 13.5px; font-weight: 700; line-height: 1.65; color: var(--ink); }
.tutorial-nav { display: grid; grid-template-columns: 1fr auto 1.4fr; align-items: center; gap: 10px; }
.tutorial-prev { min-height: 44px; padding: 0 10px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font-size: 14px; font-weight: 700; cursor: pointer; }
.tutorial-prev:disabled { opacity: .35; cursor: default; }
.tutorial-next { min-height: 48px; font-size: 17px; }
.tutorial-dots { display: flex; gap: 6px; }
.tutorial-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.tutorial-dots i.on { background: var(--red); }
.tutorial-skip { justify-self: center; }
.tutorial-open { width: 100%; margin-bottom: 8px; }
/* 背の低い横長の画面（スマホの横向きなど）では、写真を左、文を右に並べる */
@media (max-height: 560px) and (min-aspect-ratio: 4 / 3) {
  .tutorial-panel { gap: 8px; width: min(100%, 640px); padding-top: 12px; }
  .tutorial-page { grid-template-columns: 46% 1fr; grid-template-rows: auto 1fr; column-gap: 14px; overflow-y: auto; }
  .tutorial-shot { grid-row: 1 / 3; align-self: center; }
  .tutorial-page h3 { margin-top: 0; }
  .tutorial-page p { font-size: 12.5px; line-height: 1.55; }
}
.undo-panel { display: grid; gap: 10px; width: min(100%, 340px); padding: 22px 18px 18px; }
.undo-skip { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; cursor: pointer; }
.undo-skip input { width: 18px; height: 18px; margin: 0; accent-color: var(--red); }
.undo-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; }
.share-panel { display: grid; gap: 8px; width: min(100%, 360px); padding: 22px 18px 18px; }
.share-dialog-title { margin: 0 24px 0 0; font-size: 18px; font-weight: 900; line-height: 1.4; color: var(--red-deep); }
.share-dialog-text { margin: 0; font-size: 14px; font-weight: 700; line-height: 1.5; }
.share-dialog-note { margin: 0 0 6px; font-size: 12px; font-weight: 700; line-height: 1.6; color: var(--muted); }
.share-panel .btn-x { width: auto; min-height: 48px; border: 0; background: var(--ink); color: #fff; text-decoration: none; }
.share-panel .btn-x[hidden] { display: none; }

/* ---------- ランキング ---------- */
.rank-switch { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 6px; font-size: 14px; font-weight: 900; cursor: pointer; text-shadow: 0 1px 6px rgba(11, 10, 31, .9); }
.rank-switch input { width: 20px; height: 20px; accent-color: var(--red); }
.rank-status { margin: 0 0 6px; text-align: center; font-size: 12px; font-weight: 700; color: rgba(255, 255, 255, .9); white-space: pre-line; text-shadow: 0 1px 6px rgba(11, 10, 31, .9); }
.rank-status:empty { display: none; }
.rank-retry { display: block; margin: 0 auto 8px; padding: 6px 14px; border: 1.5px solid var(--red); border-radius: 999px; background: #fff; color: var(--red-deep); font-size: 13px; font-weight: 900; cursor: pointer; }
.rank-retry[hidden] { display: none; }
.rank-gate { position: fixed; left: 50%; top: max(64px, calc(var(--safe-top) + 56px)); z-index: 30; transform: translateX(-50%); }
/* 確認の画面が要るとき以外は見せず、ボタンに重ねない。display:none だと確認が動かないことがあるので、見えなくするだけにする */
.rank-gate:not(.active), .rank-gate.done { pointer-events: none; }
.rank-gate:not(.active) { visibility: hidden; }
.board-around h3 { margin: 10px 0 4px; font-size: 12px; color: var(--muted); }
.rank-result { margin: 0 0 8px; padding: 8px 10px; border: 1px solid rgba(255, 255, 255, .2); border-radius: 10px; background: rgba(255, 255, 255, .08); }
.rank-result-text { margin: 0; font-size: 12.5px; font-weight: 700; white-space: pre-line; }
.rank-publish { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: end; margin-top: 6px; text-align: left; }
.rank-publish[hidden] { display: none; }
.rank-publish label, .board-name label { display: grid; gap: 2px; font-size: 11px; font-weight: 700; }
.board-name label { color: var(--muted); }
.rank-publish input, .board-name input { min-width: 0; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; font-size: 16px; -webkit-user-select: text; user-select: text; }
.rank-publish .btn { min-height: 40px; font-size: 15px; }
.rank-publish small { grid-column: 1 / -1; font-size: 10.5px; opacity: .8; }
.board-title { margin: 0 0 4px; font-size: 18px; }
.board-lead { margin: 0 0 8px; font-size: 11.5px; color: var(--muted); }
.board-feedback { margin: 0 0 6px; font-size: 12px; font-weight: 700; color: var(--red-deep); }
.board-feedback:empty { display: none; }
.board-mine { margin-bottom: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 79, 139, .1); }
.board-mine p { margin: 0; font-size: 14px; font-weight: 900; }
.board-mine small { font-size: 11.5px; color: var(--muted); }
.board-pending { margin: 0 0 8px; padding: 0; list-style: none; display: grid; gap: 6px; }
.board-pending li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.board-pending .btn { width: auto; min-height: 34px; padding: 4px 14px; font-size: 13px; }
.board-name { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; margin-bottom: 10px; }
.board-name .btn { width: auto; min-height: 40px; font-size: 13px; }
.board-name .btn[hidden] { display: none; }
.board-list { margin: 0 0 8px; padding: 0; list-style: none; display: grid; gap: 4px; }
.board-list li { display: grid; grid-template-columns: 2.4em 1fr auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: rgba(255, 255, 255, .7); font-size: 14px; }
.board-list li.mine { background: rgba(255, 79, 139, .16); }
.board-rank { text-align: right; font-weight: 900; font-variant-numeric: tabular-nums; }
.board-entry { display: grid; font-weight: 700; overflow-wrap: anywhere; }
.board-entry small { font-size: 10.5px; color: var(--muted); font-weight: 700; }
.board-score { font-weight: 900; font-variant-numeric: tabular-nums; text-align: right; }
.board-score small { display: block; font-size: 10.5px; font-weight: 700; color: var(--muted); }
.board-empty { margin: 8px 0; text-align: center; font-size: 13px; color: var(--muted); }
.board-refresh { width: 100%; margin-bottom: 8px; }
.board-manage { font-size: 12px; color: var(--muted); }
.board-manage summary { cursor: pointer; font-weight: 700; }
.board-manage p { margin: 6px 0; }
.board-manage .menu-reset { margin: 4px 0; }

.snackbar { position: fixed; left: 50%; top: max(60px, var(--safe-top)); z-index: 20; width: max-content; max-width: calc(100% - 32px); transform: translateX(-50%); padding: 8px 16px; border-radius: 14px; background: #fff; color: var(--ink); font-size: 13px; line-height: 1.5; text-align: center; white-space: pre-line; pointer-events: none; }
.snackbar:empty { display: none; }

/* 横に広い画面では、結果を右下へ寄せて列を隠さない（プレイ中の操作盤は、見る所を1か所にするため真ん中に置く） */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  .start, .result { left: auto; right: 28px; margin-left: 0; }
}
/* 背の低い横長の画面（スマホの横向きなど）では、操作盤を左右2列にして背を低くする。
   左に順位の帯と成功率・疲労、右に案内・バー・ボタン */
@media (max-height: 520px) and (min-aspect-ratio: 4 / 3) {
  .controls { width: min(calc(100% - 24px), 900px); margin-left: calc(min(calc(100% - 24px), 900px) / -2); grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 12px; row-gap: 6px; align-items: end; }
  .controls > .goal { grid-column: 1; grid-row: 1 / 5; align-self: end; }
  .controls > .gauges { grid-column: 1; grid-row: 5; }
  .controls > .cue-line { grid-column: 2; grid-row: 1; }
  .controls > .bar-next { grid-column: 2; grid-row: 2; }
  .controls > #bar { grid-column: 2; grid-row: 3; }
  .controls > .undo-hint { grid-column: 2; grid-row: 4; }
  .controls > .actions { grid-column: 2; grid-row: 5; }
  .judge { left: 75%; }
}
/* 背の低い画面では、結果を詰める */
@media (max-height: 620px) {
  .result-total b { font-size: min(56px, var(--fit)); }
    .btn, .btn-x { min-height: 48px; }
  .result-photo { width: 30%; }
  .bar { height: 34px; }
  .start-lead { margin-bottom: 8px; }
}
