/* Dark phone shell. All colors are variables so a settings screen can retheme later. */

:root {
  --bg: #07090d;
  --phone-bg: #0f1218;
  --panel: #161b24;
  --panel-2: #1b2130;
  --border: #262e3f;
  --bubble-them: #232a38;
  --bubble-you-1: #2d68ff;
  --bubble-you-2: #2453d6;
  --text: #e9ecf3;
  --text-dim: #8b94a7;
  --accent: #2d68ff;
  --danger: #ff4d5e;
  --badge: #2d68ff;
  --radius-bubble: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(120% 90% at 50% 0%, #10141d 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---- phone frame ------------------------------------------------------------ */

.phone {
  position: relative;
  height: min(92vh, 900px);
  aspect-ratio: 9 / 19.5;
  background: var(--phone-bg);
  border: 10px solid #000;
  border-radius: 44px;
  box-shadow:
    0 0 0 1px #2a2f3a,
    0 30px 80px #000c,
    inset 0 0 40px #0006;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

@media (max-width: 540px) {
  .phone {
    width: 100vw;
    height: 100dvh;
    aspect-ratio: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
}

/* ---- status bar --------------------------------------------------------------- */

.statusbar {
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
}

.sb-icons { display: inline-flex; gap: 6px; align-items: center; }
.sb-signal, .sb-batt { height: 11px; width: auto; fill: currentColor; color: var(--text); }

/* ---- views ----------------------------------------------------------------------- */

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 10px 18px 12px;
}
.app-header h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -.02em;
}

/* ---- contacts list ----------------------------------------------------------------- */

.contact-list { overflow-y: auto; }

.contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.contact-row:active { background: var(--panel); }

.avatar {
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--panel-2);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-letter { font-size: 20px; font-weight: 600; color: var(--text-dim); }

.contact-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.contact-name { font-size: 15px; font-weight: 600; }
.contact-preview {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  flex: 0 0 auto;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ---- thread header ------------------------------------------------------------------ */

.thread-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 10px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--phone-bg) 88%, #fff 0%);
}

.thread-header .avatar { flex-basis: 36px; width: 36px; height: 36px; }
.thread-header .avatar-letter { font-size: 15px; }

.back {
  position: relative;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
  padding: 0 14px 4px 0;
  cursor: pointer;
}

/* iOS-style: unread count from OTHER conversations rides the back chevron */
.back-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--badge);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.who .name { font-size: 15px; font-weight: 600; }
.who .status { font-size: 12px; color: var(--text-dim); }

.menu {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 6px 8px;
  cursor: pointer;
}

/* ---- action sheet ----------------------------------------------------------- */

.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 45;
  background: #0009;
  display: flex;
  align-items: flex-end;
  padding: 10px;
}

.sheet {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: rise .18s ease-out;
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet-item {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}
.sheet-item:active { filter: brightness(1.2); }
.sheet-item.destructive { color: var(--danger); font-weight: 600; }
.sheet-item.cancel { background: var(--panel); color: var(--accent); font-weight: 600; }
.sheet-item.primary { background: var(--accent); color: #fff; font-weight: 600; }

/* ---- save-code dialog --------------------------------------------------------- */

.dialog-backdrop {
  position: absolute;
  inset: 0;
  z-index: 46;
  background: #000a;
  display: grid;
  place-items: center;
  padding: 16px;
}

.dialog {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: rise .18s ease-out;
}

.dialog-title { font-size: 16px; font-weight: 700; }
.dialog-hint { font-size: 12.5px; line-height: 1.45; color: var(--text-dim); }

.dialog-input {
  width: 100%;
  resize: none;
  background: var(--phone-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  word-break: break-all;
}
.dialog-input:focus-visible { outline: 2px solid var(--accent); }

.dialog-error { font-size: 12.5px; color: var(--danger); }

.dialog-actions { display: flex; gap: 8px; }
.dialog-actions .sheet-item { flex: 1; padding: 11px; }

/* ---- messages -------------------------------------------------------------------------- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Flex children default to shrink-to-fit: past one screen of chat, that
   squeezes images flat instead of letting the thread scroll. Never shrink. */
.messages > * { flex-shrink: 0; }

/* Each contact's transcript lives in its own log; the visible one is swapped
   into .messages when a thread opens. */
.thread-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.thread-log > * { flex-shrink: 0; }

.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: var(--radius-bubble);
  font-size: 15px;
  line-height: 1.35;
  overflow-wrap: break-word;
  user-select: text;
  animation: pop .14s ease-out;
}
.bubble.instant { animation: none; }

.bubble.them {
  align-self: flex-start;
  background: var(--bubble-them);
  border-bottom-left-radius: 6px;
}

.bubble.you {
  align-self: flex-end;
  background: linear-gradient(160deg, var(--bubble-you-1), var(--bubble-you-2));
  border-bottom-right-radius: 6px;
}

.bubble.img {
  padding: 0;
  width: min(62%, 240px);
  overflow: hidden;
  cursor: zoom-in;
}
.bubble.img.loading { background: var(--panel-2); }
.bubble.img img { display: block; width: 100%; height: auto; }

@keyframes pop {
  from { transform: translateY(6px) scale(.92); opacity: 0; }
}

/* Emoji render larger than the words around them (and jumbo when a message is
   nothing but emoji, messaging-app style). */
.emoji {
  font-size: 1.35em;
  line-height: 1;
  vertical-align: -0.14em;
}
.bubble.emoji-only {
  background: none;
  padding: 2px 4px;
}
.bubble.emoji-only .emoji {
  font-size: 2.3em;
  vertical-align: baseline;
}

/* typing indicator */
.bubble.typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
}
.bubble.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out;
}
.bubble.typing span:nth-child(2) { animation-delay: .15s; }
.bubble.typing span:nth-child(3) { animation-delay: .3s; }

