:root {
  --theme: #ff8a3d;
  --ink: #292032;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #e5f3fa;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button { font: inherit; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #311e3b; outline-offset: 2px; }
.game {
  --screen-w: 100vw;
  --screen-h: 100vh;
  --top: env(safe-area-inset-top, 0px);
  --right: env(safe-area-inset-right, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --left: env(safe-area-inset-left, 0px);
  position: fixed;
  inset: 0 auto auto 0;
  width: var(--screen-w);
  height: var(--screen-h);
  overflow: hidden;
  background: #e5f3fa;
}
@supports (height: 100dvh) { .game { --screen-w: 100dvw; --screen-h: 100dvh; } }
@media (orientation: portrait) {
  .game {
    --screen-w: 100vh;
    --screen-h: 100vw;
    --top: env(safe-area-inset-right, 0px);
    --right: env(safe-area-inset-bottom, 0px);
    --bottom: env(safe-area-inset-left, 0px);
    --left: env(safe-area-inset-top, 0px);
    transform-origin: top left;
    transform: translateX(var(--screen-h)) rotate(90deg);
  }
  @supports (height: 100dvh) { .game { --screen-w: 100dvh; --screen-h: 100dvw; } }
}
.scene { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.scene:not([src]) { display: none; }
.table {
  --gap: clamp(6px, calc(var(--screen-w) * .024), 36px);
  --board: min(660px, calc(var(--screen-h) - var(--top) - var(--bottom) - 16px), calc(var(--screen-w) * .58 - var(--left) - var(--right)));
  position: relative;
  height: 100%;
  padding: calc(var(--top) + 8px) calc(var(--right) + 8px) calc(var(--bottom) + 8px) calc(var(--left) + 8px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
}
.board {
  position: relative;
  isolation: isolate;
  flex: 0 0 var(--board);
  width: var(--board);
  height: var(--board);
  border: 3px solid #fffdf2;
  border-radius: 8px;
  background: rgba(255, 253, 242, .94);
  box-shadow: 0 2px 0 #816046, 0 4px 15px #19132936;
}
#tiles, .pieces { position: absolute; inset: 0; width: 100%; height: 100%; }
.piece {
  position: absolute;
  display: grid;
  place-items: center;
  width: min(var(--piece-size), 38px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 1px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: var(--team-color);
  box-shadow: 0 1px 2px #2520339e;
  padding: 0;
  pointer-events: none;
}
.piece.selectable {
  z-index: 2;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 0 0 2px #412840, 0 0 0 4px #fff9ca;
}
.piece .mp-icon { width: 76%; height: 76%; font-size: 14px; }
.piece.selectable .mp-icon { width: 82%; height: 82%; }
.controls {
  flex: 0 1 255px;
  min-width: 0;
  max-height: 100%;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding: 10px;
  background: rgba(255, 252, 243, .97);
  border: 1px solid #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px #19132936;
}
.teams { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.team {
  display: flex;
  gap: 3px;
  justify-content: space-between;
  align-items: center;
  border: 1px solid transparent;
  background: #fffcf3;
  border-left: 4px solid var(--team-color);
  border-radius: 5px;
  padding: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.team.current { background: #ffe7cc; border-color: #ad6132; border-left-color: var(--team-color); }
.turn { font-weight: 800; font-size: 20px; line-height: 1.15; }
.status { margin: 0; min-height: 3em; color: #554456; font-size: 13px; line-height: 1.5; }
.roll, .restart {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 44px;
  padding: 5px;
  border: 1px solid #a85022;
  border-radius: 8px;
  background: var(--theme);
  color: #361b0c;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.roll:disabled { cursor: default; background: #f3e5d6; border-color: #ddc6b2; }
.die {
  flex: 0 0 31px;
  height: 31px;
  display: grid;
  grid: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 4px;
  place-items: center;
  border-radius: 6px;
  color: #45252f;
  background: #fffdf5;
  box-shadow: inset 0 -2px #ead5c0;
}
.pip { width: 5px; height: 5px; border-radius: 50%; background: currentColor; visibility: hidden; }
.pip.on { visibility: visible; }
@media (max-width: 560px), (max-height: 420px) {
  .controls { padding: 7px; gap: 5px; }
  .turn { font-size: 17px; }
  .team, .status { font-size: 12px; }
  .roll, .restart { font-size: 13px; }
}
