/* 沙漠駱駝 — 手機直向優先。淺色是正午沙漠，深色是沙漠夜。 */

:root {
  color-scheme: light dark;

  --sand-1: #f7ecd8;
  --sand-2: #efdcbd;
  --sand-3: #e2c79a;
  --ink: #33240f;
  --ink-soft: #6d5734;
  --ink-faint: #9b8560;
  --surface: #fffaf1;
  --surface-2: #f3e6ce;
  --line: #d9c39a;
  --accent: #c98f2b;
  --accent-ink: #fff8e8;
  --good: #2f8f4e;
  --bad: #c0472f;
  --shadow: 0 1px 2px rgba(80, 55, 15, 0.14), 0 6px 18px rgba(80, 55, 15, 0.08);

  /* 五隻駱駝的顏色。字一律用深色 --camel-ink：
     小字（9px）需要 4.5:1 對比，白字配中彩度背景只有 1.8:1，
     對色盲玩家來說那個字是唯一的辨識線索，不能讓它糊掉。 */
  --c-purple: #b98ee0;
  --c-yellow: #eec21e;
  --c-orange: #ef8f3e;
  --c-green: #4fb56a;
  --c-blue: #4f9ee0;
  /* 瘋狂駱駝（第二版）：黑與白。黑底要配淺字，其餘都配深字。 */
  --c-white: #f7f0e2;
  --c-black: #22222c;
  --camel-ink: #1a1206;
  --camel-ink-light: #f4eee2;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --sand-1: #1c1710;
    --sand-2: #262019;
    --sand-3: #35291c;
    --ink: #f2e6d0;
    --ink-soft: #c4b394;
    --ink-faint: #8d7d63;
    --surface: #241e17;
    --surface-2: #2f2820;
    --line: #453728;
    --accent: #e0a63c;
    --accent-ink: #221a0c;
    --good: #56c07a;
    --bad: #ea7458;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 22px rgba(0, 0, 0, 0.35);
    --c-white: #ece5d6;
  }
}

:root[data-theme='dark'] {
  --sand-1: #1c1710;
  --sand-2: #262019;
  --sand-3: #35291c;
  --ink: #f2e6d0;
  --ink-soft: #c4b394;
  --ink-faint: #8d7d63;
  --surface: #241e17;
  --surface-2: #2f2820;
  --line: #453728;
  --accent: #e0a63c;
  --accent-ink: #221a0c;
  --good: #56c07a;
  --bad: #ea7458;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 22px rgba(0, 0, 0, 0.35);
  --c-white: #ece5d6;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, var(--sand-1), var(--sand-2) 60%, var(--sand-3));
  background-attachment: fixed;
  overscroll-behavior: none;
  font-size: 15px;
  line-height: 1.45;
}

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

[hidden] {
  display: none !important;
}

/* 遊戲畫面是固定一屏的 app shell：只有戰報會捲動 */
#game {
  height: 100dvh;
  overflow: hidden;
}

/* ── 開局設定 ─────────────────────────────────────────── */

#setup {
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.setup-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.brand {
  margin: 0;
  font-size: 30px;
  letter-spacing: 2px;
}

.brand-mark {
  display: block;
  font-size: 44px;
  line-height: 1.2;
}

.brand-sub {
  margin: 2px 0 22px;
  color: var(--ink-faint);
  font-size: 13px;
  letter-spacing: 3px;
}

.field {
  margin-bottom: 18px;
  text-align: left;
}

.field > label {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 7px;
  letter-spacing: 1px;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* 兩排都是 5 個選項（真人 1~5、AI 0~4），排成一致的 5 欄 */
#opt-speed {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

#opt-humans,
#opt-opponents {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}

.chip:disabled {
  opacity: 0.3;
  cursor: default;
}

.version-label {
  margin: 10px 0 0;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.field-note {
  margin: 5px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-faint);
}

.field-hint {
  float: right;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0;
}

.chip {
  flex: 1 1 0;
  min-width: 44px;
  padding: 9px 4px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-soft);
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
}

