/* Ben's 70th engine UI: the upload list, the video-message recorder and the
   calendar sheet. Everything is themed by the --b70-* variables, which each
   design sets on :root. The defaults use :where() (no specificity), so a
   design's own :root rules always win, whichever stylesheet loads first. */

:where(:root) {
  --b70-bg: #f8f3ea;
  --b70-surface: #fffdf8;
  --b70-text: #1f2420;
  --b70-muted: #545a53;
  --b70-accent: #1f3a2d;
  --b70-accent-text: #ffffff;
  --b70-line: #d9cfbb;
  --b70-error: #a3302a;
  --b70-ok: #2e6b46;
  --b70-radius: 18px;
  --b70-font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --b70-font-display: Georgia, "Times New Roman", serif;
  --b70-record: #d93025; /* the universal "recording" red; a design may change it */
}

/* ---------- Things the engine shows and hides ---------- */

/* A design's display:flex must never beat the engine hiding a hook. */
[data-ben70][hidden],
.b70-overlay[hidden],
.b70-overlay [hidden] { display: none !important; }

/* <html data-phase="before|party|after">: [data-show-phase="party after"] shows only then.
   Until the engine runs, the page counts as "before". */
html:not([data-phase]) [data-show-phase]:not([data-show-phase~="before"]),
html[data-phase="before"] [data-show-phase]:not([data-show-phase~="before"]),
html[data-phase="party"] [data-show-phase]:not([data-show-phase~="party"]),
html[data-phase="after"] [data-show-phase]:not([data-show-phase~="after"]) { display: none !important; }

/* File pickers stay in the page (not display:none): some in-app browsers won't open a hidden one. */
.b70-file-input {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  pointer-events: none !important;
}

html.b70-locked,
html.b70-locked body { overflow: hidden; }

/* Only used when a design has no error element of its own. */
.b70-error { color: var(--b70-error); font-weight: 600; margin: 8px 0 0; }

/* ---------- Upload list ---------- */

:where([data-ben70="upload-list"]) {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.b70-upload {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--b70-line);
  border-radius: calc(var(--b70-radius) * 0.7);
  background: var(--b70-surface);
  color: var(--b70-text);
  font-family: var(--b70-font-body);
  text-align: left;
  animation: b70-rise 0.35s ease both;
}

