/* CallForge - FluxForge design system
   Mobile first at 393px, real multi-column layout from 1100px up. */

:root {
  --ink:        #05080d;
  --ink-raised: #0b1119;
  --ink-line:   #17222f;
  --text:       #e8f1f6;
  --text-dim:   #8fa3b3;
  --teal:       #2bf5c4;
  --blue:       #1ea0ff;
  --alert:      #ff5c72;
  --grad:       linear-gradient(100deg, var(--teal), var(--blue));
  --r:          14px;
  --safe-t:     env(safe-area-inset-top, 0px);
  --safe-b:     env(safe-area-inset-bottom, 0px);
  --safe-l:     env(safe-area-inset-left, 0px);
  --safe-r:     env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  font-family: 'Sora', system-ui, -apple-system, sans-serif;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

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

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

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

/* ---------- Shared controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--grad);
  color: #04121a;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: filter .15s ease, opacity .15s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }

.btn-ghost {
  background: transparent;
  border-color: var(--ink-line);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--teal); }

.btn-sm { min-height: 42px; font-size: .9rem; padding: 0 16px; }

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: .85rem;
  color: var(--text-dim);
}
.field input {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r);
  background: var(--ink);
  font-size: 1rem;
}
.field input:focus { border-color: var(--teal); outline: none; }

.code-input {
  font-family: 'Space Mono', monospace;
  font-size: 1.6rem !important;
  letter-spacing: .32em;
  text-align: center;
}

/* ---------- Home ---------- */

.page-home {
  /* faint oscilloscope grid, no motion */
  background-image:
    linear-gradient(var(--ink-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--ink-line) 1px, transparent 1px);
  background-size: 64px 64px;
  background-position: center;
  background-attachment: fixed;
}
.page-home::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 70% at 50% 0%, rgba(5,8,13,.35), var(--ink) 72%);
  pointer-events: none;
}

.home {
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  padding: calc(48px + var(--safe-t)) 20px calc(48px + var(--safe-b));
}

.home-mark { margin-bottom: 36px; }
.mark-call, .mark-forge {
  font-size: clamp(2.4rem, 11vw, 4.2rem);
  line-height: .95;
  letter-spacing: -.03em;
}
.mark-call { font-weight: 700; }
.mark-forge {
  font-weight: 300;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.home-tag {
  margin: 14px 0 0;
  max-width: 46ch;
  color: var(--text-dim);
  font-size: 1.05rem;
  line-height: 1.55;
}

.home-panel {
  border: 1px solid var(--ink-line);
  border-radius: 20px;
  background: rgba(11,17,25,.86);
  padding: 24px 20px;
  margin-bottom: 18px;
}
.panel-h {
  margin: 0 0 18px;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -.01em;
}
.panel-note {
  margin: 14px 0 0;
  color: var(--text-dim);
  font-size: .88rem;
  line-height: 1.5;
}
.home-panel .btn { width: 100%; }

.home-error {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--alert);
  border-radius: var(--r);
  color: var(--alert);
  font-size: .95rem;
}

.home-foot {
  color: var(--text-dim);
  font-size: .85rem;
  line-height: 1.6;
  max-width: 62ch;
}
.foot-brand {
  font-family: 'Space Mono', monospace;
  letter-spacing: .14em;
  color: #3d5162;
}

@media (min-width: 760px) {
  .home { padding: calc(72px + var(--safe-t)) 40px 72px; }
  .home-mark { margin-bottom: 48px; }
  .home-panel { padding: 32px 30px; }
  .home-panel .btn { width: auto; min-width: 240px; }
}

@media (min-width: 1000px) {
  .home {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(0, 1.1fr);
    grid-template-areas:
      'mark  start'
      'mark  join'
      'foot  foot';
    column-gap: 56px;
    align-content: start;
  }
  .home-mark  { grid-area: mark; align-self: center; margin-bottom: 0; }
  #start-h    { }
  .home-panel:nth-of-type(1) { grid-area: start; }
  .home-panel:nth-of-type(2) { grid-area: join; }
  .home-error { grid-column: 1 / -1; }
  .home-foot  { grid-area: foot; margin-top: 48px; }
}

/* ---------- Call ---------- */

.page-call {
  height: 100dvh;
  overflow: hidden;
}

.call-shell {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  height: 100dvh;
}

.stage {
  position: relative;
  overflow: hidden;
  background: #000;
}

.video-remote {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  display: block;
}

