html, body {
  height: 100%; overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
body.team { font-size: 20px; touch-action: manipulation; }
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* 揀社 */
.picker { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px; }
.picker h1 { margin: 0; font-size: 1.6em; }
.picker-grid { display: grid; grid-template-columns: repeat(3, minmax(120px, 200px)); gap: 18px; }
.picker-grid button { aspect-ratio: 1; font-size: 3.4em; font-weight: 900; background: var(--hc); color: var(--hf); border: none; border-radius: 22px; }

/* 頂部 */
.tbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top)); background: var(--hc); color: var(--hf);
}
.tbar .hname { font-size: 1.5em; font-weight: 900; }
.tbar .conn { width: 12px; height: 12px; border-radius: 50%; background: #999; border: 2px solid rgba(255,255,255,.8); }
.tbar .conn.on { background: #3ddc84; }
.tbar .myscore { margin-left: auto; font-size: 1.1em; font-weight: 700; background: rgba(0,0,0,.15); padding: .2em .8em; border-radius: 99px; }
.tbar .myscore b { font-size: 1.3em; font-variant-numeric: tabular-nums; }
.tbar .timer { font-size: 1.9em; font-weight: 900; min-width: 2.4em; text-align: center; font-variant-numeric: tabular-nums; border-radius: 10px; }
.tbar .timer.urgent { background: var(--bad); color: #fff; }

main.tmain { flex: 1; min-height: 0; overflow: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
main.tmain > div { display: flex; flex-direction: column; gap: 14px; }
.q-head { font-weight: 700; color: var(--muted); }
.slot-q .q-text { font-size: 1.35em; font-weight: 700; line-height: 1.4; }
.slot-q .q-img img { max-height: 30vh; }

/* 選項 */
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.opt {
  display: flex; align-items: center; gap: 14px; text-align: left; min-height: 88px;
  font-size: 1.2em; padding: 14px 18px; border: 3px solid hsl(var(--line)); background: #fff; border-radius: 16px;
}
.opt:disabled { opacity: 1; color: inherit; }
.opts.off .opt:not(.chosen):not(.correct):not(.wrong) { opacity: .7; }
.opt b { flex: none; display: grid; place-items: center; width: 1.9em; height: 1.9em; border-radius: 50%; background: #eef0f4; }
.opt.chosen { border-color: var(--hc); box-shadow: inset 0 0 0 3px var(--hc); }
.opt.chosen b { background: var(--hc); color: var(--hf); }
.opt.correct { border-color: var(--ok); background: #e5f6ec; }
.opt.correct b { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: #fdecec; }
.opt.wrong span { text-decoration: line-through; }
.opt.hidden { border-style: dashed; color: #aaa; background: transparent; }

.status { font-size: 1.25em; text-align: center; padding: 8px; display: flex; gap: 16px; align-items: center; justify-content: center; flex-wrap: wrap; }
.banner { text-align: center; font-size: 1.4em; font-weight: 800; padding: 14px; border-radius: 14px; background: #e9ecf2; }
.banner[style] { background: var(--hc); color: var(--hf); }
.banner.me { background: var(--hc); color: var(--hf); }
.banner.ok { background: #dff5e6; color: #17663a; }
.banner.bad { background: #fdecec; color: #a42828; }
.banner.go { background: #fff3cd; color: #6b4e00; animation: pulse 1.2s infinite; }
.banner.wait { background: transparent; color: var(--muted); font-weight: 600; }
@keyframes pulse { 50% { filter: brightness(1.08); transform: scale(1.01); } }

.wait { flex: 1; display: grid; place-items: center; text-align: center; }
.wait .big { font-size: 7em; font-weight: 900; color: var(--hc); line-height: 1.1; }
.wait p { margin: .3em; font-size: 1.2em; }

/* 畫圖 */
main.tmain.drawing { padding: 10px 14px; overflow: hidden; }
.draw-wrap { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.draw-info { display: flex !important; flex-direction: row !important; gap: 14px; align-items: center; }
.draw-info .q-head { flex: none; }
.draw-info .q-text { font-size: 1.15em; font-weight: 700; }
.draw-info .q-img img { max-height: 80px; margin: 0; }
.draw-area { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; }
.draw-area canvas { background: #fff; border-radius: 12px; box-shadow: 0 0 0 3px var(--hc); touch-action: none; display: block; }
.draw-lock { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.6em; font-weight: 800; background: rgba(243,244,247,.7); border-radius: 12px; }
.toolbar { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; padding-bottom: env(safe-area-inset-bottom); }
.swatch { width: 48px; height: 48px; border-radius: 50%; padding: 0; border: 3px solid #fff; box-shadow: 0 0 0 1px #bbb; }
.swatch.on { box-shadow: 0 0 0 3px #222; }
.size { width: 54px; height: 48px; padding: 0; display: grid; place-items: center; }
.size i { display: block; border-radius: 50%; background: #222; }
.size.on, .tool.on { background: #222; color: #fff; border-color: #222; }
.size.on i { background: #fff; }
.tool { height: 48px; }
.size i.ring { background: transparent; border: 2px solid #222; }
.size.on i.ring { border-color: #fff; background: transparent; }
.seg-mini { display: inline-flex; border: 1px solid #222; border-radius: 10px; overflow: hidden; }
.seg-mini button { border: none; border-radius: 0; height: 46px; padding: 0 14px; }
.seg-mini button.on { background: #222; color: #fff; }
.eraser-cursor { position: absolute; border: 2px solid rgba(0,0,0,.55); background: rgba(255,255,255,.35); border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 1px rgba(255,255,255,.8); z-index: 2; }
.sep { width: 1px; height: 36px; background: hsl(var(--line)); }

/* ===== 技能卡 ===== */
.tbar .fx { display: flex; gap: 6px; flex-wrap: wrap; }
.fx-badge { background: rgba(255,255,255,.9); color: #222; border-radius: 99px; padding: .15em .6em; font-size: .75em; font-weight: 700; }
.fx-badge.freeze, .fx-badge.flip { background: #d7f0ff; }
.cardbtn { background: rgba(0,0,0,.18); color: inherit; border: 2px solid rgba(255,255,255,.6); border-radius: 99px; padding: .25em .8em; font-weight: 800; }
.cardbtn.glow { background: #ffd54f; color: #3a2c00; border-color: #fff; }
.banner.cardtime { background: #fff6d6; color: #6b4e00; }
.banner.ice { background: #d7f0ff; color: #0b4a6e; }
.opt.removed { opacity: .35; border-style: dashed; }
.opt.seer { border-color: #9c7bdc; background: #f5f0ff; }
.toasts { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; pointer-events: none; width: min(640px, 92vw); }
.toast { background: #222; color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: toastIn .3s ease-out; }
.toast.ok { background: #1d9a52; }
.toast.bad { background: #c0392b; }
@keyframes toastIn { from { transform: translateY(-12px); opacity: 0; } }
.sheet { position: fixed; inset: 0; background: rgba(10,15,30,.55); display: grid; place-items: center; z-index: 40; }
.sheet-card { background: #fff; border-radius: 20px; padding: 22px 24px; width: min(760px, 94vw); max-height: 90vh; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.sheet-card h2 { margin: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tcard { border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center; border: 2px solid hsl(var(--line)); }
.tcard.attack { background: #fdecec; border-color: #f3b4b4; }
.tcard.defense { background: #e8f0fe; border-color: #b3c8f5; }
.tcard.boost { background: #fff6d6; border-color: #f0d98a; }
.tcard.used { opacity: .4; }
.tcard .ic { font-size: 2.2em; }
.tcard .nm { font-weight: 900; font-size: 1.2em; }
.tcard .ds { font-size: .8em; color: var(--muted); flex: 1; }
.tcard .why { font-size: .8em; color: var(--muted); }
.target-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.target-grid button { aspect-ratio: 1; font-size: 2em; font-weight: 900; background: var(--hc); color: var(--hf); border: none; border-radius: 16px; }

/* ===== 數字鍵盤 ===== */
.numpad-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.num-display { font-size: 1.1em; display: flex; align-items: baseline; gap: 10px; }
.num-display b { font-size: 2em; min-width: 5em; text-align: center; border-bottom: 3px solid var(--hc); font-variant-numeric: tabular-nums; }
.num-display .unit { font-weight: 700; }
.numpad { display: grid; grid-template-columns: repeat(3, 84px); gap: 10px; }
.numpad button { height: 62px; font-size: 1.5em; font-weight: 700; border-radius: 14px; background: #fff; }
.numpad button:active { background: #e6e9ef; }
.center { text-align: center; }

/* ===== 逐步揭圖 ===== */
.reveal-box { position: relative; overflow: hidden; border-radius: 14px; background: #111; height: 38vh; display: grid; place-items: center; }
.reveal-box img { max-width: 100%; max-height: 100%; transition: filter .15s linear, transform .15s linear; }
.reveal-pts { text-align: center; font-weight: 800; color: var(--hc); font-size: 1.2em; min-height: 1.2em; }

/* ===== 押注題 ===== */
.q-head .cat { color: var(--fg); background: #fff3cd; padding: .1em .6em; border-radius: 6px; }
.wager-intro { text-align: center; font-size: 1.8em; font-weight: 900; }
.wager-intro small { font-size: .5em; font-weight: 500; color: var(--muted); }
.bet-tag { align-self: center; background: #fff3cd; padding: .3em 1em; border-radius: 99px; }
.draw-area.flipped::after { content: '🙃 畫布倒轉咗！'; position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: #d7f0ff; padding: 4px 12px; border-radius: 99px; font-weight: 700; }

/* 押注拉桿 */
.bet-slider { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(640px, 100%); margin: 0 auto; }
.bet-val { font-size: 1.4em; font-weight: 700; }
.bet-val b { font-size: 2.2em; color: var(--hc); font-variant-numeric: tabular-nums; }
/* 拉桿：自己畫軌道同填色（唔靠瀏覽器預設樣式，iPad Safari 都會填滿到圓鈕位置）*/
.bet-track { --thumb: 46px; position: relative; width: 100%; height: var(--thumb); }
.bet-track::before, .bet-fill { content: ''; position: absolute; left: 0; top: 50%; height: 18px; margin-top: -9px; border-radius: 99px; }
.bet-track::before { right: 0; background: #dde1e8; }
.bet-fill { background: var(--hc); width: calc(var(--thumb) / 2 + var(--p, 0) * (100% - var(--thumb))); }
#betRange { -webkit-appearance: none; appearance: none; position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; background: transparent; outline: none; }
#betRange::-webkit-slider-runnable-track { height: var(--thumb); background: transparent; border: none; }
#betRange::-moz-range-track { height: var(--thumb); background: transparent; border: none; }
#betRange::-webkit-slider-thumb { -webkit-appearance: none; box-sizing: border-box; width: var(--thumb); height: var(--thumb); border-radius: 50%; background: #fff; border: 4px solid var(--hc); box-shadow: 0 2px 8px rgba(0,0,0,.25); }
#betRange::-moz-range-thumb { box-sizing: border-box; width: var(--thumb); height: var(--thumb); border-radius: 50%; background: #fff; border: 4px solid var(--hc); }
.bet-marks { width: 100%; display: flex; justify-content: space-between; color: var(--muted); font-size: .9em; }
.bet-quick { display: flex; gap: 10px; }
.bet-quick button { min-width: 64px; height: 48px; font-weight: 700; }

/* 開放題搶答掣 */
.slot-btn { align-items: center; }
.big-buzz { width: min(70vw, 460px); aspect-ratio: 1; border-radius: 50%; border: none; font-size: 3em; font-weight: 900;
  color: var(--hf); background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--hc) 70%, #fff), var(--hc) 60%);
  box-shadow: 0 12px 0 color-mix(in srgb, var(--hc) 60%, #000), 0 18px 40px rgba(0,0,0,.25); transition: transform .08s; }
.big-buzz:active:not(:disabled) { transform: translateY(8px); box-shadow: 0 4px 0 color-mix(in srgb, var(--hc) 60%, #000); }
.big-buzz:disabled { opacity: .35; }
.wager-cat { font-size: .9em; color: var(--hc); margin: 10px 0 6px; }

/* ================= 手機（iPhone）適配 ================= */
.tbar { white-space: nowrap; }
.tbar .hname, .tbar .myscore { flex: none; }
.tbar, main.tmain { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }

/* 直屏手機 */
@media (max-width: 600px) {
  body.team { font-size: 16px; }
  .tbar { gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px; }
  .tbar .hname { font-size: 1.35em; }
  .tbar .myscore { font-size: .9em; padding: .2em .6em; }
  .tbar .timer { font-size: 1.6em; min-width: 1.8em; }
  .tbar .fx { gap: 3px; }
  .fx-badge { padding: .1em .35em; }
  .fx-t { display: none; }                  /* 直屏只顯示圖示，避免頂部太擠 */
  .cardbtn { padding: .2em .6em; }
  main.tmain { padding-top: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); gap: 10px; }
  main.tmain > div { gap: 10px; }
  .slot-q .q-text { font-size: 1.2em; }
  .opts { gap: 10px; }
  .opt { min-height: 64px; padding: 10px 12px; gap: 10px; font-size: 1.05em; border-radius: 14px; }
  .banner { font-size: 1.1em; padding: 10px; }
  .status { font-size: 1.05em; }
  .picker { padding: 16px; }
  .picker-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; gap: 12px; }
  .picker-grid button { font-size: 2.4em; border-radius: 16px; padding: 0; }
  .picker h1 { font-size: 1.3em; text-align: center; }
  .wait .big { font-size: 5em; }
  .numpad { grid-template-columns: repeat(3, 72px); gap: 8px; }
  .numpad button { height: 54px; }
  .num-display b { font-size: 1.7em; min-width: 4em; }
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .target-grid { grid-template-columns: repeat(3, 1fr); }
  .sheet-card { padding: 16px; }
  .big-buzz { width: 64vw; font-size: 2.4em; }
  .wager-intro { font-size: 1.4em; }
  .bet-quick button { min-width: 0; padding: 0 10px; }
  .reveal-box { height: 30vh; }
  /* 畫圖：工具列細啲 */
  .toolbar { gap: 6px; }
  .swatch { width: 36px; height: 36px; }
  .size { width: 42px; height: 38px; }
  .tool, .seg-mini button { height: 38px; padding: 0 10px; }
  .sep { display: none; }
  .draw-info { flex-wrap: wrap; gap: 6px; }
}

/* 橫屏手機（高度好矮） */
@media (max-height: 500px) {
  body.team { font-size: 15px; }
  .tbar { padding-top: 6px; padding-bottom: 6px; gap: 10px; }
  .tbar .hname { font-size: 1.25em; }
  .tbar .timer { font-size: 1.5em; }
  main.tmain { padding-top: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); gap: 8px; }
  main.tmain > div { gap: 8px; }
  .slot-q .q-text { font-size: 1.1em; }
  .slot-q .q-img img { max-height: 30vh; }
  .opts { gap: 8px; }
  .opt { min-height: 48px; padding: 6px 12px; font-size: 1em; }
  .opt b { width: 1.7em; height: 1.7em; }
  .banner { font-size: 1em; padding: 8px; }
  .status { padding: 2px; }
  .wait .big { font-size: 3.5em; }
  .picker { gap: 10px; padding: 10px; }
  .picker-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); width: min(100%, 720px); }
  .picker-grid button { padding: 0; }
  .picker-grid button { font-size: 2em; }
  /* 數字鍵盤：左邊顯示、右邊鍵盤 */
  .numpad-wrap { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 20px; row-gap: 8px; justify-content: center; align-items: center; }
  .numpad-wrap .num-display { grid-column: 1; grid-row: 1; }
  .numpad-wrap > .primary { grid-column: 1; grid-row: 2; align-self: start; }
  .numpad-wrap .numpad { grid-column: 2; grid-row: 1 / span 2; grid-template-columns: repeat(3, 60px); gap: 6px; }
  .numpad button { height: 42px; font-size: 1.2em; }
  /* PIN 鍵盤 */
  .pin-card { padding: 12px 18px; gap: 6px; }
  .pin-card h2 { font-size: 1.1em; }
  .pin-card .muted { display: none; }
  .pin-pad { grid-template-columns: repeat(3, 64px); gap: 6px; }
  .pin-pad button { height: 40px; font-size: 1.2em; }
  .pin-dots { margin: 2px 0; }
  /* 開放題搶答掣 */
  .big-buzz { width: auto; height: 46vh; font-size: 2em; }
  .reveal-box { height: 38vh; }
  .wager-intro { font-size: 1.2em; }
  .bet-slider { gap: 8px; }
  .bet-val b { font-size: 1.8em; }
  .sheet-card { max-height: 94vh; padding: 12px 16px; gap: 8px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .tcard { padding: 8px; gap: 2px; }
  .tcard .ic { font-size: 1.6em; }
  .target-grid { grid-template-columns: repeat(5, 1fr); }
  .target-grid button { font-size: 1.5em; }
  /* 畫圖：工具列放右邊直排，畫布用盡高度 */
  main.tmain.drawing { padding-top: 6px; padding-bottom: 6px; }
  main.tmain > .draw-wrap { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr; gap: 6px 10px; }
  .draw-info { grid-column: 1 / -1; font-size: .9em; }
  .draw-info .q-img { display: none; }
  .draw-area { grid-column: 1; grid-row: 2; }
  .toolbar { grid-column: 2; grid-row: 2; flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; overflow-y: auto; gap: 5px; padding: 0; }
  .swatch { width: 30px; height: 30px; flex: none; }
  .size { width: 40px; height: 32px; flex: none; }
  .tool { height: 32px; padding: 0 8px; font-size: .85em; flex: none; }
  .seg-mini { flex-direction: column; flex: none; }
  .seg-mini button { height: 30px; padding: 0 8px; font-size: .85em; }
  .sep { display: none; }
}

/* 橫屏：題目文字同圖片並排，慳垂直空間 */
@media (max-height: 500px) {
  main.tmain > .slot-q { flex-direction: row; align-items: center; gap: 14px; }
  .slot-q .q-text { flex: 1; }
  .slot-q .q-img img { max-height: 24vh; margin: 0; }
  .status .big { font-size: 1em; padding: .45em 1em; }
  .reveal-box { height: 30vh; }
}

/* 橫屏逐步揭圖：左邊圖片，右邊選項 */
@media (max-height: 500px) {
  main.tmain[data-phase="reveal"] { display: grid; grid-template-columns: 1.25fr 1fr; grid-template-rows: auto auto auto 1fr; column-gap: 14px; row-gap: 6px; align-content: start; }
  main.tmain[data-phase="reveal"] > .slot-head { grid-column: 1 / -1; }
  main.tmain[data-phase="reveal"] > .slot-img { grid-column: 1; grid-row: 2 / span 3; }
  main.tmain[data-phase="reveal"] > .slot-card,
  main.tmain[data-phase="reveal"] > .slot-banner,
  main.tmain[data-phase="reveal"] > .slot-opts { grid-column: 2; }
  main.tmain[data-phase="reveal"] .reveal-box { height: 58vh; }
  main.tmain[data-phase="reveal"] .opts { grid-template-columns: 1fr; gap: 6px; }
  main.tmain[data-phase="reveal"] .opt { min-height: 40px; }
}

/* 橫屏押注：介紹縮成一行，快捷掣同確定掣並排 */
@media (max-height: 500px) {
  main.tmain[data-phase="wager"] > .slot-q { display: block; }
  .wager-intro { font-size: 1.15em; }
  .wager-intro small { display: none; }
  .wager-cat { display: inline-block; margin: 0 0 0 12px; }
  .bet-slider { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px 10px; }
  .bet-val, .bet-track, .bet-marks { width: 100%; }
  .bet-val { text-align: center; }
  .bet-val b { font-size: 1.6em; }
  .bet-quick button { height: 40px; }
  .bet-slider > .primary { height: 40px; padding: 0 20px; }
}

/* 橫屏畫圖工具列：三欄格仔，唔使捲動 */
@media (max-height: 500px) {
  main.tmain > .draw-wrap .toolbar { display: grid; grid-template-columns: repeat(3, 32px); grid-auto-rows: min-content; align-content: start; gap: 5px; overflow-y: auto; }
  .draw-wrap .swatch { width: 30px; height: 30px; }
  .draw-wrap .size { width: 32px; height: 30px; }
  .draw-wrap .tool, .draw-wrap .seg-mini { grid-column: 1 / -1; width: 100%; }
  .draw-wrap .seg-mini { flex-direction: row; }
  .draw-wrap .seg-mini button { flex: 1; padding: 0 4px; }
}
