:root {
  --bg: #1a1510;
  --felt: #1e4d3a;
  --felt-dark: #163828;
  --wood: #6b3f24;
  --wood-light: #8b5a33;
  --point-dark: #2a1f18;
  --point-light: #c4a574;
  --white: #f3efe6;
  --black: #1c1a17;
  --text: #f5f0e8;
  --muted: #a89880;
  --accent: #e0a83a;
  --line: #3d2e22;
  --card: #241c15;
  --good: #3dbf7a;
  --bad: #e86a7a;
  --hl: rgba(224, 168, 58, .55);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(ellipse at center, #2a2018, var(--bg));
  color: var(--text);
}
#app { height: 100%; width: 100%; }

.rotate-gate {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 24px; font-size: 18px; font-weight: 700;
}
@media (orientation: landscape) {
  .rotate-gate { display: none !important; }
}
@media (orientation: portrait) {
  body.force-rotate #app { display: none; }
  body.force-rotate .rotate-gate { display: flex !important; }
}

/* Lobby / home — portrait and landscape. Board play uses .force-rotate. */
.shell {
  height: 100%; max-width: 720px; margin: 0 auto;
  padding: 10px 16px; display: flex; flex-direction: column; overflow: auto;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.h { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
input {
  width: 100%; padding: 11px; border-radius: 10px; border: 1px solid var(--line);
  background: #18120e; color: var(--text); font-size: 16px; margin: 6px 0;
}
button {
  width: 100%; padding: 12px; border-radius: 10px; border: 0;
  background: var(--accent); color: #1a1206; font-size: 15px; font-weight: 700;
  margin-top: 8px; cursor: pointer;
}
button.sec { background: #3a2c20; color: var(--text); }
button:disabled { opacity: .4; cursor: not-allowed; }
.brand { font-weight: 800; }
.hero { text-align: center; padding: 8px 0; }
.dice-ico { font-size: 42px; filter: drop-shadow(0 0 12px rgba(224,168,58,.4)); }
.code { font-size: 28px; font-weight: 800; letter-spacing: .12em; text-align: center; margin: 4px 0; }
.err { color: var(--bad); font-size: 13px; min-height: 16px; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.tiers { display: flex; gap: 6px; }
.tier {
  flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line);
  background: #18120e; color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; margin: 0;
}
.tier.sel { border-color: var(--accent); color: var(--accent); background: rgba(224,168,58,.12); }
.toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(30,22,16,.96); border: 1px solid var(--accent); color: var(--text);
  padding: 8px 16px; border-radius: 16px; font-size: 13px; font-weight: 600; z-index: 200;
  pointer-events: none; transition: opacity .5s; white-space: nowrap;
}
.qr-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.qr-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; text-align: center; max-width: 300px; width: 90%;
}
.qr-box img { display: block; margin: 10px auto; border-radius: 8px; background: #fff; padding: 6px; }

/* ===== Play layout (landscape) ===== */
.play {
  height: 100%; width: 100%;
  display: grid;
  grid-template-columns: 56px 1fr 120px;
  grid-template-rows: 100%;
  gap: 6px;
  padding: 6px;
}
.rail {
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 4px 0; font-size: 11px;
}
.score-pill {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 6px; text-align: center; width: 100%;
}
.score-pill .n { font-size: 20px; font-weight: 800; color: var(--accent); }
.cube-btn {
  width: 44px; height: 44px; margin: 0; padding: 0; border-radius: 8px;
  background: var(--white); color: #1a1206; font-weight: 800; font-size: 16px;
  border: 2px solid #888;
}
.cube-btn.offered { animation: pulse 1s ease-in-out infinite; background: var(--accent); }
@keyframes pulse { 50% { transform: scale(1.06); } }

.board-wrap {
  position: relative; height: 100%;
  background: linear-gradient(180deg, var(--wood-light), var(--wood));
  border-radius: 10px; padding: 8px; border: 2px solid #4a2f1c;
  min-width: 0;
}
.board {
  height: 100%; width: 100%;
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "tl bar tr"
    "bl bar br";
  gap: 0;
  background: var(--felt);
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid var(--felt-dark);
}
.quad.tl { grid-area: tl; }
.quad.tr { grid-area: tr; }
.quad.bl { grid-area: bl; }
.quad.br { grid-area: br; }
.bar { grid-area: bar; }
.quad {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 1fr;
  height: 100%;
  min-height: 0;
  position: relative;
  align-content: stretch;
}
.bar {
  background: var(--wood);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; position: relative; z-index: 2;
  min-height: 0;
}
.bar.src {
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 10px var(--hl);
  background: #7a4a2a;
}
.point {
  position: relative; height: 100%; min-height: 0; width: 100%;
  display: flex; flex-direction: column; align-items: center;
  cursor: default;
}
.point.src,
.point.dest,
.point.sel { cursor: pointer; }
.quad.top .point { justify-content: flex-start; }
.quad.bot .point { justify-content: flex-end; }
.point::before {
  content: ''; position: absolute; left: 8%; right: 8%;
  height: 92%; pointer-events: none; z-index: 0;
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}
.quad.top .point::before { top: 0; clip-path: polygon(50% 100%, 0 0, 100% 0); }
.quad.bot .point::before { bottom: 0; clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.point.dark::before { background: var(--point-dark); }
.point.light::before { background: var(--point-light); }
.point.src {
  z-index: 3;
}
.point.src::before {
  filter: brightness(1.4);
  background: #c4923a !important;
  opacity: .88;
}
.point.src::after {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.75);
  background: rgba(224, 168, 58, .55);
  z-index: 5; pointer-events: none;
  box-shadow: 0 0 8px rgba(224, 168, 58, .65);
}
.point.dest {
  z-index: 4;
}
.point.dest::before {
  filter: brightness(1.45);
  background: #e0a83a !important;
  opacity: .9;
}
.point.dest::after {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(224, 168, 58, .85);
  z-index: 5; pointer-events: none;
  box-shadow: 0 0 10px rgba(224, 168, 58, .9);
}
.pt-num {
  position: absolute; z-index: 2; font-size: 9px; font-weight: 700;
  color: rgba(255,255,255,.45); pointer-events: none;
}
.quad.top .pt-num { bottom: 3px; }
.quad.bot .pt-num { top: 3px; }
.hint {
  text-align: center; font-size: 11px; font-weight: 700; color: var(--accent);
  min-height: 14px;
}
.checkers {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center;
  gap: 1px; padding: 2px 0; pointer-events: none; width: 100%;
}
.quad.bot .checkers { flex-direction: column-reverse; }
.checkers.overlap { gap: 0; }
.checkers.overlap .chk:not(:first-child) {
  margin-top: calc(clamp(14px, 4.2vh, 28px) * var(--chk-overlap, .5) * -1);
}
.quad.bot .checkers.overlap .chk:not(:first-child) {
  margin-top: 0;
  margin-bottom: calc(clamp(14px, 4.2vh, 28px) * var(--chk-overlap, .5) * -1);
}
.chk {
  width: clamp(14px, 4.2vh, 28px);
  height: clamp(14px, 4.2vh, 28px);
  flex: none;
  border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,.35);
  box-shadow: inset 0 2px 3px rgba(255,255,255,.25), 0 1px 2px rgba(0,0,0,.4);
  position: relative;
}
.chk.w { background: radial-gradient(circle at 35% 30%, #fff, var(--white) 55%, #cfc6b4); }
.chk.b { background: radial-gradient(circle at 35% 30%, #555, var(--black) 60%, #000); }
.chk.tip {
  outline: 2px solid #fff;
  box-shadow:
    inset 0 2px 3px rgba(255,255,255,.25),
    0 0 0 2px var(--accent),
    0 0 10px rgba(224, 168, 58, .85);
  z-index: 20 !important;
}
.chk.chip-wait, .off-chip.chip-wait { visibility: hidden; }
.chk.flying {
  position: fixed;
  left: 0; top: 0;
  margin: 0;
  pointer-events: none;
  z-index: 90;
  transform-origin: 0 0;
  will-change: transform;
  box-shadow: inset 0 2px 3px rgba(255,255,255,.25), 0 4px 12px rgba(0,0,0,.5);
}

.off-tray {
  position: absolute; right: -2px; top: 8px; bottom: 8px; width: 18px;
  display: flex; flex-direction: column; justify-content: space-between; pointer-events: none;
}
.off-stack {
  display: flex; flex-direction: column; gap: 1px; align-items: center;
  min-height: 40%;
}
.off-stack.bot { justify-content: flex-end; }
.off-chip {
  width: 14px; height: 6px; border-radius: 2px; border: 1px solid rgba(0,0,0,.3);
}
.off-chip.w { background: var(--white); }
.off-chip.b { background: var(--black); }

.side {
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  padding: 2px 0 0; height: 100%; min-height: 0;
  margin-bottom: -6px;
}
.history {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.side-foot {
  flex: none;
  margin: 0;
  padding: 0;
}
.side-foot button {
  width: 100%;
  margin: 0;
  padding: 8px 6px;
  font-size: 13px;
  border-radius: 8px;
}
.turn-banner {
  font-size: 12px; font-weight: 700; text-align: center;
  padding: 6px; border-radius: 8px; background: var(--card); border: 1px solid var(--line);
}
.turn-banner.yours { border-color: var(--accent); color: var(--accent); }
.dice-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.die {
  width: 36px; height: 36px; border-radius: 7px;
  background: var(--white); color: #1a1206;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px;
  box-shadow: 0 2px 4px rgba(0,0,0,.35);
}
.die.used { opacity: .35; }
@keyframes die-shake {
  0% { transform: translate(0, 0) rotate(0deg); }
  20% { transform: translate(-3px, 2px) rotate(-16deg); }
  40% { transform: translate(4px, -2px) rotate(14deg); }
  60% { transform: translate(-2px, -3px) rotate(-10deg); }
  80% { transform: translate(3px, 1px) rotate(12deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
.die.rolling {
  animation: die-shake .11s linear infinite;
}
.die-modes {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
}
.die-mode {
  min-width: 44px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-weight: 800; font-size: 14px; cursor: pointer;
}
.die-mode.sel {
  border-color: var(--accent); color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.path-btn {
  display: block; width: 100%; margin: 6px 0; padding: 10px 12px;
  border-radius: 8px; border: 1px solid var(--accent);
  background: #2a2218; color: var(--text); font-weight: 700; font-size: 13px;
  cursor: pointer; text-align: left;
}
.actions button { margin-top: 4px; padding: 10px; font-size: 13px; }
.log {
  flex: 1; overflow: auto; font-size: 11px; color: var(--muted);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px;
  min-height: 0; margin-bottom: 0;
}
.log div { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.04); }

.overlay-end {
  position: absolute; inset: 0; background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center; z-index: 10;
  border-radius: 10px;
}
.overlay-end .box {
  background: var(--card); border: 1px solid var(--accent); border-radius: 14px;
  padding: 18px 22px; text-align: center; max-width: 280px;
}
.overlay-end h2 { margin: 0 0 6px; font-size: 20px; }
.overlay-end p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

@media (max-height: 360px) {
  .chk { width: clamp(12px, 3.6vh, 22px); height: clamp(12px, 3.6vh, 22px); }
  .die { width: 30px; height: 30px; font-size: 15px; }
  .play { grid-template-columns: 48px 1fr 100px; }
}
