:root {
  --wood-dark: #2b1a10; --wood: #4a2e1b; --wood-light: #6b4428; --cream: #f6ead2; --ink: #2b1a10;
  --ember: #e8772e; --gold: #f2c14e; --die: 56px; --half: 28px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--wood-dark); color: var(--cream); font: 16px/1.4 Georgia, "Times New Roman", serif; }
main { max-width: 640px; margin: 0 auto; padding: 0 16px 32px; }
h1 { margin: 8px 0; text-align: center; letter-spacing: 0.08em; color: var(--gold); }

.scene { position: relative; max-width: 640px; margin: 0 auto; }
.cabin { display: block; width: 100%; height: auto; }
.fire { position: absolute; left: 43.75%; bottom: 11%; width: 12.5%; transform-origin: 50% 100%; animation: flicker 0.9s ease-in-out infinite alternate; }
@keyframes flicker { from { transform: scale(1, 0.94) skewX(-2deg); opacity: 0.9; } to { transform: scale(1.05, 1.06) skewX(2deg); opacity: 1; } }

.panel { background: var(--wood); border: 2px solid var(--wood-light); border-radius: 12px; padding: 16px; }
label { display: block; margin: 8px 0; }
input { display: block; width: 100%; margin-top: 4px; padding: 10px; font: inherit; border: 0; border-radius: 8px; background: var(--cream); color: var(--ink); }
fieldset { border: 1px solid var(--wood-light); border-radius: 8px; margin: 8px 0; }
button { font: inherit; padding: 10px 18px; border: 0; border-radius: 8px; background: var(--ember); color: var(--ink); cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.45; cursor: default; }
button.quiet { background: var(--wood-light); color: var(--cream); }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.notice { background: var(--gold); color: var(--ink); padding: 8px 12px; border-radius: 8px; text-align: center; }
.code { font-size: 44px; letter-spacing: 0.25em; text-align: center; color: var(--gold); margin: 4px 0; }

.avatars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.avatar-pick { padding: 4px; background: transparent; border: 2px solid transparent; }
.avatar-pick[aria-pressed="true"] { border-color: var(--gold); background: var(--wood-light); }
.avatar { width: 48px; height: 48px; display: block; margin: 0 auto; }

.players { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 0; }
.players li { width: 76px; text-align: center; border: 2px solid transparent; border-radius: 10px; padding: 4px; overflow-wrap: anywhere; font-size: 13px; }
.players li.current { border-color: var(--gold); background: var(--wood); }
.players li.away { opacity: 0.5; }
.who, .points { display: block; }
.points { color: var(--gold); font-size: 16px; }
.turn { text-align: center; font-size: 20px; }
.actions { display: flex; justify-content: center; gap: 12px; margin: 12px 0; }

.tray { display: flex; justify-content: center; gap: 10px; padding: 12px 0; }
/* Each die has its own viewpoint, so a resting die shows its front face square on. */
.die { width: var(--die); height: var(--die); padding: 0; background: transparent; position: relative; perspective: 300px; }
.die:disabled { opacity: 1; }
.die.held { transform: translateY(10px); }
.die.held .face { background: var(--gold); }
.die.blank { opacity: 0.35; }
.cube { position: absolute; inset: 0; display: block; transform-style: preserve-3d; }
.face { position: absolute; inset: 0; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 6px; background: var(--cream); border: 1px solid #c9b58f; border-radius: 9px; backface-visibility: hidden; }
.pip { width: 10px; height: 10px; border-radius: 50%; background: var(--ink); place-self: center; }
.pip-1 { grid-area: 1 / 1; } .pip-2 { grid-area: 1 / 2; } .pip-3 { grid-area: 1 / 3; }
.pip-4 { grid-area: 2 / 1; } .pip-5 { grid-area: 2 / 2; } .pip-6 { grid-area: 2 / 3; }
.pip-7 { grid-area: 3 / 1; } .pip-8 { grid-area: 3 / 2; } .pip-9 { grid-area: 3 / 3; }
.face-1 { transform: rotateY(0deg) translateZ(var(--half)); }
.face-6 { transform: rotateY(180deg) translateZ(var(--half)); }
.face-3 { transform: rotateY(90deg) translateZ(var(--half)); }
.face-4 { transform: rotateY(-90deg) translateZ(var(--half)); }
.face-2 { transform: rotateX(90deg) translateZ(var(--half)); }
.face-5 { transform: rotateX(-90deg) translateZ(var(--half)); }
/* Each show-N turns face N to the front. */
.show-1 { --rx: 0deg; --ry: 0deg; }
.show-6 { --rx: 0deg; --ry: 180deg; }
.show-3 { --rx: 0deg; --ry: -90deg; }
.show-4 { --rx: 0deg; --ry: 90deg; }
.show-2 { --rx: -90deg; --ry: 0deg; }
.show-5 { --rx: 90deg; --ry: 0deg; }
.cube { transform: translateZ(calc(-1 * var(--half))) rotateX(var(--rx)) rotateY(var(--ry)); }
.tumble { animation: tumble 0.9s cubic-bezier(0.2, 0.7, 0.3, 1); }
@keyframes tumble {
  from { transform: translateY(-40px) translateZ(calc(-1 * var(--half))) rotateX(calc(var(--rx) - 720deg)) rotateY(calc(var(--ry) - 540deg)); }
  to { transform: translateY(0) translateZ(calc(-1 * var(--half))) rotateX(var(--rx)) rotateY(var(--ry)); }
}

.sheet-wrap { overflow-x: auto; }
.sheet { border-collapse: collapse; width: 100%; background: var(--cream); color: var(--ink); font-size: 14px; }
.sheet th, .sheet td { border: 1px solid #c9b58f; padding: 4px 6px; text-align: center; min-width: 52px; }
.sheet th[scope="row"] { position: sticky; left: 0; background: var(--cream); text-align: left; white-space: nowrap; }
.sheet th.current { background: var(--gold); }
.sheet .sum th, .sheet .sum td { font-style: italic; }
.sheet .total th, .sheet .total td { font-weight: bold; }
.take { padding: 4px 10px; min-width: 44px; }

@media (prefers-reduced-motion: reduce) { .tumble, .fire { animation: none; } }
