:root {
  --bg: #0a0a09;
  --ink: #e2ded3;
  --dim: #77746c;
  --cyan: #c9c5ba; /* secondary ink */
  --magenta: #d6a45f; /* the one accent */
  --amber: #d6a45f;
  --line: rgba(226, 222, 211, 0.16);
  --glass: rgba(10, 10, 9, 0.92);
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, "PingFang SC", "Noto Sans SC", monospace;
  --display: var(--mono);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.6 var(--mono);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

#tree {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#tree.dragging { cursor: grabbing; }
#tree.pointing { cursor: pointer; }

/* scanlines + vignette over everything, like an old tube */
.crt {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0 2px, rgba(0, 0, 0, 0.12) 2px 3px),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.6) 100%);
  mix-blend-mode: multiply;
}

.dim { color: var(--dim); }

.hud {
  position: fixed;
  z-index: 5;
  margin: 0;
  pointer-events: none;
  user-select: none;
}
.hud-top {
  top: max(18px, env(safe-area-inset-top));
  left: 20px;
}
.hud-top h1 {
  margin: 0;
  font: 400 13px/1 var(--mono);
  letter-spacing: 0.42em;
  color: var(--ink);
}
.sub {
  margin: 10px 0 0;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}
.hint {
  left: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--dim);
  transition: opacity 1.2s;
}
.hint.gone { opacity: 0; }

.empty {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  margin: 0;
  text-align: center;
  font: 300 12px/2 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  pointer-events: none;
  animation: flicker 4s infinite;
}
@keyframes flicker {
  0%, 100% { opacity: 0.9; }
  47% { opacity: 0.9; }
  48% { opacity: 0.35; }
  50% { opacity: 0.9; }
  83% { opacity: 0.6; }
}

/* buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(226, 222, 211, 0.06);
  color: var(--cyan);
  font: 500 12px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 11px 14px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, color 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) {
  background: rgba(226, 222, 211, 0.14);
  border-color: rgba(226, 222, 211, 0.4);
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { border-color: transparent; background: none; color: var(--dim); }

.btn-main {
  border-color: var(--magenta);
  background: rgba(10, 10, 9, 0.6);
  color: var(--magenta);
}
.btn-main:hover:not(:disabled) {
  background: var(--magenta);
  color: var(--bg);
  box-shadow: none;
}
#open-compose {
  position: fixed;
  z-index: 6;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  padding: 14px 18px;
  font-size: 13px;
}
.plus { margin-right: 6px; }

:focus-visible { outline: 1px dashed var(--amber); outline-offset: 3px; }

/* panels */
.panel {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  background: var(--glass);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: slide 0.28s ease-out;
}
@keyframes slide {
  from { transform: translateX(24px); opacity: 0; }
}
.panel-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 54px 22px calc(28px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}
.close {
  position: absolute;
  z-index: 2;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--cyan);
  font: 300 20px/1 var(--mono);
  cursor: pointer;
}
.close:hover { color: var(--magenta); border-color: var(--magenta); }

.veil {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* or the modal outgrows a phone screen */
  place-items: center;
  padding: 16px;
  background: rgba(4, 3, 8, 0.72);
}
.modal {
  position: relative;
  inset: auto;
  width: min(480px, 100%);
  max-height: 100%;
  display: flex;
  border: 1px solid var(--line);
  animation: rise 0.25s ease-out;
}
.modal .panel-scroll { height: auto; max-height: calc(100dvh - 32px); width: 100%; padding-top: 22px; }
@keyframes rise {
  from { transform: translateY(14px); opacity: 0; }
}

.panel h2 {
  margin: 0 0 16px;
  font: 400 12px/1 var(--mono);
  letter-spacing: 0.34em;
  color: var(--ink);
  text-transform: uppercase;
}

/* opened memory */
.frame {
  margin: 0;
  padding: 6px;
  border: 1px solid var(--line);
  background: #000;
  position: relative;
}
.frame::before, .frame::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid var(--magenta);
}
.frame::before { top: -4px; left: -4px; border-right: 0; border-bottom: 0; }
.frame::after { bottom: -4px; right: -4px; border-left: 0; border-top: 0; }
.frame img { display: block; width: 100%; max-height: 62vh; object-fit: contain; }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin-top: 16px;
  font-size: 12px;
}
.who { color: var(--ink); font-weight: 500; letter-spacing: 0.06em; }
.who::before { content: "@ "; color: var(--dim); }
.contact { color: var(--amber); overflow-wrap: anywhere; }
.contact:not(:empty)::before { content: "↳ "; color: var(--dim); }
time { color: var(--dim); margin-left: auto; font-size: 11px; }

