:root {
  --bg: #dce6ec;
  --ink: #14212b;
  --muted: #4a5c6a;
  --accent: #0f6e6a;
  --accent-ink: #063b39;
  --line: rgba(20, 33, 43, 0.14);
  --surface: rgba(255, 255, 255, 0.7);
  --hero-a: #9eb8c7;
  --hero-b: #6f93a6;
  --hero-c: #2f5a66;
  --font: "Manrope", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

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

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

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(15, 110, 106, 0.16), transparent 55%),
    radial-gradient(800px 480px at 90% 10%, rgba(47, 90, 102, 0.18), transparent 50%),
    linear-gradient(180deg, var(--bg), #eef3f6 55%, #d5e0e8);
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2rem);
}

.logo {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 1rem;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: right;
  max-width: 38rem;
}

.stage {
  position: relative;
  margin: 0 clamp(0.75rem, 3vw, 1.5rem);
  border-radius: 14px;
  overflow: hidden;
  min-height: 0;
  box-shadow: 0 22px 48px rgba(20, 33, 43, 0.14);
}

.remote-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 52vh;
  background:
    linear-gradient(160deg, rgba(20, 33, 43, 0.25), rgba(20, 33, 43, 0.5)),
    linear-gradient(135deg, var(--hero-a), var(--hero-b) 48%, var(--hero-c));
}

.remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0f1a20;
  opacity: 0;
  z-index: 1;
  transition: opacity 0.25s ease;
}

.remote-video.has-stream {
  opacity: 1;
  z-index: 3;
}

.remote-placeholder {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 0.45rem;
  text-align: center;
  color: #f4f8fa;
  padding: 1.5rem;
  background:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 44px 44px;
}

.remote-placeholder.is-hidden {
  display: none;
}

.brand {
  margin: 0;
  font-size: clamp(3rem, 10vw, 5.5rem);
  font-weight: 700;
  letter-spacing: 0.18em;
  line-height: 0.95;
}

.hint {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.35rem, 3.5vw, 2rem);
  font-weight: 400;
  color: rgba(244, 248, 250, 0.92);
}

.subhint {
  margin: 0.4rem 0 0;
  max-width: 28rem;
  justify-self: center;
  font-size: 0.95rem;
  line-height: 1.4;
  color: rgba(244, 248, 250, 0.75);
}

.btn-sound {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 4;
  background: rgba(20, 33, 43, 0.82);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.local-wrap {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  width: min(28vw, 200px);
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(10, 24, 30, 0.45);
  z-index: 5;
  box-shadow: 0 12px 28px rgba(20, 33, 43, 0.25);
}

.local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #24343d;
}

.local-label {
  position: absolute;
  left: 0.55rem;
  bottom: 0.45rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.88);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.1rem clamp(1rem, 4vw, 2rem) 1.5rem;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.9rem 1.35rem;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #f5fbfa;
  min-width: min(100%, 260px);
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.is-searching .brand {
  animation: pulse-soft 1.4s ease-in-out infinite;
}

@keyframes pulse-soft {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.12); }
}

@media (max-width: 640px) {
  .top {
    flex-direction: column;
    align-items: flex-start;
  }

  .status {
    text-align: left;
  }

  .local-wrap {
    width: 112px;
    right: 0.7rem;
    bottom: 0.7rem;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
  }
}

.btn-tap {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  min-width: min(90%, 320px);
  padding: 1rem 1.25rem;
  background: rgba(15, 110, 106, 0.95);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-size: 1.05rem;
}

.remote-video.has-stream {
  opacity: 1;
  z-index: 3;
  background: #000;
}

.top {
  flex-wrap: wrap;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.user-chip {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
}

.auth-screen[hidden],
.app[hidden],
.friends-panel[hidden],
#gender-field[hidden],
.btn[hidden] {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

/* display:grid overrides the native [hidden] rule — force hide */
.auth-screen[hidden],
.app[hidden],
.friends-panel[hidden],
[hidden] {
  display: none !important;
}

.auth-card {
  width: min(420px, 100%);
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 18px 40px rgba(20, 33, 43, 0.12);
}

.auth-brand {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.auth-title {
  margin: 0.7rem 0 0.35rem;
  font-family: var(--display);
  font-weight: 400;
  font-size: 2rem;
}

.auth-lead,
.auth-error {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.auth-error:not(:empty) {
  color: #8a2f2f;
}

.auth-form {
  display: grid;
  gap: 0.85rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.field input,
.field select {
  border: 1px solid rgba(20, 33, 43, 0.18);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.auth-submit {
  width: 100%;
}

.auth-switch {
  margin-top: 1rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.friends-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(380px, 100%);
  height: 100%;
  z-index: 40;
  background: rgba(247, 250, 252, 0.96);
  border-left: 1px solid var(--line);
  padding: 1rem;
  overflow: auto;
  box-shadow: -12px 0 30px rgba(20, 33, 43, 0.12);
}

.friends-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.friends-head h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
}

.friend-add {
  display: grid;
  gap: 0.6rem;
  margin: 1rem 0 1.25rem;
}

.friends-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.friends-list {
  list-style: none;
  margin: 0 0 1.2rem;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.friends-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
}

.friends-list .meta {
  display: grid;
  gap: 0.1rem;
}

.friends-list .meta strong {
  font-size: 0.95rem;
}

.friends-list .meta span {
  font-size: 0.8rem;
  color: var(--muted);
}

.friends-actions {
  display: flex;
  gap: 0.35rem;
}

.friends-actions .btn {
  padding: 0.4rem 0.55rem;
  font-size: 0.8rem;
}

.empty-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* FINAL HIDDEN OVERRIDE */
.auth-screen[hidden],
.app[hidden],
.friends-panel[hidden],
[hidden] {
  display: none !important;
}