.b70-upload-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--b70-bg);
  color: var(--b70-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.b70-upload-thumb img,
.b70-upload-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.b70-upload-thumb svg { width: 30px; height: 30px; }

.b70-upload-info { min-width: 0; display: grid; gap: 6px; }
/* Up to two lines, so "Video message from Tannie Hettie" shows the guest's own name. */
.b70-upload-name {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.b70-upload-bar { height: 10px; border-radius: 999px; background: var(--b70-line); overflow: hidden; }
.b70-upload-bar span {
  display: block;
  height: 100%;
  width: 0;
  min-width: 6px;
  border-radius: inherit;
  background: var(--b70-accent);
  transition: width 0.4s ease;
}
.b70-upload-status { margin: 0; font-size: 1.0625rem; line-height: 1.35; color: var(--b70-muted); font-variant-numeric: tabular-nums; }

.b70-upload.is-done .b70-upload-bar span { background: var(--b70-ok); }
.b70-upload.is-done .b70-upload-status { color: var(--b70-ok); font-weight: 700; }
.b70-upload.is-failed .b70-upload-bar span { background: var(--b70-error); }
.b70-upload.is-failed .b70-upload-status { color: var(--b70-error); font-weight: 600; }

.b70-retry,
.b70-send-anyway {
  justify-self: start;
  min-height: 48px;
  padding: 8px 22px;
  border-radius: 999px;
  border: 2px solid var(--b70-error);
  background: transparent;
  color: var(--b70-error);
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  cursor: pointer;
}
.b70-retry:focus-visible { outline: 3px solid var(--b70-error); outline-offset: 3px; }
.b70-send-anyway { border-color: var(--b70-accent); color: var(--b70-text); }
.b70-send-anyway:focus-visible { outline: 3px solid var(--b70-accent); outline-offset: 3px; }
/* Stop: there when needed, but quiet, so it is not tapped by mistake. */
.b70-stop {
  justify-self: start;
  min-height: 48px;
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--b70-muted);
  font: inherit;
  font-size: 1.0625rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.b70-stop:focus-visible { outline: 3px solid var(--b70-accent); outline-offset: 2px; }
.b70-upload.is-stopped .b70-upload-bar span { background: var(--b70-muted); }

/* ---------- Overlays (shared) ---------- */

.b70-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  /* Reset what the overlay would otherwise inherit from the design's body. */
  font-family: var(--b70-font-body);
  font-size: 18px;
  font-weight: 400;
  font-style: normal;
  line-height: 1.5;
  letter-spacing: normal;
  text-align: left;
  text-transform: none;
  text-shadow: none;
  white-space: normal;
  color: var(--b70-text);
  -webkit-text-size-adjust: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
}
.b70-overlay.is-visible { opacity: 1; pointer-events: auto; }
.b70-overlay *,
.b70-overlay *::before,
.b70-overlay *::after { box-sizing: border-box; }
.b70-overlay p { margin: 0; }
.b70-overlay :focus-visible { outline: 3px solid var(--b70-accent); outline-offset: 3px; }
.b70-overlay [tabindex="-1"]:focus { outline: none; }

.b70-icon { width: 22px; height: 22px; flex: none; }

.b70-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  margin: 0;
  padding: 14px 24px;
  border-radius: 999px;
  border: 2px solid transparent;
  font: inherit;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom, no tap delay */
  transition: transform 0.15s ease, background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}
.b70-btn:disabled { opacity: 0.55; cursor: default; }
.b70-btn:active { transform: scale(0.98); }
.b70-btn-primary { background: var(--b70-accent); color: var(--b70-accent-text); }
.b70-btn-secondary { background: transparent; color: var(--b70-text); border-color: var(--b70-accent); }
.b70-btn-quiet { background: transparent; color: var(--b70-text); min-height: 52px; text-decoration: underline; text-underline-offset: 3px; }
.b70-btn-small { width: auto; min-height: 48px; padding: 10px 20px; font-size: 1.0625rem; }

.b70-link {
  align-self: center;
  min-height: 48px;
  padding: 8px 12px;
  border: 0;
  background: none;
  color: var(--b70-text);
  font: inherit;
  font-size: 1.0625rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.b70-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 8px 18px 8px 12px;
  border-radius: 999px;
  border: 2px solid var(--b70-line);
  background: var(--b70-surface);
  color: var(--b70-text);
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  cursor: pointer;
}

.b70-label { display: block; font-family: var(--b70-font-display); font-size: 1.375rem; font-weight: 700; line-height: 1.25; }

/* The muted text colour as the border: at least 3:1 against the field in every design, so older eyes find it. */
.b70-input {
  width: 100%;
  min-height: 58px;
  padding: 14px 16px;
  border: 2px solid var(--b70-muted);
  border-radius: 14px;
  background: var(--b70-surface);
  color: var(--b70-text);
  font: inherit;
  font-size: 1.1875rem; /* 16px or more stops iPhones zooming in */
}
.b70-input:focus { outline: 3px solid var(--b70-accent); outline-offset: 1px; border-color: var(--b70-accent); }

.b70-msg { color: var(--b70-muted); font-size: 1.0625rem; }
.b70-msg-error { color: var(--b70-error); font-weight: 600; }

/* ---------- Recorder ---------- */

