/* Memobox — visual language from the Claude Design project (Memobox.html):
   warm linen paper, terracotta accents, Lora serif headings, Caveat
   handwriting for captions, sepia photo tones. The memories overview is
   the cork pinboard ("Fotowand") from that design.

   Structure contract (ids/screens) unchanged — see index.html header. */

/* --- self-hosted fonts (local-only: no Google requests at runtime) --- */

@font-face { font-family: "Lora"; font-style: normal; font-weight: 500;
  src: url("/static/fonts/lora-500.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Lora"; font-style: normal; font-weight: 600;
  src: url("/static/fonts/lora-600.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Lora"; font-style: italic; font-weight: 400;
  src: url("/static/fonts/lora-400-italic.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 400;
  src: url("/static/fonts/nunito-400.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 600;
  src: url("/static/fonts/nunito-600.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 700;
  src: url("/static/fonts/nunito-700.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Caveat"; font-style: normal; font-weight: 500;
  src: url("/static/fonts/caveat-500.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Caveat"; font-style: normal; font-weight: 600;
  src: url("/static/fonts/caveat-600.woff2") format("woff2"); font-display: swap; }

:root {
  /* paper / linen (design tokens.css) */
  --paper-0: #f6efd9;
  --paper-1: #f1e8d2;
  --paper-2: #ebdfbf;
  --paper-3: #ddcfa9;
  --paper-4: #c9b985;
  /* ink */
  --ink-0: #2a1f12;
  --ink-1: #4a3a22;
  --ink-2: #6a583a;
  --ink-3: #9a8866;
  /* accents */
  --terracotta: #b56a3b;
  --terracotta-deep: #8a4a25;
  --moss: #6a7a3a;
  --cream: #fcf3df;
  /* sepia photo tones */
  --sepia-1: #c9a877;
  --sepia-2: #a88450;
  /* night (device off) */
  --night-0: #1a1208;
  --night-1: #2a1f12;
  --night-2: #4a3a26;

  --focus: 0 0 0 4px var(--paper-1), 0 0 0 7px var(--terracotta);
  --shadow-card: 0 1px 2px rgba(60, 40, 20, 0.08), 0 4px 18px rgba(60, 40, 20, 0.10);
  --shadow-lift: 0 6px 16px rgba(60, 40, 20, 0.14), 0 24px 60px rgba(60, 40, 20, 0.14);

  --font-serif: "Lora", Georgia, serif;
  --font-sans: "Nunito", system-ui, sans-serif;
  --font-hand: "Caveat", "Bradley Hand", cursive;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;

  --fs-base: 1.35rem;
  --fs-big: 1.8rem;
  --fs-display: 2.5rem;
  --radius: 18px;
  --ring-size: min(46vw, 240px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  color: var(--ink-0);
  font-size: var(--fs-base);
  line-height: 1.45;
  letter-spacing: 0.005em;
  transition: background 1.2s ease;
  overflow: hidden;
  background: var(--night-1);
}

/* linen paper for the "on" screens */
body[data-screen="booting"],
body[data-screen="main_menu"],
body[data-screen="onboarding"],
body[data-screen="voices"],
body[data-screen="dialog"] {
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255, 255, 255, 0.6), transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(180, 150, 90, 0.10), transparent 60%),
    repeating-linear-gradient(0deg, rgba(120, 90, 40, 0.025) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(120, 90, 40, 0.025) 0 1px, transparent 1px 3px),
    var(--paper-1);
}
/* warm dark ambience when the device sleeps */
body[data-screen="off"], body[data-screen="login"] {
  background: radial-gradient(ellipse at 50% 60%, var(--night-2) 0%, var(--night-1) 70%, var(--night-0) 100%);
}
/* cork board behind the memories */
body[data-screen="memories"] {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 230, 180, 0.25), transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(80, 40, 10, 0.3), transparent 60%),
    repeating-radial-gradient(circle at 20% 30%, rgba(80, 40, 10, 0.12) 0 2px, transparent 2px 7px),
    repeating-radial-gradient(circle at 70% 60%, rgba(180, 120, 60, 0.1) 0 2px, transparent 2px 9px),
    repeating-radial-gradient(circle at 45% 80%, rgba(40, 20, 5, 0.08) 0 1px, transparent 1px 5px),
    linear-gradient(135deg, #c69a5a 0%, #a07640 100%);
}

.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.4rem;
  padding: 1.5rem;
  max-width: 640px;
  margin: 0 auto;
}
body[data-screen="off"]        section[data-screen="off"],
body[data-screen="login"]      section[data-screen="login"],
body[data-screen="booting"]    section[data-screen="booting"],
body[data-screen="main_menu"]  section[data-screen="main_menu"],
body[data-screen="onboarding"] section[data-screen="onboarding"],
body[data-screen="memories"]   section[data-screen="memories"],
body[data-screen="voices"]     section[data-screen="voices"],
body[data-screen="dialog"]     section[data-screen="dialog"] { display: flex; }

body[data-screen="main_menu"] .screen,
body[data-screen="dialog"] .screen { padding-bottom: 215px; }

.screen-scroll {
  justify-content: flex-start;
  overflow-y: auto;
  padding-top: 2.2rem;
  padding-bottom: 2rem;
}

/* --- type roles from the design --- */

.greeting {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: var(--fs-display);
  line-height: 1.12;
  letter-spacing: -0.01em;
  text-align: center;
  color: var(--ink-0);
}
.greeting-sub {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  color: var(--ink-1);
  text-align: center;
  text-wrap: pretty;
}
.state-text {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--ink-2);
  font-size: 1.3rem;
  min-height: 1.5em;
  text-align: center;
}

/* --- login --- */

.login-card {
  background:
    radial-gradient(ellipse at 25% 15%, rgba(255, 255, 255, 0.55), transparent 60%),
    var(--paper-0);
  border: 1px solid rgba(60, 40, 20, 0.2);
  border-radius: var(--radius);
  padding: 2.2rem;
  width: min(90vw, 420px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-lift);
}
.wordmark {
  font-family: var(--font-serif);
  font-size: var(--fs-display);
  font-weight: 600;
  color: var(--ink-0);
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.wordmark::before {
  content: "M";
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 8px;
  background: var(--terracotta);
  color: var(--cream);
  font-size: 1.5rem;
  display: grid;
  place-items: center;
}
#login-form { display: flex; flex-direction: column; gap: 0.8rem; }
#login-form label {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}
#login-form input, #register-name, #enroll-name {
  font: inherit;
  font-size: var(--fs-base);
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--paper-4);
  border-bottom-width: 3px;
  border-radius: 10px;
  background: #fffdf5;
  color: var(--ink-0);
}
#login-form input:focus-visible, #register-name:focus-visible,
#enroll-name:focus-visible { outline: none; box-shadow: var(--focus); }

/* --- buttons --- */

.btn {
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--ink-1);
  background: var(--paper-0);
  border: 1.5px solid var(--paper-4);
  border-bottom-width: 3px;
  border-radius: 14px;
  padding: 0.9rem 1.4rem;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:focus-visible, .ptt:focus-visible, #power-button:focus-visible,
.polaroid:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}
.btn-primary {
  background: var(--terracotta);
  border-color: var(--terracotta-deep);
  color: var(--cream);
}
.btn-big {
  width: 100%;
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: var(--fs-big);
  padding: 1.4rem 1.6rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  text-align: left;
  box-shadow: var(--shadow-card);
}
.btn-big:active { transform: translateY(2px); box-shadow: none; }
.btn-icon { color: var(--terracotta); font-size: 1.5rem; }
.btn-quiet {
  background: none;
  border: none;
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 1.05rem;
  font-weight: 600;
}
.menu { display: flex; flex-direction: column; gap: 1.1rem; width: 100%; }
.menu-quiet-row { display: flex; gap: 1.5rem; flex-wrap: wrap; justify-content: center; }

/* --- off screen --- */

#power-button {
  width: var(--ring-size);
  height: var(--ring-size);
  border-radius: 50%;
  border: 3px solid rgba(245, 234, 208, 0.35);
  background: radial-gradient(circle at 50% 42%, rgba(245, 234, 208, 0.1), transparent 70%);
  color: rgba(245, 234, 208, 0.85);
  cursor: pointer;
  display: grid;
  place-items: center;
  animation: breathe-dark 5s ease-in-out infinite;
}
#power-button svg { width: 34%; height: 34%; stroke: currentColor; stroke-width: 2; fill: none; }
.off-hint {
  font-family: var(--font-serif);
  font-style: italic;
  color: rgba(245, 234, 208, 0.6);
}
section[data-screen="off"] .error { max-width: 34ch; text-align: center; }

