/* The phone client.
 *
 * Light, warm and loud. A room playing tombala is a lit room with people talking
 * in it, not a cockpit — the dark version of this read as software, and the thing
 * it is standing in for is cream card stock and primary colours.
 *
 * Large targets, because the one tap that matters is made in a hurry by someone
 * who is also shouting. Nothing loaded from outside: no font, no framework, no CDN
 * — the host serves this over plain HTTP on a room network with no internet, and
 * anything external would simply hang.
 *
 * Colours live in custom properties so the brand pack can replace them at runtime
 * with one `theme` message.
 */

:root {
  --bg: #fff4e3;
  --panel: #ffffff;
  --panel-soft: #e5e4e6;
  --ink: #241f2e;
  --ink-dim: #87848c;
  --accent: #d7261b;
  --accent-ink: #f6f8ff;
  --drawn: #8fbcec;
  /* The counter a player drops on a number: moulded orange plastic, the way it
     comes in the bag. --stone-ink is the figure pressed into its face, which is
     this same colour taken down far enough to read against itself. */
  --stone: #f2561c;
  --stone-ink: #6d2710;
  --ok: #1f8a4c;
  --bad: #c62f22;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

/* A few translucent discs scattered behind everything — the counters, out of
   focus. Cheap (no image, no request) and it stops the page reading as a form. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    radial-gradient(circle at 12% 18%, var(--accent) 0 9px, transparent 10px),
    radial-gradient(circle at 78% 9%, var(--drawn) 0 13px, transparent 14px),
    radial-gradient(circle at 91% 64%, var(--accent) 0 7px, transparent 8px),
    radial-gradient(circle at 24% 81%, var(--drawn) 0 11px, transparent 12px),
    radial-gradient(circle at 56% 44%, var(--accent) 0 6px, transparent 7px),
    radial-gradient(circle at 6% 55%, var(--drawn) 0 8px, transparent 9px);
  filter: blur(1px);
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--panel);
  font-weight: 600;
  font-size: 15px;
  position: relative;
}

/* The fan of card colours, as a stripe under the title bar. It is the one piece
   of decoration that is also information: these are the colours the cards come
   in, and on a branded event they are the customer's. --card-stripe is built
   from the theme; without one the bar simply has a brand-coloured line. */
#bar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: var(--card-stripe, var(--accent));
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Capped by height so any aspect ratio survives, and never stretched: a squashed
   logo is the one thing a brand manager will notice from across the room. */
#brand-logo {
  height: 22px;
  width: auto;
  max-width: 45vw;
  object-fit: contain;
}

#room {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bad);
  transition: background 0.2s;
}

.dot.up {
  background: var(--ok);
}

/* Everything that turns together: the bar and the screens. It exists so that the
   play screen can be drawn sideways on an upright phone while the rotate hint,
   which is outside it, stays the right way up. */
#stage {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Upright, the card is not shrunk to fit a tall screen — the screen is turned
   under it. The stage takes the viewport's measurements swapped round and is
   rotated a quarter turn about its own top-left corner, which puts it back over
   the viewport exactly. The player turns the phone and gets the full sideways
   layout, on every phone, with no help from the browser: no fullscreen, no
   orientation lock, nothing a rotation lock can refuse.
   The play screen and the end of the round. The welcome and the chooser read
   fine upright and are left alone -- but the finish is not a new screen to the
   player, it is the game they were holding sideways coming to an end, and
   turning it upright at that moment made every phone in the room flip over at
   once while the winner was being announced. */
@media (orientation: portrait) {
  body[data-screen="play"] #stage,
  body[data-screen="done"] #stage {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vh;
    width: 100dvh;
    height: 100vw;
    height: 100dvw;
    transform-origin: top left;
    transform: rotate(90deg) translateY(-100%);
  }
}

main {
  flex: 1;
  position: relative;
  min-height: 0;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 16px;
  padding: 20px 16px;
  height: 100%;
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

h1 {
  margin: 0;
  font-size: 26px;
}

.muted {
  color: var(--ink-dim);
  margin: 0;
  font-size: 15px;
}

input[type="text"] {
  background: var(--panel);
  border: 2px solid var(--panel-soft);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 20px;
  padding: 16px;
  width: 100%;
}

input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
}

