/* Halloween Town Bingo — one screen, up to four players, nothing to print.

   The look is the film's own joke: Halloween Town at night behind the screen,
   and cream card stock in front of it, with a couple of Christmas colors
   sneaking in where the two holidays collide. */

:root {
  --night: #1a1230;      /* the sky over the town */
  --night-2: #241738;
  --line: #3b2a5e;

  --bone: #fbf6e9;       /* card stock */
  --bone-on: #f0e4c6;    /* a square with a chip sitting on it */
  --ink: #1a1230;
  --haunt: #52347e;      /* town purple */
  --haunt-lift: #6b47a0;
  --gourd: #e8791b;      /* pumpkin, spent sparingly */
  --moon: #f2d680;       /* moonlight */
  --quiet: #6e6288;      /* a gray with the purple left in it */
  --pale: #c9bbe4;

  /* Griffy does the shouting; Baloo 2 does the talking, same as the rest of
     Remi's games. */
  --display: Griffy, "Segoe Print", "Comic Sans MS", cursive;
  --body: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;        /* iOS ignores the meta tag; this it obeys */
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--body);
  color: #ede7f7;
  background: var(--night);
  user-select: none;
}

button { font-family: inherit; cursor: pointer; }

button:focus-visible,
input:focus-visible,
.sq:focus-visible {
  outline: 3px solid var(--moon);
  outline-offset: 2px;
}

#game {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(120% 90% at 50% 0%, #2b1a4d 0%, #1a1230 45%, #0d0819 100%);
  transition: background 0.5s ease;
  overflow: hidden;
}

/* ============================== the top bar ============================== */

#hud {
  flex: none;
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 16px);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) clamp(10px, 3vw, 20px) 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 8, 25, 0.5);
}

#hud-title {
  font-family: var(--display);
  font-size: clamp(17px, 4.4vw, 27px);
  line-height: 1;
  color: var(--moon);
  margin-right: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-item.stat { flex: none; }

.stat-label {
  font-size: clamp(11px, 2.6vw, 14px);
  font-weight: 500;
  color: var(--pale);
  white-space: nowrap;
}
.stat-label b {
  font-weight: 800;
  color: var(--moon);
}

.hud-btn {
  flex: none;
  background: transparent;
  color: var(--pale);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: clamp(11px, 2.6vw, 13px);
  font-weight: 700;
  padding: 7px 14px;
  white-space: nowrap;
}
.hud-btn:hover { border-color: var(--haunt-lift); color: #fff; }

/* ================================ the stage ============================== */

#stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: clamp(12px, 2.6vw, 20px) clamp(10px, 3vw, 22px)
           calc(env(safe-area-inset-bottom, 0px) + 28px);
}

/* ------------------------------- the caller ------------------------------ */

#caller {
  display: grid;
  grid-template-columns: minmax(0, clamp(120px, 24vw, 190px)) minmax(0, 1fr);
  gap: clamp(12px, 3vw, 24px);
  align-items: center;
  max-width: 1100px;
  margin: 0 auto clamp(14px, 3vw, 22px);
  padding: clamp(12px, 2.6vw, 20px);
  background: linear-gradient(180deg, var(--night-2), #170e2c);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.stub {
  aspect-ratio: 5 / 7;
  width: 100%;
  border-radius: 14px;
  background: var(--bone);
  color: var(--ink);
  border: 3px solid var(--haunt);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  text-align: center;
  overflow: hidden;
}
.stub .pic {
  font-size: clamp(40px, 11vw, 68px);
  line-height: 1;
}
.stub .name {
  font-size: clamp(11px, 2.6vw, 14px);
  font-weight: 800;
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.stub.empty {
  background: var(--haunt);
  color: var(--bone);
  border-color: var(--haunt-lift);
}
.stub.empty .pic { font-size: clamp(30px, 8vw, 48px); }
.stub.empty .name {
  font-family: var(--display);
  text-transform: none;
  font-size: clamp(12px, 3vw, 15px);
}

/* The card turns, and ui.js swaps its face at the halfway point — so what you
   see really is the back coming round to the front. */
.stub.flip { animation: flipcard 0.42s ease; }
@keyframes flipcard {
  0%   { transform: rotateY(0deg) scale(1); }
  48%  { transform: rotateY(90deg) scale(1.04); }
  100% { transform: rotateY(0deg) scale(1); }
}

#caller-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

#flip {
  border: none;
  border-radius: 14px;
  background: var(--moon);
  color: #241703;
  font-size: clamp(15px, 3.4vw, 19px);
  font-weight: 800;
  padding: 14px 18px;
  box-shadow: 0 6px 0 #c4a64f;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
#flip:active { transform: translateY(4px); box-shadow: 0 2px 0 #c4a64f; }
#flip:disabled {
  background: var(--night-2);
  color: var(--quiet);
  box-shadow: none;
  cursor: default;
}