/* --- the ring: ambient status (Robject presence) --- */

.ring {
  width: var(--ring-size);
  height: var(--ring-size);
  border-radius: 50%;
  border: 4px solid var(--paper-4);
  position: relative;
  transition: border-color 0.6s ease, box-shadow 0.3s ease;
  box-shadow: 0 0 0 calc(var(--level, 0) * 26px) rgba(181, 106, 59, 0.22);
  animation: breathe 5s ease-in-out infinite;
}
.ring::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(201, 168, 119, 0.28), transparent 75%);
}
.ring[data-mode="recording"] { border-color: var(--terracotta); animation: none; }
.ring[data-mode="thinking"] {
  border-style: dashed;
  border-color: var(--moss);
  animation: turn 3.5s linear infinite;
}
.ring[data-mode="speaking"] { border-color: var(--terracotta); animation: breathe 2.2s ease-in-out infinite; }
.ring-boot { border-style: dashed; border-color: var(--moss); animation: turn 3.5s linear infinite; }

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}
@keyframes breathe-dark {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 234, 208, 0); }
  50% { box-shadow: 0 0 60px 4px rgba(245, 234, 208, 0.08); }
}
@keyframes turn { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .ring, .ring-boot, #power-button { animation: none !important; }
}

.ring-wrap { display: flex; flex-direction: column; align-items: center; gap: 1rem; }