button {
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  padding: 18px;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 3px 0 rgb(0 0 0 / 22%);
  transition: transform 0.06s ease-out, box-shadow 0.06s ease-out;
}

/* Presses down rather than fading. The one tap that matters is made in a hurry
   by someone who is also shouting, and they need to feel it land. */
button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: none;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

button.ghost {
  background: var(--panel);
  color: var(--ink);
}

button:disabled {
  opacity: 0.4;
}

/* ---------------------------------------------------------------- connecting */

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--panel-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 40px auto 0;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --------------------------------------------------------------- card choice */

#screen-cards {
  align-items: center;
  text-align: center;
}

#screen-cards > * {
  width: 100%;
}

/* The hand. The cards turn about a point below the bottom edge, so they spread
   at the top and bunch at the bottom, the way cards held in one hand do. */
#fan {
  --fan: min(92vw, 60vh, 440px);
  position: relative;
  width: var(--fan);
  height: calc(var(--fan) * 0.66);
  margin: auto;
  flex: none;
}

#fan[hidden] {
  display: none;
}

#offers {
  position: absolute;
  inset: 0;
}

/* One card in the hand: upright, three across and nine down, in its own
   colour with a white border, like the printed ones. */
.fan-card {
  --lift: 0px;
  position: absolute;
  left: 50%;
  bottom: calc(var(--fan) * 0.06);
  width: calc(var(--fan) * 0.19);
  height: calc(var(--fan) * 0.54);
  margin-left: calc(var(--fan) * -0.095);
  padding: calc(var(--fan) * 0.008);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 1px;
  border: 2px solid #fff;
  border-radius: 6px;
  background: var(--card, var(--accent));
  box-shadow: -2px 0 6px rgb(0 0 0 / 28%), 0 0 0 1px var(--card-edge, rgb(0 0 0 / 30%));
  transform-origin: 50% 118%;
  transform: rotate(var(--angle)) translateY(var(--lift));
  transition: transform 0.12s ease-out, opacity 0.3s, filter 0.3s;
  overflow: hidden;
}

.fan-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #222;
  font-size: calc(var(--fan) * 0.028);
  font-weight: 700;
  line-height: 1;
}

.fan-cell.empty {
  background: transparent;
}

/* Running along the hand while the phone picks, and under a finger. */
.fan-card.lifted,
.fan-card:active {
  --lift: calc(var(--fan) * -0.07);
}

/* Coming out of the hand. */
.fan-card.pulled {
  --lift: calc(var(--fan) * -0.35);
  z-index: 50 !important;
  opacity: 0;
  transition: transform 0.4s ease-in, opacity 0.4s ease-in 0.15s;
}

/* Drawn once and put back. */
.fan-card.seen {
  opacity: 0.35;
  filter: grayscale(0.7);
  pointer-events: none;
}

/* The card drawn from the hand, whole, in the middle of the screen. */
#drawn-card {
  margin: auto;
  max-width: 460px;
}

#drawn-card[hidden] {
  display: none;
}

#drawn-card.rising .tcard {
  animation: drawn-rise 0.45s cubic-bezier(0.3, 0.7, 0.4, 1.15) both;
}

@keyframes drawn-rise {
  from {
    transform: translateY(-80px) rotate(-90deg) scale(0.4);
    opacity: 0;
  }
}

#fan-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 460px;
}

#fan-actions [hidden] {
  display: none;
}

/* --------------------------------------------------------------------- play */

#called {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

/* Drawn as the ball it is: lit from the upper left, with a shadow under it. */
#called-number {
  background:
    radial-gradient(circle at 34% 28%, rgb(255 255 255 / 28%), transparent 58%),
    var(--accent);
  color: var(--accent-ink);
  border-radius: 50%;
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  font-size: 44px;
  font-weight: 800;
  box-shadow: 0 6px 18px rgb(0 0 0 / 45%);
}