.chip[aria-checked='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ── 按鈕 ─────────────────────────────────────────────── */

.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--r-md);
  padding: 11px 14px;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.btn-lg {
  width: 100%;
  padding: 15px;
  font-size: 17px;
  letter-spacing: 2px;
}

.btn-ghost {
  width: 100%;
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
  margin-top: 8px;
}

.btn-sm {
  font-size: 13px;
  padding: 7px;
}

/* ── 頂列 ─────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  gap: 8px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.leg-badge {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 11px;
  white-space: nowrap;
}

.pyramid {
  display: flex;
  gap: 3px;
}

.die-dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  background: var(--surface);
}

.die-dot.purple { background: var(--c-purple); }
.die-dot.yellow { background: var(--c-yellow); }
.die-dot.orange { background: var(--c-orange); }
.die-dot.green { background: var(--c-green); }
.die-dot.blue { background: var(--c-blue); }

/* 灰骰：六面是黑白各三，畫成對角各半 */
.die-dot.crazy {
  background: linear-gradient(135deg, var(--c-white) 0 50%, var(--c-black) 50% 100%);
}

.die-dot.used {
  opacity: 0.22;
}

.topbar-right {
  display: flex;
  gap: 2px;
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 17px;
  padding: 6px 7px;
  border-radius: var(--r-sm);
  cursor: pointer;
  opacity: 0.8;
}

.icon-btn[aria-pressed='true'] {
  opacity: 1;
  background: var(--surface);
}

/* ── 側視賽道（實況）───────────────────────────────────── */

.race-wrap {
  padding: 0 8px 5px;
}

.race-scene {
  position: relative;
  height: 104px;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f8e6bb 0%, #f2cd88 46%, #e7ae60 100%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .race-scene {
    background: linear-gradient(180deg, #38291a 0%, #6a4423 50%, #8b5626 100%);
  }
}

