/* app.css — the colour tokens, and the page (section 2.1): the portrait column, the 48 px HUD, the stage that fills
   what is left, the caption band, the speech bubbles and the tray. Sizes are in px, except text, which is in rem and
   follows --text-scale (100, 115 or 130%). Cut-paper look: cream card stock with a hard 3 px offset shadow. */
:root {
  /* Sky */
  --sky-dark: #1E1631;
  --sky-mid: #3B2350;

  /* Stage elements */
  --block-wall: #4A5A6A;
  --window-off: #2A3340;
  --window-warm: #FFD38A;
  --window-cool: #E8F1FF;
  --platform: #8A5A3B;
  --crates: #C9A06B;

  /* Characters */
  --troupe-black: #2B2D42;
  --cards: #FFF6E5;
  --ink: #2B1B2F;
  --plum: #5B2A5E;

  /* Accents */
  --accent-star: #14A098;
  --accent-wei-jie: #F29BC2;
  --accent-nurul: #C8CDD6;
  --accent-arjun: #8E44AD;

  /* Tone colours */
  --tone-spicy: #E8443A;
  --tone-sad: #2F80ED;
  --tone-fabulous: #FFC531;
  --tone-weird: #27AE60;
  --tone-callback: #E6B422;

  /* The page */
  --velvet: #6A1426;
  --velvet-deep: #470B19;
  --meter-heart: #F25C93;
  --meter-haha: #FFC531;
  --focus-ring: #FFD38A;
  --paper-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);

  /* Text size: 1, 1.15 or 1.3 (layout.setTextScale). Every rem follows it. */
  --text-scale: 1;
  font-size: calc(100% * var(--text-scale));
}

html {
  background: #1E1631;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* manipulation everywhere; a drag or hold origin sets touch-action: none on itself. */
* {
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--sky-dark);
  color: var(--cards);
  font-family: Nunito, system-ui, sans-serif;
  font-weight: 600;
  line-height: 1.3;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Wider than the column: velvet either side of it, until C4 draws the curtains. */
@media (min-width: 481px) {
  body {
    background:
      linear-gradient(90deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.5)),
      repeating-linear-gradient(90deg, var(--velvet-deep) 0, var(--velvet) 22px, var(--velvet-deep) 44px),
      var(--velvet);
  }

  #app {
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 0 48px rgba(0, 0, 0, 0.6);
  }
}

input,
textarea,
[contenteditable] {
  -webkit-user-select: text;
  user-select: text;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: var(--window-warm);
}

/* 404.html shares this sheet; its two lines keep a gutter, and its one link is a card-stock button, as the game's
   are (section 10.7: no default browser controls). */
body[data-page="404"] {
  padding: 24px 16px;
}

body[data-page="404"] a {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 10px 20px 9px;
  border: 0;
  border-radius: 22px 18px 21px 19px;
  background: var(--cards);
  box-shadow: var(--paper-shadow);
  color: var(--ink);
  font: 800 1.0625rem/1 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.05em;
  text-decoration: none;
}

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

.e2e *, .e2e *::before, .e2e *::after { animation: none !important; transition: none !important }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* — The column — */

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  isolation: isolate; /* its z-indexes (the HUD's 2, the band's 1) stay inside it, under the fixed layers after it */
  background: var(--sky-dark);
}

/* — The HUD: the split heart, the scene dots and pause — */

#hud {
  position: relative;
  z-index: 2;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding-left: 10px;
  border-bottom: 1px solid rgba(255, 246, 229, 0.08);
}

.hud-meter {
  flex: none;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 9px 0 7px;
  border-radius: 18px;
  background: rgba(255, 246, 229, 0.07);
}

.hud-half {
  display: flex;
  align-items: center;
  gap: 3px;
}

.hud-heart {
  display: block;
  width: 24px;
  height: 24px;
}

.hud-heart path {
  fill: none;
  stroke: var(--meter-heart);
  stroke-width: 2;
  opacity: 0.6;
}

.hud-heart[data-filled="true"] {
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.35));
}

.hud-heart[data-filled="true"] path {
  fill: var(--meter-heart);
  stroke: var(--ink);
  stroke-width: 1.6;
  opacity: 1;
}

.hud-split {
  width: 8px;
  height: 28px;
  margin: 0 5px 0 4px;
}

