/* Shared components used by every theme (always loaded, last).
   Colours come from the theme's --motion-* variables; --switch-radius sets the shape. */

/* ---------- Digital clock in the top bar (HH:MM, 24-hour) ---------- */
.clock {
  display: inline-flex; align-items: center; gap: .4rem; flex: none;
  padding-right: .75rem; margin-right: .5rem;
  border-right: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  font-weight: 700; font-size: 1rem; line-height: 1;
  white-space: nowrap; cursor: default;
}
/* Analogue icon whose hands show the current time */
.clock-icon {
  width: 1.375rem; height: 1.375rem; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
}
.clock-hand { transform-box: view-box; transform-origin: 12px 12px; transition: transform .6s ease-in-out; }
.clock-hand-h { stroke-width: 2.4; }
.clock-hand-m { stroke-width: 1.8; }
.clock-pin { fill: currentColor; stroke: none; }
/* Caption above the digits, styled like the "SESSION" caption */
.clock-text { display: flex; flex-direction: column; line-height: 1.2; }
.clock-label { font-family: var(--font, inherit); font-weight: 400; }
.clock-digits { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.clock-colon { margin: 0 .05em; animation: clock-blink 1s steps(1, end) infinite; }
@keyframes clock-blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .clock-colon { animation: none; } }

/* The clock is a button (opens the end-time panel) */
.clock-wrap { position: relative; display: inline-flex; flex: none; }
button.clock {
  background: none; border-top: 0; border-bottom: 0; border-left: 0;
  padding-top: .25rem; padding-bottom: .25rem; padding-left: .375rem;
  color: inherit; text-align: left; cursor: pointer;
  border-radius: var(--menu-item-radius, 0);
  transition: background-color .15s ease, color .2s ease, box-shadow .2s ease;
}
body.in-session button.clock:hover { background: var(--menu-hover, rgba(128, 128, 128, .12)); }
body:not(.in-session) button.clock { cursor: default; }
/* A small marker shows an end time is set */
.clock.has-end .clock-icon { stroke: var(--motion-accent, currentColor); }

/* Warning: red, pulsing ring, ringing alarm-clock icon, countdown in the caption */
:root { --clock-warn: #d52b1e; --clock-warn-fg: #fff; }
:root[data-theme="dark"] { --clock-warn: #ff5f52; --clock-warn-fg: #1a0000; }
.clock.is-warning {
  color: var(--clock-warn) !important;
  background: color-mix(in srgb, var(--clock-warn) 14%, transparent);
  animation: clock-warn-pulse 1s ease-in-out infinite;
}
.clock.is-warning .clock-icon { stroke: var(--clock-warn); animation: clock-ring .9s ease-in-out infinite; transform-origin: 50% 50%; }
.clock.is-warning .clock-label { color: var(--clock-warn) !important; font-weight: 700; opacity: 1; }
@keyframes clock-warn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--clock-warn) 60%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--clock-warn) 0%, transparent); }
}
@keyframes clock-ring {
  0%, 50%, 100% { transform: rotate(0); }
  10%, 30% { transform: rotate(-14deg); }
  20%, 40% { transform: rotate(14deg); }
}
/* Time's up: solid red, caption blinks */
.clock.is-over {
  color: var(--clock-warn-fg) !important;
  background: var(--clock-warn) !important;
  text-shadow: none !important;
  animation: clock-warn-pulse 1s ease-in-out infinite;
}
.clock.is-over .clock-icon { stroke: currentColor; }
.clock.is-over .clock-label { color: inherit !important; font-weight: 700; opacity: 1; animation: clock-blink 1s steps(1, end) infinite; }
@media (prefers-reduced-motion: reduce) {
  .clock.is-warning, .clock.is-over, .clock.is-warning .clock-icon, .clock.is-over .clock-label { animation: none; }
  .clock.is-warning { box-shadow: 0 0 0 2px var(--clock-warn); }
}