/* --- boot --- */

.boot-track {
  width: min(70vw, 320px);
  height: 10px;
  border-radius: 5px;
  background: var(--paper-3);
  overflow: hidden;
}
#boot-bar {
  height: 100%;
  width: 0;
  background: var(--terracotta);
  border-radius: 5px;
  transition: width 0.8s ease;
}

/* --- dialog --- */

section[data-screen="dialog"] { justify-content: flex-start; gap: 1.6rem; padding-top: 1.4rem; }
.dialog-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  min-height: 2.4rem;
}
.dialog-badges { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.dialog-cancel {
  background: none;
  border: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  white-space: nowrap;
}
.dialog-cancel:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }
.badge {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--terracotta-deep);
  border: 1.5px solid var(--terracotta);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  background: rgba(181, 106, 59, 0.08);
}
.badge:empty { display: none; }
.badge-object { color: var(--ink-1); border-color: var(--moss); background: rgba(106, 122, 58, 0.1); }

.transcript {
  width: 100%;
  min-height: 5.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
/* what the person said — handwritten, like a margin note in the scrapbook */
.transcript-user {
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 1.65rem;
  line-height: 1.15;
  color: var(--terracotta-deep);
}
.transcript-reply { font-size: var(--fs-base); color: var(--ink-0); }

.score-dots { display: flex; gap: 0.5rem; }
.score-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--paper-3);
}
.score-dots span.on { background: var(--moss); }

/* --- shared voice controls --- */

.controls {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  align-items: flex-end;
  justify-content: center;
  gap: 1.2rem;
  max-width: 640px;
  margin: 0 auto;
  padding: 0.6rem 1.5rem 1.2rem;
}
body[data-screen="main_menu"] .controls,
body[data-screen="dialog"] .controls { display: flex; }
body[data-screen="main_menu"] .btn-side { visibility: hidden; }

