/* The Lifetimer — style, after the physical character cards (docs/design/).
   Order: 1 fonts · 2 design tokens · 3 scene colours · 3b status · 4 base elements · 5 components ·
   6 participant page · 7 organiser page · 8 login page.
   To change a colour, font or size: change its variable in section 2. */

/* 1. Fonts ------------------------------------------------------------------
   Self-hosted (privacy rule P5): nothing is loaded from another server. Lato is under the
   SIL Open Font License (fonts/OFL.txt). Subset to Latin and compressed to woff2 (42 kB).
   font-display: swap shows text in a system font until Lato has loaded. */
@font-face {
  font-family: "Lato";
  src: url("fonts/Lato-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Lato";
  src: url("fonts/Lato-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Lato";
  src: url("fonts/Lato-Black.woff2") format("woff2");
  font-weight: 900;
  font-display: swap;
}

/* 2. Design tokens ------------------------------------------------------------- */
:root {
  /* Colours from the cards */
  --bg: #100f0d;            /* card background, near-black (also saves battery on OLED) */
  --panel: #1c1b19;         /* slightly lighter boxes on the organiser page */
  --fg: #ffffff;
  --muted: #a7a9ac;
  --line: #3a3937;
  --grey: #6d6f71;          /* intro cards */
  --blue: #00aeef;          /* scene 1 */
  --green: #29b24b;         /* scene 2 */
  --magenta: #ec008c;       /* scene 3 */
  --yellow: #f2ef1d;        /* warning, non-user page */
  --gold: #d4af37;          /* premium age */
  --ink: #231f20;           /* dark text on a coloured background */
  --danger: #e5484d;
  --online: #29b24b;
  --offline: #e5484d;

  /* Fonts. Headings use Neuropol X (the cards) once its files are added; until then Lato
     Black. When Neuropol X arrives: add an @font-face above and set --heading-weight: 400. */
  --font-body: "Lato", system-ui, sans-serif;
  --font-heading: "Neuropol X", "Lato", system-ui, sans-serif;
  --heading-weight: 900;

  /* Sizes. clamp(min, preferred, max): grows with the screen width (vw), within limits. */
  --age-size: clamp(7rem, 42vw, 16rem);   /* readable through the bag from 1.5 m */
  --code-size: clamp(3rem, 12vw, 8rem);   /* the room code on the projector */
  --text-size: 1.125rem;
  --accent-bar: 0.3rem;     /* thickness of the coloured lines */
  --radius: 0.6rem;
  --gap: 1rem;
}

/* 3. Scene colours --------------------------------------------------------------
   JS sets data-color on <body> from the scene number: intro, then blue, green, magenta,
   and around again. The colour is only an accent: text stays white.
   --scene: buttons, edges, the bar under the age. --tint: a see-through glow at the top of
   the page, over the swirl pattern. rgba(r, g, b, a): a is the opacity, 0 to 1. */
:root,
[data-color="intro"] {
  --scene: var(--fg);
  --tint: rgba(255, 255, 255, 0.06);
}

[data-color="blue"] {
  --scene: var(--blue);
  --tint: rgba(0, 174, 239, 0.18);
}

[data-color="green"] {
  --scene: var(--green);
  --tint: rgba(41, 178, 75, 0.18);
}

[data-color="magenta"] {
  --scene: var(--magenta);
  --tint: rgba(236, 0, 140, 0.18);
}

/* 3b. Status (M7b, look in M7c) ---------------------------------------------------
   JS sets data-status on <body>: none (lobby), non-user, user or premium.
   --status: the colour of the small status label. --status-age: the colour of the age.
   These rules sit on <body> itself, so every element inside inherits the new values, the same
   way a value set on :root does. They come after section 3, so they win when both set the
   same variable. */
:root,
[data-status="none"] {
  --status: var(--muted);
  --status-age: var(--fg);
}

/* user: the normal dark card, the age in grey. */
[data-status="user"] {
  --status: var(--muted);
  --status-age: var(--muted);
}

/* premium: the normal dark card, the age in gold. */
[data-status="premium"] {
  --status: var(--gold);
  --status-age: var(--gold);
}

/* non-user: the yellow warning page (Lifetimers.pdf page 2). The age is replaced by the
   warning (participant.js, showTimer). Swapping the colour variables turns the whole page
   into dark ink on yellow: text, buttons, lines and the scene accent all follow. */
[data-status="non-user"] {
  --fg: var(--ink);
  --muted: var(--ink);
  --line: var(--ink);
  --scene: var(--ink);
  --status: var(--ink);
  --status-age: var(--ink);
  background: var(--yellow);
}

/* A filled button is normally dark text on the scene colour; here the scene colour is ink,
   so turn the text yellow. */
[data-status="non-user"] button.primary {
  color: var(--yellow);
}

/* The reconnect banner is yellow too: invert it so it stays visible. */
[data-status="non-user"] .banner {
  background: var(--ink);
  color: var(--yellow);
}

/* 4. Base elements --------------------------------------------------------------- */
* {
  box-sizing: border-box;   /* width includes padding and border: easier sizing */
}

body {
  margin: 0;
  min-height: 100vh;
  padding: var(--gap);
  /* Three layers, top first: the scene glow, the grey swirl from the cards (a mirrored tile,
     so it repeats without seams), and the plain colour underneath. */
  background:
    radial-gradient(ellipse at top, var(--tint), transparent 70%) fixed,
    url("img/swirl.webp") center top / 1274px auto repeat fixed,
    var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--text-size);
  line-height: 1.45;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  line-height: 1.15;
  letter-spacing: 0.02em;
}

h2 {
  font-size: 1.6rem;
}

h3 {
  font-size: 1.25rem;
}

h4 {
  font-size: 1rem;
  color: var(--muted);
}

label {
  display: block;
  margin: 0.75rem 0;
}

label span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
}

