/* Gwar: graphite neutrals, one lamplight accent, quiet chrome.
   The moment is the call screen, where the voice ring moves with real audio. */
:root {
  --bg: #141416;
  --s1: #1b1b1e;
  --s2: #232327;
  --s3: #2c2c31;
  --line: rgba(236, 236, 240, 0.08);
  --line2: rgba(236, 236, 240, 0.14);
  --t1: #ececf0;
  --t2: #a4a4ad;
  --t3: #6e6e78;
  --accent: #e8a33d;
  --accent-ink: #1a1206;
  --ok: #4fae7a;
  --bad: #d25f55;
  --r-ctl: 8px;
  --r-card: 12px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f7; --s1: #ffffff; --s2: #f0f0f2; --s3: #e6e6e9;
    --line: rgba(20, 20, 26, 0.08); --line2: rgba(20, 20, 26, 0.14);
    --t1: #17171b; --t2: #5b5b64; --t3: #8b8b94;
    --accent: #b8741a; --accent-ink: #ffffff;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--t1); font: 400 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--t2); }
.small { font-size: 12px; }
.err { color: var(--bad); min-height: 20px; margin: 0; font-size: 13px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 16px; }
.mark { width: 16px; height: 16px; border-radius: 4px; background: var(--accent); position: relative; }
.mark::after { content: ""; position: absolute; inset: 4px; border-radius: 2px; background: var(--bg); clip-path: polygon(0 0, 100% 0, 100% 60%, 40% 60%, 0 100%); }

.btn { height: 40px; padding: 0 16px; border-radius: var(--r-ctl); border: 1px solid var(--line2); background: var(--s2); transition: background-color .15s var(--ease); }
.btn:hover { background: var(--s3); }
.btn.primary { background: var(--t1); color: var(--bg); border-color: transparent; font-weight: 500; }
.btn.primary:hover { opacity: .9; }
.link { background: none; border: 0; padding: 0; color: var(--t2); text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--t1); }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r-ctl); border: 0; background: transparent; color: var(--t2); transition: background-color .15s var(--ease), color .15s var(--ease); }
.icon-btn:hover { background: var(--s2); color: var(--t1); }

