:root {
  --night: #0b0f1a;
  --card: #1a2236;
  --card-2: #212b44;
  --line: #2c3857;
  --dim: #3a4666;
  --ink: #e9ecf5;
  --soft: #b4bcd2;
  --muted: #98a2bd;
  --lcd: #7dff9b;
  --lcd-dim: #1d3b27;
  --warm: #ffcc66;
  --dave: #ffb347;
  --reply: #8ab4ff;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "DM Mono", "Menlo", "Consolas", monospace;
  --machine-h: 150px; /* kept current by app.js */
  color-scheme: dark;
}

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--night);
  min-height: 100vh;
  line-height: 1.5;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; padding: 0; background: none; }
button:disabled { cursor: default; opacity: 0.45; }
:focus-visible { outline: 3px solid var(--lcd); outline-offset: 3px; }

.sprite { position: absolute; }
.icon-pause, .is-playing > .icon-play { display: none; }
.is-playing > .icon-pause { display: block; }

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
h1 {
  margin: 0;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: -0.5px;
  line-height: 1.1;
  color: var(--warm);
}
.tagline { margin: 6px 0 0; font-size: 17px; font-weight: 600; color: var(--muted); }
.money { margin: 0; font-family: var(--mono); font-size: 13px; color: var(--muted); }
.money strong { color: var(--ink); }
.summary, .clock, .now { display: none; } /* phone only */

/* ---------- the answering machine ---------- */

.machine {
  position: sticky;
  top: 12px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
  padding: 24px;
  border-radius: 28px;
  background: var(--card);
  box-shadow: 0 2px 0 var(--line) inset, 0 18px 40px rgba(0, 0, 0, 0.45);
}

.transport { display: flex; align-items: center; gap: 12px; }
.round {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--card-2);
  display: grid;
  place-items: center;
}
.round svg { width: 20px; height: 20px; fill: var(--ink); }
.play-all {
  flex: none;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: var(--dave);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 0 #a86a12;
  transition: transform 0.08s, box-shadow 0.08s;
}
.play-all svg { width: 36px; height: 36px; fill: #1a1205; }
.play-all:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 3px 0 #a86a12; }

.lcd {
  flex: 1 1 320px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 18px;
  border: 2px solid var(--lcd-dim);
  border-radius: 16px;
  background: #07140c;
  color: var(--lcd);
  font-family: var(--mono);
}
.lcd-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; letter-spacing: 1px; }
.lcd-caller {
  font-size: 24px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.go {
  min-height: 48px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--night);
  font-size: 16px;
  font-weight: 900;
}
.go:hover:not(:disabled) { filter: brightness(1.08); }
.go:disabled { cursor: progress; }

.switches { display: flex; gap: 18px; font-size: 14px; font-weight: 800; }
.auto {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  cursor: pointer;
  user-select: none;
}
.auto input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.auto-track {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: #4a5677;
  transition: background 0.2s;
}
.auto-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--night);
  transition: transform 0.2s;
}
.auto input:checked + .auto-track { background: var(--lcd); }
.auto input:checked + .auto-track .auto-knob { transform: translateX(16px); }
.auto input:focus-visible + .auto-track { outline: 3px solid var(--lcd); outline-offset: 3px; }
.auto input:disabled + .auto-track { opacity: 0.5; }

.meta, .error { flex: 1 1 100%; margin: 0; font-size: 13px; }
.meta { font-weight: 600; color: var(--muted); text-align: right; }
.error {
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.4);
  color: #ffc9c9;
}

/* ---------- calls: Dave on the left, the reply on the right ---------- */

