/* Poster: big flat shapes, few colors, square edges, no shadows. */
:root {
  --cloth: var(--ak-accent);
  --deep: var(--ak-btn-fill);
  --amber: var(--ak-accent-2);
  --cream: var(--ak-bg);
  --wood: var(--ak-ink-muted);
  --pale-amber: color-mix(in srgb, var(--ak-accent-2) 42%, var(--ak-bg));
  --edge: 2px;
  --gap: 8px;
  --pad-top: max(8px, env(safe-area-inset-top));
  --pad-right: max(12px, env(safe-area-inset-right));
  --pad-bottom: max(10px, env(safe-area-inset-bottom));
  --pad-left: max(12px, env(safe-area-inset-left));
  --corner: 48px;
  --tray-tok: 48px;
  --mini: 22px;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, var(--ak-bg-art));
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* ---------- frame ---------- */

.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head" "board" "panel";
  gap: var(--gap);
  width: min(100%, 560px);
  margin: 0 auto;
  padding: var(--pad-top) var(--pad-right) var(--pad-bottom) var(--pad-left);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* Until the kit's start screen hands over, the game stays out of layout, so none of its
   pictures hold up the page load the start screen waits for. */
.app.is-idle { display: none; }

.head {
  grid-area: head;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  min-height: var(--corner);
  padding: 0 calc(var(--corner) + 8px);
}

.logo {
  display: block;
  height: 44px;
  width: auto;
}

.mute {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 30;
  display: grid;
  place-items: center;
  width: var(--corner);
  height: var(--corner);
  padding: 0;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  cursor: pointer;
}

.mute svg { width: 24px; height: 24px; }
.mute .mute-off { display: none; }
.mute[aria-pressed="true"] .mute-on { display: none; }
.mute[aria-pressed="true"] .mute-off { display: block; }

/* ---------- the table ---------- */

.board-wrap {
  grid-area: board;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  container-type: size;
}

.board {
  --W: min(92vw, 40dvh);
  position: relative;
  width: var(--W);
  height: calc(var(--W) * 1.08);
}

@supports (width: 1cqh) {
  .board { --W: min(100cqw, calc(100cqh / 1.08)); }
}

.window {
  position: absolute;
  top: 0;
  left: 50%;
  width: 46%;
  height: 15%;
  transform: translateX(-50%);
}

.window-glass {
  fill: var(--pale-amber);
  stroke: var(--wood);
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}

.window-frame {
  fill: none;
  stroke: var(--wood);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.table {
  --chair: 0.185;
  --tok: max(44px, calc(var(--W) * var(--chair) * 0.84));
  --seat: max(46px, calc(var(--W) * var(--chair)));
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--W);
  height: var(--W);
}

.table[data-chairs="8"] { --chair: 0.165; }

.cloth {
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  background: var(--cloth);
}

.cloth::after {
  content: '';
  position: absolute;
  inset: 5%;
  border: 2px solid var(--amber);
  border-radius: 50%;
}

.numeral {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--cream);
  font-family: var(--ak-font-display);
  font-weight: 700;
  /* A third of the screen tall: the digit's ink is about 0.76 of its size. */
  font-size: min(calc(33dvh / 0.76), calc(var(--W) * 0.84));
  line-height: 1;
  pointer-events: none;
  /* Lining digits sit on the baseline; lift them to the middle of the cloth. */
  translate: 0 -4%;
}

.numeral.is-word {
  font-size: calc(var(--W) * 0.15);
  letter-spacing: -0.01em;
}

.chair {
  position: absolute;
  display: grid;
  place-items: center;
  width: var(--seat);
  height: var(--seat);
  padding: 0;
  border: 0;
  background: none;
  transform: translate(-50%, -50%);
  cursor: pointer;
  touch-action: none;
}