:root[data-theme='dark'] .race-scene {
  background: linear-gradient(180deg, #38291a 0%, #6a4423 50%, #8b5626 100%);
}

/* 太陽貼在場景上不隨捲動移動，做出遠景不動的視差感 */
.race-sun {
  position: absolute;
  top: 7px;
  right: 16px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f7c236;
  box-shadow: 0 0 12px 4px rgba(247, 194, 54, 0.32);
  z-index: 0;
}

.race-viewport {
  position: absolute;
  inset: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.race-viewport::-webkit-scrollbar {
  display: none;
}

.race-strip {
  position: relative;
  height: 100%;
}

.race-dune {
  position: absolute;
  bottom: 21px;
  border-radius: 50% 50% 0 0;
  background: #d99a4e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .race-dune { background: #6d4522; }
}

:root[data-theme='dark'] .race-dune { background: #6d4522; }

.race-ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22px;
  background: linear-gradient(180deg, #b3742f, #9a6327);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .race-ground {
    background: linear-gradient(180deg, #4a2f17, #392411);
  }
}

:root[data-theme='dark'] .race-ground {
  background: linear-gradient(180deg, #4a2f17, #392411);
}

.race-ticks {
  position: absolute;
  inset: 0;
}

.race-tick {
  position: absolute;
  bottom: 2px;
  transform: translateX(-50%);
  font-size: 8px;
  line-height: 1;
  color: rgba(255, 245, 225, 0.55);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.race-finish {
  position: absolute;
  bottom: 16px;
  font-size: 17px;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45));
  z-index: 1;
}

.race-tiles,
.race-lane {
  position: absolute;
  inset: 0;
}

.race-tile {
  position: absolute;
  bottom: 12px;
  transform: translateX(-50%);
  font-size: 8px;
  font-weight: 800;
  line-height: 1;
  padding: 2px 3px;
  border-radius: 3px;
  color: #fff;
  z-index: 1;
}

.race-tile.oasis { background: #2f8f4e; }
.race-tile.mirage { background: #b93a22; }

/* ── 駱駝 ─────────────────────────────────────────────── */

.race-camel {
  --lift-step: 12px; /* 疊一層抬多高，約駱駝身高的四成：看得出騎在背上又不頂出畫面 */
  position: absolute;
  left: 0;
  bottom: 18px;
  width: 38px;
  margin-left: -19px;
  transform: translate(var(--x, 0px), calc(var(--lift-n, 0) * var(--lift-step) * -1));
  transition: transform var(--move-ms, 800ms) cubic-bezier(0.32, 0.72, 0.35, 1);
}

.race-camel .camel-svg {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.35));
  animation: camel-bob 2.6s ease-in-out infinite;
}

.race-camel.purple .camel-svg { fill: var(--c-purple); }
.race-camel.yellow .camel-svg { fill: var(--c-yellow); }
.race-camel.orange .camel-svg { fill: var(--c-orange); }
.race-camel.green .camel-svg { fill: var(--c-green); }
.race-camel.blue .camel-svg { fill: var(--c-blue); }
.race-camel.white .camel-svg { fill: var(--c-white); }
.race-camel.black .camel-svg { fill: var(--c-black); }

/* 瘋狂駱駝往回跑，所以整隻鏡射面向左邊 —— 一眼就看得出誰是逆行的。
   用獨立的 scale 屬性，才不會跟 camel-bob 的 transform 打架。 */
.race-camel.crazy .camel-svg {
  scale: -1 1;
}

.race-camel.black .race-tag {
  color: var(--camel-ink-light);
}

/* 領先的那隻帶一圈光暈，掃一眼就知道誰在前面 */
.race-camel.leader .camel-svg {
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.35))
    drop-shadow(0 0 4px rgba(255, 238, 170, 0.95));
}

.race-tag {
  position: absolute;
  /* 對準身體橢圓的中心（viewBox 裡的 18.6/48 與 23.8/42） */
  left: 39%;
  bottom: 43%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  color: var(--camel-ink);
  pointer-events: none;
}

.race-shadow {
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 24px;
  height: 4px;
  margin-left: -12px;
  border-radius: 50%;
  background: rgba(60, 35, 10, 0.3);
}

/* 疊在別人背上的駱駝沒有踩在地上，不該有地面影子 */
.race-camel.stacked .race-shadow {
  opacity: 0;
}

/* ── 跑步動畫 ─────────────────────────────────────────── */

.leg {
  animation: camel-trot 1.5s ease-in-out infinite;
}

/* transform-origin 的 center 會對到整個 viewBox 的中心，不是那條腿，
   所以每條腿都要給絕對座標的髖部位置 */
.leg-b1 { transform-origin: 8.1px 25.5px; animation-delay: -0.38s; }
.leg-f1 { transform-origin: 15.1px 25.5px; animation-delay: 0s; }
.leg-b2 { transform-origin: 23.6px 25.5px; animation-delay: -1.12s; }
.leg-f2 { transform-origin: 28.8px 25.5px; animation-delay: -0.75s; }

.race-camel.running .leg { animation-duration: 0.24s; }

.race-camel.running .camel-svg {
  animation: camel-gallop 0.32s ease-in-out infinite;
}

.race-dust {
  position: absolute;
  left: 4px;
  bottom: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 246, 226, 0.9);
  opacity: 0;
}

.race-camel.running .race-dust {
  animation: camel-dust 0.42s ease-out infinite;
}

@keyframes camel-trot {
  0%, 100% { transform: rotate(9deg); }
  50% { transform: rotate(-9deg); }
}

@keyframes camel-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1px); }
}

/* 移動時的彈跳做大一點：幅度太小的話整段看起來只是「滑過去」 */
@keyframes camel-gallop {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30% { transform: translateY(-7px) rotate(-5deg); }
  55% { transform: translateY(-2px) rotate(-1deg); }
  78% { transform: translateY(1px) rotate(2.5deg); }
}