.btn-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.8rem;
  min-width: 6.2rem;
  background: none;
  border: none;
  color: var(--ink-2);
  cursor: pointer;
}
.btn-side svg { width: 2.2rem; height: 2.2rem; stroke: currentColor; stroke-width: 1.8; fill: none; }

.ptt {
  width: min(38vw, 168px);
  height: min(38vw, 168px);
  border-radius: 50%;
  border: 3px solid var(--terracotta-deep);
  background: radial-gradient(circle at 38% 30%, #c97f4e, var(--terracotta) 60%);
  color: var(--cream);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  box-shadow: 0 4px 0 var(--terracotta-deep), var(--shadow-card);
}
.ptt svg { width: 2.6rem; height: 2.6rem; stroke: currentColor; fill: currentColor; stroke-width: 1; }
.ptt-label { font-size: 1rem; line-height: 1.25; text-align: center; font-weight: 600; }
.ptt:active { transform: scale(0.96); }
.ptt[data-active] {
  background: radial-gradient(circle at 38% 30%, #a2602f, var(--terracotta-deep) 65%);
  box-shadow: 0 0 0 calc(var(--level, 0) * 22px + 6px) rgba(181, 106, 59, 0.3);
  transform: scale(1.04);
}
.ptt:disabled { opacity: 0.45; cursor: default; }

/* --- memories: the cork pinboard (Fotowand) --- */

body[data-screen="memories"] .greeting {
  color: var(--paper-1);
  text-shadow: 0 2px 8px rgba(40, 20, 5, 0.55);
}
.pinboard {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.6rem 1.2rem;
  padding: 0.8rem 0.2rem 1.2rem;
  align-items: start;
}
.polaroid {
  font: inherit;
  border: none;
  background: #f7eccf;
  padding: 9px 9px 0.9rem;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  position: relative;
  text-align: center;
  transition: transform 0.25s, box-shadow 0.25s;
}
.polaroid:nth-child(2n)   { background: #fff6dd; }
.polaroid:nth-child(4n+1) { transform: rotate(-4deg); }
.polaroid:nth-child(4n+2) { transform: rotate(3deg); }
.polaroid:nth-child(4n+3) { transform: rotate(-2deg); }
.polaroid:nth-child(4n)   { transform: rotate(5deg); }
.polaroid:hover, .polaroid:focus-visible {
  transform: rotate(0deg) translateY(-6px) scale(1.04);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  z-index: 3;
}
.polaroid img,
.polaroid .photo-placeholder {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  border-radius: 2px;
}
/* sepia striped placeholder for memories without an object photo */
.polaroid .photo-placeholder {
  background: repeating-linear-gradient(135deg, var(--sepia-1) 0 14px, var(--sepia-2) 14px 28px);
  position: relative;
  display: grid;
  place-items: center;
}
.polaroid .photo-placeholder::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 240, 200, 0.4), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(40, 20, 5, 0.3), transparent 60%);
  pointer-events: none;
}
.polaroid .photo-placeholder span {
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: 3rem;
  color: rgba(40, 25, 10, 0.6);
  z-index: 1;
}
.polaroid figcaption {
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 1.35rem;
  line-height: 1.05;
  color: var(--ink-1);
  padding-top: 0.5rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.polaroid .frame-date {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-top: 0.25rem;
}
/* thumbtack */
.polaroid::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f25a3a 0%, #a02818 60%, #5a1408 100%);
  box-shadow: inset 0 -3px 4px rgba(40, 5, 0, 0.6), inset 0 2px 3px rgba(255, 180, 150, 0.5), 0 3px 6px rgba(0, 0, 0, 0.4);
  z-index: 5;
}
/* sticky note (empty board, toasts) */
.sticky-note {
  background: #fef4a8;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 1.5rem;
  line-height: 1.2;
  color: var(--ink-0);
  padding: 1rem 1.4rem;
  transform: rotate(-2deg);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  position: relative;
  max-width: 34ch;
  text-align: center;
  grid-column: 1 / -1;
  justify-self: center;
}
.sticky-note::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%) rotate(-3deg);
  width: 64px;
  height: 18px;
  background: linear-gradient(90deg, rgba(240, 210, 140, 0) 0%, rgba(240, 210, 140, 0.85) 10%, rgba(240, 210, 140, 0.85) 90%, rgba(240, 210, 140, 0) 100%);
  box-shadow: 0 2px 4px rgba(60, 40, 20, 0.15);
}

