/* Reversi — the card room of a London club, 1888, by gaslight. Self-contained. */

@import url("https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,600;0,700;0,800;1,600&family=Manrope:wght@500;700;800&display=swap");

:root{
  --ink: #f3ead8;
  --dim: rgba(243, 234, 216, 0.76);
  --faint: rgba(243, 234, 216, 0.48);
  --bg: #0b120e;
  --lamp: #d9a84e;
  --lamp-lite: #f3d68f;
  --fog: #a9bccb;
  --blood: #9b2b25;
  --line: rgba(232, 200, 130, 0.18);
  --glass: rgba(10, 18, 14, 0.84);
  --font-display: "Playfair Display", "Didot", 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(217, 168, 78, 0.55); box-shadow: 0 0 0 1px rgba(217, 168, 78, 0.18), 0 8px 30px -10px rgba(217, 168, 78, 0.5); }
.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.08rem; letter-spacing: 0.01em; white-space: nowrap; line-height: 1.15; }
.opp__role{ font-size: 0.7rem; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp__say{ font-family: var(--font-display); font-size: 0.8rem; color: var(--dim); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1em; }
.opp__say.is-think{ font-family: var(--font-ui); font-size: 0.75rem; color: var(--lamp-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: 9px; margin-right: 6px; min-width: 128px; color: var(--dim); white-space: nowrap; }
.turn__disc{ width: 17px; height: 17px; border-radius: 50%; flex: none; background: radial-gradient(circle at 35% 30%, #4a3f38, #120d0b 72%); box-shadow: 0 1px 0 #f0e4c8 inset, 0 2px 0 #3a2a1c, 0 2px 4px rgba(0,0,0,0.6); }
.turn__disc.is-white{ background: radial-gradient(circle at 35% 30%, #fffaf0, #e2d6bb 75%); box-shadow: 0 2px 0 #1a1411, 0 2px 4px rgba(0,0,0,0.6); }
.turn__text{ display: flex; flex-direction: column; line-height: 1.2; }
#turnText{ font-size: 0.8rem; font-weight: 800; color: var(--ink); }
.turn__sub{ font-size: 0.66rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.turn.is-wait .turn__disc{ animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe{ 50%{ opacity: 0.4; } }
.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(236, 214, 160, 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(236, 214, 160, 0.17); transform: translateY(-1px); }
.btn:disabled{ opacity: 0.3; cursor: default; }
.btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(217, 168, 78, 0.65); }
.btn--go{ background: linear-gradient(180deg, var(--lamp-lite), var(--lamp)); color: #2a1d08; }
.btn--go:hover:not(:disabled){ background: linear-gradient(180deg, #f8e2a6, #e2b25c); }
.btn--toggle[aria-pressed="true"]{ background: rgba(217, 168, 78, 0.2); color: var(--lamp-lite); box-shadow: inset 0 0 0 1px rgba(217, 168, 78, 0.5); }
.btn--big{ padding: 11px 16px; font-size: 0.86rem; }
.btn--wide{ min-width: 128px; }
.btn--sure{ background: rgba(155, 43, 37, 0.3); }

/* ---------- 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.8rem, 7vw, 3.1rem); line-height: 1;
  color: var(--lamp-lite); text-align: center; white-space: nowrap;
  text-shadow: 0 2px 0 #4a320c, 0 0 36px rgba(230, 180, 90, 0.6), 0 8px 30px rgba(0, 0, 0, 0.85);
}
.callout[hidden]{ display: none; }
.callout.is-cool{ color: #e3edf4; text-shadow: 0 2px 0 #22323d, 0 0 36px rgba(169, 188, 203, 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: 7; pointer-events: none; margin: 0;
  left: 50%; transform: translateX(-50%);
  top: calc(max(12px, env(safe-area-inset-top)) + 66px);
  padding: 6px 13px; border-radius: 999px;
  width: max-content; max-width: calc(100vw - 24px); text-align: center;
  font-size: 0.78rem; font-weight: 700; color: var(--ink);
  background: rgba(10, 18, 14, 0.88); 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)); }
.help-btn{ right: max(58px, calc(env(safe-area-inset-right) + 58px)); font-weight: 800; font-size: 16px; }
.corner-btn:hover{ transform: translateY(-1px); border-color: var(--lamp); }
.corner-btn[aria-pressed="false"]{ opacity: 0.45; }
.corner-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(217, 168, 78, 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(14, 30, 22, 0.6), rgba(4, 8, 6, 0.95));
  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; }
.overlay--lesson{ z-index: 12; }
.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(22, 36, 28, 0.96), rgba(9, 14, 11, 0.97));
  box-shadow: 0 30px 90px -20px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(236, 214, 160, 0.08);
}
.panel--result{ max-width: 540px; }
.panel--lesson{ max-width: 420px; }
.panel__eyebrow{ margin: 0 0 4px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.24em; text-transform: uppercase; color: var(--lamp); }
.panel__title{
  margin: 0 0 10px; font-family: var(--font-display); font-weight: 800;
  font-size: clamp(2.6rem, 9vw, 3.9rem); letter-spacing: 0.02em; line-height: 1.05;
  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: -2px auto 2px; max-width: 46ch; font-size: 0.76rem; line-height: 1.5; color: var(--faint); min-height: 2.3em; }
.seg{ display: inline-flex; flex-wrap: wrap; justify-content: center; padding: 3px; border-radius: 12px; background: rgba(236, 214, 160, 0.07); border: 1px solid var(--line); }
.seg[hidden]{ display: none; }
.seg__btn{
  appearance: none; cursor: pointer; border: 0; background: none; color: var(--dim);
  font-family: var(--font-ui); font-weight: 800; font-size: 0.86rem; letter-spacing: 0.01em;
  min-height: 40px; padding: 6px 16px; border-radius: 9px;
  transition: background 160ms ease, color 160ms ease;
}
.seg--small .seg__btn{ font-size: 0.8rem; padding: 6px 14px; }
.seg__btn[aria-checked="true"]{ background: linear-gradient(180deg, rgba(243, 214, 143, 0.95), rgba(217, 168, 78, 0.95)); color: #2a1d08; }
.seg__btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(217, 168, 78, 0.55); }

/* ---------- the regulars ---------- */
.cast{ display: grid; gap: 8px; margin: 0 0 10px; grid-template-columns: repeat(3, 1fr); }
.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(236, 214, 160, 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(236, 214, 160, 0.09); border-color: rgba(217, 168, 78, 0.45); }
.foe:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(217, 168, 78, 0.6); }
.foe.is-pick{ border-color: rgba(217, 168, 78, 0.6); background: rgba(236, 214, 160, 0.08); }
.foe__seal{ width: 38px; height: 38px; }
.foe__name{ font-family: var(--font-display); font-weight: 700; font-size: 1.08rem; line-height: 1.15; }
.foe__role{ font-size: 0.68rem; color: var(--faint); margin-top: -2px; }
.foe__rank{ font-size: 0.64rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--lamp); }
.foe__trait{ font-size: 0.72rem; line-height: 1.45; color: var(--dim); }
.foe__won{ position: absolute; top: 9px; right: 10px; font-style: normal; font-size: 0.58rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; background: rgba(169, 188, 203, 0.18); color: #e3edf4; max-width: 58%; text-align: right; }

.play-btn{
  appearance: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; letter-spacing: 0.01em;
  padding: 11px 30px; border-radius: 999px; border: 0;
  background: linear-gradient(180deg, var(--lamp-lite), var(--lamp));
  color: #2a1d08; box-shadow: 0 10px 30px -8px rgba(217, 168, 78, 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(217, 168, 78, 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(243, 214, 143, 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__fine{ margin: 0 0 8px; font-size: 0.66rem; color: var(--faint); }
.panel__keys{ margin: 4px 0 0; font-size: 0.7rem; color: var(--faint); line-height: 1.7; }
.linkbtn{ appearance: none; border: 0; background: none; padding: 2px 0; cursor: pointer; font: inherit; font-weight: 800; color: var(--lamp-lite); text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(217, 168, 78, 0.55); border-radius: 4px; }

/* ---------- the lesson ---------- */
.lesson__stage{ display: flex; justify-content: center; margin: 6px 0 12px; }
#lessonCv{ width: 240px; height: 240px; border-radius: 14px; box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.9); }
.lesson__title{ margin: 0 0 6px; font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; }
.lesson__text{ margin: 0 auto 8px; max-width: 40ch; font-size: 0.86rem; line-height: 1.55; color: var(--dim); min-height: 4.6em; }
.lesson__aside{ margin: 0 auto 12px; max-width: 40ch; font-size: 0.76rem; line-height: 1.5; color: var(--faint); }
.lesson__aside:empty{ display: none; }
.lesson__aside b{ color: var(--lamp-lite); }
.lesson__nav{ display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lesson__nav .btn{ min-width: 84px; }
.lesson__dots{ display: flex; gap: 6px; }
.lesson__dots i{ width: 7px; height: 7px; border-radius: 50%; background: rgba(236, 214, 160, 0.2); }
.lesson__dots i.on{ background: var(--lamp); }

/* ---------- 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.3rem; color: var(--lamp-lite); font-variant-numeric: lining-nums; }
.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); }
.result__quote{ font-family: var(--font-display); font-style: italic; font-size: 1.02rem; }
.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(--lamp); }
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; }
  .seg__btn{ padding: 6px 12px; font-size: 0.8rem; }
}
@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: 0.98rem; }
  .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 10px; }
  .note{ top: calc(max(12px, env(safe-area-inset-top)) + 58px); }
  .btn{ padding: 7px 11px; font-size: 0.76rem; }
  .turn{ min-width: 104px; margin-right: 2px; gap: 7px; }
  #turnText{ font-size: 0.76rem; }
  .seg__btn{ padding: 6px 10px; }
  .panel{ padding: 18px 14px; }
}
@media (max-width: 380px){
  .turn{ min-width: 0; }
  .btn{ padding: 7px 9px; }
  .seg__btn{ padding: 6px 8px; font-size: 0.76rem; }
}
@media (max-width: 620px) and (max-height: 740px){
  .bar{ bottom: max(52px, calc(env(safe-area-inset-bottom) + 42px)); padding: 4px 4px 4px 9px; }
  .btn{ min-height: 36px; padding: 6px 10px; }
  .note{ top: calc(max(8px, env(safe-area-inset-top)) + 52px); }
  .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; }
  #lessonCv{ width: 200px; height: 200px; }
}
@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; }
  .help-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{ top: calc(max(6px, env(safe-area-inset-top)) + 50px); }
  .hint{ display: none; }
  .callout{ top: 24%; }
  #lessonCv{ width: 170px; height: 170px; }
}
@media (prefers-reduced-motion: reduce){
  .play-btn, .corner-btn, .overlay, .btn, .foe, .note, .seg__btn, .opp{ transition: none; }
  .callout.is-pop, .turn.is-wait .turn__disc{ 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 it. 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; }

.sr-only{ position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.panel__title{ letter-spacing: 0.01em; }
.foe__name, .opp__name{ letter-spacing: 0; }