@keyframes camel-dust {
  0% { opacity: 0.9; transform: translate(0, 0) scale(0.4); }
  100% { opacity: 0; transform: translate(-16px, -8px) scale(1.6); }
}

/* ── 骰子亮相 ─────────────────────────────────────────── */

.dice-pop {
  /* 貼在賽道上緣：放中間會正好擋住正在跑的那一疊駱駝 */
  position: absolute;
  left: 50%;
  top: 7px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 11px 4px 4px;
  border-radius: 999px;
  background: rgba(28, 18, 6, 0.82);
  backdrop-filter: blur(2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) scale(0.8);
}

.dice-pop.show {
  animation: dice-in 0.34s cubic-bezier(0.2, 1.5, 0.4, 1) forwards;
}

.race-wrap {
  position: relative;
}

.dice-face {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 800;
  color: var(--camel-ink);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.dice-face.purple { background: var(--c-purple); }
.dice-face.yellow { background: var(--c-yellow); }
.dice-face.orange { background: var(--c-orange); }
.dice-face.green { background: var(--c-green); }
.dice-face.blue { background: var(--c-blue); }
.dice-face.white { background: var(--c-white); }
.dice-face.black { background: var(--c-black); color: var(--camel-ink-light); }

.dice-name {
  font-size: 12px;
  font-weight: 700;
  color: #fff6e4;
  white-space: nowrap;
}

@keyframes dice-in {
  0% { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(0.55) rotate(-14deg); }
  70% { opacity: 1; transform: translateX(-50%) scale(1.08) rotate(3deg); }
  100% { opacity: 1; transform: translateX(-50%) scale(1) rotate(0deg); }
}

/* ── 賽道 ─────────────────────────────────────────────── */

.track-wrap {
  padding: 0 8px;
}

.track {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}

.cell {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  min-height: 84px;
  padding: 2px 2px 13px;
  display: flex;
  flex-direction: column-reverse; /* 陣列 index 0 是最底層，要畫在下面 */
  justify-content: flex-start;
  gap: 2px;
}

.cell.finish {
  border-color: var(--accent);
  border-width: 2px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}

.cell-no {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1px;
  text-align: center;
  font-size: 9px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.cell.pickable {
  border-color: var(--accent);
  border-style: dashed;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  cursor: pointer;
}

.cell.pickable:active {
  filter: brightness(1.06);
}

.camel {
  height: 15px;
  /* 白駱駝在淺色格子上幾乎融進背景，需要一圈描邊把它切出來 */
  border: 1px solid rgba(0, 0, 0, 0.22);
  color: var(--camel-ink);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.14);
  will-change: transform;
}

.camel.purple { background: var(--c-purple); }
.camel.yellow { background: var(--c-yellow); }
.camel.orange { background: var(--c-orange); }
.camel.green { background: var(--c-green); }
.camel.blue { background: var(--c-blue); }
.camel.white { background: var(--c-white); }
.camel.black { background: var(--c-black); color: var(--camel-ink-light); }

/* 瘋狂駱駝是逆行的，在方格賽道上用一條左向箭頭標出來 */
.camel.crazy::before {
  content: '◀';
  font-size: 7px;
  margin-right: 2px;
  opacity: 0.75;
}

.tile-mark {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  padding: 2px 3px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--surface);
  z-index: 2;
}

.tile-mark.mine {
  background: var(--accent);
  color: var(--accent-ink);
}

/* 終點區：越線的駱駝 */
.finish-lane {
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  font-size: 11px;
  font-weight: 700;
}

.finish-lane .camel {
  width: 34px;
}

/* ── 狀態列 ───────────────────────────────────────────── */

.status {
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
  padding: 8px 12px 4px;
  min-height: 30px;
}

.status.thinking::after {
  content: '';
  animation: dots 1.1s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ''; }
  25% { content: '·'; }
  50% { content: '··'; }
  75% { content: '···'; }
}