.chair-shape {
  position: absolute;
  inset: 0;
  /* The seat sits low in the picture; lift it so a token lands on the seat. */
  transform: rotate(var(--turn)) translateY(-9%);
  background: var(--amber);
  -webkit-mask: url("./art/chair.png") center / contain no-repeat;
  mask: url("./art/chair.png") center / contain no-repeat;
}

.chair.is-window .chair-shape {
  background: url("./art/chair.png") center / contain no-repeat;
  -webkit-mask: none;
  mask: none;
}

.chair::after {
  content: '';
  position: absolute;
  inset: -5px;
  border: 3px dashed transparent;
  border-radius: 50%;
  pointer-events: none;
}

.chair.is-open-pick::after { border-color: var(--cream); }

/* Where a note points: a solid amber ring with a dark rim, readable on cloth and floor. */
.chair.is-zone::after {
  border: 4px solid var(--amber);
  outline: 2px solid var(--ak-ink);
}

.chair.is-target::after { border: 4px solid var(--cream); outline: 0; }

.chair.is-blocked::after,
.chair.is-refused::after {
  border: 4px solid var(--ak-accent);
  outline: 2px solid var(--cream);
}

.refuse-mark {
  position: absolute;
  top: -10px;
  right: -10px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--ak-accent);
  border-radius: 50%;
  background: var(--cream);
  color: var(--ak-accent);
}

.refuse-mark svg { width: 14px; height: 14px; }

.chair.is-host { cursor: default; }

.host-crown {
  position: relative;
  width: var(--tok);
  height: var(--tok);
}

.host-crown .crown-back { fill: var(--cream); stroke: var(--ak-ink); stroke-width: 3; }
.host-crown .crown { fill: var(--deep); }

/* ---------- guest tokens ---------- */

.token {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--tok);
  height: var(--tok);
  pointer-events: none;
}

.token-art {
  display: block;
  width: calc(var(--tok) * var(--sw) / 106);
  height: var(--tok);
  background-image: url("./art/guest-tokens.png");
  background-repeat: no-repeat;
  background-size: calc(var(--tok) * 384 / 106) calc(var(--tok) * 228 / 106);
  background-position: calc(var(--tok) * var(--sx) / -106) calc(var(--tok) * var(--sy) / -106);
}

.token::after {
  content: '';
  position: absolute;
  inset: -4px;
  border: 3px solid transparent;
  border-radius: 50%;
}

.is-selected > .token::after { border-color: var(--cream); outline: 3px solid var(--ak-ink); }
.is-lit > .token::after { border-color: var(--amber); }
.is-pointed > .token::after { border-color: var(--amber); outline: 3px solid var(--cream); outline-offset: -6px; }
.is-lifted > .token { opacity: 0.3; }

.ghost {
  position: fixed;
  z-index: 50;
  left: 0;
  top: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.12);
}

/* ---------- ledger: the evening and the streak, in the table's empty corner ---------- */

.ledger {
  padding: 5px 8px 5px 9px;
  border-left: 5px solid var(--amber);
  background: var(--ak-surface);
  color: var(--ak-ink);
  pointer-events: none;
}

.ledger p { margin: 0; }