.b70-recorder {
  background: var(--b70-bg);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.b70-rec {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 560px;
  min-height: 100%;
  margin: 0 auto;
  padding:
    calc(12px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

.b70-rec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.b70-rec-title {
  min-width: 0;
  margin: 0;
  font-family: var(--b70-font-display);
  font-size: clamp(1.15rem, 5.2vw, 1.375rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--b70-text);
}

.b70-rec-prompt {
  padding: 12px 16px;
  border: 1px solid var(--b70-line);
  border-radius: calc(var(--b70-radius) * 0.75);
  background: var(--b70-surface);
  font-size: 1.0625rem;
  line-height: 1.45;
}

.b70-rec-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 260px;
  border-radius: var(--b70-radius);
  overflow: hidden;
  background: #121212;
  color: #fff;
  isolation: isolate;
}
.b70-rec-live,
.b70-rec-play {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #121212;
}
/* The live view is mirrored like a bathroom mirror; the playback is not, so its controls read normally. */
.b70-rec-live { object-fit: cover; transform: scaleX(-1); }
.b70-rec-play { object-fit: contain; }

.b70-rec-wait {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}
.b70-rec-stage .b70-btn-secondary { color: #fff; border-color: rgba(255, 255, 255, 0.75); margin-top: 8px; }
.b70-rec-stage :focus-visible { outline-color: #fff; }

.b70-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: b70-spin 1s linear infinite;
}

.b70-rec-count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--b70-font-display);
  font-size: 8rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6), 0 0 2px rgba(0, 0, 0, 0.6);
  font-variant-numeric: lining-nums tabular-nums;
}
.b70-rec-count.is-pop { animation: b70-pop 0.95s ease-out both; }

.b70-rec-chip {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 1.0625rem;
  font-weight: 700;
  font-variant-numeric: lining-nums tabular-nums;
}
.b70-rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--b70-record); animation: b70-blink 1.2s ease-in-out infinite; }