/* ── 玩家列 ───────────────────────────────────────────── */

.players {
  display: flex;
  gap: 5px;
  padding: 0 10px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.players::-webkit-scrollbar {
  display: none;
}

.pcard {
  /* 整桌上限 5 人，min-width 壓到 5 張剛好塞得進 375px，就不必橫向捲動 */
  flex: 1 1 0;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 6px 8px;
  text-align: center;
}

.pcard.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.pcard.me .pname {
  color: var(--accent);
}

.pname {
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pmoney {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.pbets {
  display: flex;
  gap: 2px;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 8px;
  margin-top: 3px;
}

.bet-pip {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.16);
}

/* ── 行動按鈕 ─────────────────────────────────────────── */

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 0 10px 8px;
}

.btn-act,
.btn-roll {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 9px 2px;
  line-height: 1.25;
}

.btn-roll {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.act-ico {
  font-size: 19px;
}

.act-txt {
  font-size: 11px;
  font-weight: 700;
}

.act-sub {
  font-size: 9px;
  opacity: 0.7;
}

/* ── 戰報 ─────────────────────────────────────────────── */

.log-wrap {
  flex: 1;
  /* min-height:auto 會讓戰報內容把容器撐開，整頁就跟著長高。
     設成 0 才輪得到 .log 自己的 overflow 生效。 */
  min-height: 0;
  padding: 0 10px 10px;
  display: flex;
}

.log {
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-soft);
  -webkit-overflow-scrolling: touch;
}

.log-line {
  padding: 1px 0;
}

.log-line + .log-line {
  border-top: 1px dashed color-mix(in srgb, var(--line) 55%, transparent);
}

.log-line .who {
  font-weight: 700;
  color: var(--ink);
}

.log-line .why {
  display: block;
  font-size: 11px;
  color: var(--ink-faint);
}

.log-line.big {
  color: var(--ink);
  font-weight: 700;
  background: var(--surface-2);
  margin: 4px -10px;
  padding: 4px 10px;
}

.gain {
  color: var(--good);
  font-weight: 700;
}

.loss {
  color: var(--bad);
  font-weight: 700;
}

/* ── 底部彈出面板 ─────────────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 5, 0.45);
  backdrop-filter: blur(2px);
  z-index: 40;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  background: var(--surface);
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
  padding: 8px 14px calc(14px + env(safe-area-inset-bottom));
  max-height: 76dvh;
  overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(60, 40, 10, 0.25);
  animation: rise 0.22s cubic-bezier(0.22, 0.8, 0.3, 1);
}

@keyframes rise {
  from { transform: translateY(24px); opacity: 0; }
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 0 auto 10px;
}

.sheet-title {
  margin: 0 0 4px;
  font-size: 16px;
  text-align: center;
}

.sheet-body {
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--r-md);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}

.opt:disabled {
  opacity: 0.34;
}

.opt-swatch {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.22);
  color: var(--camel-ink);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
}

.opt-main {
  flex: 1;
  min-width: 0;
}

.opt-name {
  font-size: 14px;
  font-weight: 700;
}

.opt-note {
  font-size: 11px;
  color: var(--ink-faint);
}

.opt-ev {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.seg {
  display: flex;
  gap: 5px;
  margin-bottom: 4px;
}

.seg .chip {
  padding: 10px 4px;
}

/* ── 覆蓋層 ───────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(30, 20, 5, 0.55);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 18px;
}

.overlay-card {
  width: 100%;
  max-width: 420px;
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px 18px;
  box-shadow: var(--shadow);
  animation: rise 0.2s cubic-bezier(0.22, 0.8, 0.3, 1);
}

.overlay-card h2 {
  margin: 0 0 12px;
  font-size: 19px;
  text-align: center;
}

.overlay-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.overlay-actions .btn {
  flex: 1;
  margin-top: 0;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
}

.result-row + .result-row {
  margin-top: 4px;
}

.result-row.me {
  background: color-mix(in srgb, var(--accent) 15%, var(--surface));
  border-color: var(--accent);
}

.result-rank {
  font-size: 18px;
  font-weight: 800;
  width: 30px;
  text-align: center;
}

.result-name {
  flex: 1;
}

.result-money {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.settle-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.settle-table th,
.settle-table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.settle-table td:last-child,
.settle-table th:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rules-body {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink-soft);
}

.rules-body h3 {
  font-size: 14px;
  color: var(--ink);
  margin: 14px 0 4px;
}

.rules-body ul {
  margin: 4px 0;
  padding-left: 18px;
}

.rules-body b {
  color: var(--ink);
}

/* ── 勝率提示 ─────────────────────────────────────────── */

.info-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
  padding: 0 10px 8px;
}