#called-number.idle {
  background: var(--panel);
  color: var(--ink-dim);
}

/* A drawn number lands with a short pulse. The player is looking at the card,
   not at this circle, so it has to move to be noticed. */
#called-number.pop {
  animation: pop 0.45s ease-out;
}

@keyframes pop {
  0% {
    transform: scale(0.7);
  }
  55% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}

/* ------------------------------------------------------------------- a card
 *
 * Drawn as the printed thing it is: a coloured rectangle, white cells with black
 * numbers, and the card's own number down the left edge. The colour is not
 * decoration — in a real set every card is a different one, and that is how a
 * player tells theirs from the one next to it, which matters most on the screen
 * where three are offered at once.
 *
 * --card and --card-ink are set per card from the theme's palette.
 */

/* The rim is the card's own colour darkened. A real card has one, and it is
   doing work: on a light page a pale card with no edge stops looking like a
   card, and the white cells printed on it stop looking like cells. */
.tcard {
  position: relative;
  background: var(--card, var(--panel));

  /* Printed card stock: a white edge trimmed round the coloured field, the way
     the real ones are cut. The coloured field then shows through between the
     squares as the grid's own lines — there is no border drawn anywhere in the
     grid, the card is simply visible behind it. */
  border: 5px solid var(--panel);
  outline: 1px solid var(--card-edge, var(--ink));
  outline-offset: -6px;
  border-radius: 12px;
  padding: 7px 8px 7px 26px;
  box-shadow: 0 3px 12px rgb(0 0 0 / 22%);
}

/* Down the left edge, the way it is printed. Turned rather than stacked so the
   card keeps its proportions on a narrow phone. */
.tcard-no {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 26px;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 800;
  color: var(--card-ink, var(--ink));
  opacity: 0.85;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);

  /* Ruled, like the printed card: a line between every pair of squares and a
     frame round the lot.

     Twice wrong first. With the squares meeting edge to edge, two white
     neighbours were one white rectangle. Then a two-pixel gap let the card's
     own colour show through -- which separated a white square from a white
     one, and nothing else: two coloured squares side by side had a line of
     their own colour between them, and ran together into one block. The rule
     has to be a colour neither of them is. So the grid itself is painted in
     --card-rule (the card's colour taken darker, or lighter on a dark card) and
     every square, coloured ones included, sits on it with a gap between. */
  gap: 2px;
  padding: 2px;
  background: var(--card-rule, var(--card-edge, var(--ink)));
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: var(--panel);
  font-size: 16px;
  font-weight: 800;

  /* The card's own colour, darkened until it reads on the white square — not the
     ink that reads on the CARD, which is a different question: on a red card that
     answer is white, and white on white is nothing. */
  color: var(--card-print, var(--ink));
}

#card .cell {
  font-size: 20px;
}

/* Nothing there: the card shows through, as on the printed one. */
/* Nothing there: the card's colour, as on the printed one -- filled rather than
   see-through, so the rule shows round it like round every other square. */
.cell.empty {
  background: var(--card, var(--panel));
}

/* The token a player drops on a number.
   Three layers over the wood colour, in this order: the light, then the printed
   ring, then the wood itself. The light comes from pul.png — a render of the real
   shape, blended as light rather than painted, so it tints with whatever wood the
   brand pack asks for and still has a chamfer and a domed face. Stacked gradients
   got the sheen but never the form.
   The ring is above the wood and below the light, so the print gets shaded along
   with the face, the way ink on a curved surface is.
   Inside its square, not proud of it. It used to overhang by eight per cent on
   every side, which on a phone-sized card is a counter half as big again as the
   square it is covering — it read as a sticker dropped on the grid rather than
   something put down in a box.
   Drawn BEHIND the cell's own text: the real token carries the same number on
   its face, and covering it would lose the one thing that lets a player check at
   a glance that the right square is the one they covered. */