.ledger-top {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.pips { display: flex; gap: 4px; }

/* Done, now, and still to come differ by fill and edge, not by color alone. */
.pip {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 2px solid var(--ak-choice-border);
  border-radius: 50%;
  color: var(--ak-ink-muted);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
}

.pip.is-now { border: 3px solid var(--amber); background: var(--cream); color: var(--ak-ink); }
.pip.is-done { border: 2px solid var(--deep); background: var(--deep); color: var(--ak-btn-ink); }

.ledger-moves,
.ledger-streak {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
}

.ledger.is-broken .ledger-run { color: var(--ak-accent); }

/* Upright the logo heads the screen; sideways it sits in the table's empty top-right corner,
   and the ledger takes its place beside the status. */
.logo-corner { display: none; }

@media (orientation: landscape) {
  .logo-head { display: none; }

  .logo-corner {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 3;
    display: block;
    height: 48px;
  }
}

/* ---------- guided pointer ---------- */

.pointer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pointer-ring {
  position: absolute;
  width: calc(var(--seat) * 1.34);
  height: calc(var(--seat) * 1.34);
  border: 4px solid var(--cream);
  outline: 3px solid var(--amber);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.pointer-arrow {
  position: absolute;
  width: calc(var(--W) * 0.07);
  height: calc(var(--W) * 0.11);
  transform: translate(-50%, -50%) rotate(var(--turn));
}

.pointer-arrow path {
  fill: var(--amber);
  stroke: var(--ak-ink);
  stroke-width: 3;
  stroke-linejoin: round;
}

/* ---------- panel ---------- */

.panel {
  grid-area: panel;
  display: grid;
  gap: var(--gap);
  min-width: 0;
  container-type: inline-size;
}

.status {
  min-height: 66px;
  padding: 8px 12px;
  border-left: 6px solid var(--amber);
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.caption,
.message {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

.caption { font-weight: 700; }
.caption + .message:not(:empty) { margin-top: 4px; }
.caption + .message:not(.is-wrong) { font-size: 16px; }
.message.is-wrong { color: var(--ak-accent); font-weight: 700; }

.tray {
  display: flex;
  justify-content: center;
  gap: 0;
  min-height: calc(var(--tray-tok) + 18px);
  padding: 4px 0 2px;
  border-top: var(--edge) solid var(--wood);
  border-bottom: var(--edge) solid var(--wood);
}

.slot {
  --tok: var(--tray-tok);
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 1 60px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: none;
}

.slot .token { margin-bottom: 6px; }

.slot-name {
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
  color: var(--ak-ink);
}

.slot-empty {
  width: var(--tok);
  height: var(--tok);
  border: 2px dashed var(--ak-choice-border);
  border-radius: 50%;
}

.slot.is-empty .slot-name { color: var(--ak-ink-muted); font-weight: 400; }

.notes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px 8px;
  padding-top: 8px;
}

.note {
  --tok: var(--mini);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 3px 6px;
  border: var(--edge) solid var(--deep);
  border-radius: 0;
  background: var(--cream);
  color: var(--ak-ink);
  text-align: left;
  cursor: pointer;
}

.note::before {
  content: '';
  position: absolute;
  top: -7px;
  left: 50%;
  width: 18px;
  height: 7px;
  transform: translateX(-50%);
  background: var(--deep);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.note-icons {
  display: flex;
  gap: 2px;
}

.note-icons svg {
  display: block;
  width: var(--mini);
  height: var(--mini);
}

.note-text {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}

/* The verdict pins to the card's corner so the words keep the whole width. */
.note-mark {
  position: absolute;
  top: -11px;
  right: -9px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: var(--cream);
}

.note-mark:empty { display: none; }

/* A kind of note this evening has not had yet. */
/* It sits on the card's top edge, right of the notch and left of the verdict mark, over no words or faces. */
.note-new {
  position: absolute;
  top: -13px;
  right: 22px;
  padding: 0 5px;
  border: 2px solid var(--deep);
  background: var(--cream);
  color: var(--deep);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 12px;
  text-transform: uppercase;
}

.note-mark svg { display: block; width: 14px; height: 14px; }

.note.is-lit {
  border-color: var(--amber);
  outline: 3px solid var(--amber);
  outline-offset: -1px;
}

.note.is-failed {
  border: 3px solid var(--ak-accent);
  outline: 3px solid var(--ak-accent);
  outline-offset: 0;
}

.note.is-failed::before { background: var(--ak-accent); }
.note.is-failed .note-mark { color: var(--ak-accent); }

.note.is-held {
  border: 3px solid var(--amber);
  outline: 3px solid var(--amber);
  outline-offset: 0;
}

.note.is-held::before { background: var(--amber); }
.note.is-held .note-mark { color: var(--amber); }

.actions {
  display: flex;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
  min-width: 48px;
  padding: 0 14px;
  border: var(--edge) solid var(--ak-outline);
  border-radius: 0;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

.btn svg { width: 22px; height: 22px; flex: none; }

.btn-primary { background: var(--ak-btn-fill); color: var(--ak-btn-ink); }
.btn-primary:active { background: var(--ak-btn-active); }
.btn-quiet { background: var(--ak-choice-bg); color: var(--ak-choice-ink); border-color: var(--ak-choice-border); }
.btn-quiet:disabled { color: var(--ak-ink-muted); cursor: default; }
.btn-check { flex: 1; }

.btn-check[aria-disabled="true"] {
  background: var(--ak-choice-bg);
  color: var(--ak-ink-muted);
  border: var(--edge) dashed var(--ak-choice-border);
}

@media (hover: hover) {
  .btn-primary:hover { background: var(--ak-btn-hover); }
  .btn-check[aria-disabled="true"]:hover { background: var(--ak-choice-bg); }
}

/* ---------- ending poster ---------- */

.flood {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--deep);
  visibility: hidden;
}

.is-over-page .flood { visibility: visible; }

.is-over-page .mute { border-color: var(--cream); }

/* The ending keeps the notes, now all ticked, so the seating can be read against them.
   The result sits above them and the next step below. */
.app.is-over .status,
.app.is-over .tray,
.app.is-over .actions { display: none; }

/* The help button belongs to the kit; on the dark poster it needs a light rim to be seen. */
.is-over-page #activity-help { border-color: var(--cream); }

.ending:not([hidden]) { display: contents; }

.end-result {
  order: -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-left: 6px solid var(--amber);
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.end-card {
  display: block;
  width: 84px;
  height: auto;
}

.end-words p { margin: 0; }

.end-reason {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.end-says {
  margin-top: 2px;
  font-family: var(--ak-font-display);
  font-size: 16px;
  line-height: 1.3;
}

.end-streak,
.end-next {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.3;
}

.end-next { font-weight: 700; }

.end-actions {
  order: 1;
  display: flex;
  gap: 8px;
}

.end-actions .btn { flex: 1; }

.btn-light {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border: 3px solid var(--amber);
}

.btn-ghost {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border-color: var(--ak-choice-border);
}

/* Upright the poster keeps the table big: the ticked notes become a short list to read, not tap. */
@media (orientation: portrait) {
  .app.is-over .notes { gap: 11px 6px; }
  .app.is-over .note { --mini: 18px; min-height: 0; padding: 3px 6px; pointer-events: none; }
  .app.is-over .note-text { font-size: 12px; line-height: 1.2; }
  .app.is-over .note-mark { width: 20px; height: 20px; top: -9px; }
  .app.is-over .note-mark svg { width: 12px; height: 12px; }
  .end-card { width: 64px; }
  .end-says { font-size: 15px; }
}

/* ---------- phone on its side ---------- */

@media (orientation: landscape) {
  .app {
    width: min(100%, 1100px);
    grid-template-columns: minmax(0, 1fr) minmax(min(430px, 56vw), 1.1fr);
    grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas: "board ." "board panel" "board .";
    row-gap: 0;
    column-gap: 16px;
  }

  /* The ledger runs along the top of the status band as one line; the logo is in the table's corner. */
  .head {
    grid-area: panel;
    align-self: start;
    justify-self: stretch;
    z-index: 2;
    min-height: 0;
    margin: 8px calc(var(--corner) + 14px) 0 16px;
    padding: 0;
    pointer-events: none;
  }

  .panel { align-content: start; }

  .status {
    min-height: 72px;
    margin-right: calc(var(--corner) + 6px);
    padding-top: 29px;
  }

  .ledger-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0;
    border: 0;
    background: none;
    white-space: nowrap;
  }

  .ledger-head .ledger-moves,
  .ledger-head .ledger-streak { margin: 0; font-size: 12px; }

  .notes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .note-icons { flex-direction: column; }

  /* Sideways the ledger steps aside: the result says the same, with room for the notes below it. */
  .app.is-over .head { display: none; }
  .end-result { grid-template-columns: minmax(0, 1fr); margin-right: calc(var(--corner) + 6px); padding: 6px 10px; }
  .end-card { display: none; }
  .end-says { font-size: 15px; }
}

@media (orientation: landscape) and (max-height: 480px) {
  .app { --gap: 6px; }
  .tray { min-height: calc(var(--tray-tok) + 4px); padding: 1px 0; }
  .slot .token { margin-bottom: 0; }
  .slot-name { display: none; }
  .caption { line-height: 1.22; }
  .message { font-size: 16px; line-height: 1.25; }
  .status { padding: 29px 10px 6px; }
  .notes { gap: 10px 6px; padding-top: 6px; }
  .note { --mini: 19px; padding: 2px 5px; gap: 5px; }
  .note-text { font-size: 12px; }
  .btn { min-height: 48px; }
}

/* A short phone held upright: names go, the initials on the tokens already match them. */
@media (orientation: portrait) and (max-height: 760px) {
  .slot .token { margin-bottom: 0; }
  .slot-name { display: none; }
  .tray { min-height: calc(var(--tray-tok) + 8px); }
}

/* ---------- motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  .token.is-settling { animation: settle 280ms cubic-bezier(0.3, 1.5, 0.5, 1); }

  .pointer-ring { animation: pulse 1.3s ease-in-out infinite; }

  .note.is-held {
    animation: flip 380ms ease-in-out both;
    animation-delay: calc(var(--i) * 120ms);
  }

  .is-solving .chair .token {
    animation: cheer 340ms ease-out both;
    animation-delay: calc(var(--i) * 90ms);
  }

  .numeral.is-word { animation: stamp 420ms cubic-bezier(0.2, 1.4, 0.4, 1) both; }

  .is-over-page .flood { animation: flood 520ms cubic-bezier(0.6, 0, 0.3, 1) both; }

  .app.is-over .end-result,
  .app.is-over .end-actions { animation: rise 420ms cubic-bezier(0.2, 1, 0.4, 1) 160ms both; }

  .app.is-over .board { animation: grow 520ms cubic-bezier(0.2, 1, 0.4, 1) both; }

  .ledger.is-up,
  .ledger.is-broken { animation: nudge 420ms cubic-bezier(0.3, 1.5, 0.5, 1); }
}

@keyframes settle {
  0% { transform: translateY(-10%) scale(1.14); }
  55% { transform: translateY(2%) scale(0.95); }
  100% { transform: none; }
}

@keyframes pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes flip {
  0% { transform: scaleX(1); border-color: var(--deep); outline-color: transparent; }
  49% { transform: scaleX(0); border-color: var(--deep); outline-color: transparent; }
  50% { transform: scaleX(0); border-color: var(--amber); outline-color: var(--amber); }
  100% { transform: scaleX(1); border-color: var(--amber); outline-color: var(--amber); }
}

@keyframes cheer {
  0% { transform: none; }
  45% { transform: translateY(-12%) scale(1.1); }
  100% { transform: none; }
}

@keyframes stamp {
  0% { opacity: 0; transform: scale(1.5); }
  100% { opacity: 1; transform: none; }
}

@keyframes flood {
  0% { clip-path: circle(0% at 50% 40%); }
  100% { clip-path: circle(150% at 50% 40%); }
}

@keyframes rise {
  0% { opacity: 0; transform: translateY(24px); }
  100% { opacity: 1; transform: none; }
}

@keyframes nudge {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: none; }
}

@keyframes grow {
  0% { transform: scale(0.94); }
  100% { transform: none; }
}
