/* AfterBedtime — UI overlay. Nostalgic 2003 bedroom at night: dark blue, sage, warm off-white, honey timber. */

:root {
  --night: #10162e;
  --night-2: #18213f;
  --night-3: #222d52;
  --ink: #131a33;
  --sage: #9fbf9a;
  --sage-deep: #5f8466;
  --cream: #f4ecd8;
  --cream-dim: #c9c1ad;
  --honey: #e2aa5c;
  --honey-deep: #a9742f;
  --rose: #e98a78;
  --lilac: #b9aae6;
  --glass: rgba(16, 22, 46, 0.62);
  --font: "Fredoka", "Nunito", "Arial Rounded MT Bold", ui-rounded, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--night);
  color: var(--cream);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  user-select: none;
}

.screen {
  position: absolute;
  inset: 0;
}

/* ------------------------------------------------------------------ shared bits */

.card {
  pointer-events: auto;
  background: linear-gradient(180deg, var(--night-3) 0%, var(--night-2) 100%);
  border: 3px solid rgba(159, 191, 154, 0.32);
  border-radius: 26px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  color: var(--cream);
}

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.05em 0.45em;
  margin: 0 0.12em;
  border-radius: 7px;
  background: var(--cream);
  color: var(--ink);
  font: 600 0.82em/1.5 var(--font);
  text-align: center;
  box-shadow: 0 2px 0 var(--cream-dim);
}

.ico { width: 1.2em; height: 1.2em; flex: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  font: 600 16px/1.2 var(--font);
  color: var(--ink);
  background: var(--sage);
  border: 0;
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: 0 4px 0 var(--sage-deep);
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s, filter 0.15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--sage-deep); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible, .seg button:focus-visible, input:focus-visible { outline: 3px solid var(--honey); outline-offset: 2px; }
.btn-small { font-size: 14px; padding: 8px 12px; }
.btn-big { width: 100%; font-size: 21px; padding: 14px 18px; margin-top: 6px; }
.btn-honey { background: var(--honey); box-shadow: 0 5px 0 var(--honey-deep); }
.btn-honey:active:not(:disabled) { box-shadow: 0 1px 0 var(--honey-deep); }

.meter {
  position: relative;
  flex: 1;
  height: 10px;
  min-width: 60px;
  border-radius: 6px;
  background: rgba(244, 236, 216, 0.12);
  overflow: hidden;
}
.meter > i {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--sage), #d6e7a8);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.08s linear;
}
.meter-small { height: 6px; min-width: 70px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  font-size: 13.5px;
  color: var(--cream-dim);
}
.legend span { white-space: nowrap; }

/* ------------------------------------------------------------------ lobby */

#lobby {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: max(24px, 4vh) 16px;
  pointer-events: auto;
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(244, 236, 216, 0.8), transparent 60%),
    radial-gradient(1px 1px at 78% 12%, rgba(244, 236, 216, 0.7), transparent 60%),
    radial-gradient(1.5px 1.5px at 88% 64%, rgba(244, 236, 216, 0.6), transparent 60%),
    radial-gradient(1px 1px at 22% 78%, rgba(244, 236, 216, 0.6), transparent 60%),
    radial-gradient(1.2px 1.2px at 52% 8%, rgba(244, 236, 216, 0.7), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(226, 170, 92, 0.16), transparent 60%),
    rgba(12, 17, 36, 0.62);
  backdrop-filter: blur(3px);
}

.lobby-card {
  width: min(920px, 100%);
  margin: auto 0;
  padding: 26px 30px 22px;
}

.lobby-head {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}
.moon {
  width: 64px;
  height: 64px;
  flex: none;
  color: var(--honey);
  filter: drop-shadow(0 0 14px rgba(226, 170, 92, 0.45));
}
.title {
  margin: 0;
  font-size: clamp(38px, 6vw, 58px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.5px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.title .accent { color: var(--honey); }
.tagline { margin: 6px 0 0; color: var(--cream-dim); font-size: 16px; }

@media (max-width: 760px) {
  .lobby-card { padding: 20px 18px; }
}

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sage);
}
#name-input {
  width: 100%;
  font: 600 18px/1.2 var(--font);
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid rgba(0, 0, 0, 0.12);
  background: var(--cream);
  color: var(--ink);
  user-select: text;
}
#name-input:disabled { background: rgba(244, 236, 216, 0.1); color: var(--cream); border-color: transparent; }