/* legacy list style kept for the voices screen */
.memories-list { display: flex; flex-direction: column; gap: 0.9rem; width: 100%; }
.memory-card {
  background: var(--paper-0);
  border: 1.5px solid var(--paper-4);
  border-bottom-width: 3px;
  border-radius: var(--radius);
  padding: 1rem 1.3rem;
  text-align: left;
  font: inherit;
  width: 100%;
  box-shadow: var(--shadow-card);
}
.memory-card h3 { font-family: var(--font-serif); font-weight: 600; font-size: 1.3rem; margin-bottom: 0.15rem; }
.memory-card p { color: var(--ink-2); font-size: 1rem; }
.memory-meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.memory-detail {
  background: var(--paper-0);
  border: 1px solid rgba(60, 40, 20, 0.2);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  box-shadow: var(--shadow-lift);
}
.memory-detail h2 { font-family: var(--font-serif); font-weight: 600; font-size: 1.7rem; }
.memory-detail details summary {
  color: var(--terracotta-deep);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 600;
}
.memory-transcript { white-space: pre-wrap; color: var(--ink-1); font-size: 1.05rem; margin-top: 0.5rem; }
.memories-empty { color: var(--ink-2); text-align: center; }

body[data-screen="memories"] #memories-back {
  box-shadow: 0 6px 18px rgba(20, 10, 0, 0.4);
}

/* --- memory viewer: flip card --- */

#memory-viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 1.5rem;
  /* solid tint, no backdrop-filter: a live blur behind a 3D transform
     re-composites every frame and makes the flip stutter */
  background: rgba(26, 18, 8, 0.9);
}
#memory-viewer[hidden] { display: none; }

/* hero-zoom layer: the card grows from the tapped thumbnail (set in JS) */
#zoom-wrap {
  width: min(82vw, 360px);
  will-change: transform;
}
/* perspective must live on the PARENT of the rotating element, otherwise
   the flip renders flat */
.flip {
  width: 100%;
  perspective: 1500px;
  cursor: pointer;
}
#memory-card {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.45, 0.05, 0.2, 1);
  will-change: transform;
}
#memory-card.flipped { transform: rotateY(180deg); }
@media (prefers-reduced-motion: reduce) {
  #memory-card, #zoom-wrap { transition: none !important; }
}
.flip-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
/* the front sits in normal flow and sizes the card; the back overlays it,
   so both faces share the exact same box and the flip stays rock-steady */
.flip-front {
  position: relative;
  /* an explicit identity 3D transform forces the browser to treat the
     front as a real 3D layer, so its backface is culled when the card is
     turned — without it some browsers keep painting the mirrored photo
     tilting behind the text */
  transform: rotateY(0deg);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  /* no overflow here — it would break backface-visibility in Firefox */
  background:
    radial-gradient(ellipse at 25% 15%, rgba(255, 255, 255, 0.5), transparent 60%),
    var(--paper-0);
  border-radius: 4px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
/* the scrollable text panel on the back (date, summary, full dialog) */
.back-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  border-radius: 4px;
}

/* front: the enlarged polaroid — the whole photo at its TRUE aspect ratio
   (never cropped or stretched), bounded so it can't fill the screen */