input,
select {
  width: 100%;
  max-width: 28rem;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--scene);
}

/* Buttons: outlined, like the "Persona / Job / Life" pills on the cards. */
button {
  min-height: 2.75rem;      /* big enough for a thumb */
  padding: 0.5rem 1.1rem;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  border-color: var(--line);
  color: var(--muted);
  cursor: default;
}

details summary {
  cursor: pointer;
  color: var(--muted);
}

/* 5. Components ---------------------------------------------------------------- */

/* The main action of a screen: filled with the scene colour. */
button.primary {
  border-color: var(--scene);
  background: var(--scene);
  color: var(--ink);
}

button.primary:disabled {
  border-color: var(--line);
  background: var(--line);
  color: var(--muted);
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--fg);
}

.error {
  color: var(--danger);
}

.warning {
  color: var(--yellow);
}

.muted {
  color: var(--muted);
}

.banner {
  margin: 0 0 var(--gap);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--yellow);
  color: var(--ink);
  font-weight: 700;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Page header: the logo on the left, connection dot or logout on the right. */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--gap);
}

/* Logo placeholder until the real logo arrives: the name in the heading font. */
.logo {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: 1.1rem;
  letter-spacing: 0.04em;
}

/* M8: the wake lock indicator and the connection dot, together on the right. */
.header-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* A small text label; its colour says the state: green = on, red = off (tap to retry),
   muted = not possible here. */
#wake-indicator {
  font-size: 0.8rem;
  font-weight: 700;
  text-align: right;
}

#wake-indicator.on {
  color: var(--online);
}

#wake-indicator.off {
  color: var(--offline);
}

#wake-indicator.unsupported {
  color: var(--muted);
}

/* On the yellow non-user page green and red are hard to read: use ink. */
[data-status="non-user"] #wake-indicator {
  color: var(--ink);
}

.dot {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.online {
  background: var(--online);
}

.dot.offline {
  background: var(--offline);
}

/* pre-line keeps the line breaks from the CSV story. */
.story {
  white-space: pre-line;
}

/* 6. Participant page ------------------------------------------------------------- */
.participant {
  max-width: 34rem;
  margin: 0 auto;
}

.participant section {
  margin-top: var(--gap);
}

/* The character name above the age, on every screen after the lobby. */
#character-name {
  margin: 0.75rem 0 0;
  text-align: center;
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: 1.5rem;
  line-height: 1.2;
}

/* M7b: a small outlined label under the name, in the status colour. */
#status-label {
  width: fit-content;
  margin: 0.4rem auto 0;
  padding: 0.15rem 0.7rem;
  border: 2px solid var(--status);
  border-radius: 999px;     /* fully rounded: a pill */
  color: var(--status);
  font-weight: 700;
  text-align: center;
}