.cell.marked::before,
.cell.fresh::before {
  content: "";
  position: absolute;
  inset: 4%;
  z-index: -1;
  border-radius: 50%;
  background-color: var(--stone);

  /* 108% because counter.py frames the disc at 92.6% of its square; blown up by
     1/0.926 the rendered edge IS this element's edge, so the counter fills its
     circle and there is no flat unlit ring of plastic left showing round it.

     There used to be a radial-gradient under this, drawing a ring on the face in
     the brand's accent. That came from a photograph of a wooden set. On the
     moulded plastic ones the ring round the rim is a LIP -- part of the
     moulding -- so it is in the render's geometry now, where the key light finds
     it, and the two screens no longer have to agree about a percentage. */
  background-image: url("pul.png");
  background-size: 108% 108%;
  background-position: center;
  background-repeat: no-repeat;

  /* Hard light, not soft. Soft light holds a colour near where it started, which
     is right for a wash and wrong for a shading pass: the render's own range --
     near black at the far chamfer, near white at the highlight -- came out as a
     fifteen per cent wobble around the colour, and the counter read as a printed
     circle. "Hiç derinlik yok" was the verdict, and it was fair. Hard light lets
     the render reach black and white again, so the lip has an edge and the face
     has a sheen. */
  background-blend-mode: hard-light;

  /* Two shadows: a tight one where it touches the card and a soft one under it.
     A single blurred shadow reads as a sticker; a contact shadow is most of what
     says the thing is sitting ON the paper rather than printed into it. */
  box-shadow:
    0 1px 2px rgb(0 0 0 / 38%),
    0 4px 8px rgb(0 0 0 / 28%);
}

/* The number moulded into the counter's face.
   On the real ones it is the same colour as the plastic and you read it by its
   relief, which is unreadable on a phone at arm's length — so this is that
   colour taken down to 3:1, the large-text bar, which keeps it recognisably the
   counter's own colour and still legible. See BrandColor.InkOn.
   The relief is the text-shadow: the counter is lit from the upper left, so a
   figure pressed INTO the face has a pale edge down and to the right of it and a
   dark one above and to the left. */
.cell.marked,
.cell.fresh {
  color: var(--stone-ink, #6d2710);
  font-size: 1.12em;
  text-shadow:
    1px 1px 0 rgb(255 255 255 / 45%),
    -1px -1px 0 rgb(0 0 0 / 22%);

  /* Load-bearing, and not for the reason it looks like. The counter is drawn as
     a ::before at z-index -1 so the cell's own number stays on top of it; a
     negative child only paints above its parent's BACKGROUND if the parent is a
     stacking context, and this is what makes the cell one. Without it the white
     square is painted over the counter and there is nothing to see. */
  z-index: 1;
}

/* The one just called wears a ring in the brand colour, so the eye finds it
   without the player searching their own card. */
.cell.fresh::before {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  animation: drop 0.35s ease-out;
}

@keyframes drop {
  0% {
    transform: scale(1.9);
    opacity: 0;
  }
  70% {
    transform: scale(0.92);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

/* The card sits in the middle of what is left, with the claim buttons pinned
   low where a thumb already is. Before this the card hugged the called number
   and left a third of the screen empty underneath it. */
#card {
  margin: auto 0;
}

/* Not a game mechanic — the card marks itself. This is for the player who
   looked away for ten seconds and wants to know what they missed, which at a
   company dinner is most of them most of the time. */
#recent {
  display: flex;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
}

#recent span {
  background: var(--panel);
  color: var(--ink-dim);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  padding: 6px 9px;
}

#recent span:first-child {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ------------------------------------------------------------------ winning
 *
 * Over everything, in the brand colour, for a few seconds. The player is about
 * to be looked at by a room; the phone's job here is to make them certain it is
 * them and tell them what happens next, not to show them their card again.
 */
#win {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: var(--accent);
  color: var(--accent-ink);
  animation: rise 0.35s ease-out;
}

#win[hidden] {
  display: none;
}

/* Somebody else won: a band across the middle of the card, in the brand's
   colour, the award small and the name large. Over the card rather than the
   whole screen, because for everyone who did not win the game is still on. */