.polaroid-big {
  background: #f7eccf;
  padding: 14px 14px 1rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  transform: none;
}
.polaroid-big::before { display: none; } /* no thumbtack on the big card */
.polaroid-big #mv-photo { display: block; width: 100%; }
.polaroid-big #mv-photo img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 58vh;      /* tall portraits stay on screen */
  object-fit: contain;
  border-radius: 2px;
}
.polaroid-big #mv-photo .photo-placeholder {
  width: 100%;
  aspect-ratio: 1;       /* memories without a photo: a square sepia card */
  background: repeating-linear-gradient(135deg, var(--sepia-1) 0 18px, var(--sepia-2) 18px 36px);
  display: grid;
  place-items: center;
  position: relative;
  border-radius: 2px;
}
.polaroid-big #mv-photo .photo-placeholder span {
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: 5rem;
  color: rgba(40, 25, 10, 0.6);
}
.polaroid-big figcaption {
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: 1.7rem;
  line-height: 1.05;
  color: var(--ink-1);
  padding-top: 0.6rem;
  text-align: center;
}
.flip-back h2 { font-family: var(--font-serif); font-weight: 600; font-size: 1.6rem; color: var(--ink-0); }
#mv-summary { color: var(--ink-1); font-size: 1.1rem; }
.dialog-log {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 0.4rem;
  border-top: 1px dashed var(--paper-4);
  padding-top: 0.9rem;
}
.dialog-line { display: flex; flex-direction: column; gap: 0.15rem; }
.dialog-who {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.dialog-text {
  font-size: 1.05rem;
  line-height: 1.35;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  background: var(--paper-2);
  color: var(--ink-0);
}
.dialog-line.box { align-items: flex-start; }
.dialog-line.box .dialog-text { background: rgba(181, 106, 59, 0.14); }
.dialog-line.person { align-items: flex-end; }
.dialog-line.person .dialog-text {
  background: rgba(106, 122, 58, 0.14);
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 1.25rem;
}
.mv-delete {
  align-self: center;
  margin-top: 0.4rem;
  font-size: 1rem;
  color: #a02818;
  border-color: rgba(160, 40, 24, 0.4);
  background: rgba(160, 40, 24, 0.06);
}
.flip-hint {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.flip-back .flip-hint { color: var(--ink-2); }
#memory-viewer-close { min-width: 12rem; }

/* --- voices --- */

.role-row { display: flex; gap: 1.4rem; justify-content: center; font-size: 1.1rem; }
.role-row input { transform: scale(1.4); margin-right: 0.4rem; accent-color: var(--terracotta); }
#enroll-record[data-active] {
  background: var(--terracotta-deep);
  border-color: var(--terracotta-deep);
}
.voice-role {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--moss);
}

/* --- camera overlay --- */

#camera-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 60%, var(--night-2) 0%, var(--night-1) 70%, var(--night-0) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 1.5rem;
  z-index: 20;
}
#camera-overlay[hidden] { display: none; }
#camera-video {
  width: min(92vw, 560px);
  border-radius: var(--radius);
  background: #000;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.4);
}
.camera-actions { margin-top: 0.4rem; }
.row { display: flex; gap: 0.9rem; justify-content: center; flex-wrap: wrap; }
#register-panel {
  background: var(--paper-0);
  border-radius: var(--radius);
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  text-align: center;
  width: min(92vw, 480px);
  box-shadow: var(--shadow-lift);
}
#register-panel[hidden] { display: none; }

/* --- feedback --- */

.error { color: #a02818; }
#toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  background: #fef4a8;
  color: var(--ink-0);
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 1.35rem;
  line-height: 1.2;
  padding: 0.8rem 1.5rem;
  box-shadow: 0 6px 16px rgba(40, 20, 5, 0.35);
  z-index: 30;
  max-width: 90vw;
  text-align: center;
}
#toast[hidden] { display: none; }

#build-tag {
  position: fixed;
  bottom: 4px;
  right: 8px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: rgba(130, 110, 80, 0.55);
  z-index: 5;
}

@media (max-height: 640px) {
  :root { --ring-size: 150px; --fs-display: 1.9rem; --fs-big: 1.45rem; }
}