.b70-rec-watch {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 12px 26px 12px 20px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font: inherit;
  font-size: 1.125rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.b70-rec-watch .b70-icon { width: 26px; height: 26px; }

.b70-rec-controls { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.b70-rec-button {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.b70-rec-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.b70-ring-track { fill: var(--b70-surface); stroke: var(--b70-line); stroke-width: 6; }
.b70-ring-fill { fill: none; stroke: var(--b70-record); stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 0.25s linear, stroke 0.4s ease; }
.b70-rec-button.is-full .b70-ring-fill { stroke: var(--b70-ok); }
.b70-rec-core {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--b70-record);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: width 0.25s ease, height 0.25s ease, border-radius 0.25s ease, opacity 0.25s ease;
}
.b70-rec-button.is-recording .b70-rec-core { width: 34px; height: 34px; border-radius: 8px; }
.b70-rec-button.is-counting .b70-rec-core { opacity: 0.55; }
.b70-rec-button:active .b70-rec-core { transform: scale(0.94); }

.b70-rec-hint { min-height: 3em; max-width: 24em; text-align: center; font-size: 1.0625rem; line-height: 1.45; }

.b70-rec-actions { display: grid; gap: 10px; }
.b70-rec-length { text-align: center; color: var(--b70-muted); font-size: 1.0625rem; }

.b70-rec-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 8px 0 12px;
  text-align: center;
}
.b70-rec-panel[data-steps="name"] { justify-content: flex-start; padding-top: 6vh; text-align: left; }
.b70-rec-big { font-family: var(--b70-font-display); font-size: 1.5rem; font-weight: 700; line-height: 1.25; }
.b70-rec-bar { height: 14px; }
.b70-rec-status { font-size: 1.125rem; font-variant-numeric: tabular-nums; }
[data-rec-step="failed"] .b70-rec-status { color: var(--b70-error); font-weight: 600; }
[data-rec-step="failed"] .b70-rec-bar span { background: var(--b70-error); }

.b70-rec-tick {
  width: 96px;
  height: 96px;
  margin: 0 auto 4px;
  border-radius: 50%;
  background: var(--b70-ok);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: b70-tick 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.b70-rec-tick .b70-icon { width: 54px; height: 54px; stroke-width: 2.4; }

.b70-rec-icon {
  width: 84px;
  height: 84px;
  margin: 0 auto;
  border-radius: 50%;
  border: 1px solid var(--b70-line);
  background: var(--b70-surface);
  color: var(--b70-accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.b70-rec-icon .b70-icon { width: 40px; height: 40px; }

.b70-rec-confirm {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(10, 10, 10, 0.5);
}
.b70-rec-confirm-box {
  width: 100%;
  max-width: 440px;
  display: grid;
  gap: 12px;
  padding: 24px 20px 20px;
  border-radius: var(--b70-radius);
  background: var(--b70-surface);
  color: var(--b70-text);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: b70-rise 0.3s ease both;
}

/* Short phone screens (iPhone SE in Safari, small Androids with the browser bars showing):
   the red button and its hint must fit without scrolling, so the camera gives way. */
@media (orientation: portrait) and (max-height: 680px) {
  .b70-rec { gap: 10px; }
  .b70-rec-prompt { padding: 8px 12px; font-size: 1rem; line-height: 1.35; }
  .b70-rec-stage { min-height: 150px; }
  .b70-rec-hint { min-height: 0; }
}
@media (orientation: portrait) and (max-height: 520px) {
  .b70-rec-prompt { display: none; }
  .b70-rec-stage { min-height: 120px; }
  .b70-rec-button { width: 84px; height: 84px; }
}

/* A phone held sideways: camera on the left, buttons on the right. */
@media (orientation: landscape) and (max-height: 540px) {
  .b70-rec {
    max-width: none;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 36%);
    grid-template-rows: auto 1fr;
    align-items: stretch;
  }
  .b70-rec-head { grid-column: 1 / -1; }
  .b70-rec-prompt { display: none; }
  .b70-rec-stage { grid-column: 1; grid-row: 2; min-height: 200px; }
  .b70-rec-controls,
  .b70-rec-actions { grid-column: 2; grid-row: 2; align-self: center; }
  .b70-rec-panel { grid-column: 1 / -1; grid-row: 2; }
  .b70-rec-panel[data-steps="name"] { padding-top: 0; }
}

/* ---------- Calendar sheet ---------- */

.b70-sheet-wrap { display: flex; align-items: flex-end; justify-content: center; }
.b70-backdrop { position: absolute; inset: 0; background: rgba(10, 10, 10, 0.5); }
.b70-sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  display: grid;
  gap: 12px;
  padding: 26px calc(20px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
  border-radius: var(--b70-radius) var(--b70-radius) 0 0;
  background: var(--b70-surface);
  color: var(--b70-text);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
  transform: translateY(28px);
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.b70-sheet-wrap.is-visible .b70-sheet { transform: none; }
.b70-sheet-title {
  margin: 0;
  font-family: var(--b70-font-display);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  color: var(--b70-text);
}
.b70-sheet-text { color: var(--b70-muted); font-size: 1.0625rem; text-align: center; margin-bottom: 6px; }
.b70-sheet-options { display: grid; gap: 10px; }
.b70-sheet-status { color: var(--b70-text); font-size: 1.0625rem; text-align: center; }
.b70-sheet-status:empty { display: none; }

@media (min-width: 600px) {
  .b70-sheet-wrap { align-items: center; padding: 24px; }
  .b70-sheet { border-radius: var(--b70-radius); padding-bottom: 20px; }
}

/* ---------- Motion ---------- */

@keyframes b70-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes b70-spin { to { transform: rotate(360deg); } }
@keyframes b70-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@keyframes b70-pop { 0% { opacity: 0; transform: scale(1.4); } 25% { opacity: 1; } 100% { opacity: 0.9; transform: scale(0.92); } }
@keyframes b70-tick { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .b70-overlay,
  .b70-overlay *,
  .b70-upload,
  .b70-upload * { animation: none !important; transition: none !important; }
  .b70-sheet { transform: none; }
  .b70-spinner { border-top-color: rgba(255, 255, 255, 0.25); }
}
