: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; touch-action: none; }
#board, #fx { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
#fx { pointer-events: none; }

/* ---------- 見出し ---------- */
.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; }
.panel-actions { display: grid; grid-template-columns: 1.5fr 1fr; gap: 10px; }
.convert-lead { margin: 6px 0 10px; font-size: 13px; line-height: 1.6; opacity: .92; }
.convert-grid { display: grid; gap: 10px; margin-bottom: 10px; }
.convert-grid .btn { min-height: 56px; font-size: 20px; }
.convert-grid .btn small { font-size: 12px; font-weight: 700; opacity: .92; }

/* ---------- メニュー ---------- */
.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; }

.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; }

/* ---------- 最初の画面（盤面の上に重ねる） ---------- */
.start { padding: 14px 16px 14px; border: 1px solid rgba(255, 255, 255, .22); border-radius: 22px; background: rgba(14, 12, 40, .82); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); box-shadow: 0 16px 50px rgba(0, 0, 0, .45); }
.start-logo { color: var(--gold); }
.spec { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 6px; margin: 0 0 10px; padding: 0; list-style: none; font-size: 11px; font-weight: 700; }
.spec li { padding: 2px 9px; border-radius: 999px; background: rgba(255, 255, 255, .13); white-space: nowrap; }
.result-dev { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0 0 10px; font-size: 11px; }
.result-dev div { display: grid; gap: 1px; padding: 6px 4px; border-radius: 10px; background: rgba(255, 255, 255, .1); }
.result-dev b { font: 400 18px/1.1 var(--display); color: var(--cyan); font-variant-numeric: tabular-nums; }
.result-photo { display: block; width: 34%; margin: 0 auto 8px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .3); }
.result-total small { font: 900 18px/1 var(--ui); }
.panel-actions { grid-template-columns: 1fr 1fr; }
.panel-actions #retryBtn { grid-column: 1 / -1; }

