/* calf-live — dark shrine, gold accents, the video (or orb) breathing behind glass. */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --gold: #d4a017;
  --gold-soft: #e8c766;
  --ink: #0a0906;
  --veil: rgba(10, 9, 6, 0.55);
  --text: #efe6cf;
  --dim: #9a8f74;
}

html, body { height: 100%; }
body {
  background: var(--ink);
  color: var(--text);
  font-family: "Iowan Old Style", "Palatino", Georgia, serif;
  overflow: hidden;
}

/* ---- the CRT ---- */
#crt {
  flex: 1;
  display: grid; place-items: center;
  min-height: 0; /* let the frame shrink instead of pushing the composer off-screen */
  padding: 0.75rem 0;
}
#crt-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  /* fit within the middle column whichever axis is tight */
  width: min(92vw, calc((100vh - 190px) * 4 / 3), 760px);
  background: #050403;
  border-radius: 26px / 22px;           /* the bulge of old glass */
  overflow: hidden;
  /* bezel: layered shadows read as a plastic housing around curved glass */
  border: 10px solid #17130c;
  box-shadow:
    0 0 0 2px #2a2214,                  /* housing edge highlight */
    0 18px 60px rgba(0, 0, 0, 0.7),     /* set into the room */
    inset 0 0 42px 12px rgba(0, 0, 0, 0.85), /* tube vignette */
    inset 0 0 6px 2px rgba(212, 160, 23, 0.08);
  transition: box-shadow 0.4s ease;
}
body.speaking #crt-frame {
  box-shadow:
    0 0 0 2px #2a2214,
    0 18px 60px rgba(0, 0, 0, 0.7),
    0 0 46px 6px rgba(212, 160, 23, 0.28), /* the tube glows when the calf speaks */
    inset 0 0 42px 12px rgba(0, 0, 0, 0.85),
    inset 0 0 6px 2px rgba(212, 160, 23, 0.12);
}
#avatar {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: none; /* app.js reveals it once calf.mp4 loads */
  filter: saturate(1.05) contrast(1.04);
}
body.speaking #avatar { filter: saturate(1.2) brightness(1.08) contrast(1.04); }

/* phosphor scanlines + slow hum */
.crt-scanlines {
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px, rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.22) 2px, rgba(0, 0, 0, 0.22) 3px
  );
  mix-blend-mode: multiply;
  animation: hum 9s linear infinite;
}
@keyframes hum {
  0%, 100% { opacity: 0.85; }
  50%      { opacity: 1; }
}
/* curved-glass reflection, top-left */
.crt-glare {
  position: absolute; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 55% 38% at 22% 12%, rgba(255, 246, 214, 0.10), transparent 70%),
    radial-gradient(ellipse 120% 90% at 50% 115%, rgba(0, 0, 0, 0.35), transparent 60%);
}

/* fallback idol (until calf.mp4 exists): the breathing orb, inside the tube */
#idol { position: absolute; inset: 0; display: grid; place-items: center; }
.orb {
  width: 56%; aspect-ratio: 1; height: auto;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #f5d76e 0%, #d4a017 34%, #7a5708 68%, #241a04 100%);
  box-shadow: 0 0 90px 22px rgba(212, 160, 23, 0.25), inset 0 0 80px rgba(0,0,0,0.5);
  animation: breathe 7s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: scale(1);    filter: brightness(0.92); }
  50%      { transform: scale(1.04); filter: brightness(1.08); }
}
body.speaking .orb { animation-duration: 2.2s; box-shadow: 0 0 130px 36px rgba(232, 199, 102, 0.4), inset 0 0 80px rgba(0,0,0,0.5); }