#award-banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 20px;
  background: var(--panel);
  color: var(--ink);
  border-top: 4px solid var(--accent);
  border-bottom: 4px solid var(--accent);
  box-shadow: 0 10px 30px rgb(0 0 0 / 25%);
  text-align: center;
  animation: banner-in 0.3s ease-out;
  pointer-events: none;
}

#award-banner[hidden] {
  display: none;
}

#award-banner span {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
}

#award-banner strong {
  font-size: 34px;
  font-weight: 800;
  line-height: 1.1;
}

#award-banner.tombala {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent-ink);
}

#award-banner.tombala span {
  color: inherit;
}

@keyframes banner-in {
  from {
    opacity: 0;
    transform: translateY(-50%) scaleY(0.6);
  }
}

#win-award {
  font-size: 20px;
  font-weight: 700;
  opacity: 0.8;
  letter-spacing: 0.08em;
}

#win-shout {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
}

#win-note {
  font-size: 18px;
  opacity: 0.85;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
}

#claims {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
}

.claim {
  background: var(--panel);
  color: var(--ink-dim);
}

/* Lit only when the card really qualifies — but the host decides, not this. */
.claim.ready {
  background: var(--ok);
  color: #06210f;
}

.claim.tombala.ready {
  background: var(--accent);
  color: var(--accent-ink);
}

/* Taken by somebody else: still there, so the row of three keeps its shape, but
   plainly not something to press -- and it says who took it, so the button
   answers the question a player has when they see it go dark. */
.claim.taken {
  opacity: 0.55;
}

.claim.taken::after {
  content: attr(data-by);
  display: block;
  margin-top: 2px;
  font-size: 0.72em;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

.claim.won {
  background: var(--panel-soft);
  color: var(--ok);
}

#winners {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#winners li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 17px;
}

#winners li span {
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
}

#winners li strong {
  font-size: 20px;
  font-weight: 800;
  text-align: right;
}

#winners li.tombala {
  order: -1;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 20px 22px;
}

#winners li.tombala span {
  color: inherit;
  font-size: 20px;
}

#winners li.tombala strong {
  font-size: 30px;
}

/* The end of the round. Out of the landscape query on purpose: drawn sideways
   on an upright phone the stage is landscape-shaped but the media query still
   says portrait, so anything that only lived in there never applied. */
#screen-done {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  justify-content: center;
  gap: 16px;
}

#screen-done h1 {
  text-align: center;
  font-size: 30px;
  margin: 0;
}

/* -------------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--panel-soft);
  color: var(--ink);
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --------------------------------------------------------------- sideways
 *
 * A tombala card is nine cells across and three down. On an upright phone those
 * nine cells share about 340 pixels, which is 34 pixels a number with the gaps
 * taken out — smaller than the printed card and read by somebody in a dim room
 * who is also talking. Turned sideways the same nine share 740.
 *
 * So the game is played sideways. The client asks the phone to lock there when
 * a card is chosen, and where the browser will not (every iPhone), this says so
 * in the only words that work: turn it.
 */

#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}

#rotate strong {
  font-size: 26px;
}

/* A phone, turning. Drawn rather than an icon file: one more request on a room
   network is one more thing that can hang. */
#rotate-icon {
  width: 76px;
  height: 124px;
  border: 5px solid var(--accent);
  border-radius: 14px;
  animation: turn 2.4s ease-in-out infinite;
}

@keyframes turn {
  0%,
  30% {
    transform: rotate(0deg);
  }
  55%,
  85% {
    transform: rotate(-90deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

/* Shown once, when the card is chosen, for about a second and a half. It used to
   sit over the card for as long as the phone was upright, which made turning the
   phone a condition of playing: a player who would not, or whose rotation lock
   was on, simply could not get in. The card plays upright now, so this is a
   suggestion, it arrives with the card, and it leaves on its own. */
body.rotate-hint #rotate {
  display: flex;
}

#rotate {
  transition: opacity 0.45s ease;
  pointer-events: none;
}

body.rotate-hint-leaving #rotate {
  opacity: 0;
}