.video-local {
  position: absolute;
  right: calc(14px + var(--safe-r));
  top: calc(14px + var(--safe-t));
  width: 30vw;
  max-width: 132px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(43,245,196,.35);
  background: #000;
  transform: scaleX(-1); /* mirror the local preview, like every other call app */
  z-index: 3;
}
.video-local.rear-facing { transform: none; }

.stage-idle {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(90% 60% at 50% 45%, #0b1119, var(--ink));
}
.idle-status {
  margin: 0;
  color: var(--text-dim);
  font-size: .95rem;
}
.idle-code {
  margin: 6px 0 0;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: clamp(2.6rem, 15vw, 5rem);
  letter-spacing: .18em;
  text-indent: .18em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.idle-hint {
  margin: 0;
  max-width: 34ch;
  color: var(--text-dim);
  font-size: .9rem;
  line-height: 1.5;
}
.idle-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}

.stage-badge {
  position: absolute;
  left: calc(14px + var(--safe-l));
  top: calc(14px + var(--safe-t));
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(5,8,13,.66);
  backdrop-filter: blur(8px);
  font-family: 'Space Mono', monospace;
  font-size: .74rem;
  letter-spacing: .06em;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.dot.live   { background: var(--teal); }
.dot.warn   { background: #ffc44d; }
.dot.down   { background: var(--alert); }

.controls {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 6px;
  padding: 12px 10px calc(12px + var(--safe-b));
  padding-left: calc(10px + var(--safe-l));
  padding-right: calc(10px + var(--safe-r));
  background: var(--ink-raised);
  border-top: 1px solid var(--ink-line);
}

.ctrl {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-height: 58px;
  padding: 8px 2px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.ctrl i { font-size: 1.25rem; }
.ctrl-label { font-size: .68rem; color: var(--text-dim); }
.ctrl:hover { background: rgba(43,245,196,.07); }
.ctrl[aria-pressed="true"] { color: var(--alert); }
.ctrl[aria-pressed="true"] .ctrl-label { color: var(--alert); }
.ctrl-end { color: var(--alert); }
.ctrl-end i { font-size: 1.35rem; }

/* Rail: drawer on phones */
.rail {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  transform: translateY(102%);
  transition: transform .22s ease;
  max-height: 78dvh;
  overflow-y: auto;
  padding: 20px 20px calc(24px + var(--safe-b));
  background: var(--ink-raised);
  border-top: 1px solid var(--ink-line);
  border-radius: 20px 20px 0 0;
}
.rail.open { transform: translateY(0); }

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.rail-h { margin: 0; font-size: 1.05rem; font-weight: 600; }
.rail-code {
  font-family: 'Space Mono', monospace;
  letter-spacing: .16em;
  color: var(--teal);
}
.rail-close {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px;
}

.rail-stats { margin: 0 0 22px; }
.rail-stats > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--ink-line);
}
.rail-stats dt { color: var(--text-dim); font-size: .85rem; }
.rail-stats dd {
  margin: 0;
  font-family: 'Space Mono', monospace;
  font-size: .85rem;
  text-align: right;
}

.rail-label { margin: 0 0 8px; color: var(--text-dim); font-size: .85rem; }
.rail-link {
  display: block;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--ink-line);
  border-radius: 10px;
  font-family: 'Space Mono', monospace;
  font-size: .78rem;
  word-break: break-all;
  color: var(--teal);
}
.rail-note {
  margin: 18px 0 0;
  color: var(--text-dim);
  font-size: .8rem;
  line-height: 1.55;
}

.toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(5,8,13,.92);
  border: 1px solid var(--ink-line);
  font-size: .85rem;
  white-space: nowrap;
}

/* Tablet: bigger self view, roomier controls */
@media (min-width: 720px) {
  .video-local { max-width: 200px; right: 20px; top: 20px; }
  .controls { gap: 20px; padding: 14px 24px calc(14px + var(--safe-b)); }
  .ctrl { flex: 0 0 96px; }
  .ctrl-label { font-size: .74rem; }
}

/* Desktop: rail becomes a permanent column, stage takes the rest.
   No centered column, no dead margins. */
@media (min-width: 1100px) {
  .call-shell {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: 1fr auto;
    grid-template-areas:
      'stage    rail'
      'controls rail';
  }
  .stage    { grid-area: stage; }
  .controls { grid-area: controls; justify-content: center; gap: 34px; }
  .rail {
    grid-area: rail;
    position: static;
    transform: none;
    max-height: none;
    border-radius: 0;
    border-top: 0;
    border-left: 1px solid var(--ink-line);
    padding: 26px 24px;
  }
  .rail-close { display: none; }
  #btn-info { display: none; }
  .video-local { max-width: 260px; }
  .toast { bottom: 110px; }
}