.seg {
  display: flex;
  padding: 4px;
  gap: 4px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.25);
}
.seg button {
  flex: 1;
  font: 600 15px/1 var(--font);
  padding: 10px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--cream-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--cream); }
.seg button[aria-pressed="true"] { background: var(--sage); color: var(--ink); }
.seg button[data-pref="parent"][aria-pressed="true"] { background: var(--honey); }

.mic-row { display: flex; align-items: center; gap: 12px; }
#mic-btn[data-state="on"] { background: #cfe3a4; box-shadow: 0 4px 0 #7f9a58; opacity: 1; }
#mic-btn[data-state="denied"] { background: var(--rose); box-shadow: 0 4px 0 #a6564a; }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--cream-dim); }
.hint.talking { color: #d6e7a8; }

.lobby-status { min-height: 1.3em; margin: 10px 0 0; font-size: 14px; color: var(--cream-dim); text-align: center; }

.col-title {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 600;
  color: var(--cream);
}
.col-title .count { color: var(--cream-dim); font-weight: 500; }

.player-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 6px;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(244, 236, 216, 0.06);
}
.player-list li.me { background: rgba(159, 191, 154, 0.16); }
.player-list .pname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .you { color: var(--sage); font-weight: 500; font-size: 13px; }
.player-list .empty { color: var(--cream-dim); background: transparent; font-style: italic; }
.chip {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(244, 236, 216, 0.12);
  color: var(--cream-dim);
}
.chip.parent { background: rgba(226, 170, 92, 0.2); color: var(--honey); }
.chip.child { background: rgba(159, 191, 154, 0.2); color: var(--sage); }

.last-result {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(226, 170, 92, 0.12);
  color: var(--cream);
  font-size: 14px;
}

.how { display: grid; gap: 10px; }
.how-item { padding: 10px 14px; border-radius: 14px; background: rgba(0, 0, 0, 0.18); }
.how-item h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.how-child h3 { color: var(--sage); }
.how-parent h3 { color: var(--honey); }
.how-item p { margin: 0; font-size: 13.5px; line-height: 1.45; color: var(--cream-dim); }

.lobby-card > .legend {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 2px dashed rgba(244, 236, 216, 0.12);
}

/* v2: quick start, game mode, difficulty, captions toggle */
.lobby-head-text { min-width: 0; }
.lobby-col { min-width: 0; }

.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--honey); outline-offset: 2px; }
.seg button[data-difficulty][aria-pressed="true"] { background: var(--honey); }
.seg button[data-difficulty="easy"][aria-pressed="true"] { background: var(--sage); }
.seg button[data-difficulty="hard"][aria-pressed="true"] { background: var(--rose); }
.seg button:disabled { opacity: 0.45; cursor: default; }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.toggle-track {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: rgba(244, 236, 216, 0.16);
  transition: background 0.15s;
}
.toggle-track > i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cream-dim);
  transition: transform 0.15s, background 0.15s;
}
.toggle input:checked + .toggle-track { background: var(--sage); }
.toggle input:checked + .toggle-track > i { transform: translateX(16px); background: var(--ink); }
.toggle-text { display: flex; flex-direction: column; font-size: 14px; font-weight: 500; min-width: 0; }
.toggle-text small { font-size: 12.5px; color: var(--cream-dim); font-weight: 400; }

.chip.bot { background: rgba(185, 170, 230, 0.2); color: var(--lilac); }

/* Narrow screens (embedded browsers, small windows): nothing may stick out sideways. */
@media (max-width: 520px) {
  #lobby { padding: 12px 10px; }
  .lobby-card { padding: 18px 14px 16px; border-radius: 20px; }
  .lobby-head { gap: 12px; margin-bottom: 14px; }
  .moon { width: 46px; height: 46px; }
  .title { font-size: 34px; }
  .tagline { font-size: 14px; }
  .mic-row { flex-wrap: wrap; }
  .mic-row .meter { min-width: 80px; }
  .seg button { padding: 10px 2px; font-size: 14px; }
  .btn-big { font-size: 19px; }
  .legend { gap: 6px 12px; font-size: 12.5px; }
  .legend span { white-space: normal; }
}
@media (max-width: 360px) {
  .title { font-size: 28px; }
  .moon { display: none; }
}

/* ------------------------------------------------------------------ HUD */

