/* Backgammon — a café table by the sea. Self-contained. */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Manrope:wght@500;700;800&display=swap");

:root{
  --ink: #fbf3e3;
  --dim: rgba(251, 243, 227, 0.7);
  --faint: rgba(251, 243, 227, 0.42);
  --bg: #0f2a36;
  --sun: #f2b44c;
  --sun-lite: #ffdb94;
  --sea: #4a9cc0;
  --terra: #d9714a;
  --good: #a4dcb4;
  --line: rgba(255, 236, 200, 0.18);
  --glass: rgba(9, 27, 37, 0.8);
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after{ box-sizing: border-box; }
html, body{
  height: 100%; margin: 0; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
canvas#canvas{
  display: block; width: 100%; height: 100%; touch-action: none;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}

/* ---------- the opponent across the table ---------- */
.opp{
  position: fixed; z-index: 6; pointer-events: none;
  top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 11px;
  padding: 7px 14px 7px 8px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  max-width: min(520px, calc(100vw - 150px));
}
.opp[hidden]{ display: none; }
.opp__seal{ width: 40px; height: 40px; flex: none; }
.opp__body{ display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.opp__top{ display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.opp__name{ font-family: var(--font-display); font-weight: 700; font-size: 0.98rem; letter-spacing: 0.01em; white-space: nowrap; }
.opp__role{ font-size: 0.7rem; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp__say{ font-size: 0.74rem; color: var(--dim); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1em; }
.opp__say.is-think{ color: var(--sun); font-style: normal; }
.opp__say.is-think::after{
  content: "…"; display: inline-block; width: 0; overflow: hidden; vertical-align: bottom;
  animation: dots 1.1s steps(4, end) infinite;
}
@keyframes dots{ to{ width: 1.2em; } }
.opp__pips{ display: flex; flex-direction: column; align-items: flex-end; flex: none; padding-left: 10px; border-left: 1px solid var(--line); line-height: 1.1; }
.opp__pips b{ font-size: 0.98rem; font-variant-numeric: tabular-nums; }
.opp__pips small{ font-size: 0.6rem; color: var(--faint); letter-spacing: 0.08em; text-transform: uppercase; }

/* ---------- match score ---------- */
.score{
  position: fixed; z-index: 6; pointer-events: none;
  top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left));
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 11px 6px; min-width: 58px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.score[hidden]{ display: none; }
.score__row{ display: flex; align-items: baseline; gap: 5px; font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; line-height: 1; font-variant-numeric: tabular-nums; }
.score__me{ color: var(--sun-lite); }
.score__dash{ color: var(--faint); font-size: 0.9rem; }
.score__to{ font-size: 0.6rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
.score__to.is-crawford{ color: var(--terra); }
.score.is-bump .score__row{ animation: bump 700ms ease; }
@keyframes bump{ 30%{ transform: scale(1.25); } }

/* ---------- the bar ---------- */
.bar{
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: max(44px, calc(env(safe-area-inset-bottom) + 32px));
  display: flex; flex-wrap: nowrap; justify-content: center; align-items: center; gap: 6px;
  padding: 6px 7px 6px 12px;
  border: 1px solid var(--line); border-radius: 15px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  width: max-content; max-width: calc(100vw - 16px);
}
.bar[hidden]{ display: none; }
.me{ display: flex; flex-direction: column; margin-right: 6px; min-width: 86px; line-height: 1.15; }
.me__turn{ font-size: 0.76rem; font-weight: 800; color: var(--dim); white-space: nowrap; }
.me__turn.is-you{ color: var(--sun-lite); }
.me__pips{ font-size: 0.66rem; color: var(--faint); white-space: nowrap; }
.me__pips b{ color: var(--ink); font-variant-numeric: tabular-nums; }
.btn{
  appearance: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 0.8rem; font-weight: 800; letter-spacing: 0.01em;
  min-height: 40px; padding: 8px 13px; border-radius: 10px;
  border: 1px solid transparent; background: rgba(255, 236, 200, 0.09); color: var(--ink);
  transition: background 140ms ease, transform 120ms ease, opacity 140ms ease, box-shadow 140ms ease;
}
.btn[hidden]{ display: none; }
.btn:hover:not(:disabled){ background: rgba(255, 236, 200, 0.17); transform: translateY(-1px); }
.btn:disabled{ opacity: 0.3; cursor: default; }
.btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(242, 180, 76, 0.6); }
.btn--go{ background: linear-gradient(180deg, var(--sun-lite), var(--sun)); color: #33200a; min-width: 64px; }
.btn--go:hover:not(:disabled){ background: linear-gradient(180deg, #ffe4ad, #f6bd5c); }
.btn--go:not(:disabled){ box-shadow: 0 6px 20px -8px rgba(242, 180, 76, 0.9); }
.btn--go:disabled{ background: rgba(255, 236, 200, 0.09); color: var(--ink); }
.btn--go.is-ready:not(:disabled){ animation: ready 1.8s ease-in-out infinite; }
@keyframes ready{ 50%{ box-shadow: 0 6px 26px -4px rgba(255, 210, 120, 1); } }
.btn--cube{ background: rgba(217, 113, 74, 0.2); color: #ffc7ad; }
.btn--more{ padding: 8px 10px; font-size: 1rem; line-height: 1; }
.btn--big{ padding: 11px 16px; font-size: 0.86rem; }

.menu{
  position: fixed; z-index: 8;
  bottom: calc(max(44px, calc(env(safe-area-inset-bottom) + 32px)) + 58px);
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
  border: 1px solid var(--line); border-radius: 14px;
  background: rgba(9, 27, 37, 0.94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.menu[hidden]{ display: none; }

/* ---------- a question at the table (a double, the end of a game) ---------- */
.ask{
  position: fixed; z-index: 9; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 32px));
  padding: 18px 18px 16px; text-align: center;
  border: 1px solid rgba(255, 220, 160, 0.3); border-radius: 18px;
  background: linear-gradient(180deg, rgba(14, 40, 54, 0.95), rgba(8, 24, 33, 0.96));
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.85);
  animation: rise 260ms ease both;
}
.ask[hidden]{ display: none; }
@keyframes rise{ from{ opacity: 0; transform: translate(-50%, -44%); } }
.ask__title{ margin: 0 0 6px; font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; color: var(--sun-lite); }
.ask__text{ margin: 0 0 14px; font-size: 0.84rem; line-height: 1.5; color: var(--dim); }
.ask__text b{ color: var(--ink); }
.ask__btns{ display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ask__btns .btn{ min-width: 96px; }

/* ---------- callout + status note ---------- */
.callout{
  position: fixed; z-index: 7; pointer-events: none;
  left: 50%; top: 34%; transform: translate(-50%, -50%);
  font-family: var(--font-display); font-weight: 700; letter-spacing: 0.005em;
  font-size: clamp(1.5rem, 6vw, 2.7rem); line-height: 1;
  color: var(--sun-lite); text-align: center; white-space: nowrap;
  text-shadow: 0 2px 0 #6b3a08, 0 0 34px rgba(242, 180, 76, 0.55), 0 8px 30px rgba(0, 0, 0, 0.8);
}
.callout[hidden]{ display: none; }
.callout.is-bad{ color: #ffd0c0; text-shadow: 0 2px 0 #5e1a08, 0 0 30px rgba(217, 113, 74, 0.6), 0 8px 30px rgba(0, 0, 0, 0.8); }
.callout.is-pop{ animation: pop 1.4s ease both; }
@keyframes pop{
  0%{ opacity: 0; transform: translate(-50%, -40%) scale(0.86); }
  14%{ opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
  24%{ transform: translate(-50%, -50%) scale(1); }
  80%{ opacity: 1; }
  100%{ opacity: 0; transform: translate(-50%, -58%); }
}
.note{
  position: fixed; z-index: 6; pointer-events: none; margin: 0;
  left: 50%; transform: translateX(-50%);
  bottom: calc(max(44px, calc(env(safe-area-inset-bottom) + 32px)) + 60px);
  padding: 5px 12px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 700; color: var(--ink); white-space: nowrap;
  background: rgba(9, 27, 37, 0.72);
  opacity: 0; transition: opacity 260ms ease;
}
.note.is-on{ opacity: 1; }

/* ---------- sound ---------- */
.sound-btn{
  position: fixed; z-index: 7;
  top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--glass); color: var(--ink);
  font-size: 15px; cursor: pointer; backdrop-filter: blur(8px);
  transition: transform 140ms ease, border-color 140ms ease, opacity 140ms ease;
}
.sound-btn:hover{ transform: translateY(-1px); border-color: var(--sun); }
.sound-btn[aria-pressed="false"]{ opacity: 0.45; }
.sound-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(242, 180, 76, 0.5); }

/* ---------- overlays ---------- */
.overlay{
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(90% 70% at 50% 40%, rgba(10, 34, 46, 0.66), rgba(4, 14, 20, 0.94));
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  transition: opacity 240ms ease; overflow-y: auto;
}
.overlay[hidden]{ display: none; }
.overlay.is-out{ opacity: 0; pointer-events: none; }
.panel{
  max-width: 720px; width: 100%; text-align: center; margin: auto;
  padding: clamp(20px, 4vw, 30px);
  border: 1px solid var(--line); border-radius: 20px;
  background: linear-gradient(180deg, rgba(16, 44, 58, 0.93), rgba(8, 24, 33, 0.95));
  box-shadow: 0 30px 90px -20px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 236, 200, 0.08);
}
.panel--result{ max-width: 540px; }
.panel__eyebrow{ margin: 0 0 4px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.24em; text-transform: uppercase; color: var(--sun); }
.panel__title{
  margin: 0 0 12px; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.2rem, 7.6vw, 3.3rem); letter-spacing: -0.005em; line-height: 1.02;
  color: var(--ink); text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.5);
}
.panel__text{ margin: 0 auto 16px; max-width: 52ch; font-size: 0.88rem; line-height: 1.6; color: var(--dim); }
.panel__text b{ color: var(--ink); font-weight: 800; }

.opts{ display: flex; flex-wrap: wrap; gap: 10px 14px; justify-content: center; align-items: center; margin: 0 0 14px; }
.opts__note{ flex-basis: 100%; margin: -4px 0 0; font-size: 0.74rem; color: var(--faint); }
.switch{
  appearance: none; cursor: pointer; display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 6px; border: 0; background: none; color: var(--dim);
  font-family: var(--font-ui); font-size: 0.84rem; font-weight: 700; border-radius: 10px;
}
.switch:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(242, 180, 76, 0.5); }
.switch__track{ position: relative; width: 38px; height: 22px; border-radius: 999px; background: rgba(255, 236, 200, 0.16); transition: background 160ms ease; flex: none; }
.switch__dot{ position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: transform 160ms ease; }
.switch[aria-checked="true"]{ color: var(--ink); }
.switch[aria-checked="true"] .switch__track{ background: var(--terra); }
.switch[aria-checked="true"] .switch__dot{ transform: translateX(16px); background: #2a1206; }

/* ---------- the regulars ---------- */
.cast{ display: grid; gap: 8px; margin: 0 0 16px; grid-template-columns: repeat(3, 1fr); }
.foe{
  appearance: none; cursor: pointer; text-align: left; position: relative;
  display: flex; flex-direction: column; gap: 5px;
  padding: 11px 11px 12px;
  border: 1px solid var(--line); border-radius: 14px;
  background: rgba(255, 236, 200, 0.04); color: var(--ink);
  font-family: var(--font-ui);
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}
.foe:hover{ transform: translateY(-3px); background: rgba(255, 236, 200, 0.09); border-color: rgba(242, 180, 76, 0.42); }
.foe:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(242, 180, 76, 0.55); }
.foe.is-pick{ border-color: rgba(242, 180, 76, 0.55); }
.foe__seal{ width: 38px; height: 38px; }
.foe__name{ font-family: var(--font-display); font-weight: 700; font-size: 0.96rem; }
.foe__role{ font-size: 0.68rem; color: var(--faint); margin-top: -3px; }
.foe__trait{ font-size: 0.72rem; line-height: 1.45; color: var(--dim); }
.foe__won{ position: absolute; top: 9px; right: 10px; font-size: 0.9rem; color: var(--good); }
.foe__pips{ display: flex; gap: 3px; margin-top: 1px; }
.foe__pip{ width: 12px; height: 3px; border-radius: 2px; background: rgba(255, 236, 200, 0.15); }
.foe__pip.on{ background: var(--sun); }

.play-btn{
  appearance: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: 1.06rem; letter-spacing: 0.01em;
  padding: 12px 28px; border-radius: 999px; border: 0;
  background: linear-gradient(180deg, var(--sun-lite), var(--sun));
  color: #33200a; box-shadow: 0 10px 30px -8px rgba(242, 180, 76, 0.6), inset 0 -2px 0 rgba(120, 70, 10, 0.35);
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.play-btn:hover{ transform: translateY(-2px); box-shadow: 0 16px 38px -10px rgba(242, 180, 76, 0.8), inset 0 -2px 0 rgba(120, 70, 10, 0.35); }
.play-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(242, 180, 76, 0.55); }
.panel__or{ margin: 14px 0 10px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); }
.panel__keys{ margin: 4px 0 0; font-size: 0.7rem; color: var(--faint); line-height: 1.6; }

/* ---------- result ---------- */
.result__line{ margin: 8px 0 4px; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim); }
.result__btns{ display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
.result__record{ margin: 14px 0 8px; font-size: 0.72rem; color: var(--faint); }
.panel--result [data-more-games]{ margin-top: 14px; }

/* ---------- frame + hint ---------- */
.frame{ position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.frame__corner{ position: fixed; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--faint); }
.frame__corner--tl{ top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); }
.frame__corner--tr{ top: max(14px, env(safe-area-inset-top)); right: max(62px, calc(env(safe-area-inset-right) + 62px)); }
.frame__corner--bl{ bottom: max(14px, env(safe-area-inset-bottom)); left: max(14px, env(safe-area-inset-left)); pointer-events: auto; }
.frame__corner--bl a{ color: var(--faint); text-decoration: none; }
.frame__corner--bl a:hover{ color: var(--sun); }
body.is-playing .frame__corner--tl, body.is-playing .frame__corner--tr{ display: none; }
.hint{
  position: fixed; z-index: 4; pointer-events: none;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 4px)); left: 50%; transform: translateX(-50%);
  margin: 0; font-size: 0.7rem; letter-spacing: 0.06em; color: var(--faint); white-space: nowrap;
  transition: opacity 500ms ease;
}
.hint.is-gone{ opacity: 0; }

