/* Mancala — the back room of a bookshop, after closing. Self-contained. */

@import url("https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@600;700&family=Manrope:wght@500;700;800&display=swap");

:root{
  --ink: #f7ecd9;
  --dim: rgba(247, 236, 217, 0.72);
  --faint: rgba(247, 236, 217, 0.44);
  --bg: #120c09;
  --brass: #dcaa58;
  --brass-lite: #f6d593;
  --p1: #f2c46d;
  --p2: #7fd6c4;
  --ruby: #e0566a;
  --line: rgba(255, 226, 186, 0.17);
  --glass: rgba(20, 13, 9, 0.8);
  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", 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 regular across the board ---------- */
.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 15px 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));
  transition: border-color 260ms ease, box-shadow 260ms ease;
}
.opp[hidden]{ display: none; }
.opp.is-turn{ border-color: rgba(127, 214, 196, 0.5); box-shadow: 0 0 0 1px rgba(127, 214, 196, 0.18), 0 8px 30px -10px rgba(127, 214, 196, 0.45); }
.opp__seal{ width: 40px; height: 40px; flex: none; }
.opp__body{ display: flex; flex-direction: column; gap: 1px; 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: 1.12rem; letter-spacing: 0.01em; white-space: nowrap; line-height: 1.1; }
.opp__role{ font-size: 0.7rem; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp__say{ font-size: 0.75rem; color: var(--dim); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1em; }
.opp__say.is-think{ color: var(--brass-lite); 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; } }