/* ---------- 持ち玉と出玉 ---------- */
.hud { position: absolute; left: 50%; top: calc(max(8px, var(--safe-top)) + 40px); width: min(calc(100% - 20px), 440px); transform: translateX(-50%); display: grid; grid-template-columns: 1fr 1.25fr; gap: 6px; pointer-events: none; }
.hud p { margin: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 6px; padding: 4px 10px; border: 1.5px solid rgba(255, 255, 255, .28); border-radius: 12px; background: rgba(11, 10, 31, .72); white-space: nowrap; }
.hud span { font-size: 11px; font-weight: 800; opacity: .9; }
.hud b { font: 400 clamp(19px, 5.6vw, 24px)/1.1 var(--display); font-variant-numeric: tabular-nums; will-change: transform; display: inline-block; }
.hud i { font: 800 11px/1 var(--ui); font-style: normal; margin-left: 2px; }
.hud .hud-stake b { color: #fff; }
.hud .hud-stake[data-low="1"] { border-color: #ff4f6a; }
.hud .hud-stake[data-low="1"] b { color: #ff7a8c; }
.hud .hud-stake[data-free="1"] { border-color: var(--cyan); }
.hud .hud-stake[data-free="1"] b { color: var(--cyan); }
.hud .hud-score { border-color: rgba(255, 210, 74, .8); }
.hud .hud-score b { color: var(--gold); }
.hud-note { grid-column: 1 / -1; display: flex; justify-content: center; gap: 6px; min-height: 0; }
.hud-note small { padding: 1px 9px; border-radius: 999px; background: rgba(11, 10, 31, .7); font-size: 11px; font-weight: 800; }
.hud-note small[hidden] { display: none; }
#modeBadge[data-mode="jackpot"] { background: var(--gold); color: #4a1a00; }
#modeBadge[data-mode="rush"] { background: var(--cyan); color: #032b3a; }

/* ---------- 操作盤（ハンドルと、左打ち・右打ち・止めるのボタン） ---------- */
.controls { position: absolute; left: 50%; bottom: max(10px, var(--safe-bottom)); width: min(calc(100% - 20px), 440px); transform: translateX(-50%); display: grid; gap: 6px; }
.cue { margin: 0; min-height: 18px; text-align: center; font: 900 clamp(13px, 4vw, 16px)/1.3 var(--ui); text-shadow: 0 2px 6px rgba(11, 10, 31, .95); pointer-events: none; }
/* 打ち出しは自動。いまの打ち方（左打ち・右打ち）と、止めるボタンだけを置く */
.autobar { display: grid; grid-template-columns: 1.4fr 1fr; gap: 6px; }
.shot-mode { margin: 0; display: grid; place-items: center; min-height: 50px; border: 2px solid var(--gold); border-radius: 14px; background: rgba(11, 10, 31, .78); font: 400 clamp(17px, 5.2vw, 22px)/1 var(--display); color: var(--gold); box-shadow: 0 0 14px rgba(255, 210, 74, .4); }
.shot-mode[data-side="right"] { border-color: var(--cyan); color: var(--cyan); box-shadow: 0 0 14px rgba(95, 242, 255, .5); }
.autobar button { min-height: 50px; border: 1.5px solid rgba(255, 255, 255, .6); border-radius: 14px; background: rgba(11, 10, 31, .72); font-size: 15px; font-weight: 900; cursor: pointer; touch-action: manipulation; }
.autobar button[aria-pressed="true"] { border-color: #fff; background: var(--red); }
/* PUSHボタン。スーパーリーチの間だけ、盤面の下に出る。脈打つ動きはスクリプトが時刻から決める */
.push { position: absolute; left: 50%; bottom: calc(100% + 10px); width: 104px; height: 104px; margin-left: -52px; border: 4px solid #fff; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffb0c8, var(--red) 55%, var(--red-deep)); box-shadow: 0 8px 0 #6d0f39, 0 0 34px rgba(255, 79, 139, .9); font: 400 24px/1 var(--display); color: #fff; cursor: pointer; will-change: transform; touch-action: manipulation; }
.quit { justify-self: center; padding: 4px 14px; border: 0; background: none; font-size: 12px; font-weight: 700; color: rgba(255, 255, 255, .75); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
/* 2回押しの確認を待っている間（two-tap.ts）。もう一度押せば決まると分かるように目立たせる */
.quit[data-armed] { padding: 6px 16px; border-radius: 999px; background: var(--gold); color: var(--night); text-decoration: none; }
.menu-reset[data-armed] { padding: 4px 10px; border-radius: 8px; background: #b0412a; color: #fff; text-decoration: none; font-weight: 700; }
.app:not([data-state="play"]) .hud, .app:not([data-state="play"]) .controls { display: none; }

/* 横に広い画面では、最初の画面と結果を右下へ寄せて盤面を隠さない */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  .start, .result { left: auto; right: 28px; margin-left: 0; }
}
@media (max-height: 620px) {
  .result-total b { font-size: min(56px, var(--fit)); }
  .btn, .btn-x { min-height: 48px; }
  .shot-mode, .autobar button { min-height: 42px; }
  .start-lead { margin-bottom: 8px; }
}

/* 金のPUSHとドパブル。ふつうのPUSHより大きく、金色に光る */
.push[data-style="gold"], .push[data-style="shake"] { width: 124px; height: 124px; margin-left: -62px; background: radial-gradient(circle at 35% 30%, #fffbd0, #ffc400 55%, #b36200); box-shadow: 0 8px 0 #6b3a00, 0 0 44px rgba(255, 210, 74, 1); color: #4a1a00; font-size: 28px; }
.push[data-style="shake"] { border-color: #ff3050; box-shadow: 0 8px 0 #6b3a00, 0 0 54px rgba(255, 48, 80, 1); }

/* ---------- 演出の信頼度 ---------- */
.odds-open { width: 100%; margin-bottom: 8px; }
.odds-list { display: grid; gap: 10px; }
.odds-list h3 { margin: 0 0 4px; font-size: 13px; color: var(--red-deep); }
.odds-list dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; font-size: 13px; }
.odds-list dt { font-weight: 700; }
.odds-list dd { margin: 0; font-weight: 900; font-variant-numeric: tabular-nums; text-align: right; }
.odds-list dd[data-hot="1"] { color: var(--red-deep); }
.odds-list i { grid-column: 1 / -1; display: block; height: 5px; margin-bottom: 3px; border-radius: 999px; background: linear-gradient(90deg, var(--red) calc(var(--p) * 1%), var(--line) 0); }
