/* ==========================================================================
   Kingfisher — Common Kingfisher plumage theme
   Midnight river navy · electric turquoise · rufous orange · white throat
   Rule: vivid surfaces (turquoise, orange) always carry dark ink text.
   ========================================================================== */

:root {
  --navy-900: #0B132B;
  --navy-800: #111D3B;
  --slate-800: #1E293B;
  --cyan: #06B6D4;
  --cyan-soft: #67E8F9;
  --blue: #0284C7;
  --orange: #F97316;
  --rufous: #EA580C;
  --white: #F8FAFC;
  --ink: #071022;
  --muted: #A3B1C6;
  --line: rgba(6, 182, 212, 0.24);

  --grad-water: linear-gradient(135deg, #06B6D4 0%, #0284C7 100%);
  --grad-rufous: linear-gradient(135deg, #F97316 0%, #EA580C 100%);

  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Figtree", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

[hidden], .hidden { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--white);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(6, 182, 212, 0.20), transparent 62%),
    radial-gradient(720px 440px at -12% 108%, rgba(249, 115, 22, 0.13), transparent 62%),
    linear-gradient(180deg, #0B132B 0%, #0A1126 100%);
  background-attachment: fixed;
  background-color: var(--navy-900);
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--cyan-soft);
  outline-offset: 2px;
}

svg.icon { width: 20px; height: 20px; flex: none; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: transform 0.12s ease, filter 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--grad-rufous);
  color: var(--ink);
  box-shadow: 0 10px 26px -10px rgba(249, 115, 22, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-block { width: 100%; min-height: 50px; font-size: 1.02rem; }

.btn-ghost {
  background: rgba(6, 182, 212, 0.10);
  color: var(--cyan-soft);
  border: 1px solid var(--line);
}
.btn-ghost:hover:not(:disabled) { background: rgba(6, 182, 212, 0.20); }

.btn-water {
  background: var(--grad-water);
  color: var(--ink);
  box-shadow: 0 10px 24px -12px rgba(6, 182, 212, 0.8);
}
.btn-water:hover:not(:disabled) { filter: brightness(1.08); }

.btn-danger {
  min-height: 40px;
  padding: 0 14px;
  background: rgba(234, 88, 12, 0.10);
  color: #FDBA74;
  border: 1px solid rgba(249, 115, 22, 0.55);
}
.btn-danger:hover:not(:disabled) { background: rgba(234, 88, 12, 0.24); }

.btn-chip {
  min-height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  background: rgba(6, 182, 212, 0.18);
  color: var(--cyan-soft);
}
.btn-chip:hover:not(:disabled) { background: rgba(6, 182, 212, 0.32); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(6, 182, 212, 0.10);
  color: var(--cyan-soft);
  transition: background-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: rgba(6, 182, 212, 0.24); }
.icon-btn-lg { width: 46px; height: 46px; }

/* ---------- Brand ---------- */

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, #F8FAFC 15%, #67E8F9 62%, #06B6D4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sm .brand-title { font-size: 1.3rem; line-height: 1; }
.brand-bird { width: 34px; height: 34px; flex: none; }

/* ---------- Onboarding ---------- */

#onboarding-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}

.onboarding-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  padding: 38px 30px 28px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(17, 29, 59, 0.80);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  box-shadow:
    0 34px 80px -34px rgba(2, 132, 199, 0.55),
    inset 0 1px 0 rgba(248, 250, 252, 0.06);
}

/* the feather band: blue back to rufous breast */
.onboarding-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: linear-gradient(90deg, #06B6D4 0%, #0284C7 55%, #F97316 100%);
}

.hero { display: grid; justify-items: center; text-align: center; margin-bottom: 26px; }

/* the one orchestrated moment: the bird dives in, the water ripples */
.hero-mark {
  position: relative;
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
}
.hero-mark::before,
.hero-mark::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1.5px solid var(--cyan);
  border-radius: 50%;
  opacity: 0;
  animation: ripple 2.6s ease-out 0.55s 2;
}
.hero-mark::after { animation-delay: 1.15s; }

.hero-bird {
  position: relative;
  width: 96px;
  height: 96px;
  filter: drop-shadow(0 10px 18px rgba(6, 182, 212, 0.45));
  animation: dive 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}

@keyframes dive {
  from { opacity: 0; transform: translate(-18px, -26px) rotate(-14deg); }
  to   { opacity: 1; transform: none; }
}
@keyframes ripple {
  0%   { opacity: 0.65; transform: scale(0.7); }
  100% { opacity: 0;    transform: scale(1.75); }
}

.hero .brand-title { font-size: 2.5rem; line-height: 1.05; }

.tagline { margin: 8px 0 0; color: var(--muted); font-size: 1rem; max-width: 30ch; }

.field-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 12px; margin-bottom: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 0.9rem; font-weight: 600; color: var(--white); }

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--navy-900);
  color: var(--white);
  font-size: 1rem; /* 16px stops iOS zoom on focus */
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder { color: #6B7A93; }
input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.28);
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.form-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(249, 115, 22, 0.12);
  border: 1px solid rgba(249, 115, 22, 0.45);
  color: #FDBA74;
  font-size: 0.92rem;
}

.id-box {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid rgba(6, 182, 212, 0.5);
  border-radius: 18px;
  background: rgba(6, 182, 212, 0.08);
  box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.06), 0 16px 40px -24px rgba(6, 182, 212, 0.8);
}
.id-box-label { margin: 0 0 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }

