:root {
  --ink: #3a2e5c;
  --panel: rgba(255, 255, 255, 0.94);
  --pri: #7c4dff;
  --pri-d: #5b34d6;
  --accent: #ffb703;
  --good: #2ecc71;
  --bad: #e5484d;
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Comic Sans MS", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--font); color: var(--ink); }
body { background: linear-gradient(180deg, #bfe3ff 0%, #dff3ff 55%, #c9f0c4 100%); }
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* ---------- overlays & panels (same look as chess and snakes) ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.overlay.dim { background: rgba(40, 20, 90, 0.35); backdrop-filter: blur(3px); z-index: 30; }
.panel {
  position: relative; width: min(560px, 100%); max-height: 100%; overflow: auto;
  background: var(--panel); border-radius: 28px; padding: 28px 26px 24px;
  box-shadow: 0 18px 50px rgba(60, 30, 140, 0.35), 0 0 0 4px rgba(255, 255, 255, 0.6) inset;
  text-align: center; animation: pop 0.35s cubic-bezier(.2, 1.4, .4, 1);
}
.panel.small { width: min(420px, 100%); }
.panel section { padding-top: 14px; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }
h1 { margin: 6px 0 4px; font-size: clamp(1.7rem, 5vw, 2.4rem); }
h2 { margin: 0 0 6px; font-size: 1.6rem; }
.logo { display: inline-block; animation: wiggle 2.4s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
.sub { margin: 4px 0 16px; color: #62588a; font-size: 1.02rem; }
.label { margin: 14px 0 8px; font-weight: 700; }
.label small { font-weight: 400; color: #7a70a8; }
.hint-small { margin: 8px 0 0; font-size: 0.85rem; color: #7a70a8; }
.home-link { position: absolute; left: 18px; top: 14px; font-size: 0.85rem; color: #7a70a8; text-decoration: none; }
.home-link:hover { text-decoration: underline; }
.big-emoji { font-size: 4rem; line-height: 1; animation: wiggle 1.2s ease-in-out infinite; }
.rules { text-align: left; list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; font-weight: 600; font-size: 0.95rem; }
.rules li { background: #f6f2ff; border-radius: 14px; padding: 10px 14px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; }
.dot.red { background: #ff6b6b; }
.dot.green { background: #6bff9a; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12); }
/* ---------- buttons ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 8px; }
.card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px 8px; cursor: pointer;
  background: linear-gradient(180deg, #fff, #f1ebff); border: 3px solid #d9ccff; border-radius: 20px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s; font-size: 1rem;
}
.card .emoji { font-size: 2.4rem; }
.card small { color: #7a70a8; }
.card:hover, .card:focus-visible { transform: translateY(-4px) scale(1.03); border-color: var(--pri); box-shadow: 0 8px 18px rgba(124, 77, 255, 0.28); outline: none; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; cursor: pointer; font-weight: 800; font-size: 1.05rem;
  background: #fff; border: 3px solid #e1d8fa; border-radius: 16px; transition: all 0.12s;
}
.choice small { font-weight: 600; font-size: 0.72rem; color: #7a70a8; }
.choice:hover, .choice:focus-visible { border-color: var(--pri); outline: none; }
.choice.selected { border-color: var(--pri); background: #efe8ff; box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.2); }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 999px; padding: 12px 24px; font-size: 1.05rem; font-weight: 800; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}
.btn.primary { background: linear-gradient(180deg, #9a73ff, var(--pri)); color: #fff; box-shadow: 0 5px 0 var(--pri-d); }
.btn.primary:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.06); }
.btn.primary:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--pri-d); }
.btn.primary:disabled { filter: grayscale(0.6) opacity(0.6); cursor: default; }
.btn.ghost { background: #efeaff; color: var(--pri-d); }
.btn.ghost:hover { background: #e4dbff; }
/* ---------- setup slots ---------- */
.slots { display: grid; gap: 8px; }
.slot { display: flex; align-items: center; gap: 8px; background: #f6f2ff; border-radius: 16px; padding: 6px 8px; border-left: 8px solid var(--c); }
.slot .kind, .slot .animal { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: #fff; font-size: 1.5rem; cursor: pointer; box-shadow: 0 2px 8px rgba(60, 30, 140, 0.2); }
.slot .kind:hover, .slot .animal:hover { transform: scale(1.08); }
.slot input { flex: 1; min-width: 0; font: inherit; font-size: 1.05rem; padding: 10px 12px; border: 3px solid #d9ccff; border-radius: 14px; color: var(--ink); }
.slot input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; }
/* The HUD floats over the canvas: only the real controls catch the pointer, so you can still drag the view. */
#hud, #hud .topbar, #hud .toolbar, #hud .tray, #hud .tray-top, #hud .rollrow { pointer-events: none; }
#hud button, #hud .status, #hud .scorecard, #hud .prompt, #hud .played, #hud .hand { pointer-events: auto; }
.topbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px; flex: none; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--panel); font-size: 1.3rem; cursor: pointer; flex: none;
  box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25); transition: transform 0.12s;
}
.icon-btn:hover { transform: scale(1.1); }
.status {
  flex: 1; max-width: 640px; margin: 0 auto; text-align: center; font-weight: 800; font-size: 1.02rem; min-height: 46px;
  display: flex; align-items: center; justify-content: center; line-height: 1.2;
  background: var(--panel); padding: 8px 18px; border-radius: 999px; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25);
}
.status.good { background: #e8fff0; color: #1c7d45; }
.status.bad { background: #fff0f0; color: #c0392b; animation: shake 0.5s; }
.status.big { background: #fff8d9; color: #8a5a00; }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; z-index: 1; }
.toolbar { position: absolute; left: 10px; top: 66px; display: flex; flex-direction: column; gap: 8px; z-index: 2; }
.tool {
  display: flex; align-items: center; gap: 6px; height: 42px; padding: 0 12px; border-radius: 999px; border: 3px solid transparent; background: var(--panel);
  font-size: 0.9rem; font-weight: 800; cursor: pointer; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25); white-space: nowrap; transition: transform 0.12s;
}
.tool:hover { transform: translateX(3px) scale(1.04); }
.tool.on { border-color: var(--accent); background: #fff8d9; }
.tool .state { display: inline-block; padding: 1px 7px; border-radius: 999px; background: #e6e0f5; color: #6c6190; font-size: 0.75rem; }
.tool.on .state { background: var(--good); color: #fff; }
/* ---------- scoreboard ---------- */
.scorecard {
  position: absolute; right: 12px; top: 66px; width: 250px; padding: 12px 14px; background: var(--panel); border-radius: 20px;
  box-shadow: 0 6px 18px rgba(60, 30, 140, 0.28); z-index: 2; font-weight: 700;
}
.sc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.95rem; }
.sc-head .role { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 8px; border-radius: 999px; background: #efe8ff; color: var(--pri-d); }
.sc-main { display: flex; align-items: baseline; gap: 8px; margin: 2px 0 2px; }
.sc-main span { font-size: 2.1rem; font-weight: 900; line-height: 1; }
.sc-main small { color: #7a70a8; font-size: 0.9rem; }
.sc-target { margin: 2px 0 4px; padding: 4px 10px; border-radius: 12px; background: #fff8d9; color: #8a5a00; font-size: 0.85rem; }
.dots { display: flex; gap: 5px; margin: 6px 0; min-height: 26px; flex-wrap: wrap; }
.dots i {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 0.8rem; font-weight: 900;
  background: #efe8ff; color: #6c6190; animation: pop 0.3s cubic-bezier(.2, 1.4, .4, 1);
}
.dots i.r4 { background: #ffb347; color: #fff; }
.dots i.r6 { background: #e056c1; color: #fff; }
.dots i.w { background: var(--bad); color: #fff; }
.dots i.x { background: #ffe9a8; color: #8a5a00; font-size: 0.65rem; }
.sc-who { display: grid; gap: 2px; font-size: 0.85rem; margin-top: 4px; }
.sc-who > div { display: flex; gap: 6px; }
.sc-who .k { width: 1.3em; text-align: center; flex: none; }
.sc-who span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-field { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 2px dashed #e6defa; font-size: 0.78rem; color: #62588a; }
.legend { display: flex; align-items: center; gap: 4px; font-weight: 600; white-space: nowrap; }
.legend .dot { margin-left: 4px; }
/* ---------- card tray ---------- */
.tray {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); width: min(880px, calc(100vw - 20px)); z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.tray-top { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.prompt { background: var(--panel); border-radius: 999px; padding: 7px 18px; font-weight: 800; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25); text-align: center; }
.played { display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 999px; padding: 5px 8px; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25); font-weight: 800; font-size: 0.9rem; }
.played .vs { color: #7a70a8; font-size: 0.8rem; }
.played .chip-card { background: #f1ebff; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.played .chip-card.hidden-card { background: #ddd; color: #888; }
.hand { display: flex; gap: 10px; justify-content: center; max-width: 100%; padding: 6px 4px 4px; overflow-x: auto; overflow-y: visible; scrollbar-width: none; }
.hand::-webkit-scrollbar { display: none; }
.hand:empty { display: none; }
.pcard {
  position: relative; flex: none; width: 128px; min-height: 164px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 8px 8px;
  background: linear-gradient(180deg, #fff, #f6f1ff); border: 3px solid #d9ccff; border-radius: 18px; cursor: pointer; text-align: center;
  box-shadow: 0 6px 16px rgba(60, 30, 140, 0.28); transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s; animation: deal 0.35s cubic-bezier(.2, 1.3, .4, 1) backwards;
}
.pcard:nth-child(2) { animation-delay: 0.04s; } .pcard:nth-child(3) { animation-delay: 0.08s; } .pcard:nth-child(4) { animation-delay: 0.12s; } .pcard:nth-child(5) { animation-delay: 0.16s; }
@keyframes deal { from { transform: translateY(60px) rotate(8deg); opacity: 0; } to { transform: none; opacity: 1; } }
.pcard:hover, .pcard:focus-visible, .pcard.picked { transform: translateY(-12px) scale(1.04); border-color: var(--pri); box-shadow: 0 14px 24px rgba(124, 77, 255, 0.4); outline: none; z-index: 2; }
.pcard.picked { border-color: var(--accent); background: linear-gradient(180deg, #fffdf2, #fff3c4); }
.pcard.delivery { background: linear-gradient(180deg, #fff, #ffeef0); border-color: #ffc9d0; }
.pcard.delivery:hover, .pcard.delivery.picked { border-color: #e5484d; }
.pcard .c-key { position: absolute; left: 8px; top: 6px; font-size: 0.7rem; color: #a89ccf; font-weight: 800; }
.pcard .c-emoji { font-size: 2.1rem; line-height: 1.1; }
.pcard .c-name { font-size: 0.95rem; line-height: 1.1; }
.pcard .c-where { font-size: 0.72rem; color: #7a70a8; font-weight: 700; line-height: 1.15; }
.chip { display: inline-block; margin-top: auto; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 900; background: #efe8ff; color: #6c6190; }
.chip.good { background: #dcfbe7; color: #14733c; }
.chip.bad { background: #ffe1e1; color: #b8302f; }
.chip.warn { background: #fff0c9; color: #8a5a00; }
.chip + .chip { margin-top: 2px; }
.fieldpick { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.fbtn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; width: 150px; padding: 10px 8px; cursor: pointer; background: linear-gradient(180deg, #fff, #f1ebff);
  border: 3px solid #d9ccff; border-radius: 18px; box-shadow: 0 6px 16px rgba(60, 30, 140, 0.28); transition: transform 0.15s, border-color 0.15s;
}
.fbtn:hover, .fbtn:focus-visible { transform: translateY(-5px); border-color: var(--pri); outline: none; }
.fbtn .e { font-size: 1.8rem; }
.fbtn small { color: #7a70a8; font-weight: 700; font-size: 0.72rem; line-height: 1.15; text-align: center; }
.rollrow { display: flex; gap: 10px; justify-content: center; }
.rollrow .btn { padding: 11px 26px; }
#roll { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
/* ---------- toss & result ---------- */
.coin { font-size: 4.5rem; line-height: 1; animation: flip 1.2s ease-in-out; }
@keyframes flip { from { transform: rotateY(0) translateY(0); } 50% { transform: rotateY(900deg) translateY(-40px); } to { transform: rotateY(1800deg) translateY(0); } }
.over-card { display: grid; gap: 8px; text-align: left; margin-top: 6px; }
.over-card .inn { background: #f6f2ff; border-radius: 14px; padding: 8px 12px; font-weight: 700; font-size: 0.9rem; }
.over-card .inn b { display: flex; justify-content: space-between; font-size: 1.05rem; }
.over-card .inn small { color: #7a70a8; font-weight: 600; }
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
#confetti span { position: absolute; top: -10%; font-size: 1.8rem; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(115vh) rotate(540deg); } }
@media (prefers-reduced-motion: reduce) {
  .logo, .big-emoji, #roll, .coin, #confetti span, .pcard { animation: none; }
}
/* ---------- small screens ---------- */
@media (max-width: 859px) {
  .tool span:not(.e) { display: none; }
  .tool { width: 42px; padding: 0; justify-content: center; }
  .tool .e { font-size: 1.2rem; }
  .scorecard { left: 60px; right: 10px; top: 62px; width: auto; padding: 8px 12px; border-radius: 16px; }
  .sc-main span { font-size: 1.6rem; }
  .sc-who, .sc-field { display: none; }
  .dots { margin: 4px 0 0; min-height: 22px; }
  .dots i { width: 22px; height: 22px; font-size: 0.7rem; }
  .status { font-size: 0.9rem; min-height: 40px; padding: 6px 12px; }
  .pcard { width: 108px; min-height: 142px; padding: 8px 6px 6px; }
  .pcard .c-emoji { font-size: 1.7rem; }
  .pcard .c-name { font-size: 0.85rem; }
  .hand { justify-content: flex-start; }
}
@media (max-width: 859px) and (max-height: 700px) {
  .pcard { min-height: 118px; width: 98px; }
  .pcard .c-where { display: none; }
}