.memory-text { margin: 12px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.memory-text:empty { display: none; }

.answers { margin: 16px 0 0; }
.answers:empty { display: none; }
.answers dt {
  margin-top: 14px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}
.answers dd { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.player {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid rgba(214, 164, 95, 0.4);
  background: rgba(214, 164, 95, 0.06);
}
.play {
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--magenta);
  background: none;
  color: var(--magenta);
  font-size: 13px;
  cursor: pointer;
}
.play:hover { background: rgba(214, 164, 95, 0.2); }
.bar { flex: 1; height: 16px; cursor: pointer; display: flex; align-items: center; }
.bar i {
  display: block;
  height: 2px;
  width: 0;
  background: var(--magenta);
}
.bar {
  background: linear-gradient(rgba(214, 164, 95, 0.25), rgba(214, 164, 95, 0.25)) center / 100% 2px no-repeat;
}
.clock { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }

/* thread */
.thread { margin-top: 30px; padding-top: 20px; border-top: 1px dashed var(--line); }
.thread h2 { margin-bottom: 12px; }
.comments, .comments ul { list-style: none; margin: 0; padding: 0; }
.comments ul { margin-left: 10px; padding-left: 12px; border-left: 1px solid rgba(226, 222, 211, 0.16); }
.comments li { margin-top: 14px; }
.comments .meta { margin-top: 0; }
.comments p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.reply {
  appearance: none;
  border: 0;
  background: none;
  padding: 2px 0;
  color: var(--dim);
  font: 400 11px var(--mono);
  letter-spacing: 0.08em;
  cursor: pointer;
}
.reply:hover { color: var(--magenta); }
.none { color: var(--dim); font-size: 12px; }

/* forms */
.say { margin-top: 22px; }
textarea, input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgba(0, 0, 0, 0.45);
  color: var(--ink);
  font: 400 16px/1.5 var(--mono); /* 16px keeps iOS from zooming on focus */
  padding: 10px 12px;
  resize: vertical;
}
textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: rgba(226, 222, 211, 0.5);
}
::placeholder { color: #5a5852; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row.end { justify-content: flex-end; align-items: center; margin-top: 12px; }
.status { margin-right: auto; font-size: 12px; color: var(--amber); }
.replying { margin: 0 0 6px; font-size: 12px; color: var(--dim); }
.replying b { color: var(--cyan); }
.replying button { border: 0; background: none; color: var(--magenta); cursor: pointer; font-size: 14px; }

.field { display: block; margin-top: 18px; }
.question { display: block; margin-top: 12px; font-size: 12px; color: var(--ink); }
.question textarea { display: block; margin-top: 4px; }
.field b, .recorder > b, .drop b {
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
}

.consent { margin: 18px 0 0; padding: 0; border: 0; font-size: 12px; color: var(--cyan); }
.consent legend { padding: 0; }
.consent p { margin: 0; }
.consent ul { margin: 8px 0 12px; padding-left: 16px; }
.consent li { margin-top: 4px; }
.removal { color: var(--amber); overflow-wrap: anywhere; }
.check { display: flex; gap: 8px; margin-top: 10px; color: var(--ink); cursor: pointer; }
.check input { flex: none; width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--amber); }

.drop {
  display: grid;
  place-items: center;
  min-height: 150px;
  padding: 16px;
  border: 1px dashed var(--line);
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover { border-color: var(--cyan); background: rgba(226, 222, 211, 0.05); }
.drop img { max-width: 100%; max-height: 240px; display: block; }

.recorder { margin-top: 18px; }
.rec-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.rec { flex: none; color: var(--magenta); border-color: rgba(214, 164, 95, 0.5); background: rgba(214, 164, 95, 0.06); }
.rec.live { color: var(--ink); background: rgba(214, 164, 95, 0.4); animation: pulse 1s infinite; }
@keyframes pulse { 50% { background: rgba(214, 164, 95, 0.15); } }
#rec-meter { flex: 1; min-width: 0; height: 32px; }
#rec-audio { flex: 1; min-width: 0; height: 36px; }
.inline { position: static; }

@media (max-width: 640px) {
  .hud-top h1 { font-size: 26px; }
  .hint { display: none; }
  .panel:not(.modal) { width: 100vw; border-left: 0; }
  .row:not(.end) { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .modal, .empty, .rec.live { animation: none; }
}
