@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --bg: #f8edf4;
  --bg-top: #fff4f9;
  --bg-accent: #f2cddd;
  --ink: #1b1b22;
  --muted: #6e6b74;
  --accent: #ff7aa6;
  --accent-dark: #d14579;
  --line: rgba(224, 224, 224, 1);
  --call: #35cf74;
  --hangup: #dd2f58;
  --confirm: #f35f86;
  --message-disabled: #d1c8ce;
  --message-active: #f3d5e3;
  --app-height: 100dvh;
  --app-offset-top: 0px;
  --center-shift-connected: clamp(112px, 22vh, 220px);
  --action-size: clamp(66px, 9.6vh, 78px);
  --action-radius: clamp(18px, 2.8vh, 22px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, #ffe6f1 0%, transparent 42%),
    radial-gradient(circle at 88% 18%, #f6d7e7 0%, transparent 46%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 55%, #efe6ee 100%);
}

.page {
  display: flex;
  justify-content: center;
}

.page--splash {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.phonebook {
  width: min(540px, 94vw);
  margin: 24px auto 30px;
  flex: 1;
}

.phonebook__header {
  padding: 8px 10px 14px;
  background: rgba(255, 255, 255, 0.48);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(18px);
  display: grid;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.phonebook__title {
  margin: 0;
  font-size: 1.8rem;
  padding-left: 10px;
}

.phonebook__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  position: relative;
}

.phonebook__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.phonebook__brand-icon-shell {
  display: block;
  width: 76px;
  height: 54px;
  overflow: hidden;
  flex: 0 0 auto;
}

.phonebook__brand-icon {
  display: block;
  height: 100%;
  width: auto;
}

.phonebook__brand-wordmark {
  font-size: 2.15rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: linear-gradient(135deg, #f4a1cb 0%, #df81b4 42%, #b6a8ee 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.phonebook__search {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
}

.phonebook__search:focus {
  outline: 2px solid rgba(255, 122, 166, 0.4);
  outline-offset: 2px;
}

.debug-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  padding-left: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  user-select: none;
}

.debug-toggle input {
  accent-color: var(--accent);
}

.phonebook__list {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.phonebook__loading {
  color: var(--muted);
  padding: 16px 8px;
}

.phonebook__letter {
  display: inline-flex;
  position: relative;
  top: 5px;
  left: 16px;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--accent);
  font-size: 1.2rem;
  font-weight: 600;
  color: #fff;
}

.phonebook__items {
  display: grid;
  margin-top: 7px;
}

.phonebook__item {
  display: grid;
  gap: 2px;
  padding: 11px 8px 11px 24px;
  text-decoration: none;
  color: var(--ink);
  position: relative;
  transition: background 0.15s ease;
}

.phonebook__item:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 24px;
  right: 8px;
  bottom: 0;
  height: 2px;
  background: var(--line);
}

.phonebook__item:hover {
  background: rgba(255, 122, 166, 0.08);
}

.phonebook__name {
  font-size: 1.05rem;
  font-weight: 600;
}

.phonebook__address {
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(27, 27, 34, 0.5);
  line-height: 1.35;
}

.page--client {
  min-height: 100svh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  overscroll-behavior: none;
}

.call-screen {
  width: min(560px, 94vw);
  min-height: var(--app-height, 100dvh);
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
  padding: calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  gap: clamp(10px, 2vh, 20px);
  position: fixed;
  top: var(--app-offset-top, 0px);
  left: 0;
  right: 0;
  margin: 0 auto;
  overflow: hidden;
}

.call-screen__header {
  position: relative;
  z-index: 70;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.call-screen__back,
.call-screen__debug-link {
  text-decoration: none;
  color: var(--accent-dark);
  font-weight: 600;
  font-size: 17px;
}

.call-screen__debug-link {
  display: none;
}

.call-screen__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.call-screen__chat-client {
  display: none;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  max-width: min(76vw, 420px);
}

.call-screen__chat-client-name {
  margin: 0;
  font-size: clamp(1rem, 2.6vw, 1.12rem);
  font-weight: 600;
  line-height: 1.12;
  color: var(--ink);
}

.call-screen__chat-client-address {
  margin: 0;
  font-size: clamp(0.888rem, 2.28vw, 1.008rem);
  font-weight: 500;
  line-height: 1.28;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.call-screen__back-icon {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
}

.call-screen__center {
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  min-height: 0;
  transform: translateY(0);
  transition: transform 0.38s cubic-bezier(0.2, 0.75, 0.2, 1), padding-top 0.3s ease;
  will-change: transform;
}

.call-screen--connected .call-screen__center {
  place-content: start center;
  padding-top: 0;
  transform: translateY(0);
}

.call-screen--chat-open .call-screen__center {
  display: none;
}

.call-screen--chat-open .call-screen__header {
  justify-content: flex-start;
  align-items: flex-start;
}

.call-screen--chat-open .call-screen__back {
  display: none;
}

.call-screen--chat-open .call-screen__chat-client {
  display: flex;
}

.call-screen--chat-open .call-screen__actions,
.call-screen--chat-open .call-screen__status {
  display: none;
}

.call-screen__name {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 600;
}

.call-screen--connected .call-screen__name {
  font-size: clamp(1.1rem, 3vw, 1.35rem);
}

.call-screen--chat-open .call-screen__name {
  font-size: clamp(1.06rem, 2.8vw, 1.2rem);
  font-weight: 600;
}

.call-screen__address {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.9922rem, 2.6015vw, 1.1132rem);
  font-weight: 500;
  line-height: 1.32;
  max-width: min(420px, 90vw);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.orb-indicator {
  position: fixed;
  left: 50%;
  top: 50%;
  width: clamp(220px, 43vmin, 370px);
  aspect-ratio: 1 / 1;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-50% + 22px)) scale(0.92);
  transition: opacity 0.34s ease, transform 0.45s cubic-bezier(0.16, 0.84, 0.2, 1);
  display: grid;
  place-items: center;
}

.call-screen--connected .orb-indicator {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.orb-indicator__core {
  width: 72%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: none;
  background-image: url("/assets/glossyorb.webp");
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  box-shadow: none;
  transform: scale(0.97);
}

@keyframes orb-breathe {
  0% {
    transform: scale(0.97);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(0.97);
  }
}

.call-screen--connected .orb-indicator__core {
  animation: orb-breathe 7.8s ease-in-out infinite;
}

.call-screen__actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
}

.action-slot {
  position: relative;
  width: var(--action-size);
  height: var(--action-size);
}

.action {
  border: none;
  width: var(--action-size);
  height: var(--action-size);
  border-radius: var(--action-radius);
  display: grid;
  place-items: center;
  gap: 4px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  color: #fff;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}

.action-slot .action {
  position: absolute;
  inset: 0;
}

.action svg {
  width: clamp(24px, 3.2vh, 28px);
  height: clamp(24px, 3.2vh, 28px);
}

.action:active {
  transform: scale(0.97);
}

.action--call {
  background: var(--call);
  box-shadow: 0 16px 30px rgba(53, 207, 116, 0.35);
}

.action--hangup {
  background: var(--hangup);
  box-shadow: 0 16px 30px rgba(221, 47, 88, 0.3);
}

.action--message {
  background: var(--accent-dark);
  color: #fff;
  box-shadow: 0 16px 30px rgba(209, 69, 121, 0.34);
  cursor: pointer;
}

.action--message:disabled {
  background: var(--message-disabled);
  color: rgba(255, 255, 255, 0.9);
  box-shadow: none;
  cursor: not-allowed;
}

.action--call[disabled] {
  opacity: 0.55;
  cursor: default;
}

.action--hidden {
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
}

.call-screen__status {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.modal-open .call-screen {
  filter: blur(8px);
  transform: scale(0.995);
  transition: filter 0.2s ease, transform 0.2s ease;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(20, 14, 19, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: min(420px, 92vw);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 20px 55px rgba(30, 15, 27, 0.28);
  padding: 20px 20px 16px;
  transform: translateY(10px) scale(0.97);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.modal-backdrop.is-visible .modal-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-card__title {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--ink);
}

.modal-card__text {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

.modal-card__actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  border: none;
  border-radius: 12px;
  min-width: 96px;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.modal-btn:active {
  transform: scale(0.98);
}

.modal-btn--ghost {
  background: rgba(241, 232, 238, 0.9);
  color: #4a4550;
}

.modal-btn--danger {
  background: linear-gradient(180deg, var(--confirm) 0%, #dd2f58 100%);
  color: #fff;
  box-shadow: 0 12px 24px rgba(221, 47, 88, 0.32);
}

.chat-panel {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 73px);
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  width: min(560px, calc(100vw - 14px));
  transform: translate(-50%, 14px) scale(0.995);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.66);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 22px 60px rgba(24, 16, 24, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overscroll-behavior: contain;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.chat-panel.is-open {
  transform: translate(-50%, 0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.chat-panel__header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(230, 220, 227, 0.92);
}

.chat-panel__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  min-width: 0;
  pointer-events: none;
}

.chat-panel__brand-icon-shell {
  display: block;
  width: 50px;
  height: 36px;
  overflow: hidden;
  flex: 0 0 auto;
}

.chat-panel__brand-icon {
  display: block;
  height: 100%;
  width: auto;
}

.chat-panel__brand-wordmark {
  font-size: 1.42rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: linear-gradient(135deg, #f4a1cb 0%, #df81b4 42%, #b6a8ee 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  pointer-events: none;
}

.chat-panel__state {
  margin: 0;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8a7884;
  white-space: nowrap;
  pointer-events: none;
}

.chat-panel__state[data-state="connecting"] {
  color: #8d6b34;
}

.chat-panel__state[data-state="connected"] {
  color: #258051;
}

.chat-panel__state[data-state="error"] {
  color: #bf4063;
}

.chat-panel__close {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: rgba(243, 95, 134, 0.16);
  color: var(--accent-dark);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.chat-panel__close svg {
  width: 20px;
  height: 20px;
}

.chat-panel__log {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.chat-entry {
  max-width: 86%;
  height: fit-content;
  align-self: start;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.93rem;
  font-weight: 600;
  line-height: 1.34;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-entry--assistant {
  justify-self: start;
  background: rgba(255, 235, 244, 0.98);
  color: #2d2530;
}

.chat-entry--user {
  justify-self: end;
  background: rgba(243, 95, 134, 0.95);
  color: #fff;
}

.chat-entry--system {
  justify-self: center;
  max-width: 96%;
  background: transparent;
  color: #6c6470;
  font-size: 0.82rem;
  text-align: center;
  padding: 2px 0;
}

.chat-panel__composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(230, 220, 227, 0.92);
}

.chat-panel__input {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid #f1eff3;
  background: #f1eff3;
  padding: 0 12px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.2;
  color: #2f2a31;
}

.chat-panel__input::placeholder {
  color: #5f5963;
  opacity: 1;
}

.chat-panel__input:focus {
  outline: none;
  border-color: #f1eff3;
  box-shadow: 0 0 0 3px rgba(95, 89, 99, 0.18);
}

.chat-panel__send {
  min-width: 78px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--confirm) 0%, #dd2f58 100%);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.chat-panel__input:disabled,
.chat-panel__send:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

#remoteAudio {
  display: none;
}

.debug-ghost {
  position: fixed;
  top: calc(84px + env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  left: auto;
  bottom: auto;
  z-index: 72;
  width: min(380px, 34vw);
  max-width: calc(100vw - 24px);
  display: block;
}

.debug-ghost__hidden-controls {
  display: none;
}

.debug-panel {
  min-width: 0;
}

.debug-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.debug-panel__head h2 {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4b4550;
}

.debug-panel__actions {
  display: inline-flex;
  gap: 6px;
}

.debug-panel__head button {
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  color: #2f2a31;
  background: rgba(241, 236, 243, 0.92);
  cursor: pointer;
}

.debug-panel__head button:hover {
  background: rgba(233, 225, 236, 0.98);
}

.debug-panel__log {
  margin: 8px 0 0;
  border: 1px solid rgba(219, 210, 222, 0.95);
  border-radius: 10px;
  min-height: 260px;
  max-height: 260px;
  overflow-y: auto;
  padding: 10px;
  background: rgba(251, 249, 252, 0.96);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.4;
  color: #2f2a31;
}

.debug-panel #log .entry {
  margin-bottom: 10px;
  line-height: 1.4;
}

.debug-panel #log .role {
  display: inline-block;
  margin-right: 8px;
  font-weight: 700;
}

.debug-panel #log .role-user {
  color: #144e9e;
}

.debug-panel #log .role-assistant {
  color: #0f7b46;
}

.debug-panel #log .role-system {
  color: #875d08;
}

@media (max-width: 640px) {
  .phonebook {
    width: min(94vw, 520px);
  }

  .phonebook__title {
    font-size: 1.5rem;
  }

  .phonebook__title-row {
    min-height: 47px;
  }

  .phonebook__brand {
    gap: 10px;
  }

  .phonebook__brand-icon-shell {
    width: 62px;
    height: 45px;
  }

  .phonebook__brand-wordmark {
    font-size: 1.76rem;
    letter-spacing: 0.1em;
  }

  .call-screen {
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    gap: 10px;
  }

  .call-screen__name {
    font-size: clamp(1.4rem, 7vw, 2rem);
  }

  .call-screen__address {
    font-size: 1.1132rem;
  }

  .call-screen--chat-open .call-screen__chat-client-name {
    font-size: clamp(1.15rem, 2.99vw, 1.288rem);
  }

  .call-screen--chat-open .call-screen__chat-client-address {
    font-size: clamp(1.021rem, 2.622vw, 1.159rem);
  }

  .chat-panel {
    width: 100vw;
    max-width: 100vw;
    top: calc(var(--app-offset-top, 0px) + env(safe-area-inset-top) + 69px);
    bottom: auto;
    height: calc(var(--app-height, 100dvh) - (env(safe-area-inset-top) + 69px));
    max-height: calc(var(--app-height, 100dvh) - (env(safe-area-inset-top) + 69px));
    border-radius: 0;
  }

  .chat-panel__brand {
    gap: 9px;
  }

  .chat-panel__brand-icon-shell {
    width: 44px;
    height: 31px;
  }

  .chat-panel__brand-wordmark {
    font-size: 1.24rem;
    letter-spacing: 0.09em;
  }

  .debug-ghost {
    display: none;
  }
}

@media (max-height: 760px) {
  .call-screen {
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  .call-screen__header {
    font-size: 0.88rem;
  }

  .call-screen__status {
    font-size: 0.78rem;
  }
}