#called-head {
  font-size: clamp(10px, 2.4vw, 12px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--quiet);
}
#called-head b { color: var(--pale); }

#called {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 82px;
  overflow-y: auto;
}
#called i {
  font-style: normal;
  font-size: 18px;
  line-height: 1;
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #1e1336;
  border: 1px solid var(--line);
}
#called .none {
  font-size: 13px;
  color: var(--quiet);
  font-style: italic;
}

/* -------------------------------- the tabs ------------------------------- */

#tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  max-width: 1100px;
  margin: 0 auto;
}

.tab {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: #1e1336;
  color: var(--pale);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: clamp(13px, 3vw, 15px);
  font-weight: 700;
  max-width: 46vw;
}
.tab .chip-i { font-size: 17px; line-height: 1; }
.tab .who-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab[aria-selected="true"] {
  background: var(--bone);
  color: var(--ink);
  border-color: var(--bone);
}

/* ------------------------------- the cards ------------------------------- */

#cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: clamp(14px, 2.6vw, 22px);
  max-width: 1100px;
  margin: 0 auto;
}

.card {
  background: var(--bone);
  color: var(--ink);
  border-radius: 16px;
  padding: 11px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.42);
  min-width: 0;
}

.card-name {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 9px;
}
.card-name .chip-i { font-size: 21px; line-height: 1; flex: none; }
.card-name h3 {
  font-family: var(--display);
  font-size: clamp(18px, 4vw, 23px);
  line-height: 1;
  margin: 0;
  color: var(--haunt);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-name .tally {
  margin-left: auto;
  flex: none;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--quiet);
  font-variant-numeric: tabular-nums;
}

.word {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--haunt);
  border-radius: 8px 8px 0 0;
}
.word span {
  font-family: var(--display);
  font-size: clamp(18px, 4.2vw, 25px);
  line-height: 1.3;
  text-align: center;
  color: var(--bone);
}

.squares {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  padding: 3px;
  background: var(--ink);
  border-radius: 0 0 8px 8px;
}

.sq {
  position: relative;
  aspect-ratio: 1;
  border: none;
  border-radius: 3px;
  background: var(--bone);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 3px 2px;
  overflow: hidden;
}
.sq .pic {
  font-size: clamp(19px, 5vw, 29px);
  line-height: 1;
  transition: opacity 0.15s ease;
}
.sq .lbl {
  font-size: clamp(6.5px, 1.5vw, 8px);
  font-weight: 800;
  line-height: 1.1;
  text-transform: uppercase;
  color: var(--ink);
  text-align: center;
  overflow-wrap: anywhere;
  transition: opacity 0.15s ease;
}

/* The chip that lands on a covered square. */
.sq .stamp {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(25px, 6.6vw, 38px);
  opacity: 0;
  transform: scale(0.4) rotate(-18deg);
  transition: opacity 0.16s ease, transform 0.22s cubic-bezier(0.2, 1.5, 0.4, 1);
  pointer-events: none;
}
.sq.on { background: var(--bone-on); }
.sq.on .pic { opacity: 0.24; }
.sq.on .lbl { opacity: 0.32; }
.sq.on .stamp { opacity: 1; transform: scale(1) rotate(-8deg); }