/* ---------- 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; }
.turn{ display: inline-flex; align-items: center; gap: 8px; margin-right: 6px; min-width: 112px; font-size: 0.8rem; font-weight: 800; color: var(--dim); white-space: nowrap; }
.turn__dot{ width: 10px; height: 10px; border-radius: 50%; flex: none; background: rgba(255, 236, 200, 0.2); transition: background 200ms ease, box-shadow 200ms ease; }
.turn.is-p1{ color: var(--brass-lite); }
.turn.is-p1 .turn__dot{ background: var(--p1); box-shadow: 0 0 10px 1px rgba(242, 196, 109, 0.75); }
.turn.is-p2{ color: #b5efe3; }
.turn.is-p2 .turn__dot{ background: var(--p2); box-shadow: 0 0 10px 1px rgba(127, 214, 196, 0.75); }
.turn.is-wait .turn__dot{ animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe{ 50%{ opacity: 0.35; } }
.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, 230, 196, 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, 230, 196, 0.17); transform: translateY(-1px); }
.btn:disabled{ opacity: 0.3; cursor: default; }
.btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(220, 170, 88, 0.65); }
.btn--go{ background: linear-gradient(180deg, var(--brass-lite), var(--brass)); color: #34210a; min-width: 64px; }
.btn--go:hover:not(:disabled){ background: linear-gradient(180deg, #ffe2a9, #e6b664); }
.btn--big{ padding: 11px 16px; font-size: 0.86rem; }

.bar--replay{ padding: 6px; gap: 5px; }
.rp__label{ display: inline-flex; flex-direction: column; align-items: center; min-width: 96px; padding: 0 4px; line-height: 1.2; }
#rpLabel{ font-size: 0.78rem; font-weight: 800; white-space: nowrap; }
.rp__count{ font-size: 0.64rem; color: var(--faint); font-variant-numeric: tabular-nums; }

/* ---------- callout + status note ---------- */
.callout{
  position: fixed; z-index: 7; pointer-events: none;
  left: 50%; top: 30%; transform: translate(-50%, -50%);
  font-family: var(--font-display); font-weight: 700; letter-spacing: 0.01em;
  font-size: clamp(1.9rem, 7.4vw, 3.3rem); line-height: 1;
  color: var(--brass-lite); text-align: center; white-space: nowrap;
  text-shadow: 0 2px 0 #5b3a0c, 0 0 36px rgba(242, 190, 100, 0.6), 0 8px 30px rgba(0, 0, 0, 0.85);
}
.callout[hidden]{ display: none; }
.callout.is-p2{ color: #c9f5ea; text-shadow: 0 2px 0 #0d4038, 0 0 36px rgba(127, 214, 196, 0.6), 0 8px 30px rgba(0, 0, 0, 0.85); }
.callout.is-bad{ color: #ffd0c6; text-shadow: 0 2px 0 #561410, 0 0 30px rgba(224, 86, 106, 0.6), 0 8px 30px rgba(0, 0, 0, 0.85); }
.callout.is-pop{ animation: pop 1.3s ease both; }
@keyframes pop{
  0%{ opacity: 0; transform: translate(-50%, -40%) scale(0.86); }
  14%{ opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  24%{ transform: translate(-50%, -50%) scale(1); }
  78%{ 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: 6px 13px; border-radius: 999px;
  max-width: calc(100vw - 24px); text-align: center;
  font-size: 0.78rem; font-weight: 700; color: var(--ink);
  background: rgba(20, 13, 9, 0.84); border: 1px solid var(--line);
  opacity: 0; transition: opacity 260ms ease;
}
.note.is-on{ opacity: 1; }

/* ---------- corner buttons ---------- */
.corner-btn{
  position: fixed; z-index: 7;
  top: max(12px, env(safe-area-inset-top));
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--glass); color: var(--ink);
  font-family: var(--font-ui); font-size: 15px; cursor: pointer; backdrop-filter: blur(8px);
  transition: transform 140ms ease, border-color 140ms ease, opacity 140ms ease;
}
.sound-btn{ right: max(12px, env(safe-area-inset-right)); }
.counts-btn{ right: max(58px, calc(env(safe-area-inset-right) + 58px)); font-size: 12px; font-weight: 800; letter-spacing: 0.02em; }
.corner-btn:hover{ transform: translateY(-1px); border-color: var(--brass); }
.corner-btn[aria-pressed="false"]{ opacity: 0.45; }
.corner-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(220, 170, 88, 0.55); }

/* ---------- 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(30, 18, 11, 0.66), rgba(8, 5, 3, 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(36, 23, 15, 0.94), rgba(16, 10, 7, 0.96));
  box-shadow: 0 30px 90px -20px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 230, 196, 0.08);
}
.panel--result{ max-width: 540px; }
.panel__eyebrow{ margin: 0 0 2px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.24em; text-transform: uppercase; color: var(--brass); }
.panel__title{
  margin: 0 0 10px; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 3.9rem); letter-spacing: 0.005em; line-height: 1;
  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: 54ch; font-size: 0.88rem; line-height: 1.6; color: var(--dim); }
.panel__text b{ color: var(--ink); font-weight: 800; }

.opts{ display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 0 0 16px; }
.opts__note{ margin: -3px auto 2px; max-width: 46ch; font-size: 0.76rem; line-height: 1.5; color: var(--faint); min-height: 2.3em; }
.seg{ display: inline-flex; padding: 3px; border-radius: 12px; background: rgba(255, 230, 196, 0.07); border: 1px solid var(--line); }
.seg__btn{
  appearance: none; cursor: pointer; border: 0; background: none; color: var(--dim);
  font-family: var(--font-display); font-weight: 700; font-size: 1.12rem; letter-spacing: 0.02em;
  min-height: 40px; padding: 6px 22px; border-radius: 9px;
  transition: background 160ms ease, color 160ms ease;
}
.seg--small .seg__btn{ font-family: var(--font-ui); font-size: 0.8rem; font-weight: 800; padding: 6px 15px; }
.seg__btn[aria-checked="true"]{ background: linear-gradient(180deg, rgba(246, 213, 147, 0.95), rgba(220, 170, 88, 0.95)); color: #34210a; }
.seg__btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(220, 170, 88, 0.55); }
.switches{ display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; }
.switch{
  appearance: none; cursor: pointer; display: inline-flex; align-items: center; gap: 10px;
  min-height: 40px; 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(220, 170, 88, 0.5); }
.switch__track{ position: relative; width: 38px; height: 22px; border-radius: 999px; background: rgba(255, 230, 196, 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(--brass); }
.switch[aria-checked="true"] .switch__dot{ transform: translateX(16px); background: #2a1806; }

/* ---------- the regulars ---------- */
.cast{ display: grid; gap: 8px; margin: 0 0 16px; grid-template-columns: repeat(3, 1fr); }
.cast[hidden]{ display: none; }
.foe{
  appearance: none; cursor: pointer; text-align: left; position: relative;
  display: flex; flex-direction: column; gap: 4px;
  padding: 11px 11px 12px;
  border: 1px solid var(--line); border-radius: 14px;
  background: rgba(255, 230, 196, 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, 230, 196, 0.09); border-color: rgba(220, 170, 88, 0.45); }
.foe:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(220, 170, 88, 0.6); }
.foe.is-pick{ border-color: rgba(220, 170, 88, 0.6); background: rgba(255, 230, 196, 0.08); }
.foe__seal{ width: 38px; height: 38px; }
.foe__name{ font-family: var(--font-display); font-weight: 700; font-size: 1.12rem; line-height: 1.1; }
.foe__role{ font-size: 0.68rem; color: var(--faint); margin-top: -2px; }
.foe__trait{ font-size: 0.72rem; line-height: 1.45; color: var(--dim); }
.foe__won{ position: absolute; top: 9px; right: 10px; display: flex; gap: 4px; }
.foe__won i{ font-style: normal; font-size: 0.58rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 5px; border-radius: 6px; background: rgba(127, 214, 196, 0.16); color: #b5efe3; }
.foe__pips{ display: flex; gap: 3px; margin-top: 1px; }
.foe__pip{ width: 12px; height: 3px; border-radius: 2px; background: rgba(255, 230, 196, 0.15); }
.foe__pip.on{ background: var(--brass); }

.play-btn{
  appearance: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; letter-spacing: 0.01em;
  padding: 11px 30px; border-radius: 999px; border: 0;
  background: linear-gradient(180deg, var(--brass-lite), var(--brass));
  color: #34210a; box-shadow: 0 10px 30px -8px rgba(220, 170, 88, 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(220, 170, 88, 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(246, 213, 147, 0.7); }
.panel__or{ margin: 14px 0 10px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); }
.panel__or[hidden]{ display: none; }
.panel__keys{ margin: 4px 0 0; font-size: 0.7rem; color: var(--faint); line-height: 1.6; }

/* ---------- result ---------- */
.result__line{ margin: 8px 0 2px; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim); }
.result__score{ margin: -2px 0 8px; font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; color: var(--brass-lite); font-variant-numeric: lining-nums; }
.result__why{ margin: -6px auto 14px; max-width: 46ch; font-size: 0.76rem; line-height: 1.5; color: var(--faint); }
.result__why:empty{ display: none; }
.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(108px, calc(env(safe-area-inset-right) + 108px)); }
.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(--brass); }
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 - 132px); padding: 6px 11px 6px 6px; gap: 8px; left: max(12px, env(safe-area-inset-left)); transform: none; }
  .opp__seal{ width: 32px; height: 32px; }
  .opp__name{ font-size: 1rem; }
  .opp__role{ display: none; }
  /* clear the tickets pill and the docked badges along the bottom edge */
  .bar{ bottom: max(62px, calc(env(safe-area-inset-bottom) + 52px)); gap: 5px; padding: 5px 5px 5px 11px; }
  .note{ bottom: calc(max(62px, calc(env(safe-area-inset-bottom) + 52px)) + 56px); }
  .btn{ padding: 7px 11px; font-size: 0.76rem; }
  .turn{ min-width: 96px; margin-right: 2px; font-size: 0.76rem; }
  .rp__label{ min-width: 70px; }
  .bar--replay .btn{ padding: 7px 9px; }
}
@media (max-width: 380px){
  .turn{ min-width: 0; }
  .btn{ padding: 7px 9px; }
  .bar--replay{ gap: 3px; }
  .bar--replay .btn{ padding: 7px 7px; }
  .rp__label{ min-width: 58px; }
}
@media (max-width: 620px) and (max-height: 740px){
  .bar{ bottom: max(52px, calc(env(safe-area-inset-bottom) + 42px)); padding: 4px 4px 4px 10px; }
  .btn{ min-height: 36px; padding: 6px 10px; }
  .note{ bottom: calc(max(52px, calc(env(safe-area-inset-bottom) + 42px)) + 50px); }
  .opp{ top: max(8px, env(safe-area-inset-top)); padding: 5px 10px 5px 5px; }
  .opp__seal{ width: 30px; height: 30px; }
  .corner-btn{ top: max(8px, env(safe-area-inset-top)); width: 38px; height: 38px; }
}
@media (max-height: 560px){
  .opp{ top: max(6px, env(safe-area-inset-top)); padding: 4px 10px 4px 6px; left: max(12px, env(safe-area-inset-left)); transform: none; }
  .opp__seal{ width: 28px; height: 28px; }
  .corner-btn{ top: max(6px, env(safe-area-inset-top)); width: 36px; height: 36px; }
  .counts-btn{ right: max(52px, calc(env(safe-area-inset-right) + 52px)); }
  .bar{ bottom: max(6px, env(safe-area-inset-bottom)); padding: 4px 5px 4px 10px; }
  .btn{ min-height: 36px; padding: 6px 10px; }
  .note{ bottom: calc(max(6px, env(safe-area-inset-bottom)) + 52px); }
  .hint{ display: none; }
  .callout{ top: 24%; }
}
@media (prefers-reduced-motion: reduce){
  .play-btn, .corner-btn, .overlay, .btn, .foe, .switch__dot, .switch__track, .note, .seg__btn, .opp{ transition: none; }
  .callout.is-pop, .turn.is-wait .turn__dot{ 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 a store. Dock them along the bottom edge,
   side by side. 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; }