.hud-split path {
  fill: none;
  stroke: rgba(255, 246, 229, 0.4);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.hud-ha {
  width: 30px;
  height: 22px;
  border: 2px dashed rgba(255, 197, 49, 0.6);
  border-radius: 6px;
  color: rgba(255, 197, 49, 0.6);
  font: 800 13px/18px "Baloo 2", system-ui, sans-serif;
  text-align: center;
}

.hud-ha[data-filled="true"] {
  border: 2px solid var(--ink);
  background: var(--meter-haha);
  color: var(--ink);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}

.hud-slot[data-filled="true"] {
  animation: hud-pop 240ms cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

@keyframes hud-pop {
  from { transform: scale(1.45); }
  to { transform: scale(1); }
}

.hud-dots {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 0;
}

.hud-dot {
  width: 10px;
  height: 10px;
  border: 2px solid rgba(255, 246, 229, 0.45);
  border-radius: 50%;
}

.hud-dot[data-state="played"] {
  border-color: transparent;
  background: rgba(255, 246, 229, 0.55);
}

.hud-dot[data-state="now"] {
  width: 14px;
  height: 14px;
  border-color: var(--window-warm);
  background: var(--window-warm);
  box-shadow: 0 0 0 3px rgba(255, 211, 138, 0.22);
}

.hud-pause {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.hud-pause svg {
  width: 36px;
  height: 36px;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.35));
}

.hud-pause circle {
  fill: var(--plum);
}

.hud-pause rect {
  fill: var(--cards);
}

.hud-pause:active svg {
  transform: scale(0.92);
}

/* YOU: a cut-out tag pinned to the Conductor's chest in the first scene, its pointer up at his face. hud.js puts its
   middle where the stage shows YOU_AT, every frame while it shows: --you-x and --you-y, from the stage's top left,
   which is the HUD's bottom left (its 47 px padding box and its 1 px border). It is sized by the camera's scale
   (--you-k): its text at most 48 px a unit of scale, everything else in em, so with its pointer and shadow it stays
   in the room round his chest that no face, sign or board of a first scene comes into, between his eye band (its foot
   at y 797), the front-row auntie's board (from x 302, y 912) and Kopi's eyes on the chess table: about x 110 to 300
   and y 815 to 945 at most. On a tall stage that cap is past the text size's 0.875rem (ui.css), so there it grows with
   the text; a phone lying down drops it (below). Until hud.js has placed it, it is out of sight. */
.hud-you {
  position: absolute;
  top: calc(100% + 1px + var(--you-y, 0px));
  left: var(--you-x, 0px);
  padding: 0.21em 0.5em 0.07em;
  border-radius: 0.43em;
  background: var(--cards);
  color: var(--ink);
  font: 800 min(14px, calc(var(--you-k, 0.52) * 48px))/1.1 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.04em;
  transform: translate(-50%, -50%) rotate(-4deg);
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.35));
  pointer-events: none;
}

.hud-you:not([data-placed]) {
  visibility: hidden;
}

.hud-you::after {
  content: "";
  position: absolute;
  bottom: calc(100% - 1px);
  left: 50%;
  width: 0.86em;
  height: 0.5em;
  margin-left: -0.43em;
  background: var(--cards);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

/* — The stage: it takes what the HUD, the caption band and the tray leave — */

#stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--sky-dark);
}

#stage {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

#bubbles,
#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#title-name {
  position: absolute;
  top: 7%;
  left: 0;
  right: 0;
  margin: 0;
  padding: 0 16px;
  color: var(--window-warm);
  font: 800 clamp(30px, 10vw, 46px)/0.95 "Baloo 2", system-ui, sans-serif;
  text-align: center;
  text-shadow: 3px 3px 0 var(--plum);
  pointer-events: none;
}

/* Speech bubbles: bubble.js places each one with a transform and sets its tail: --tail-x, the x of the tail's base
   (its middle), the tail's box under the bubble (--tail-left, --tail-w, --tail-h) and, in that box, the x's of the
   triangle's two base corners and its point (--tail-a, --tail-b, --tail-c). A straight tail is 18 x 12 px. */
.bubble {
  position: absolute;
  top: 0;
  left: 0;
  max-width: min(78%, 20em);
  padding: 7px 12px 8px;
  border-radius: 14px;
  background: var(--cards);
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1.3;
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.35));
}

.bubble[data-tail="down"]::after {
  content: "";
  position: absolute;
  top: 100%;
  left: var(--tail-left, calc(var(--tail-x, 50%) - 9px));
  width: var(--tail-w, 18px);
  height: var(--tail-h, 12px); /* TAIL_PX in bubble.js */
  background: var(--cards);
  clip-path: polygon(var(--tail-a, 0px) 0, var(--tail-b, 18px) 0, var(--tail-c, 9px) 100%);
}

.bubble-text,
.caption-text {
  margin: 0;
}

.untyped {
  visibility: hidden;
}

/* — The caption band: one line, growing to three at the current text size — */

#caption {
  position: relative;
  z-index: 1;
  flex: none;
  min-height: calc(1lh + 20px);
  max-height: calc(3lh + 20px);
  margin: 8px 6px 0;
  padding: 10px 12px;
  border-radius: 13px 10px 14px 9px;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.3;
}

#caption[data-state="line"],
#caption[data-state="caption"] {
  background: var(--cards);
  box-shadow: var(--paper-shadow);
}

.caption-text {
  max-height: 3lh;
  overflow: hidden;
}

/* A beat line's thought bubble, risen from the band's left end towards the teller's chair: it sits on the band's top
   edge, its lower 10 px in the band's 10 px top padding, so it rises only 14 px over the stage's foot, under Kopi's eyes
   on the chess table and the front-row auntie's board on every stage held upright (the camera fits a short stage by its
   height, showing the world down to y 1080, and the board ends at 1020; hung 10 px above the band it once covered both
   at 360x640 and 130% text); lying down it sits under the sky beside the world. */