.sq.free { background: #fbefce; }
.sq.free .lbl { color: var(--gourd); letter-spacing: 0.08em; }

/* Just called, and this card hasn't covered it yet. */
.sq.hot { box-shadow: inset 0 0 0 2.5px var(--gourd); }

.sq.nope { animation: nope 0.34s ease; }
@keyframes nope {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-4px); }
  46% { transform: translateX(4px); }
  72% { transform: translateX(-2px); }
}

/* ================================ messages =============================== */

#banner {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translate(-50%, 18px);
  background: var(--ink);
  color: var(--bone);
  border: 1px solid var(--haunt-lift);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: clamp(13px, 3vw, 15px);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 6;
  max-width: 90vw;
  text-align: center;
}
#banner.show { opacity: 1; transform: translate(-50%, 0); }

#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* ============================ overlays =================================== */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 18px
           calc(env(safe-area-inset-bottom, 0px) + 18px);
  background: rgba(9, 5, 17, 0.84);
  overflow-y: auto;
}
.overlay.show { display: grid; }

.card-box {
  background: var(--bone);
  color: var(--ink);
  border: 4px solid var(--haunt);
  border-radius: 20px;
  padding: clamp(20px, 5vw, 34px);
  width: min(440px, 100%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.card-box .kicker {
  margin: 0;
  font-size: clamp(9px, 2.4vw, 11px);
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gourd);
}
.card-box .title {
  font-family: var(--display);
  font-size: clamp(34px, 9vw, 50px);
  line-height: 0.95;
  margin: 0;
  color: var(--haunt);
  text-wrap: balance;
}
.card-box .blurb {
  margin: 0;
  font-size: clamp(13.5px, 3.2vw, 15.5px);
  line-height: 1.5;
  color: #3a2f52;
  text-wrap: balance;
}
.card-box .tip {
  margin: 0;
  font-size: clamp(12px, 2.8vw, 13px);
  line-height: 1.45;
  color: var(--quiet);
  text-wrap: balance;
}

.card-box .shout {
  font-family: var(--display);
  font-size: clamp(42px, 12vw, 66px);
  line-height: 0.9;
  margin: 0;
  color: var(--gourd);
}
.card-box .won-who {
  margin: 0;
  font-size: clamp(17px, 4.2vw, 21px);
  font-weight: 800;
  color: var(--haunt);
  text-wrap: balance;
}

.who {
  display: flex;
  flex-direction: column;
  gap: 9px;
  width: 100%;
}
.who-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--quiet);
  text-align: left;
}
.who-row { display: flex; align-items: center; gap: 9px; }
.who-row .pin {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 21px;
  border-radius: 50%;
  background: #f2ead6;
  border: 1px solid #ddd0b4;
}
.who-row input {
  flex: 1;
  min-width: 0;
  font-family: var(--body);
  font-size: 16px;              /* 16px or iOS zooms the whole page in */
  font-weight: 600;
  color: var(--ink);
  background: #fffdf7;
  border: 1px solid #ddd0b4;
  border-radius: 10px;
  padding: 11px 13px;
}
.who-row input::placeholder { color: #a99cc0; font-weight: 500; }

.big {
  border: none;
  border-radius: 999px;
  background: var(--gourd);
  color: #2b1200;
  font-size: clamp(16px, 3.8vw, 19px);
  font-weight: 800;
  padding: 14px 38px;
  box-shadow: 0 7px 0 #a8500c;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.big:active { transform: translateY(4px); box-shadow: 0 3px 0 #a8500c; }

/* ============================== fitting in =============================== */

/* On a phone there is only room for one card, so the tabs swap between them.
   Give it a bigger screen and every card is on show at once. */
@media (max-width: 820px) {
  .card { display: none; }
  .card.active { display: block; }
}
@media (min-width: 821px) {
  #tabs { display: none !important; }
}

@media (max-width: 430px) {
  .hud-word { display: none; }
}

/* A short landscape phone: the caller card would eat the whole screen. */
@media (max-height: 520px) and (orientation: landscape) {
  #caller { grid-template-columns: minmax(0, 110px) minmax(0, 1fr); }
  #called { max-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}