.id-value {
  display: block;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--navy-900);
  color: var(--cyan-soft);
  font-family: var(--font-mono);
  font-size: 0.98rem;
  letter-spacing: 0.02em;
  line-height: 1.45;
  word-break: break-all;
  user-select: all;
}

.hint { margin: 10px 0 14px; color: var(--muted); font-size: 0.9rem; }

.id-box-actions { display: grid; grid-template-columns: auto 1fr; gap: 10px; }

.fineprint {
  margin: 20px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

/* ---------- Chat shell ---------- */

#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  background: rgba(11, 19, 43, 0.55);
  border-inline: 1px solid rgba(6, 182, 212, 0.12);
}

.chat-header {
  display: grid;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 12px;
  background: rgba(17, 29, 59, 0.88);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(6, 182, 212, 0.12), 0 14px 30px -24px rgba(2, 132, 199, 0.9);
}

.header-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.my-id-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(6, 182, 212, 0.08);
}
.my-id-label { flex: none; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.my-id-value {
  min-width: 0;
  max-width: 26ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--cyan-soft);
}

.header-peer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.peer-input { flex: 1 1 190px; min-width: 0; min-height: 44px; }

.header-peer .btn-water { min-height: 44px; padding: 0 18px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(6, 182, 212, 0.55);
  border-radius: 999px;
  background: rgba(6, 182, 212, 0.12);
  color: var(--cyan-soft);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 0 18px -6px rgba(6, 182, 212, 0.9);
}

.header-peer .btn-danger { margin-left: auto; }

/* ---------- Messages ---------- */

.messages {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(6, 182, 212, 0.35) transparent;
}

.empty-state {
  margin: auto;
  max-width: 300px;
  text-align: center;
  color: var(--muted);
}
.empty-state p { margin: 10px 0 0; }
.empty-bird { width: 64px; height: 64px; opacity: 0.85; }
.messages:has(.message-row, .system-note) .empty-state { display: none; }

.message-row { display: flex; }
.message-row.outgoing { justify-content: flex-end; }
.message-row.incoming { justify-content: flex-start; }

.bubble {
  max-width: min(80%, 520px);
  padding: 9px 13px 7px;
  border-radius: 18px;
  overflow-wrap: anywhere;
}

.outgoing .bubble {
  background: var(--grad-water);
  color: var(--ink);
  border-bottom-right-radius: 6px;
  box-shadow: 0 12px 26px -16px rgba(6, 182, 212, 0.9);
}

.incoming .bubble {
  background: var(--slate-800);
  color: var(--white);
  border: 1px solid rgba(6, 182, 212, 0.18);
  border-left: 3px solid var(--cyan);
  border-bottom-left-radius: 6px;
}

.msg-text { margin: 0; white-space: pre-wrap; }

.msg-image {
  display: block;
  width: 220px;
  max-width: 100%;
  max-height: 240px;
  margin: 2px 0 6px;
  object-fit: cover;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  cursor: zoom-in;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 5px;
}

.msg-time { font-size: 0.72rem; opacity: 0.75; font-variant-numeric: tabular-nums; }
.incoming .msg-time { color: var(--muted); opacity: 1; }

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.status-pill.sent { background: rgba(7, 16, 34, 0.20); color: var(--ink); }
.status-pill.seen { background: var(--grad-rufous); color: var(--ink); }

.system-note {
  align-self: center;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.7);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

/* ---------- Composer ---------- */

.composer {
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(17, 29, 59, 0.92);
  border-top: 1px solid var(--line);
}

.preview-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(6, 182, 212, 0.08);
}
.preview-thumb {
  width: 56px;
  height: 56px;
  flex: none;
  object-fit: cover;
  border-radius: 10px;
  background: var(--navy-900);
}
.preview-label { flex: 1 1 auto; min-width: 0; color: var(--muted); font-size: 0.9rem; }

.composer-row { display: flex; align-items: center; gap: 8px; }

.message-input { flex: 1 1 auto; min-width: 0; min-height: 46px; border-radius: 999px; padding: 0 18px; }

.btn-send { min-height: 46px; padding: 0 20px; border-radius: 999px; }

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: calc(64px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  background: rgba(5, 9, 22, 0.93);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.lightbox-img {
  max-width: 94vw;
  max-height: 80dvh;
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(6, 182, 212, 0.3);
}
.lightbox-close { position: absolute; top: calc(14px + var(--safe-top)); right: 14px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  z-index: 120;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--grad-water);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  box-shadow: 0 16px 36px -14px rgba(6, 182, 212, 0.9);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  .onboarding-card { padding: 32px 22px 24px; border-radius: 24px; }
  .hero .brand-title { font-size: 2.2rem; }

  #chat-screen { border-inline: 0; }
  .my-id-value { max-width: 12ch; }
  .bubble { max-width: 86%; }
  .btn-send span { display: none; }
  .btn-send { padding: 0; width: 46px; }
}

@media (max-width: 380px) {
  .my-id-label { display: none; }
  .brand-sm .brand-title { font-size: 1.15rem; }
  .header-peer .btn-danger span { display: none; }
  .header-peer .btn-danger { padding: 0 12px; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .hero-mark::before, .hero-mark::after { display: none; }
}