/* The life timer: as big as the screen allows, coloured by status (section 3b). */
.age {
  margin: 0;
  color: var(--status-age);
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: var(--age-size);
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* A short bar in the scene colour, between the age and "Scène x van y". ::before adds an
   element in CSS only, before the content of #playing-scene. */
#playing-scene::before {
  content: "";
  display: block;
  width: 4rem;
  height: var(--accent-bar);
  margin: 0 auto 0.5rem;
  border-radius: var(--accent-bar);
  background: var(--scene);
}

#playing-scene {
  margin: 0.5rem 0 var(--gap);
  text-align: center;
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  letter-spacing: 0.04em;
}

#role-name {
  margin: 0.5rem 0;
  font-size: 2.2rem;
}

.participant .story {
  font-size: 1.15rem;
}

#earlier {
  margin-top: 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

#earlier h3 {
  margin: 1rem 0 0.25rem;
  color: var(--muted);
  font-size: 1rem;
}

/* Code screen */
#join-form {
  text-align: center;
}

#join-form label span {
  font-size: 1.1rem;
}

.code-input {
  max-width: 12ch;
  margin: 0 auto;
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  text-align: center;
}

#join-button {
  min-width: 12rem;
  font-size: 1.25rem;
}

/* M7c: the non-user warning, in the place of the age. The SVG triangle has no fill, only an
   outline. The corners are rounded in the path itself (Q = a curve through the corner
   point). vector-effect keeps the line the same thickness however big it is drawn. */
#warning {
  text-align: center;
}

/* position: relative makes this box the reference for the absolutely placed age below. */
#warning-triangle {
  position: relative;
  container-type: inline-size;  /* lets the age below size itself to this box (cqw) */
  width: 70%;
  max-width: 18rem;
  margin: 0 auto;
}

#warning svg {
  display: block;
  width: 100%;
}

/* The age in the middle of the triangle. absolute: taken out of the normal flow and placed
   relative to #warning-triangle. top: 64% is the centre of mass of the triangle (2/3 down,
   a little higher for the look); translate(-50%, -50%) moves the text back by half its own
   size, so its centre (not its top-left corner) lands on that point. */
#warning-age {
  position: absolute;
  top: 64%;
  left: 50%;
  margin: 0;
  transform: translate(-50%, -50%);
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: 26cqw;         /* 26% of the triangle width: "104" still fits inside */
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#warning path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

#warning-title {
  margin: 0.5rem 0 0;
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: clamp(2.5rem, 14vw, 4.5rem);
  line-height: 1.1;
}

#warning-text {
  margin: 0.25rem 0 0;
  font-weight: 700;
  font-size: 1.2rem;
}

/* Video message: the open button above the story, the player in the place of the age. */
#video-button-box {
  margin: 0 0 var(--gap);
  text-align: center;
}

#video-player {
  text-align: center;
}

video {
  display: block;
  width: 100%;
  max-height: 60vh;
  margin: 0 auto 0.75rem;
  border-radius: var(--radius);
  background: #000;
}

/* Finished and closed: centred, like the back of a card. */
#finished-screen,
#closed-screen {
  text-align: center;
}

#finished-text,
#closed-text {
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: 1.4rem;
}

/* 7. Organiser page ---------------------------------------------------------------- */
.organiser {
  max-width: 72rem;
  margin: 0 auto;
}

.organiser section > h2,
#scenario-admin > h2 {
  margin-top: 2rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--line);
}

.organiser ul {
  padding-left: 1.2rem;
}

.organiser li {
  margin: 0.4rem 0;
}

/* A rounded box, like the facilitator script cards; the top edge in the scene colour. */
.panel {
  margin: var(--gap) 0;
  padding: var(--gap);
  border-top: calc(2 * var(--accent-bar)) solid var(--scene);
  border-radius: var(--radius);
  background: var(--panel);
}

#room-title {
  margin: var(--gap) 0 0;
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: 1.6rem;
}

.room-code {
  margin: 0.25rem 0;
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: var(--code-size);
  letter-spacing: 0.1em;
  line-height: 1;
}

#join-url {
  margin: 0;
  font-size: 1.4rem;
}

#scene-label {
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: 1.4rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.45rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-weight: 700;
}

/* 8. Login page ------------------------------------------------------------------- */
.login {
  max-width: 24rem;
  margin: 15vh auto 0;
}