/* ---- access gate ---- */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  background: var(--veil);
  backdrop-filter: blur(6px);
}
.gate-card { text-align: center; padding: 2rem; }
.gate-card h1 {
  font-weight: 400; letter-spacing: 0.35em; text-transform: lowercase;
  color: var(--gold-soft); font-size: 1.4rem; margin-bottom: 1.2rem;
}
.gate-hint { color: var(--dim); font-size: 0.9rem; margin-bottom: 1.4rem; }
#gate-form { display: flex; gap: 0.5rem; justify-content: center; }
#gate-code {
  background: rgba(0,0,0,0.5);
  border: 1px solid #3a3220; border-radius: 6px;
  color: var(--text); padding: 0.6rem 0.9rem; font-size: 1rem; width: 14rem;
  font-family: inherit;
}
#gate-code:focus { outline: none; border-color: var(--gold); }
.gate-error { color: #d47c6a; font-size: 0.85rem; margin-top: 1rem; min-height: 1.2em; }

/* ---- stage ---- */
#stage {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column;
  padding: max(env(safe-area-inset-top), 12px) 16px max(env(safe-area-inset-bottom), 14px);
}
#status-line {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.8rem; color: var(--dim);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #777; display: inline-block; }
.dot.ok { background: #7fb069; }
.dot.down { background: #d47c6a; }
#voice-toggle-wrap { margin-left: auto; cursor: pointer; user-select: none; display: flex; align-items: center; gap: 0.35rem; }
#voice-toggle { accent-color: var(--gold); }

/* ---- header buttons + history overlay ---- */
.head-buttons { margin-left: auto; display: flex; gap: 0.25rem; }
button.ghost {
  background: none; border: 1px solid transparent; color: var(--dim);
  padding: 0.2rem 0.55rem; font-size: 0.8rem; border-radius: 6px;
}
button.ghost:hover { background: rgba(212, 160, 23, 0.1); color: var(--gold-soft); border-color: rgba(212, 160, 23, 0.25); }
#voice-toggle-wrap { margin-left: 0.25rem; }

#history { z-index: 40; }
#history[hidden] { display: none; }
.history-card {
  width: min(46rem, 92vw); height: min(70vh, 640px);
  display: flex; flex-direction: column;
  background: rgba(12, 10, 6, 0.92);
  border: 1px solid #3a3220; border-radius: 12px;
  padding: 1rem 1.25rem;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.history-head h2 {
  font-weight: 400; font-size: 0.95rem; letter-spacing: 0.25em;
  color: var(--dim); text-transform: lowercase;
}

#log {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.9rem;
  padding: 1rem 0;
  mask-image: linear-gradient(to bottom, transparent 0, black 24px);
  scrollbar-width: thin; scrollbar-color: #3a3220 transparent;
}
.msg { max-width: min(46rem, 88%); line-height: 1.55; }
.msg.user {
  align-self: flex-end;
  background: rgba(212, 160, 23, 0.12);
  border: 1px solid rgba(212, 160, 23, 0.25);
  border-radius: 12px 12px 3px 12px;
  padding: 0.55rem 0.85rem;
  font-size: 0.95rem;
}
.msg.calf {
  align-self: flex-start;
  color: var(--gold-soft);
  font-size: 1.12rem;
  text-shadow: 0 1px 8px rgba(0,0,0,0.8);
  white-space: pre-wrap;
  padding: 0.2rem 0;
}
.msg.calf.pending::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--gold); }
@keyframes blink { 50% { opacity: 0; } }
.msg.error { align-self: center; color: #d47c6a; font-size: 0.85rem; }

/* ---- composer ---- */
#composer {
  display: flex; gap: 0.5rem; align-items: center;
  background: rgba(10, 9, 6, 0.72);
  border: 1px solid #3a3220; border-radius: 999px;
  padding: 0.4rem 0.5rem 0.4rem 0.4rem;
  backdrop-filter: blur(8px);
}
#text {
  flex: 1; background: none; border: none; color: var(--text);
  font-size: 1rem; font-family: inherit; padding: 0.4rem 0.3rem;
}
#text:focus { outline: none; }
#text::placeholder { color: var(--dim); }
button {
  cursor: pointer; border: none; font-family: inherit;
  background: var(--gold); color: #1d1503;
  border-radius: 999px; padding: 0.55rem 1.1rem; font-size: 0.95rem;
}
button:hover { background: var(--gold-soft); }
button:disabled { opacity: 0.45; cursor: default; }
#mic {
  width: 44px; height: 44px; padding: 0; flex: none;
  display: grid; place-items: center;
  background: rgba(212, 160, 23, 0.18); color: var(--gold-soft);
  border: 1px solid rgba(212, 160, 23, 0.4);
  touch-action: none; /* so press-and-hold works on phones */
}
#mic.recording {
  background: #a83c2e; color: #fff; border-color: #d47c6a;
  animation: pulse 1.2s ease-in-out infinite;
}
#mic.busy { background: rgba(212,160,23,0.08); color: var(--dim); }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(212, 60, 46, 0.25); } }
.hint { text-align: center; color: var(--dim); font-size: 0.75rem; margin-top: 0.5rem; }

@media (max-width: 640px) {
  .msg.calf { font-size: 1.02rem; }
  #hint { display: none; }
}