.calls { display: flex; flex-direction: column; gap: 32px; }
.calls:empty { display: none; }
.call { display: flex; flex-direction: column; gap: 14px; }
.call-head { display: flex; align-items: center; gap: 12px; }
.call-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--warm);
}
.call-time { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.call-rule { flex: 1; height: 0; border-top: 2px dashed var(--line); }
.call-body { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }

.track {
  --c: var(--reply);
  flex: 1 1 340px;
  min-width: 0;
  margin-top: 36px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border: 2px solid var(--card);
  border-radius: 22px 22px 6px 22px;
  background: var(--card);
  scroll-margin: calc(var(--machine-h) + 64px) 0 40px;
}
.track.dave { --c: var(--dave); margin-top: 0; border-radius: 22px 22px 22px 6px; }
.track.active { border-color: var(--c); }
.track.new { animation: arrive 0.5s ease-out; }

.track-top { display: flex; align-items: center; gap: 12px; }
.track-play {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--c);
  display: grid;
  place-items: center;
}
.track-play svg { width: 20px; height: 20px; fill: var(--night); }
.track-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.track-who { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.caller {
  font-size: 17px;
  font-weight: 900;
  color: var(--c);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dur { font-family: var(--mono); font-size: 13px; color: var(--soft); }

.wave { display: flex; align-items: center; gap: 3px; height: 26px; }
.wave span {
  flex: 1;
  height: calc(var(--h) * 100%);
  border-radius: 2px;
  background: var(--dim);
}
.wave span.on, .track.played .wave span { background: var(--c); }

.track-text { text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 44px; }
.text {
  font-size: 15px;
  line-height: 1.5;
  font-weight: 600;
  color: #cfd5e6;
  white-space: pre-line;
}
.track:not(.open) .text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.track-foot { display: flex; justify-content: space-between; gap: 12px; width: 100%; font-size: 13px; }
.more { font-weight: 900; color: var(--ink); text-decoration: underline; }
.meta-line { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* Where the next voicemail will land. */
.pending {
  flex: 1 1 340px;
  min-width: 0;
  margin-top: 36px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 2px dashed var(--dim);
  border-radius: 22px 22px 6px 22px;
}
.pending.dave { flex-grow: 0; flex-basis: calc(50% - 10px); margin-top: 0; border-radius: 22px 22px 22px 6px; }
.pending-title { font-size: 17px; font-weight: 900; }
.pending-sub { margin: 0; font-size: 15px; font-weight: 600; color: var(--muted); }
.dots { display: flex; gap: 4px; }
.pending.idle .dots { display: none; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--reply); animation: pulse 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
.pending.dave .dots i { background: var(--dave); }

.empty { margin: 0; text-align: center; color: var(--muted); padding: 40px 0; }

footer { text-align: center; color: var(--muted); font-size: 13px; font-weight: 600; }
footer p { margin: 0; }

/* Narrow desktop: the generate button and switches share one row, so the sticky panel stays short. */
@media (min-width: 760px) and (max-width: 1040px) {
  .machine { padding: 18px 20px; gap: 12px 20px; }
  .play-all { width: 72px; height: 72px; }
  .play-all svg { width: 30px; height: 30px; }
  .side { flex: 1 1 100%; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
}

/* ---------- phone: a chat thread with the player docked at the bottom ---------- */

@media (max-width: 759px) {
  .page { padding: 18px 16px calc(var(--machine-h) + 24px); gap: 16px; }

  .masthead { flex-wrap: nowrap; align-items: center; gap: 12px; }
  h1 { font-size: 26px; }
  .tagline { margin-top: 2px; font-size: 13px; line-height: 1.35; }
  .summary { display: block; margin: 4px 0 0; font-size: 13px; font-weight: 700; color: var(--muted); }
  .money { display: none; }
  .clock {
    display: block;
    flex: none;
    padding: 4px 10px;
    border: 2px solid var(--lcd-dim);
    border-radius: 10px;
    background: #07140c;
    color: var(--lcd);
    font-family: var(--mono);
    font-size: 22px;
  }

  .machine {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    gap: 10px 12px;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    border-radius: 26px 26px 0 0;
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.5);
  }
  .transport { display: contents; }
  #prev, .lcd { display: none; }
  .play-all { order: 1; width: 64px; height: 64px; box-shadow: 0 5px 0 #a86a12; }
  .play-all svg { width: 26px; height: 26px; }
  .now { order: 2; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
  .now-top { font-size: 12px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
  .now-caller { font-size: 16px; font-weight: 900; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #next { order: 3; width: 44px; height: 44px; }
  #next svg { width: 18px; height: 18px; }
  .side { order: 4; flex: 1 1 100%; gap: 4px; }
  .switches { justify-content: center; gap: 24px; }
  .meta, .error { order: 5; }
  .meta { text-align: center; font-size: 12px; }

  .calls, .call, .call-body { gap: 10px; }
  .call-head { justify-content: center; gap: 0; padding-top: 6px; }
  .call-head h2, .call-time {
    font-family: inherit;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--warm);
  }
  .call-time:not(:empty)::before { content: "\00a0·\00a0"; }
  .call-rule { display: none; }
  .call-body { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }

  .track {
    flex: none;
    align-self: flex-end;
    width: min(100% - 44px, 420px);
    margin-top: 0;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 20px 20px 6px 20px;
    scroll-margin: 16px 0 calc(var(--machine-h) + 16px);
  }
  .track.dave { align-self: flex-start; border-radius: 20px 20px 20px 6px; }
  .track.active { background: var(--card-2); }
  .track-top { gap: 10px; }
  .track-play { width: 44px; height: 44px; }
  .track-play svg { width: 18px; height: 18px; }
  .track-main { gap: 4px; }
  .caller { font-size: 13px; }
  .wave { height: 20px; gap: 2px; }
  .wave span { background: #4a5677; }
  .wave span:nth-child(n+31) { display: none; }
  .track-text { gap: 4px; }
  .text { font-size: 14px; line-height: 1.45; color: var(--ink); }
  .track-foot { flex-wrap: wrap; font-size: 12px; }
  .more { color: var(--soft); }
  .track:not(.open) .meta-line { display: none; } /* the cost shows with the full transcript */

  .pending, .pending.dave {
    flex: none;
    align-self: flex-end;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    margin-top: 0;
    padding: 10px 14px;
    border-radius: 20px 20px 6px 20px;
    font-size: 13px;
    font-weight: 800;
    color: var(--soft);
  }
  .pending.dave { align-self: flex-start; border-radius: 20px 20px 20px 6px; }
  .pending-title, .pending-sub { font-size: inherit; font-weight: inherit; color: inherit; }
  .pending.idle .pending-sub { display: none; }
  .pending-sub::before { content: "· "; }
}

@keyframes arrive { from { opacity: 0; transform: translateY(8px); } }
@keyframes pulse { 0%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