input, textarea { background: var(--s2); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 0 12px; height: 40px; outline: none; transition: border-color .15s var(--ease); width: 100%; }
input:focus, textarea:focus { border-color: var(--line2); }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.auth-card h1 { font-size: 24px; font-weight: 500; margin: 24px 0 0; }
.auth-card p { margin: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; color: var(--t2); font-size: 13px; }
.auth-card label input { color: var(--t1); font-size: 14px; }
.auth-card .link { align-self: flex-start; }
.or { display: flex; align-items: center; gap: 12px; color: var(--t3); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.btn.ek { display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn.ek:disabled { opacity: .6; cursor: default; }

/* app shell */
.app { display: grid; grid-template-columns: 280px 1fr; grid-template-rows: minmax(0, 1fr); height: 100dvh; overflow: hidden; }
.side { background: var(--s1); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 12px 12px 16px; }
.add { display: flex; gap: 4px; padding: 0 12px; }
.add input { height: 36px; }
.add-msg { margin: 4px 16px 0; font-size: 12px; color: var(--t2); min-height: 16px; }
.section-label { margin: 16px 16px 4px; font-size: 12px; color: var(--t3); }
.list { flex: 1; overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; height: 52px; padding: 0 8px; border-radius: var(--r-ctl); border: 0; background: transparent; text-align: left; transition: background-color .15s var(--ease); }
.row:hover { background: var(--s2); }
.row.active { background: var(--s2); box-shadow: inset 0 0 0 1px var(--line); }
.row .meta { flex: 1; min-width: 0; }
.row .name { font-weight: 500; }
.row .preview { color: var(--t2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { color: var(--t3); font-size: 12px; font-variant-numeric: tabular-nums; }
.row .unread { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 500; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.req { display: flex; align-items: center; gap: 8px; margin: 0 8px; padding: 8px; border-radius: var(--r-ctl); }
.req .meta { flex: 1; min-width: 0; }
.req .icon-btn { width: 32px; height: 32px; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--t2); font-size: 13px; }
.me { display: flex; align-items: center; gap: 8px; }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--s3); color: var(--t1); display: grid; place-items: center; font-weight: 500; flex: none; position: relative; text-transform: uppercase; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; border: 2px solid var(--s1); width: 12px; height: 12px; }
.avatar.lg { width: 48px; height: 48px; font-size: 18px; }
.avatar.xl { width: 112px; height: 112px; font-size: 40px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--t3); display: inline-block; }
.dot.on { background: var(--ok); }

/* thread */
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.empty { margin: auto; text-align: center; }
.empty p { margin: 4px 0; }
.thread-in { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread-head { display: flex; align-items: center; gap: 8px; height: 64px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.who .name { font-weight: 500; }
.head-actions { display: flex; gap: 4px; }
.head-actions .icon-btn:disabled { opacity: .4; cursor: default; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 24px 24px 8px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; color: var(--t3); font-size: 12px; margin: 16px 0 8px; }
.bubble { max-width: min(560px, 75%); padding: 8px 12px; border-radius: var(--r-card); background: var(--s2); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.mine { align-self: flex-end; background: var(--s3); }
.bubble .at { display: block; font-size: 11px; color: var(--t3); margin-top: 2px; font-variant-numeric: tabular-nums; }
.bubble.gap { margin-top: 8px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px 16px; }
.composer textarea { resize: none; padding: 9px 12px; height: 40px; overflow-y: auto; scrollbar-width: none; max-height: 160px; line-height: 20px; }
.send { color: var(--t1); }

/* incoming card */
.incoming { position: fixed; top: 16px; right: 16px; z-index: 30; width: 320px; max-width: calc(100vw - 32px); background: var(--s1); border: 1px solid var(--line2); border-radius: 16px; padding: 16px; display: flex; align-items: center; gap: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: rise .2s var(--ease); }
.incoming .name { font-weight: 500; }
.in-actions { margin-left: auto; display: flex; gap: 8px; }
.incoming .round { width: 44px; height: 44px; }

/* call */
.call { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; animation: fade .2s var(--ease); }
.stage { flex: 1; position: relative; min-height: 0; overflow: hidden; }
#remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.callee { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--bg); }
.callee .name { font-size: 20px; font-weight: 500; margin-top: 16px; }
.voice { position: relative; display: grid; place-items: center; }
.ring { position: absolute; inset: -12px; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; transform: scale(1); }
.local { position: absolute; right: 16px; bottom: 16px; width: 200px; aspect-ratio: 16 / 10; object-fit: cover; border-radius: var(--r-card); background: #000; border: 1px solid var(--line2); }
.local.mirror { transform: scaleX(-1); }
.controls { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.round { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--s3); color: var(--t1); display: grid; place-items: center; transition: background-color .15s var(--ease), transform .1s var(--ease); }
.round:hover { background: var(--line2); }
.round:active { transform: scale(.96); }
.round.on { background: var(--t1); color: var(--bg); }
.round.decline { background: var(--bad); color: #fff; }
.round.accept { background: var(--ok); color: #fff; }
.round svg { width: 20px; height: 20px; }
.meter { width: 4px; height: 32px; border-radius: 2px; background: var(--s3); position: relative; overflow: hidden; margin-right: 4px; }
.meter span { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; background: var(--t1); color: var(--bg); padding: 8px 16px; border-radius: var(--r-ctl); font-size: 13px; max-width: calc(100vw - 32px); animation: rise .2s var(--ease); }

@keyframes rise { from { opacity: 0; translate: 0 4px; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* phones: one pane at a time */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.in-thread .side { display: none; }
  .app:not(.in-thread) .thread { display: none; }
  .back { display: grid; }
  .thread-head { padding-left: 4px; }
  .msgs { padding: 16px 12px 8px; }
  .bubble { max-width: 85%; }
  .local { width: 112px; right: 12px; bottom: 12px; aspect-ratio: 3 / 4; }
  .incoming { left: 16px; right: 16px; width: auto; }
}