/* End-time panel: drops down from the clock, in the theme's menu colours */
.timer-panel {
  position: absolute; left: 0; top: calc(100% + .5rem); z-index: 50;
  width: 16.5rem; padding: .5rem .75rem .75rem;
  background: var(--menu-bg, #fff); color: var(--menu-fg, #000);
  border: 1px solid var(--menu-border, rgba(0, 0, 0, .12));
  border-radius: var(--menu-radius, 0);
  box-shadow: var(--menu-shadow, 0 8px 24px rgba(0, 0, 0, .18));
  text-shadow: none;
  transform-origin: top left;
  animation: design-menu-in .16s ease-out;
}
.timer-panel .design-menu-title { padding-left: 0; padding-right: 0; }
.timer-row { display: flex; align-items: center; gap: .375rem; margin: .25rem 0 .75rem; }
.timer-colon { font-weight: 700; font-size: 1.5rem; }
.timer-select {
  min-height: 2.75rem; padding: .375rem .5rem;
  background: var(--menu-bg, #fff); color: var(--menu-fg, #000);
  border: 1px solid currentColor; border-radius: var(--menu-item-radius, 0);
  font: inherit; font-size: 1.125rem; font-variant-numeric: tabular-nums;
}
.timer-row .timer-select { flex: 1; font-size: 1.5rem; font-weight: 700; text-align: center; }
.timer-label { display: block; margin: 0 0 .25rem; font-size: .875rem; font-weight: 700; }
.timer-label::after { content: none !important; }
.timer-warn { width: 100%; }
.timer-note { margin: .5rem 0 .75rem; font-size: .8125rem; opacity: .8; }
.timer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.timer-actions .btn { width: 100%; min-height: 2.5rem; padding-left: .5rem; padding-right: .5rem; }
.timer-actions .btn[hidden] { display: none !important; }
.timer-actions:has(#timer-clear[hidden]) { grid-template-columns: 1fr; }

/* Phones: in a session the header holds clock + session + 3 icons, so the brand makes way
   (the session name already says where you are). */
@media (max-width: 30rem) {
  body.in-session .brand { display: none; }
  body.in-session .header-actions { flex: 1; }
  body.in-session .clock { margin-right: auto; border-right: 0; padding-right: 0; } /* clock left, session + icons right */
  body.in-session .nav-session-name { max-width: 7.5rem; }     /* use the room the brand left */
  .clock { margin-right: .25rem; padding-right: .5rem; }
}

/* ---------- Reactions ---------- */
.actions { grid-template-columns: 1fr 1fr auto; } /* Reveal | New round | reaction button */
.react { position: relative; display: flex; }
.react-toggle { padding-left: .85rem; padding-right: .85rem; }
.react-toggle svg {
  width: 1.5rem; height: 1.5rem; display: block;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transition: transform .25s var(--motion-bounce, ease);
}
.react-toggle[aria-expanded="true"] svg { transform: scale(1.15) rotate(-10deg); }

/* Picker: pops up above the button, in the theme's menu colours (menu.css variables) */
.react-picker {
  position: absolute; right: 0; bottom: calc(100% + .5rem); z-index: 45;
  display: flex; gap: .125rem; padding: .375rem;
  background: var(--menu-bg, #fff); color: var(--menu-fg, #000);
  border: 1px solid var(--menu-border, rgba(0, 0, 0, .12));
  border-radius: var(--menu-radius, 0);
  box-shadow: var(--menu-shadow, 0 8px 24px rgba(0, 0, 0, .18));
  transform-origin: bottom right;
  animation: react-picker-in .22s var(--motion-bounce, ease-out);
}
@keyframes react-picker-in { from { opacity: 0; transform: scale(.85) translateY(6px); } }
.react-option {
  width: 2.75rem; height: 2.75rem; padding: 0;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: var(--menu-item-radius, 0);
  font-size: 1.5rem; line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  transition: transform .15s var(--motion-bounce, ease), background-color .15s ease;
}
@media (hover: hover) { .react-option:hover { background: var(--menu-hover, rgba(0, 0, 0, .06)); transform: translateY(-3px) scale(1.15); } }
.react-option:focus-visible { outline: 2px solid var(--menu-accent, currentColor); outline-offset: -2px; }
@media (max-width: 30rem) {
  .react-picker { display: grid; grid-template-columns: repeat(4, 2.75rem); } /* 4 × 2 fits a phone */
}

/* Floating reactions layer (created by app.js) */
#reactions { position: fixed; inset: 0; z-index: 65; pointer-events: none; overflow: hidden; }
.float-reaction {
  position: absolute; bottom: calc(6rem + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: .2rem;
  will-change: transform, opacity;
}
.float-emoji {
  font-size: 2.75rem; line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .25));
}
.float-name {
  max-width: 8rem; padding: .1rem .45rem; border-radius: 999px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 600 .75rem/1.3 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #fff; background: rgba(0, 0, 0, .6);
}

/* ---------- "You're the last one" cue (only in that person's browser) ---------- */
.last-cue {
  position: fixed; z-index: 55;
  top: calc(env(safe-area-inset-top) + 4.25rem); left: 50%;
  width: min(92vw, 26rem);
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem;
  background: var(--menu-bg, #fff); color: var(--menu-fg, #000);
  border: 3px solid var(--motion-accent, #e17000);
  border-radius: var(--menu-radius, 0);
  box-shadow: var(--menu-shadow, 0 8px 24px rgba(0, 0, 0, .18));
  cursor: pointer;
  transform: translateX(-50%);
  animation:
    last-cue-in .5s var(--motion-bounce, ease-out),
    last-cue-glow 1.6s ease-in-out .5s infinite;
}
@keyframes last-cue-in { from { opacity: 0; transform: translate(-50%, -24px) scale(.9); } }
@keyframes last-cue-glow {
  50% {
    box-shadow: var(--menu-shadow, 0 8px 24px rgba(0, 0, 0, .18)),
                0 0 0 6px color-mix(in srgb, var(--motion-accent, #e17000) 35%, transparent);
  }
}
.last-cue-icon {
  width: 2rem; height: 2rem; flex: none;
  fill: none; stroke: var(--motion-accent, #e17000); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  animation: last-cue-turn 2s ease-in-out infinite;
}
@keyframes last-cue-turn { 0%, 70% { transform: rotate(0); } 85%, 100% { transform: rotate(180deg); } }
.last-cue-text { display: flex; flex-direction: column; line-height: 1.3; }
.last-cue-text strong { font-size: 1.0625rem; }
.last-cue-text span { font-size: .875rem; opacity: .8; }

/* Your cards give a little nudge every few seconds */
body.is-last .deck .card:not(:disabled) {
  animation: last-nudge 2.4s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 40ms);
}
@keyframes last-nudge {
  0%, 70%, 100% { transform: none; }
  76% { transform: translateY(-4px) rotate(-4deg); }
  82% { transform: translateY(-4px) rotate(4deg); }
  88% { transform: translateY(-2px) rotate(-2deg); }
  94% { transform: none; }
}
body.is-last .tray-title { color: var(--motion-accent, #e17000); }

@media (prefers-reduced-motion: reduce) {
  .last-cue { animation: none; }
  .last-cue-icon, body.is-last .deck .card:not(:disabled) { animation: none; }
}

/* ---------- Observer switch on the join screen ---------- */
.switch-row { margin: 0 0 1.25rem; }
.switch {
  display: flex; align-items: flex-start; gap: .75rem;
  margin: 0; font-weight: 400; cursor: pointer;
}
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; margin: 0; }
.switch-track {
  position: relative; flex: none;
  width: 2.75rem; height: 1.625rem; margin-top: .1rem;
  border-radius: var(--switch-radius, 999px);
  background: var(--switch-off, rgba(120, 120, 128, .32));
  transition: background-color .2s ease;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 1.25rem; height: 1.25rem;
  border-radius: var(--switch-radius, 999px);
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .25s var(--motion-bounce, ease);
}
.switch input:checked + .switch-track { background: var(--motion-accent, #e17000); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(1.125rem); }
.switch input:focus-visible + .switch-track { outline: 2px dashed currentColor; outline-offset: 3px; }
.switch-text { display: flex; flex-direction: column; line-height: 1.3; }
.switch-text strong { font-weight: 700; }
.switch-text small { font-size: .875rem; opacity: .75; margin-top: .15rem; }

/* ---------- Observers in the room ---------- */
#room-view.is-observer .tray { display: none; }          /* no cards to pick */
.person.observer .mini { display: none; }                /* no seat card */
.person .role:empty { display: none; }
.person .role {
  display: inline-block; align-self: flex-start; margin-top: .15rem;
  padding: 0 .4rem; border: 1px solid currentColor; border-radius: var(--switch-radius, 999px);
  font-size: .6875rem; font-weight: 700; line-height: 1.5; text-transform: uppercase; letter-spacing: .06em;
  opacity: .75;
}
.observer-note { margin: .75rem 0 0; font-size: .9375rem; opacity: .8; }