.rolls-panel {
  flex: 0 0 104px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 7px 8px;
  display: flex;
  flex-direction: column;
}

/* 勝率提示關掉時，骰子紀錄自己撐滿整列 */
.info-row.solo .rolls-panel {
  flex: 1;
}

.rolls-head {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--ink-faint);
  margin-bottom: 4px;
}

.rolls-head span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0;
}

.rolls-body {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 3px;
}

.rolls-empty {
  font-size: 10px;
  color: var(--ink-faint);
}

.roll-chip {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 2px 4px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.22);
  color: var(--camel-ink);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.roll-chip.purple { background: var(--c-purple); }
.roll-chip.yellow { background: var(--c-yellow); }
.roll-chip.orange { background: var(--c-orange); }
.roll-chip.green { background: var(--c-green); }
.roll-chip.blue { background: var(--c-blue); }
.roll-chip.white { background: var(--c-white); }
.roll-chip.black { background: var(--c-black); color: var(--camel-ink-light); }

.roll-step {
  opacity: 0.85;
}

.odds-panel {
  flex: 1;
  min-width: 0;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 7px 10px;
  font-size: 11px;
}

.odds-head {
  display: flex;
  justify-content: space-between;
  color: var(--ink-faint);
  margin-bottom: 3px;
  font-size: 10px;
  letter-spacing: 1px;
}

.odds-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}

.odds-swatch.black { color: var(--camel-ink-light); }

.odds-swatch {
  width: 15px;
  height: 15px;
  border-radius: 3px;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.22);
  color: var(--camel-ink);
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 800;
}

.odds-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.odds-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.odds-num {
  width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

/* ── 桌機放大 ─────────────────────────────────────────── */

@media (min-width: 720px) {
  body {
    font-size: 16px;
  }

  #game {
    max-width: 860px;
    margin: 0 auto;
  }

  .race-scene {
    height: 140px;
  }

  .race-camel {
    --lift-step: 16px;
    width: 52px;
    margin-left: -26px;
    bottom: 24px;
  }

  .race-tag {
    font-size: 11px;
  }

  .cell {
    min-height: 108px;
  }

  .camel {
    height: 19px;
    font-size: 11px;
  }

  .cell-no {
    font-size: 11px;
  }

  .act-txt {
    font-size: 13px;
  }

  .act-sub {
    font-size: 11px;
  }
}

/* ── 矮螢幕（iPhone SE 這類）──────────────────────────── */
/* 加了賽道實況之後，667px 高的機器會擠爆版面，這裡整體縮一號 */

@media (max-height: 740px) {
  .race-scene {
    height: 82px;
  }

  .race-camel {
    --lift-step: 9px;
    width: 32px;
    margin-left: -16px;
    bottom: 15px;
  }

  .race-sun {
    width: 16px;
    height: 16px;
  }

  .cell {
    min-height: 70px;
  }

  .camel {
    height: 12px;
    font-size: 8px;
  }

  .odds-panel,
  .rolls-panel {
    padding: 5px 8px;
  }

  .rolls-panel {
    flex-basis: 92px;
  }

  .odds-row {
    padding: 0;
  }

  .status {
    padding: 5px 12px 2px;
    min-height: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
