/* Spud & Root: town/bar.html, Ship, Captain and Crew (bar-dice.js).
 * The bar top in dark oak under the lamp, a leather cup, ivory dice, and a
 * red leather mat with chalk wells for ship, captain, crew and cargo.
 * --die is set by the script from the room on the bar. */

.bdice {
  --die: 48px;
  --oak-deep: #3a2214;
  --oak: #5a341c;
  --brass: #d9a441;
  --leather: #7a1f1f;
  --ivory: #fbf1da;
  --chalk: rgba(255, 244, 222, 0.62);
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  /* clear of the engine's buttons above and its captions below */
  padding: 66px 16px 88px;
  box-sizing: border-box;
  font-family: var(--font-body);
  color: var(--ink);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.bdice *,
.bdice *::before,
.bdice *::after {
  box-sizing: border-box;
}
.bdice [hidden] {
  display: none !important;
}

.bdice__frame {
  position: relative;
  width: 100%;
  max-width: 880px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

/* ---------- Scoreline and status ---------- */
.bdice__head {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bdice__scores {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
}
.bdice__score {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  min-height: 42px;
  padding: 3px 14px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  background: var(--cream);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s;
}
.bdice__score.is-on {
  background: var(--logo-yellow);
}
.bdice__score--them {
  padding-right: 4px;
}
.bdice__pts {
  min-width: 1.6em;
  padding: 0 6px;
  font-size: 1.25rem;
  line-height: 1.3;
  text-align: center;
  color: var(--white);
  background: var(--ink);
  border-radius: var(--radius-pill);
}
.bdice__face {
  width: 34px;
  height: 34px;
  object-fit: contain;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.bdice__mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
  color: var(--cream);
  text-align: center;
  text-shadow: 0 2px 0 var(--ink);
}
.bdice__round {
  font-size: 0.78rem;
  color: var(--brass);
}

.bdice__statusrow {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
}
.bdice__status,
.bdice__beat {
  margin: 0;
  padding: 6px 16px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.25;
  background: var(--white);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}
.bdice__status {
  flex: 0 1 auto;
  min-width: 0;
  min-height: calc(1.25em + 18px);
  text-align: center;
}
.bdice__beat {
  flex: 0 0 auto;
  white-space: nowrap;
  background: var(--logo-yellow);
}
.bdice__beat b {
  font-weight: 700;
}

/* ---------- The bar top ---------- */
.bdice__bar {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border: var(--stroke) solid var(--ink);
  border-radius: 22px;
  box-shadow: 6px 6px 0 var(--ink);
  /* the lamp's pool of light on polished oak, and a faint grain */
  background:
    radial-gradient(ellipse 65% 75% at 50% 0%, rgba(255, 190, 110, 0.26), rgba(255, 190, 110, 0) 70%),
    repeating-linear-gradient(179deg, rgba(0, 0, 0, 0) 0 26px, rgba(0, 0, 0, 0.1) 26px 28px, rgba(0, 0, 0, 0) 28px 61px, rgba(255, 214, 160, 0.06) 61px 63px),
    var(--oak);
}
/* the bar's front edge: darker oak with a brass rail */
.bdice__bar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: max(14px, calc(var(--die) * 0.3));
  background: var(--oak-deep);
  border-top: 3px solid var(--brass);
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* the mat: deep red leather with chalk lines */
.bdice__mat {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px 6px;
  background: var(--leather);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: 4px 4px 0 var(--ink), inset 0 0 0 3px #8e2a28;
}
.bdice__crew {
  display: flex;
  align-items: flex-start;
  gap: inherit;
}
/* a phone held upright: the cargo on its own row */
.bdice.is-stacked .bdice__mat {
  flex-direction: column;
  align-items: center;
  row-gap: 4px;
}
.bdice.is-stacked .bdice__slot--cargo {
  margin-left: 0;
}
.bdice__slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.bdice__wells {
  display: flex;
  gap: 6px;
  padding: 0 4px;
  border: 2px dashed var(--chalk);
  border-radius: 12px;
}
.bdice__slot--cargo {
  margin-left: 4px;
}
.bdice__well {
  position: relative;
  display: block;
  width: calc(var(--die) + 12px);
  height: calc(var(--die) + 12px);
  border: 2px dashed var(--chalk);
  border-radius: 12px;
}
.bdice__wells .bdice__well {
  width: calc(var(--die) + 6px);
  height: calc(var(--die) + 8px);
  border: 0;
}
/* the number the well is waiting for, in chalk */
.bdice__well[data-need]::before {
  content: attr(data-need);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: calc(var(--die) * 0.55);
  color: rgba(255, 244, 222, 0.22);
}
.bdice__well.is-next {
  border-color: var(--logo-yellow);
}
.bdice__well.is-next::before {
  color: rgba(255, 222, 0, 0.75);
}
.bdice__well.is-full::before {
  content: none;
}
.bdice__label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: max(11px, calc(var(--die) * 0.25));
  line-height: 1.2;
  color: var(--cream);
  white-space: nowrap;
}
.bdice__label b {
  display: inline-block;
  min-width: 1.4em;
  color: var(--logo-yellow);
}

/* the cup: brown leather, stitched rim; it shakes, then tips */
.bdice__cup {
  position: absolute;
  left: 4%;
  bottom: calc(max(14px, var(--die) * 0.3) + 6px);
  width: calc(var(--die) * 1.4);
  height: calc(var(--die) * 1.736);
  padding: 0;
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transform-origin: 85% 95%;
  transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
  filter: drop-shadow(4px 4px 0 var(--ink));
  z-index: 2;
}
.bdice__cup svg {
  display: block;
  width: 100%;
  height: 100%;
}
.bdice__cup[aria-disabled="true"] {
  cursor: default;
}
@media (hover: hover) {
  .bdice__cup.is-ready:hover {
    transform: translateY(-3px) rotate(-3deg);
  }
  .bdice__btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--ink);
  }
}
.bdice__cup.is-shaking {
  animation: bdice-shake 0.12s linear infinite;
}
.bdice__cup.is-tipped {
  transform: rotate(78deg);
}
@keyframes bdice-shake {
  0% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(-3px, -4px) rotate(-7deg); }
  75% { transform: translate(3px, -2px) rotate(7deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* the dice: ivory, rounded, ink outline, black pips */
.bdice__die {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--die);
  height: var(--die);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: calc(var(--die) * 0.12);
  background: var(--ivory);
  border: max(2px, calc(var(--die) * 0.05)) solid var(--ink);
  border-radius: 24%;
  box-shadow: max(2px, calc(var(--die) * 0.05)) max(2px, calc(var(--die) * 0.05)) 0 var(--ink);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  will-change: transform;
}
.bdice__pip {
  align-self: center;
  justify-self: center;
  width: 62%;
  height: 62%;
  background: #1b1718;
  border-radius: 50%;
  visibility: hidden;
}

/* the nudge beside the cup at the start */
.bdice__hint {
  position: absolute;
  z-index: 1;
  margin: 0;
  transform: translateY(-50%);
  max-width: 46%;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: max(13px, calc(var(--die) * 0.26));
  line-height: 1.2;
  color: var(--cream);
  text-shadow: 0 2px 0 var(--ink);
  pointer-events: none;
}
.bdice__hint::before {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin: 0 0.45em 0.08em 0;
  border-left: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: rotate(45deg);
}

/* the round's result, over the open bar */
.bdice__banner {
  position: absolute;
  left: 50%;
  top: 60%;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px 20px;
  transform: translate(-50%, -50%);
  text-align: center;
  background: var(--cream);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  animation: bdice-pop 0.3s var(--ease-spring);
  pointer-events: none;
}
.bdice__banner b {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
}
.bdice__banner span {
  font-family: var(--font-display);
  font-size: 0.95rem;
}
@keyframes bdice-pop {
  from { transform: translate(-50%, -50%) scale(0.85); }
  to { transform: translate(-50%, -50%) scale(1); }
}

/* ---------- Buttons ---------- */
.bdice__controls {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
}
.bdice__btn {
  min-height: 50px;
  min-width: 120px;
  padding: 10px 24px;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
  background: var(--white);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.15s, opacity 0.15s;
}
.bdice__btn--roll,
.bdice__btn--again {
  background: var(--logo-yellow);
}
.bdice__btn--help {
  min-width: 50px;
  width: 50px;
  padding: 0;
  font-size: 1.3rem;
}
.bdice__btn:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}
/* not now: a muted card colour, still focusable so focus doesn't jump */
.bdice__btn[aria-disabled="true"] {
  color: #776b66;
  background: #cbbfa9;
  cursor: default;
  transform: none;
  box-shadow: var(--shadow-sm);
}
.bdice__btn:focus-visible,
.bdice__cup:focus-visible {
  outline: 3px solid var(--logo-yellow);
  outline-offset: 4px;
}
.bdice__btn--roll:focus-visible,
.bdice__btn--again:focus-visible {
  outline-color: var(--white);
}