@keyframes blink {
  0%, 60%, 100% { opacity: .35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* dividers */
.divider {
  align-self: center;
  margin: 10px 0 4px;
  padding: 4px 12px;
  border-radius: 999px;
  background: #ffffff10;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.divider.big {
  font-size: 13px;
  padding: 6px 16px;
  margin: 16px 0 8px;
}

/* end-of-demo card */
.endcard {
  align-self: center;
  width: 88%;
  margin: 18px 0 10px;
  padding: 16px 18px;
  border: 1px solid var(--accent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 12%, var(--phone-bg));
  text-align: center;
  animation: pop .18s ease-out;
}
.endcard-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.endcard-body {
  font-size: 14px;
  line-height: 1.45;
  user-select: text;
}
.endcard-link {
  display: block;
  margin-top: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
}
.endcard-link:active { filter: brightness(1.15); }
.endcard-tip {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-dim);
  user-select: text;
}

/* ---- composer / choice tray ---------------------------------------------------------------- */

.composer {
  flex: 0 0 auto;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.fake-input {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 16px;
  color: var(--text-dim);
  font-size: 14px;
}

.choice-tray {
  display: flex;
  flex-direction: column;
  gap: 7px;
  animation: rise .18s ease-out;
}

@keyframes rise {
  from { transform: translateY(14px); opacity: 0; }
}

.choice {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 13px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.3;
  cursor: pointer;
  transition: transform .06s ease, background .12s ease;
}
.choice:hover { background: #212a3c; }
.choice:active { transform: scale(.98); }
.choice:focus-visible, .back:focus-visible, .contact-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.choice-num {
  flex: 0 0 auto;
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
}

/* ---- notification banner (message in another thread) ------------------------------------------- */

.notif {
  position: absolute;
  top: 40px;
  left: 10px;
  right: 10px;
  z-index: 48;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: #1c2330f2;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 8px 26px #000a;
}
.notif .avatar { flex-basis: 34px; width: 34px; height: 34px; }
.notif .avatar-letter { font-size: 14px; }
.notif-main { display: flex; flex-direction: column; min-width: 0; }
.notif-name { font-size: 13px; font-weight: 700; }
.notif-preview {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notif-in { animation: notif-drop .22s ease-out; }
@keyframes notif-drop {
  from { transform: translateY(-14px); opacity: 0; }
}

/* ---- one-time coach (first second-thread message) ----------------------------------------------- */

.coach-backdrop {
  position: absolute;
  inset: 0;
  z-index: 75;
  background: #000b;
  display: grid;
  place-items: center;
  padding: 18px;
}

.coach-card {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 300px;
  animation: rise .2s ease-out;
}
.coach-title { font-size: 16px; font-weight: 700; color: var(--accent); }
.coach-text { font-size: 14px; line-height: 1.5; }

/* ---- lightbox ---------------------------------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000e;
  display: grid;
  place-items: center;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}

/* ---- toast / error panel ------------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 70;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13px;
  box-shadow: 0 10px 30px #0009;
}

.error-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #16090bee;
  display: grid;
  place-items: center;
  padding: 24px;
}
.error-panel pre {
  max-width: min(92vw, 720px);
  max-height: 80vh;
  overflow: auto;
  background: #200d10;
  border: 1px solid var(--danger);
  border-radius: 12px;
  padding: 18px 20px;
  color: #ffd7db;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* ---- dev overlay ------------------------------------------------------------------------------------ */

.dev-overlay {
  position: fixed; /* lives on the body, outside the phone — park it anywhere */
  top: 44px;
  right: 16px;
  z-index: 55;
  background: #0c0f14e6;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 175px;
}
.dev-overlay table { border-collapse: collapse; }
.dev-overlay td { padding: 2px 6px 2px 0; }
.dev-overlay .dev-val { color: var(--text); font-weight: 700; text-align: right; }
.dev-overlay button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  padding: 3px 7px;
  margin-right: 4px;
  cursor: pointer;
}
.dev-overlay button:hover { background: #222b3e; }
.dev-overlay .dev-speed button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.dev-walk { align-items: center; }
.dev-walk select {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  padding: 3px 5px;
}
.dev-overlay .dev-actions { display: flex; flex-wrap: wrap; gap: 4px; }

.dev-overlay { max-width: 250px; max-height: calc(100vh - 60px); overflow-y: auto; }
.dev-info { cursor: move; user-select: none; padding: 2px 0 4px; border-bottom: 1px solid var(--border); touch-action: none; }
.dev-tag { color: var(--accent); font-size: 9px; letter-spacing: .06em; }
.dev-val.changed { animation: dev-flash 0.7s ease-out; }
@keyframes dev-flash { from { color: var(--accent); } }

.dev-watches { display: flex; flex-direction: column; gap: 3px; }
.dev-watch { display: flex; align-items: center; gap: 5px; }
.dev-watch-expr { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.dev-watch-result.true { color: #5dd97c; }
.dev-watch-result.false { color: var(--danger); }
.dev-watch-result.warn { color: #e8b04b; }
.dev-watch button { margin: 0; padding: 0 5px; }
.dev-watch-form { display: flex; gap: 4px; }
.dev-watch-form input {
  flex: 1;
  min-width: 0;
  background: var(--phone-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  padding: 3px 6px;
}
.dev-watch-form input:focus-visible { outline: 1px solid var(--accent); }

.dev-log {
  max-height: 150px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-wrap: break-word;
}
.dev-log > div { color: var(--text); opacity: .9; }
.dev-log > .dev-log-skip { color: var(--text-dim); opacity: .8; }

/* ---- misc ------------------------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .messages { scroll-behavior: auto; }
}
