/* 学祭カジノ 共通スタイル（外部フォント・画像なし） */
:root {
  --bg: #0b0f1a;
  --bg2: #141a2b;
  --felt: #0f5132;
  --felt2: #0b3d26;
  --panel: rgba(20, 26, 43, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f1e6;
  --muted: #a9b0c3;
  --gold: #f6c453;
  --gold2: #e09b1a;
  --red: #ff4d5e;
  --green: #3ddc84;
  --blue: #4da3ff;
  --purple: #b57bff;
  --radius: 14px;
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", system-ui, sans-serif;
  --num: "Segoe UI", "Helvetica Neue", Arial, var(--font);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(ellipse at top, #1d2540 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; }
input { font-family: inherit; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.gold { color: var(--gold); }
.plus { color: var(--green); }
.minus { color: var(--red); }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- レイアウト ---------- */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#topbar {
  height: 64px; flex: 0 0 64px;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: linear-gradient(180deg, rgba(0,0,0,.55), rgba(0,0,0,.25));
  border-bottom: 1px solid var(--line);
}
#topbar .logo { font-weight: 900; letter-spacing: .08em; color: var(--gold); font-size: 22px; text-shadow: 0 0 12px rgba(246,196,83,.5); }
#topbar .who { font-size: 18px; }
#topbar .chips { font-size: 26px; font-weight: 800; color: var(--gold); }
#topbar .chips::before { content: ""; display: inline-block; width: 20px; height: 20px; border-radius: 50%; margin-right: 8px; vertical-align: -2px; background: radial-gradient(circle, #fff3c4 0 25%, var(--gold) 26% 60%, var(--gold2) 61%); box-shadow: 0 0 0 2px rgba(0,0,0,.4) inset; }
#topbar .bet-info { font-size: 16px; color: var(--muted); }
#topbar .bet-info b { color: var(--text); }
#screen { flex: 1; position: relative; overflow: hidden; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: safe center; padding: 24px; overflow-y: auto; animation: fadeIn .25s ease; }
.game-screen { overflow: hidden; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 44px; }
h2 { font-size: 30px; }

/* ---------- ボタン ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  padding: 14px 26px; border-radius: 12px; font-size: 20px; font-weight: 800;
  color: #1a1305; background: linear-gradient(180deg, #ffe08a, var(--gold) 50%, var(--gold2));
  box-shadow: 0 4px 0 #8a5d0c, 0 8px 20px rgba(0,0,0,.35);
  transition: transform .05s, filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a5d0c; }
.btn:disabled { filter: grayscale(1) brightness(.6); cursor: not-allowed; }
.btn.secondary { color: var(--text); background: linear-gradient(180deg, #3a4560, #252d42); box-shadow: 0 4px 0 #11151f, 0 8px 20px rgba(0,0,0,.35); }
.btn.danger { color: #fff; background: linear-gradient(180deg, #ff7d88, var(--red) 50%, #c5162a); box-shadow: 0 4px 0 #6d0b16, 0 8px 20px rgba(0,0,0,.35); }
.btn.blue { color: #fff; background: linear-gradient(180deg, #8cc4ff, var(--blue) 50%, #1f6fd1); box-shadow: 0 4px 0 #0d3870, 0 8px 20px rgba(0,0,0,.35); }
.btn.green { color: #062814; background: linear-gradient(180deg, #9ff5c4, var(--green) 50%, #1fa75a); box-shadow: 0 4px 0 #0b5a2c, 0 8px 20px rgba(0,0,0,.35); }
.btn.small { padding: 8px 14px; font-size: 16px; }
.btn.big { padding: 18px 40px; font-size: 26px; }
.btn.sel { outline: 4px solid #fff; outline-offset: 2px; }
.btn kbd { font-size: 12px; opacity: .7; margin-left: 6px; font-family: var(--num); }

/* ---------- 待機画面 ---------- */
.standby { gap: 20px; }
.standby .title { font-size: 72px; font-weight: 900; letter-spacing: .1em; color: var(--gold); text-shadow: 0 0 24px rgba(246,196,83,.6), 0 4px 0 #6b4708; }
.standby .sub { font-size: 28px; }
.text-input {
  font-size: 22px; padding: 12px 16px; border-radius: 10px; border: 2px solid var(--line); background: #0d1220; color: var(--text); width: 260px;
  user-select: text; -webkit-user-select: text;
}
.text-input:focus { outline: none; border-color: var(--gold); }
.chips-float { position: absolute; font-size: 40px; opacity: .15; animation: floaty 8s ease-in-out infinite; pointer-events: none; }
@keyframes floaty { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-30px) rotate(20deg); } }

/* ---------- メッセージ ---------- */
.msgbox { max-width: 760px; text-align: center; font-size: 24px; line-height: 1.6; }
.msgbox .big-icon { font-size: 80px; line-height: 1; margin-bottom: 12px; }
.error-text { color: var(--red); font-weight: 700; min-height: 1.5em; }

/* ---------- ゲーム選択 ---------- */
.menu { justify-content: flex-start; padding-top: 30px; }
.menu-head { display: flex; align-items: center; gap: 20px; width: min(1200px, 100%); margin-bottom: 18px; }
.menu-head h2 { margin: 0; }
.game-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; width: min(1200px, 100%); }
.game-card {
  position: relative; cursor: pointer; border-radius: 18px; padding: 20px; min-height: 170px;
  background: linear-gradient(145deg, rgba(255,255,255,.08), rgba(255,255,255,.02)); border: 2px solid var(--line);
  transition: transform .12s, border-color .12s, box-shadow .12s; overflow: hidden;
}
.game-card:hover, .game-card:focus { transform: translateY(-4px); border-color: var(--gold); box-shadow: 0 10px 40px rgba(246,196,83,.25); outline: none; }
.game-card .icon { font-size: 46px; line-height: 1; }
.game-card .name { font-size: 24px; font-weight: 900; margin: 10px 0 6px; }
.game-card .desc { font-size: 15px; color: var(--muted); line-height: 1.5; }
.game-card .tag { position: absolute; top: 14px; right: 14px; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--red); color: #fff; font-weight: 800; }
.game-card .odds { margin-top: 8px; font-size: 13px; color: var(--gold); }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 18px; padding: 8px 14px; border-radius: 999px; border: 2px solid var(--line); }
.toggle.on { border-color: var(--green); color: var(--green); }
.toggle .knob { width: 44px; height: 24px; border-radius: 12px; background: #333b52; position: relative; transition: background .15s; }
.toggle .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on .knob { background: var(--green); }
.toggle.on .knob::after { left: 23px; }

/* ---------- 賭け設定 ---------- */
.bet-panel { width: min(900px, 100%); }
.bet-amount { font-size: 72px; font-weight: 900; color: var(--gold); text-align: center; line-height: 1; margin: 6px 0 12px; }
.bet-amount small { font-size: 26px; color: var(--muted); }
.bet-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.lev-row .btn { min-width: 110px; font-size: 26px; }
.lev-row .btn[data-lev="5"] { background: linear-gradient(180deg, #ffb07a, #ff8a3d 50%, #d4600f); box-shadow: 0 4px 0 #7a3405; }
.lev-row .btn[data-lev="10"] { background: linear-gradient(180deg, #ff8a8a, var(--red) 50%, #b5122a); color: #fff; box-shadow: 0 4px 0 #6d0b16; }
input[type=range] { width: 100%; accent-color: var(--gold); height: 30px; }
.risk { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.risk > div { background: rgba(0,0,0,.3); border-radius: 12px; padding: 12px 16px; font-size: 18px; }
.risk b { font-size: 28px; }
.payout-table { font-size: 15px; color: var(--muted); margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; }
.payout-table span b { color: var(--text); }
.warn { color: #ffb36b; font-weight: 700; }

/* ---------- 結果 ---------- */
.result .label { font-size: 40px; font-weight: 900; }
.result .delta { font-size: 120px; font-weight: 900; line-height: 1.1; font-family: var(--num); }
.result .delta.plus { text-shadow: 0 0 40px rgba(61,220,132,.6); }
.result .delta.minus { text-shadow: 0 0 40px rgba(255,77,94,.6); }
.result .formula { font-size: 22px; color: var(--muted); }
.result .now { font-size: 30px; }
.confetti { position: fixed; top: -20px; width: 12px; height: 18px; pointer-events: none; animation: fall linear forwards; z-index: 50; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- ロスカット ---------- */
.losscut { background: radial-gradient(circle, rgba(255,0,40,.35), rgba(0,0,0,.9)); animation: lcflash .4s steps(2) 6; }
@keyframes lcflash { 50% { background: radial-gradient(circle, rgba(255,255,255,.4), rgba(255,0,40,.6)); } }
.losscut .lc-title { font-size: 120px; font-weight: 900; color: #fff; letter-spacing: .05em; text-shadow: 0 0 30px var(--red), 6px 6px 0 #6d0b16; animation: shake .08s infinite; }
@keyframes shake { 0% { transform: translate(2px, 1px) rotate(-1deg); } 50% { transform: translate(-3px, -2px) rotate(1deg); } 100% { transform: translate(1px, 2px); } }
.losscut .lc-sub { font-size: 30px; margin-top: 10px; }
.losscut .lc-chart { width: 600px; height: 160px; margin: 10px auto; }
.tape { position: absolute; left: -10%; width: 120%; height: 54px; background: repeating-linear-gradient(45deg, #ffd400 0 40px, #111 40px 80px); opacity: .85; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 26px; color: #fff; text-shadow: 0 0 6px #000, 0 0 6px #000; }

/* ---------- アイドル警告・トースト ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fadeIn .2s; }
.overlay .panel { text-align: center; font-size: 24px; }
.overlay .count { font-size: 90px; font-weight: 900; color: var(--gold); }
#toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast div { background: rgba(0,0,0,.85); border: 1px solid var(--line); padding: 12px 22px; border-radius: 12px; font-size: 20px; animation: fadeIn .2s; }
#toast div.err { border-color: var(--red); color: #ffb3ba; }

/* ---------- ゲーム共通 ---------- */
.game-screen { padding: 12px 20px; justify-content: flex-start; }
.table-felt { background: radial-gradient(ellipse at center, #17734a 0%, var(--felt) 45%, var(--felt2) 100%); border: 10px solid #4a2b12; border-radius: 40px; box-shadow: inset 0 0 60px rgba(0,0,0,.6), 0 20px 50px rgba(0,0,0,.5); }
.game-title { font-size: 22px; font-weight: 800; color: var(--gold); }
.timer-bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.15); overflow: hidden; width: 240px; }
.timer-bar > div { height: 100%; background: var(--gold); transition: width .2s linear; }
.timer-bar.low > div { background: var(--red); }
.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.status-line { font-size: 22px; min-height: 34px; text-align: center; font-weight: 700; }
.rules-box { max-width: 900px; font-size: 18px; line-height: 1.7; text-align: left; }
.rules-box ul { margin: 8px 0; padding-left: 1.4em; }
.rules-box table { border-collapse: collapse; width: 100%; font-size: 16px; }
.rules-box td, .rules-box th { border-bottom: 1px solid var(--line); padding: 3px 8px; text-align: left; }
.rules-box th, .rules-box td:nth-child(2) { white-space: nowrap; }
.rules-box .yaku-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }

/* ---------- トランプ ---------- */
.pcard {
  --cw: calc(var(--card-scale, 1) * 84px);
  width: var(--cw); height: calc(var(--cw) * 1.4); border-radius: calc(var(--cw) * .1);
  background: linear-gradient(160deg, #ffffff, #ece7da); color: #161616; position: relative; flex: 0 0 auto;
  box-shadow: 0 3px 8px rgba(0,0,0,.45); font-family: var(--num); font-weight: 800;
  display: inline-block; transition: transform .15s, box-shadow .15s;
}
.pcard.red { color: #d0182b; }
.pcard .tl { position: absolute; top: 6%; left: 8%; font-size: calc(var(--cw) * .24); line-height: .95; text-align: center; }
.pcard .tl i { display: block; font-style: normal; font-size: calc(var(--cw) * .2); }
.pcard .br { position: absolute; bottom: 6%; right: 8%; font-size: calc(var(--cw) * .24); line-height: .95; transform: rotate(180deg); text-align: center; }
.pcard .br i { display: block; font-style: normal; font-size: calc(var(--cw) * .2); }
.pcard .mid { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * .5); }
.pcard.joker .mid { font-size: calc(var(--cw) * .2); writing-mode: vertical-rl; letter-spacing: .1em; color: #6a1bb0; }
.pcard.back { background: repeating-linear-gradient(45deg, #8a1424 0 6px, #a81d30 6px 12px); border: 4px solid #fff; }
.pcard.back > * { display: none; }
.pcard.deal { animation: deal .3s ease-out; }
@keyframes deal { from { transform: translate(-40px, -80px) rotate(-15deg); opacity: 0; } }
.pcard.flip { animation: flip .35s ease-out; }
@keyframes flip { from { transform: rotateY(90deg); } }
.pcard.selectable { cursor: pointer; }
.pcard.selectable:hover { transform: translateY(-8px); }
.pcard.selected { transform: translateY(-22px); box-shadow: 0 0 0 4px var(--gold), 0 10px 20px rgba(0,0,0,.5); }
.pcard.dim { filter: brightness(.55); }
.pcard.win { box-shadow: 0 0 0 4px var(--gold), 0 0 24px var(--gold); }
.cards { display: flex; gap: 8px; justify-content: center; align-items: flex-end; min-height: calc(var(--cw, 84px) * 1.4); }
.cards.overlap { gap: 0; }
.cards.overlap .pcard + .pcard { margin-left: calc(var(--cw) * -.55); }

/* ---------- 花札 ---------- */
.hana {
  --hw: calc(var(--hana-scale, 1) * 64px);
  width: var(--hw); height: calc(var(--hw) * 1.6); border-radius: 6px; position: relative; flex: 0 0 auto;
  background: #1b1b1b; border: 3px solid #e9e1cf; box-shadow: 0 3px 8px rgba(0,0,0,.5); overflow: hidden; color: #fff;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 4px 2px; transition: transform .15s, box-shadow .15s;
}
.hana .m { font-size: calc(var(--hw) * .34); font-weight: 900; line-height: 1.1; text-shadow: 0 1px 2px #000; }
.hana .mn { font-size: calc(var(--hw) * .16); font-weight: 700; opacity: .9; font-family: var(--num); }
.hana .badge { flex-shrink: 0; white-space: nowrap; font-size: calc(var(--hw) * .2); font-weight: 900; line-height: 1; padding: 3px 4px; border-radius: 4px; }
.hana .nm { font-size: calc(var(--hw) * .15); line-height: 1.1; text-align: center; max-height: 2.3em; overflow: hidden; }
.hana.t-hikari .badge { background: radial-gradient(circle, #fff6c8, var(--gold) 60%, #b07800); color: #3a2400; border-radius: 50%; width: calc(var(--hw) * .45); height: calc(var(--hw) * .45); display: flex; align-items: center; justify-content: center; box-shadow: 0 0 10px var(--gold); }
.hana.t-tane .badge { background: #fff; color: #222; }
.hana.t-tan .badge { background: #c62828; color: #fff; padding: 3px 4px; font-size: calc(var(--hw) * .2); box-shadow: 0 0 0 1px rgba(255,255,255,.5); }
.hana.t-tan.f-ao .badge { background: #1565c0; }
.hana.t-tan.f-plain .badge { background: #6a1b9a; }
.hana.t-kasu .badge { background: rgba(0,0,0,.35); color: #ddd; font-size: calc(var(--hw) * .15); }
.hana.back { background: repeating-linear-gradient(135deg, #3b0d0d 0 5px, #561616 5px 10px); }
.hana.back > * { display: none; }
.hana.selectable { cursor: pointer; }
.hana.selectable:hover { transform: translateY(-6px); }
.hana.match { box-shadow: 0 0 0 3px var(--gold), 0 0 16px var(--gold); }
.hana.choose { box-shadow: 0 0 0 4px var(--green), 0 0 18px var(--green); cursor: pointer; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: translateY(-4px); } }
.hana.small { --hw: 34px; border-width: 2px; }
.hana.small .nm, .hana.small .mn { display: none; }
.hana.small .badge { font-size: 9px; }

/* ---------- 早見表（右サイド） ---------- */
.game-screen.with-side { flex-direction: row; align-items: stretch; gap: 14px; }
.game-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; }
.side-panel { width: 300px; flex: 0 0 300px; display: flex; flex-direction: column; background: linear-gradient(180deg, rgba(40,22,70,.92), rgba(16,14,36,.95)); border: 1px solid rgba(246,196,83,.35); border-radius: 16px; box-shadow: 0 0 30px rgba(181,123,255,.15), inset 0 1px 0 rgba(255,255,255,.08); min-height: 0; overflow: hidden; }
.side-title { padding: 10px 14px; font-weight: 900; font-size: 17px; color: var(--gold); border-bottom: 1px solid rgba(246,196,83,.25); background: rgba(0,0,0,.25); letter-spacing: .05em; }
.side-body { padding: 8px 10px 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.side-body h4 { margin: 8px 2px 2px; font-size: 14px; color: var(--muted); font-weight: 700; }
.side-row { padding: 7px 9px; border-radius: 10px; background: rgba(255,255,255,.05); border: 1px solid transparent; transition: background .2s, border-color .2s; }
.side-row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 15px; }
.side-note { font-size: 13px; color: var(--gold); font-weight: 800; white-space: nowrap; }
.side-desc { font-size: 12.5px; color: var(--muted); margin: 2px 0 4px; line-height: 1.4; }
.side-row.on { background: linear-gradient(90deg, rgba(61,220,132,.28), rgba(61,220,132,.06)); border-color: var(--green); box-shadow: 0 0 14px rgba(61,220,132,.25); }
.side-row.on .side-row-head b::after { content: ' ← いまココ'; color: var(--green); font-size: 12px; }
.side-row.done { background: linear-gradient(90deg, rgba(246,196,83,.3), rgba(246,196,83,.06)); border-color: var(--gold); }
.side-row.done .side-row-head b::after { content: ' ✓ 成立'; color: var(--gold); font-size: 12px; }
.side-row.warn-on { border-color: var(--red); background: rgba(255,77,94,.15); }
.mini-cards { display: flex; gap: 3px; flex-wrap: wrap; align-items: center; }
.mini-cards .arrow { color: var(--muted); font-size: 13px; padding: 0 2px; }
.pcard.mini { box-shadow: 0 1px 3px rgba(0,0,0,.5); border-radius: 4px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.pcard.mini .mr { font-size: calc(var(--cw) * .48); font-weight: 900; letter-spacing: -.04em; }
.pcard.mini .ms { font-size: calc(var(--cw) * .45); }
.pcard.mini.joker { color: #6a1bb0; }
.pcard.mini.joker .ms { font-size: calc(var(--cw) * .32); }
.hana.dim, .pcard.dim { filter: grayscale(.8) brightness(.45); }
.strength-line { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.strength-line .lt { color: var(--muted); font-size: 11px; }
.easy-label { display: block; font-size: 11px; font-weight: 700; opacity: .85; margin-top: 2px; }

/* 大富豪のテーブル配置 */
.df-table { position: relative; width: 100%; flex: 1; padding: 12px; display: grid; grid-template-columns: 170px 1fr 170px; grid-template-rows: auto 1fr; gap: 8px; min-height: 0; }
.df-cpu-top { grid-column: 2; display: flex; justify-content: center; }
.df-cpu-left { grid-column: 1; grid-row: 2; display: flex; align-items: center; }
.df-cpu-right { grid-column: 3; grid-row: 2; display: flex; align-items: center; }
.df-field { grid-column: 2; grid-row: 2; align-items: center; justify-content: center; }
.side-toggle, .side-close, .pb-touch-bar { display: none; }