/* ---------- responsive ---------- */
@media (max-width: 720px){
  .cast{ grid-template-columns: repeat(2, 1fr); }
  .panel__text{ font-size: 0.82rem; }
}
@media (max-width: 620px){
  .hint{ display: none; }
  .opp{ max-width: calc(100vw - 162px); padding: 6px 10px 6px 6px; gap: 8px; }
  .opp__seal{ width: 32px; height: 32px; }
  .opp__name{ font-size: 0.86rem; }
  .opp__role{ display: none; }
  .opp__pips{ padding-left: 8px; }
  .score{ min-width: 52px; padding: 6px 8px 5px; }
  .score__cube{ display: none; }
  /* clear the tickets pill and the docked badges along the bottom edge */
  .bar{ bottom: max(84px, calc(env(safe-area-inset-bottom) + 72px)); gap: 5px; padding: 5px 5px 5px 10px; }
  .menu{ bottom: calc(max(84px, calc(env(safe-area-inset-bottom) + 72px)) + 56px); }
  .note{ bottom: calc(max(84px, calc(env(safe-area-inset-bottom) + 72px)) + 58px); }
  .btn{ padding: 7px 10px; font-size: 0.76rem; }
  .btn--go{ min-width: 58px; }
  .me{ min-width: 74px; margin-right: 2px; }
  .me__turn{ font-size: 0.72rem; }
}
@media (max-width: 380px){
  .me{ min-width: 0; }
  .me__turn{ max-width: 78px; overflow: hidden; text-overflow: ellipsis; }
  .btn{ padding: 7px 8px; }
}
@media (max-height: 560px){
  .opp{ top: max(6px, env(safe-area-inset-top)); padding: 4px 10px 4px 6px; }
  .opp__seal{ width: 28px; height: 28px; }
  .score{ top: max(6px, env(safe-area-inset-top)); padding: 4px 9px; }
  .sound-btn{ top: max(6px, env(safe-area-inset-top)); }
  .bar{ bottom: max(6px, env(safe-area-inset-bottom)); padding: 4px 5px 4px 10px; }
  .btn{ min-height: 36px; padding: 6px 10px; }
  .menu{ bottom: calc(max(6px, env(safe-area-inset-bottom)) + 52px); }
  .note{ bottom: calc(max(6px, env(safe-area-inset-bottom)) + 54px); }
  .hint{ display: none; }
}
@media (prefers-reduced-motion: reduce){
  .play-btn, .sound-btn, .overlay, .btn, .foe, .switch__dot, .switch__track, .note{ transition: none; }
  .callout.is-pop, .ask, .btn--go.is-ready, .score.is-bump .score__row{ animation: none; }
  .opp__say.is-think::after{ animation: none; width: 1.2em; }
}

/* The board fills the middle of the screen, so the shared tip-jar / full-screen
   badges at right-center would sit on the bear-off tray. Dock them along the
   bottom edge, side by side, under the bar. Doubled classes out-specify the
   injected styles. */
.opt-tipjar.opt-tipjar{ top: auto; bottom: max(12px, env(safe-area-inset-bottom)); transform: none; }
.opt-fs.opt-fs{ top: auto; bottom: max(13px, calc(env(safe-area-inset-bottom) + 1px)); right: max(56px, calc(env(safe-area-inset-right) + 56px)); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge{ animation: none; }