.hud-top {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(560px, 92vw);
  text-align: center;
}
.clock-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 16px 5px 12px;
  border-radius: 999px;
  background: var(--glass);
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}
.clock-pill .ico { color: var(--honey); }
.clock-pill.late { animation: late-pulse 1.6s ease-in-out infinite; }
@keyframes late-pulse { 50% { box-shadow: 0 0 0 3px rgba(226, 170, 92, 0.55), 0 2px 12px rgba(0, 0, 0, 0.3); } }

.role-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: rgba(159, 191, 154, 0.85);
  color: var(--ink);
}
.role-badge.parent { background: rgba(226, 170, 92, 0.92); }
.role-badge .swatch { width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 1.5px rgba(19, 26, 51, 0.5); }

.objective {
  padding: 3px 12px;
  border-radius: 12px;
  background: rgba(16, 22, 46, 0.45);
  font-size: 17px;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}
.objective:empty { display: none; }

.progress {
  display: flex;
  align-items: center;
  gap: 8px;
}
.progress-bar {
  position: relative;
  width: min(240px, 60vw);
  height: 14px;
  border-radius: 8px;
  background: rgba(16, 22, 46, 0.7);
  border: 2px solid rgba(244, 236, 216, 0.25);
  overflow: hidden;
}
.progress-bar > i {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--sage), #d6e7a8);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.3s ease-out;
}
.progress-text {
  min-width: 3ch;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: left;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--cream);
  box-shadow: 0 0 0 1.5px rgba(16, 22, 46, 0.7);
  transition: transform 0.12s, background 0.12s;
}
.crosshair.target { transform: scale(1.6); background: var(--honey); }