/* How to play: above the buttons (beside them on landscape phones) */
.bdice__help {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 12px);
  z-index: 6;
  width: min(400px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 12px 16px;
  font-size: 0.95rem;
  line-height: 1.4;
  background: var(--cream);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.bdice__help p {
  margin: 0 0 6px;
}
.bdice__help .bdice__helptitle {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
}
.bdice__help p:last-child {
  margin: 0;
}

/* ---------- Match over ---------- */
.bdice__card {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 70px 16px 24px;
  background: rgba(35, 31, 32, 0.45);
}
.bdice__cardin {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(320px, 100%);
  padding: 20px 24px 24px;
  text-align: center;
  background: var(--cream);
  border: var(--stroke) solid var(--ink);
  border-radius: 22px;
  box-shadow: 6px 6px 0 var(--ink);
  animation: bdice-card 0.3s var(--ease-spring);
}
@keyframes bdice-card {
  from { transform: scale(0.9); }
  to { transform: scale(1); }
}
.bdice__cardtitle {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.45rem;
  line-height: 1.15;
}
.bdice__cardscore {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 1.1rem;
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  /* room at the bottom for the engine's captions */
  .bdice {
    padding: 66px 12px 96px;
  }
  .bdice__frame {
    gap: 8px;
  }
  .bdice__score {
    min-height: 38px;
    padding: 2px 10px;
    font-size: 0.95rem;
  }
  .bdice__score--them {
    padding-right: 3px;
  }
  .bdice__face {
    width: 30px;
    height: 30px;
  }
  .bdice__mid {
    font-size: 0.8rem;
  }
  .bdice__status,
  .bdice__beat {
    padding: 5px 12px;
    font-size: 0.9rem;
  }
  .bdice__btn {
    min-height: 48px;
    min-width: 104px;
    padding: 8px 18px;
  }
  .bdice__btn--help {
    min-width: 48px;
    width: 48px;
  }
  .bdice__mat {
    gap: 5px;
    padding: 6px 7px 4px;
  }
  .bdice__well {
    width: calc(var(--die) + 10px);
    height: calc(var(--die) + 10px);
    border-radius: 10px;
  }
  .bdice__wells {
    gap: 4px;
    padding: 0 3px;
  }
  .bdice__wells .bdice__well {
    width: calc(var(--die) + 4px);
    height: calc(var(--die) + 6px);
  }
  .bdice__slot--cargo {
    margin-left: 2px;
  }
}

/* Landscape phones: scoreline and status side by side, the buttons in a
   column beside the bar */
@media (max-height: 520px) and (orientation: landscape) {
  .bdice {
    padding: 64px 16px 56px;
  }
  .bdice__frame {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px 12px;
  }
  .bdice__head {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .bdice__scores {
    flex: 0 1 auto;
    gap: 10px;
  }
  .bdice__score {
    min-height: 36px;
    padding: 2px 10px;
    font-size: 0.9rem;
    box-shadow: 3px 3px 0 var(--ink);
  }
  .bdice__face {
    width: 28px;
    height: 28px;
  }
  .bdice__mid {
    font-size: 0.78rem;
  }
  .bdice__statusrow {
    flex: 0 1 auto;
    justify-content: flex-end;
  }
  .bdice__status,
  .bdice__beat {
    padding: 4px 12px;
    font-size: 0.88rem;
    box-shadow: 3px 3px 0 var(--ink);
  }
  .bdice__bar {
    grid-column: 1;
    grid-row: 2;
  }
  .bdice__controls {
    grid-column: 2;
    grid-row: 2;
    flex-direction: column;
    justify-content: flex-start;
    padding: 2px 4px 0 0;
  }
  .bdice__btn {
    min-height: 44px;
    min-width: 116px;
    padding: 6px 14px;
  }
  .bdice__btn--help {
    min-width: 44px;
    width: 44px;
  }
  .bdice__help {
    left: auto;
    right: calc(100% + 14px);
    bottom: auto;
    top: 0;
    width: min(380px, 62vw);
    transform: none;
  }
}

/* opts.reduceMotion (and the system setting): no shaking, no pops */
.bdice.is-reduced .bdice__cup.is-shaking,
.bdice.is-reduced .bdice__banner,
.bdice.is-reduced .bdice__cardin {
  animation: none;
}
@media (prefers-reduced-motion: reduce) {
  .bdice__cup.is-shaking,
  .bdice__banner,
  .bdice__cardin {
    animation: none;
  }
}