.caption-thought {
  position: absolute;
  bottom: calc(100% - 10px);
  left: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 11px 2px 5px;
  border-radius: 999px;
  background: var(--cards);
  color: var(--ink);
  font: 800 14px/1 Nunito, system-ui, sans-serif;
  letter-spacing: 0.03em;
  white-space: nowrap;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.35));
}

.caption-thought::before,
.caption-thought::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: var(--cards);
}

.caption-thought::before {
  top: -8px;
  left: 4px;
  width: 9px;
  height: 9px;
}

.caption-thought::after {
  top: -16px;
  left: -2px;
  width: 6px;
  height: 6px;
}

.caption-thought-art {
  display: block;
  width: 44px;
  height: 20px;
}

/* The star's captions: a gold STAR stamp slammed on the band's top edge, clear of the text under it. */
.caption-star {
  position: absolute;
  right: 12px;
  bottom: calc(100% - 1px);
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 9px 1px 6px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--tone-callback);
  color: var(--ink);
  font: 800 15px/1.1 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.08em;
  outline: 1.5px dashed rgba(43, 27, 47, 0.5);
  outline-offset: -5px;
  box-shadow: var(--paper-shadow);
  transform: rotate(-7deg);
  animation: caption-stamp 260ms cubic-bezier(0.3, 1.4, 0.5, 1);
}

.caption-star svg {
  width: 14px;
  height: 14px;
}

.caption-star path {
  fill: var(--ink);
}

@keyframes caption-stamp {
  from { transform: rotate(-7deg) scale(1.7); opacity: 0; }
  55% { transform: rotate(-7deg) scale(0.94); opacity: 1; }
  to { transform: rotate(-7deg) scale(1); }
}

/* — The tray: the bottom thumb zone, always in normal flow — */

#tray {
  position: relative;
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 64px;
  padding: 8px;
}

/* — The layers after #app: the config banner and the toast — */

/* Both are fixed, so they sit in the viewport over the column, never in the flow under the 100dvh #app, and #app's
   isolation keeps its own layers under them. B12 fills and styles #curtain, the loading curtain, in ui.css. */

/* The config banner, which the boot fills and shows when sharon.config.js fell back to its defaults (B12 adds the
   dismiss): a card over the top of the column, inside the safe area, so the deployer sees it at once. */
#config-banner {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 6px);
  left: 0;
  right: 0;
  z-index: 10;
  width: min(100% - 16px, 464px);
  max-height: 40vh;
  max-height: 40dvh;
  margin: 0 auto;
  padding: 9px 14px 10px;
  overflow-y: auto;
  border-radius: 10px 13px 9px 14px;
  background: var(--cards);
  box-shadow: var(--paper-shadow);
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/* The toast (B9 fills it, and may restyle it in ui.css): a slip just under the HUD, centred on the column, over the
   stage. It takes no taps, so whatever it covers still works. Empty, it has no box, but stays in the accessibility
   tree as the status region it is, so its next text is read out. */
#toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 56px);
  left: 0;
  right: 0;
  z-index: 11;
  width: fit-content;
  max-width: min(100% - 32px, 448px);
  margin: 0 auto;
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
  pointer-events: none;
}

#toast:not(:empty) {
  padding: 8px 16px 9px;
  border-radius: 14px;
  background: var(--cards);
  box-shadow: var(--paper-shadow);
}

/* While the config banner shows, a toast drops to the foot of the screen, so neither hides the other's text. */
#config-banner:not([hidden]) ~ #toast {
  top: auto;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
}

/* A phone lying down keeps the portrait column, packed tighter (computeColumn's landscapePhone). */
@media (orientation: landscape) and (max-height: 500px) {
  #caption {
    min-height: calc(1lh + 12px);
    max-height: calc(3lh + 12px);
    margin-top: 4px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  /* Lying down, it keeps under the sky beside the world, and under Kopi's eyes on the chess table at the strip's foot:
     from the band's very edge, a size smaller, it ends before the world's strip begins and rises 13 px, even as a
     punch zooms the world out over the wings. (#caption outranks ui.css's text size for it.) */
  #caption .caption-thought {
    bottom: calc(100% - 6px);
    left: 0;
    gap: 4px;
    padding: 1px 9px 1px 4px;
    font-size: min(0.875rem, 12px);
  }

  #caption .caption-thought-art {
    width: 38px;
    height: 17px;
  }

  /* Lying down, the world is too small for the YOU tag to read on the Conductor (its text would come down to 6 px to
     keep off the faces and signs round him), and the speech bubbles, the size they are anywhere, lie over him: there
     it is dropped, as I16 allows where no place reads. */
  .hud-you {
    display: none;
  }

  #tray {
    min-height: 56px;
    padding: 4px 8px;
  }
}

/* Reduced motion (the class B12 sets from the settings and the OS): no pops or slams. */
html.reduced-motion .hud-slot[data-filled="true"],
html.reduced-motion .caption-star {
  animation: none;
}

/* Nor a squish: the pause icon holds still when pressed, as every card and button does. */
html.reduced-motion .hud-pause:active svg {
  transform: none;
}