/* Hold-E progress ring around the crosshair (slow, quiet door). --p = 0..1 */
.hold-ring {
  --p: 0;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: conic-gradient(var(--cream) calc(var(--p) * 360deg), rgba(16, 22, 46, 0.45) 0);
  -webkit-mask: radial-gradient(circle, transparent 15px, #000 15.5px, #000 20.5px, transparent 21px);
  mask: radial-gradient(circle, transparent 15px, #000 15.5px, #000 20.5px, transparent 21px);
  filter: drop-shadow(0 0 2px rgba(16, 22, 46, 0.9));
}
.hold-ring.busy {
  background: conic-gradient(var(--honey) calc(var(--p) * 360deg), rgba(226, 170, 92, 0.2) 0);
  animation: ring-breathe 1.1s ease-in-out infinite;
}
@keyframes ring-breathe { 50% { transform: scale(1.12); } }

.prompt {
  position: absolute;
  left: 50%;
  top: calc(50% + 22px);
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px 6px;
  max-width: 92vw;
  width: max-content;
  padding: 5px 12px;
  border-radius: 12px;
  background: var(--glass);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
}
.prompt .sep { opacity: 0.45; margin: 0 4px; }
.prompt .part { white-space: nowrap; }

/* Heartbeat vignette: outer opacity = level (JS), inner pulses lub-dub. */
.heartbeat {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease-out;
}
.heartbeat > i {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, transparent 52%, rgba(120, 20, 30, 0.34) 78%, rgba(70, 8, 16, 0.72) 100%);
  animation: lubdub 0.92s ease-out infinite;
}
@keyframes lubdub {
  0% { opacity: 0.55; }
  8% { opacity: 1; }
  20% { opacity: 0.6; }
  30% { opacity: 0.92; }
  55%, 100% { opacity: 0.5; }
}

/* Toy count (child) / flashlight (parent) chips, bottom right */
.hud-chips {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.chip-hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 10px;
  border-radius: 14px;
  background: var(--glass);
  color: var(--cream);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.chip-hud .ico { width: 22px; height: 22px; color: var(--honey); }
.chip-hud .chip-key { color: var(--cream-dim); font-size: 13px; }
.chip-hud .chip-sub { color: var(--cream-dim); font-size: 13px; margin-left: -3px; }
.chip-hud.pop { animation: chip-pop 0.35s ease-out; }
@keyframes chip-pop { 40% { transform: scale(1.12); } }
#hud-flash .beam { opacity: 0.2; transition: opacity 0.2s; }
#hud-flash.on { background: rgba(244, 226, 170, 0.9); color: var(--ink); }
#hud-flash.on .ico { color: var(--ink); }
#hud-flash.on .beam { opacity: 0.9; }
#hud-flash.on .chip-key { color: rgba(19, 26, 51, 0.7); }

/* Subtitles: what you can hear (barks always; other sounds with the captions option). */
.captions {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: min(640px, 56vw);
  pointer-events: none;
}
.caption {
  max-width: 100%;
  padding: 5px 14px;
  border-radius: 10px;
  background: rgba(8, 11, 24, 0.72);
  font-size: 18px;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  transition: opacity 0.5s;
  animation: toast-in 0.2s ease-out;
}
.caption b { color: var(--honey); font-weight: 600; }
.caption.sound { font-size: 15px; font-style: italic; color: var(--cream-dim); background: rgba(8, 11, 24, 0.55); }
.caption.muffled { color: var(--cream-dim); }
.caption.leaving { opacity: 0 !important; }

#hud[data-role="parent"] .kid-only, #hud[data-role="child"] .parent-only { display: none; }

.countdown {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  z-index: 3;             /* stays above the click-to-play overlay */
  font-size: clamp(72px, 14vh, 120px);
  line-height: 1;
  font-weight: 700;
  color: var(--cream);
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 40px rgba(226, 170, 92, 0.5);
  animation: count-pop 1s ease-out infinite;
}
.countdown.go { color: var(--honey); animation: go-pop 0.9s ease-out forwards; }
@keyframes count-pop { 0% { transform: translate(-50%, -50%) scale(1.25); opacity: 0.4; } 25% { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes go-pop { 0% { transform: translate(-50%, -50%) scale(0.7); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1.3); opacity: 0; } }

.status {
  position: absolute;
  left: 50%;
  top: 64%;
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: 18px;
  background: var(--glass);
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.status-title { font-size: 24px; font-weight: 600; }
.status-sub { font-size: 14px; color: var(--cream-dim); }
.status-sub:empty { display: none; }
.status.bad .status-title { color: var(--rose); }
.status.calm .status-title { color: var(--sage); }
.status.compact { padding: 5px 16px; border-radius: 14px; }
.status.compact .status-title { font-size: 17px; }

.talk {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 10px;
  border-radius: 16px;
  background: var(--glass);
  color: var(--cream-dim);
  transition: background 0.15s, color 0.15s;
}
.talk .ico { width: 22px; height: 22px; }
.talk-body { display: flex; flex-direction: column; gap: 4px; }
.talk-body .meter { flex: none; }
.talk-label { font-size: 13px; font-weight: 500; white-space: nowrap; }
.talk[data-state="off"] { opacity: 0.7; }
.talk[data-state="off"] .meter { display: none; }
.talk[data-state="talking"] { background: rgba(159, 191, 154, 0.9); color: var(--ink); }
.talk[data-state="whisper"] { background: rgba(185, 170, 230, 0.9); color: var(--ink); }
.talk[data-state="talking"] .meter, .talk[data-state="whisper"] .meter { background: rgba(19, 26, 51, 0.25); }
.talk[data-state="talking"] .meter > i, .talk[data-state="whisper"] .meter > i { background: var(--ink); }

.click-to-play {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20vh 16px 16px;  /* sits below centre so the countdown above stays readable */
  pointer-events: auto;
  cursor: pointer;
  background: rgba(10, 14, 30, 0.55);
}
.ctp-card {
  padding: 22px 28px;
  max-width: 560px;
  text-align: center;
}
.ctp-title { font-size: 34px; font-weight: 700; color: var(--honey); }
.ctp-role { margin: 6px 0 16px; font-size: 16px; color: var(--cream); }
.ctp-role:empty { display: none; }
.leave-btn { margin-top: 18px; padding: 8px 18px; font-size: 14px; background: transparent; color: var(--cream);
  border: 1px solid rgba(255,255,255,0.25); border-radius: 10px; cursor: pointer; opacity: 0.85; }
.leave-btn:hover { opacity: 1; border-color: var(--honey); color: var(--honey); }
.leave-btn.confirm { background: #b8574f; border-color: #b8574f; color: #fff; opacity: 1; }

/* ------------------------------------------------------------------ end screen */

#end {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: max(24px, 5vh) 16px;
  pointer-events: auto;
  background: rgba(10, 14, 30, 0.72);
  backdrop-filter: blur(4px);
}
.end-card {
  width: min(640px, 100%);
  margin: auto 0;
  padding: 26px 30px 24px;
  text-align: center;
}
.end-banner {
  font-size: clamp(30px, 5vw, 44px);
  font-weight: 700;
  line-height: 1.1;
  color: var(--sage);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.end-banner.parent { color: var(--honey); }
.end-sub { margin-top: 6px; font-size: 18px; font-weight: 600; }
.end-reason { margin: 8px 0 16px; color: var(--cream-dim); }
.end-stats {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}
.end-stats > div {
  display: flex;
  flex-direction: column;
  padding: 8px 18px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.2);
}
.end-stats span { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--cream-dim); }
.end-stats b { font-size: 22px; }
.end-card .col-title { text-align: left; }

.timeline {
  list-style: none;
  margin: 0 0 16px;
  padding: 4px;
  max-height: 38vh;
  overflow-y: auto;
  text-align: left;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
}
.timeline li {
  display: flex;
  gap: 12px;
  padding: 7px 10px;
  border-radius: 10px;
}
.timeline li:nth-child(odd) { background: rgba(244, 236, 216, 0.04); }
.timeline time {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--honey);
}
.timeline .empty { color: var(--cream-dim); font-style: italic; }
.timeline li.ai span { color: var(--cream-dim); }
.timeline li.ai time { color: var(--lilac); }
.timeline .who {
  flex: none;
  align-self: flex-start;
  margin-top: 1px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: rgba(185, 170, 230, 0.18);
  color: var(--lilac);
}
@media (max-width: 520px) {
  #end { padding: 12px 10px; }
  .end-card { padding: 18px 14px; }
  .end-stats { flex-wrap: wrap; }
  .timeline li { gap: 8px; }
}

/* ------------------------------------------------------------------ toasts & banners */

.toasts {
  position: absolute;
  left: 50%;
  bottom: 140px;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  width: min(520px, 92vw);
}
.toast {
  padding: 9px 16px;
  border-radius: 14px;
  background: rgba(24, 33, 63, 0.92);
  border: 2px solid rgba(244, 236, 216, 0.14);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.4s, transform 0.4s;
}
.toast.good { border-color: rgba(159, 191, 154, 0.7); }
.toast.bad { border-color: rgba(233, 138, 120, 0.8); }
.toast.leaving { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
/* the same toast again while it is still up: refresh it with a small pop instead of stacking a copy */
.toast.pop { animation: toast-pop 0.3s ease-out; }
@keyframes toast-pop { 40% { transform: scale(1.06); } }

.conn-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 10px 16px;
  text-align: center;
  font-weight: 600;
  background: var(--rose);
  color: var(--ink);
  pointer-events: auto;
}

/* Narrow HUD: captions clear the talk indicator and chips, toasts sit above the captions. */
@media (max-width: 760px) {
  .captions { bottom: 76px; width: 92vw; }
  .caption { font-size: 16px; }
  /* no room between the prompt and the captions: toasts go under the top HUD instead */
  .toasts { top: 150px; bottom: auto; flex-direction: column; }
}

/* v4: under the covers — almost nothing to see: dark fabric with a faint weave and a sliver of light at the edge */
.covers {
  position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(120% 60% at 50% 115%, rgba(60, 70, 95, 0.35), transparent 60%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.025) 0 2px, transparent 2px 5px),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.25) 0 2px, transparent 2px 6px),
    radial-gradient(90% 80% at 50% 45%, rgba(18, 20, 30, 0.93), rgba(6, 7, 12, 0.985));
  animation: covers-breathe 4.2s ease-in-out infinite;
}
@keyframes covers-breathe { 0%, 100% { opacity: 0.97; } 50% { opacity: 1; } }