/* The play screen is sideways either way: the phone is turned, or the stage is.
   So its layout is not behind an orientation query at all — the card beside the
   drawn number, the claims along the bottom, always. */
#screen-play {
  padding: 10px 16px;
  gap: 10px;
  grid-template-columns: 148px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 18px;
  row-gap: 8px;
}

/* Grid only while it is the screen that is up. `display: grid` sat in the rule
   above for a while, and an id beats `.screen { display: none }`: the play
   screen was on screen whatever screen was showing. Nobody noticed during the
   game, because during the game it is the screen; at the end of the round the
   finish was laid out underneath a card nobody could play any more. */
#screen-play.active {
  display: grid;
}

#called {
  grid-column: 1;
  grid-row: 1;
}

#screen-play #called-number {
  width: 112px;
  height: 112px;
  font-size: 54px;
}

#screen-play #recent {
  grid-column: 1;
  grid-row: 2;
  flex-wrap: wrap;
}

#screen-play #recent span {
  font-size: 13px;
  padding: 4px 7px;
}

#screen-play #card {
  grid-column: 2;
  grid-row: 1;
  margin: 0;

  /* Take the column. Without this the card was shrink-to-fit — auto side margins
     make a grid item size to its contents, and its contents are nine cells whose
     only opinion about width is the font inside them. It came out about half the
     room it had, which on a phone held at arm's length is the difference between
     reading your own card and squinting at it.
     The cells are already 1fr and square, so width is the only dial: give the
     card the column and they grow with it. */
  width: 100%;

  /* Nine square cells across and three down, so the card's height is its own
     width divided by three. Capping the width by whatever is left after the bar
     and the claim row is what keeps those buttons on screen: sideways a phone is
     about 370 across the short way with the browser's own chrome taken out, and a
     card sized purely by width walks straight off the end of it. */
  max-width: calc((100vh - 168px) * 3);
  max-width: calc((100dvh - 168px) * 3);
  margin-inline: auto;
}

#screen-play #claims {
  grid-column: 2;
  grid-row: 2;
  flex-direction: row;
  gap: 10px;
  margin: 0;
  padding: 0;
}

#screen-play .claim {
  padding: 12px 6px;
  font-size: 16px;
}

/* Inside the turned stage the viewport's axes are swapped: what limits the card's
   height is the phone's width. dvh and dvw measure the viewport, not the box they
   are written in, so the cap has to be written the other way round here. */
@media (orientation: portrait) {
  body[data-screen="play"] #screen-play #card {
    max-width: calc((100vw - 168px) * 3);
    max-width: calc((100dvw - 168px) * 3);
  }
}

@media (orientation: landscape) {
  .screen {
    padding: 10px 16px;
    gap: 10px;
  }

  /* Sideways the hand is sized by the height, and the title and buttons go
     beside it rather than under it. */
  #screen-cards.active {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto 1fr auto;
    column-gap: 20px;
    align-items: start;
    text-align: left;
  }

  #screen-cards h1 {
    grid-column: 2;
    font-size: 22px;
  }

  #screen-cards #fan-hint {
    grid-column: 2;
  }

  #fan {
    --fan: min(118vh, 50vw);
    grid-column: 1;
    grid-row: 1 / 5;
    align-self: center;
  }

  #drawn-card {
    grid-column: 1;
    grid-row: 1 / 5;
    width: min(56vw, 150vh);
    margin: 0;
    align-self: center;
  }

  #fan-actions {
    grid-column: 2;
    grid-row: 4;
  }

  #card .cell {
    font-size: 27px;
  }

  .tcard {
    padding: 9px 10px 9px 34px;
  }

  .tcard-no {
    width: 34px;
    font-size: 21px;
  }

  /* (The three face-up offers sat here, two to a row.) */

  /* A name field and one button do not want the whole width of a landscape
     phone; a 700 pixel text input looks like a mistake. */
  #screen-name {
    max-width: 460px;
    margin: 0 auto;
    justify-content: center;
  }

  #win-shout {
    font-size: 64px;
  }
}