/* v5: a drowsy parent's eyelids — they close slowly as the drowsiness rises (--lid 0..1, JS), blink heavily when
   very sleepy, and shut while dozing. The edge vignette darkens with them. */
.eyelids {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0;
  --lid: 0; opacity: 0; transition: opacity 0.8s ease-out;
}
.eyelids.on { opacity: 1; }
.eyelids::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse 75% 60% at 50% 50%, transparent 35%, rgba(4, 4, 8, calc(var(--lid) * 1.25)) 100%);
}
.eyelids > .lid {
  position: absolute; left: -12%; right: -12%; height: 52%;
  transition: transform 0.9s ease-in-out;
}
.eyelids > .top {
  top: 0; transform: translateY(calc(-100% + var(--lid) * 100%));
  background: linear-gradient(to bottom, #050508 0%, #07070b 82%, rgba(12, 10, 14, 0.75) 100%);
  border-radius: 0 0 50% 50% / 0 0 38% 38%;
}
.eyelids > .bottom {
  bottom: 0; transform: translateY(calc(100% - var(--lid) * 100%));
  background: linear-gradient(to top, #050508 0%, #07070b 82%, rgba(12, 10, 14, 0.75) 100%);
  border-radius: 50% 50% 0 0 / 38% 38% 0 0;
}
.eyelids.heavy > .top { animation: lid-droop-top 5.2s ease-in-out infinite; }
.eyelids.heavy > .bottom { animation: lid-droop-bottom 5.2s ease-in-out infinite; }
@keyframes lid-droop-top { 0%, 55%, 100% { translate: 0 0; } 70%, 80% { translate: 0 22%; } }
@keyframes lid-droop-bottom { 0%, 55%, 100% { translate: 0 0; } 70%, 80% { translate: 0 -22%; } }
.eyelids.dozing > .lid { transition-duration: 1.4s; height: 72%; }
.eyelids.dozing > .top { transform: translateY(0); }
.eyelids.dozing > .bottom { transform: translateY(0); }

/* ------------------------------------------------------------------ v6 (DESIGN-v4-build.md) */

/* Soft cover: a subtle veil at the edges while you are covered (only you see it; it never says whether anyone sees you).
   fabric = curtains / coats: soft folds at the sides; behind = the couch / the plant: a dark rim low in the view. */
.cover-veil { position: absolute; inset: 0; pointer-events: none; z-index: 0; opacity: 0; animation: veil-in 0.5s ease-out forwards; }
@keyframes veil-in { to { opacity: 1; } }
.cover-veil > i { position: absolute; inset: 0; }
.cover-veil.fabric > i {
  background:
    repeating-linear-gradient(90deg, rgba(10, 14, 30, 0.16) 0 26px, rgba(10, 14, 30, 0) 26px 58px),
    linear-gradient(90deg, rgba(8, 11, 24, 0.78) 0%, rgba(8, 11, 24, 0.18) 16%, transparent 30%, transparent 70%, rgba(8, 11, 24, 0.18) 84%, rgba(8, 11, 24, 0.78) 100%);
  -webkit-mask: linear-gradient(90deg, #000 0 24%, transparent 36% 64%, #000 76%);
  mask: linear-gradient(90deg, #000 0 24%, transparent 36% 64%, #000 76%);
}
.cover-veil.behind > i {
  background: radial-gradient(ellipse 85% 75% at 50% 35%, transparent 55%, rgba(6, 8, 18, 0.55) 100%),
    linear-gradient(to top, rgba(6, 8, 18, 0.7) 0%, rgba(6, 8, 18, 0) 26%);
}
.status.compact.cover .status-title { font-size: 16px; }
.status.hint { background: rgba(16, 22, 46, 0.5); }
.status.compact.hint .status-title { font-size: 15px; font-weight: 500; color: var(--cream-dim); }

/* the combination lock: three brass-ringed wheels over the crosshair */
.dial {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 14px 20px 12px; border-radius: 22px;
  background: linear-gradient(180deg, rgba(34, 45, 82, 0.95), rgba(24, 33, 63, 0.95));
  border: 3px solid rgba(226, 170, 92, 0.45);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  text-align: center; min-width: 260px; max-width: calc(100vw - 32px);
}
.dial.shake { animation: dial-shake 0.45s ease-in-out; }
@keyframes dial-shake {
  15% { transform: translate(calc(-50% - 9px), -50%); } 35% { transform: translate(calc(-50% + 8px), -50%); }
  55% { transform: translate(calc(-50% - 6px), -50%); } 75% { transform: translate(calc(-50% + 4px), -50%); }
}
.dial-title { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--honey); font-weight: 600; }
.dial-wheels { display: flex; justify-content: center; gap: 12px; margin: 10px 0 8px; }
.wheel {
  display: flex; flex-direction: column; align-items: center; width: 58px; padding: 4px 0;
  border-radius: 14px; background: linear-gradient(180deg, #0b1022, #1c2547 50%, #0b1022);
  border: 2px solid rgba(244, 236, 216, 0.14);
  transition: border-color 0.12s, transform 0.12s;
}
.wheel .w-prev, .wheel .w-next { font-size: 17px; line-height: 1.2; color: rgba(244, 236, 216, 0.28); }
.wheel .w-cur { font-size: 36px; line-height: 1.15; font-weight: 700; color: var(--cream); font-variant-numeric: tabular-nums; }
.wheel.sel { border-color: var(--honey); transform: translateY(-2px); box-shadow: 0 0 0 3px rgba(226, 170, 92, 0.22); }
.wheel.sel .w-cur { color: var(--honey); }
.dial.trying .wheel { border-color: rgba(159, 191, 154, 0.6); }
.dial-known { font-size: 14px; color: var(--sage); margin-bottom: 6px; }
.dial-wait { --w: 0; height: 4px; margin: 0 auto 8px; width: 70%; border-radius: 3px; background: rgba(233, 138, 120, 0.2); overflow: hidden; }
.dial-wait > i { display: block; height: 100%; background: var(--rose); transform-origin: left; transform: scaleX(var(--w)); }
.dial-keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; font-size: 13px; color: var(--cream-dim); }

/* chips: the code you know, the babyfoon receiver (parent), the power cut */
.code-digits { display: inline-flex; gap: 4px; }
.code-digits > b {
  display: inline-block; min-width: 20px; padding: 1px 4px; border-radius: 6px; text-align: center;
  font-variant-numeric: tabular-nums; background: rgba(226, 170, 92, 0.2); color: var(--honey);
}
.code-digits > b.unknown { background: rgba(244, 236, 216, 0.08); color: var(--cream-dim); font-weight: 500; }
#hud-babyfoon .led { fill: var(--sage); }
#hud-babyfoon.bf-muffled .led { fill: var(--honey); }
#hud-babyfoon.bf-lost { background: rgba(233, 138, 120, 0.9); color: var(--ink); }
#hud-babyfoon.bf-lost .ico { color: var(--ink); }
#hud-babyfoon.bf-lost .led { fill: #7a1d17; animation: led-blink 1s steps(2) infinite; }
@keyframes led-blink { 50% { opacity: 0.2; } }
#hud-power { background: rgba(8, 10, 20, 0.85); color: var(--cream); }
#hud-power .ico { color: var(--cream-dim); }

@media (max-width: 520px) {
  .dial { padding: 12px 12px 10px; min-width: 0; }
  .wheel { width: 50px; }
  .wheel .w-cur { font-size: 30px; }
}
/* at the combination lock only the newest toast shows (below the dial), so the wheels stay readable */
#ui.dialing .toast:not(:first-child) { display: none; }

/* ------------------------------------------------------------------ v7: a simpler lobby and HUD */

/* lobby: one column, three big ways to play, the rest folded */
.lobby-card { width: min(580px, 100%); }
.name-field { margin-bottom: 12px; }
.play-list { display: grid; gap: 10px; margin-bottom: 6px; }
.solo-block { display: grid; gap: 10px; }
.play-btn {
  width: 100%;
  justify-content: flex-start;
  gap: 14px;
  padding: 12px 18px;
  text-align: left;
}
.play-btn .ico { width: 30px; height: 30px; flex: none; }
.play-text { display: flex; flex-direction: column; min-width: 0; }
.play-main { font-size: 21px; font-weight: 700; line-height: 1.15; }
.play-main small { font-size: 15px; font-weight: 500; opacity: 0.8; }
.play-sub { font-size: 13.5px; font-weight: 500; opacity: 0.8; }
.play-practice { background: rgba(159, 191, 154, 0.2); color: var(--cream); border: 2px solid rgba(159, 191, 154, 0.55); }
.play-practice .ico { color: var(--sage); }
.play-practice:hover:not(:disabled) { background: rgba(159, 191, 154, 0.3); }
.play-friends { background: rgba(0, 0, 0, 0.22); color: var(--cream); border: 2px solid rgba(244, 236, 216, 0.16); }
.play-friends .ico { color: var(--lilac); }
.play-friends:hover:not(:disabled) { border-color: rgba(244, 236, 216, 0.34); }

.house {
  margin-top: 12px;
  padding: 14px 16px 16px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.2);
}
.house .col-title { font-size: 16px; }
.house .player-list { margin-bottom: 12px; }
.house .field { margin-bottom: 12px; }
.house .hint { margin: 6px 0 12px; }
.mode-seg button { font-size: 14px; padding-left: 4px; padding-right: 4px; }
.mode-seg button[aria-checked="true"] { background: var(--sage); color: var(--ink); }
.mode-seg button[data-mode="ai"][aria-checked="true"] { background: var(--honey); }
.lobby-status:empty { display: none; }

details.more { margin-top: 12px; border-radius: 14px; background: rgba(0, 0, 0, 0.14); }
details.more > summary, .legend-more > summary {
  cursor: pointer;
  list-style: none;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--cream-dim);
  border-radius: 14px;
}
details.more > summary::-webkit-details-marker, .legend-more > summary::-webkit-details-marker { display: none; }
details.more > summary::before, .legend-more > summary::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 9px 2px 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
details[open].more > summary::before, .legend-more[open] > summary::before { transform: rotate(45deg); }
details.more > summary:hover, .legend-more > summary:hover { color: var(--cream); }
details.more > :not(summary) { margin: 4px 14px 14px; }
details.more .field:last-child { margin-bottom: 0; }

.legend { display: block; }
.legend-basics { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; }
.legend-compact .legend-basics { gap: 8px 11px; }
.legend-basics span { white-space: nowrap; }
.legend-more { margin-top: 8px; text-align: center; }
.legend-more > summary { display: inline-block; padding: 4px 10px; font-size: 13px; }
.legend-groups {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 8px auto 0;
  max-width: 480px;
  text-align: left;
  font-size: 13px;
}
.legend-groups dt { font-weight: 600; color: var(--cream); }
.legend-groups dd { margin: 0; color: var(--cream-dim); }
#hud:not([data-mode="sandbox"]) .sandbox-only { display: none; }

/* HUD: clock, one objective line, progress; the role is in the pause card, not on screen */
.role-badge { display: none; }
.objective { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ONE prompt, one line */
.prompt {
  flex-wrap: nowrap;
  max-width: min(92vw, 560px);
  overflow: hidden;
  white-space: nowrap;
  font-size: 15px;
}
.prompt .part { overflow: hidden; text-overflow: ellipsis; }

/* the status pill: one short line (grounded counts down in rose) */
.status { top: 60%; padding: 4px 14px; border-radius: 14px; box-shadow: none; }
.status .status-title { font-size: 15px; font-weight: 600; white-space: nowrap; }
.status .status-sub { display: none; }
.status.grounded { background: rgba(120, 36, 36, 0.72); }
.status.grounded .status-title { color: #ffd9d0; font-variant-numeric: tabular-nums; }

/* small chips, only while they apply */
.hud-chips { gap: 6px; }
.chip-hud { padding: 5px 10px 5px 8px; gap: 6px; font-size: 13px; border-radius: 12px; }
.chip-hud .ico { width: 18px; height: 18px; }
.chip-hud .chip-key kbd { font-size: 11px; }

/* one toast at a time, low in the view */
.toasts { bottom: 96px; width: min(460px, 92vw); }
.toast { padding: 7px 14px; font-size: 14px; border-radius: 12px; }

/* the practice tools (practice night only) */
.practice {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 3;                 /* above the pause backdrop: clickable while the mouse is free */
  pointer-events: auto;
  width: 220px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid rgba(159, 191, 154, 0.35);
  font-size: 13px;
}
.practice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  background: none;
  color: var(--sage);
  font: 600 13px/1.2 var(--font);
  cursor: pointer;
}
.practice-head span { color: var(--cream-dim); font-weight: 500; }
.practice-body { padding: 0 8px 8px; }
.practice-label { margin: 6px 2px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--cream-dim); }
.practice-group { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.practice-body button[data-sb] {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border: 1px solid rgba(244, 236, 216, 0.14);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--cream);
  font: 500 12.5px/1.15 var(--font);
  text-align: left;
  cursor: pointer;
}
.practice-body button[data-sb]:hover { border-color: var(--sage); }
.practice-body button[data-sb] kbd { font-size: 10.5px; min-width: 1.6em; padding: 0 4px; }
.practice-body button.pop { animation: chip-pop 0.3s ease-out; }
.practice-reset { width: 100%; margin-top: 6px; justify-content: center; color: var(--rose) !important; }
.practice-sd { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; margin-top: 4px; padding: 5px 6px;
  border: 1px solid rgba(226, 170, 92, 0.4); border-radius: 9px; background: rgba(0, 0, 0, 0.25); color: var(--honey);
  font: 500 12.5px/1.15 var(--font); cursor: pointer; }
.practice-sd:hover { border-color: var(--honey); }
.practice-sd kbd { font-size: 10.5px; padding: 0 4px; }

@media (max-width: 520px) {
  .play-main { font-size: 19px; }
  .practice { width: 180px; right: 8px; }
  .legend-groups { grid-template-columns: 1fr; }
}

/* ai-kids: "Play the parent" (vs AI children) in the lobby */
.play-parent { background: rgba(232, 176, 108, 0.16); color: var(--cream); border: 2px solid rgba(232, 176, 108, 0.5); }
.play-parent .ico { color: #e8b06c; }
.play-parent:hover:not(:disabled) { background: rgba(232, 176, 108, 0.26); }
