:root {
  color-scheme: light;
  --page: #eef1f4;
  --page-2: #e6edf0;
  --ink: #15181d;
  --muted: #68717d;
  --line: #d7dde3;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --teal: #147b72;
  --teal-dark: #0d5f57;
  --teal-soft: #dcefeb;
  --indigo: #33355f;
  --coral: #d86f55;
  --danger: #b4423d;
  --shadow: 0 20px 54px rgba(27, 33, 39, 0.13);
  --shadow-deep: 0 28px 86px rgba(18, 22, 28, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 16% 16%, rgba(20, 123, 114, 0.16), transparent 28%),
    radial-gradient(circle at 82% 10%, rgba(216, 111, 85, 0.14), transparent 24%),
    linear-gradient(180deg, #f8fafb 0%, var(--page) 58%, var(--page-2) 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.app-topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  height: 68px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(20px, calc((100vw - 1180px) / 2));
  background: rgba(248, 250, 251, 0.82);
  border-bottom: 1px solid rgba(215, 221, 227, 0.82);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
  font-weight: 820;
}

.brand:visited {
  color: var(--ink);
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--indigo), var(--teal));
  color: #fff;
  font-size: 12px;
  font-weight: 860;
}

.topbar-status {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(215, 221, 227, 0.9);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.locked-shell,
.setup-shell,
.shell {
  width: min(1180px, calc(100vw - 40px));
  min-height: calc(100vh - 68px);
  margin: 0 auto;
  padding: 32px 0 40px;
}

.locked-shell,
.setup-shell {
  display: grid;
  align-items: center;
}

.locked-panel {
  width: min(560px, 100%);
  margin: 0 auto;
  border: 1px solid rgba(215, 221, 227, 0.9);
  border-radius: 8px;
  padding: clamp(28px, 4vw, 44px);
  display: grid;
  gap: 22px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.locked-copy {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.setup-layout {
  min-height: min(780px, calc(100vh - 140px));
  display: grid;
  grid-template-columns: minmax(360px, 0.72fr) minmax(430px, 0.95fr);
  gap: 28px;
  align-items: stretch;
}

.setup-panel {
  order: 2;
}

.preview-panel {
  order: 1;
}

.setup-panel,
.preview-panel,
.friend-panel,
.voice-workspace {
  border: 1px solid rgba(215, 221, 227, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.setup-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 28px;
  padding: clamp(26px, 4vw, 44px);
}

.section-heading {
  display: grid;
  gap: 8px;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 13px;
  font-weight: 820;
}

h1 {
  margin: 0;
  font-size: clamp(40px, 4.8vw, 68px);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: clamp(28px, 3.3vw, 42px);
  line-height: 1.02;
  letter-spacing: 0;
}

.compact-heading {
  gap: 6px;
}

.setup-form,
.field {
  display: grid;
}

.setup-form {
  align-content: start;
  gap: 16px;
}

.field {
  gap: 8px;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 251, 0.92);
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 50px;
  padding: 0 14px;
}

textarea {
  min-height: 0;
  padding: 15px;
  resize: vertical;
  line-height: 1.5;
}

.feature-input {
  height: 138px;
  max-height: 220px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(20, 123, 114, 0.72);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(20, 123, 114, 0.12);
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-weight: 780;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.primary-button {
  background: var(--teal);
  color: #fff;
}

.primary-button:not(:disabled):hover {
  background: var(--teal-dark);
}

.secondary-button {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.secondary-button:not(:disabled):hover {
  background: #c7e6df;
}

.ghost-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.ghost-button:not(:disabled):hover {
  background: var(--panel-soft);
  color: var(--ink);
}

.wide-button {
  width: 100%;
  margin-top: 4px;
}

.button-icon {
  width: 18px;
  text-align: center;
  line-height: 1;
}

.setup-status {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.setup-status.is-error {
  color: var(--danger);
}

.voice-panel {
  display: grid;
  gap: 10px;
}

.voice-options {
  display: grid;
  gap: 10px;
}

.voice-option {
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: rgba(248, 250, 251, 0.82);
}

.voice-option.is-selected {
  border-color: rgba(20, 123, 114, 0.72);
  box-shadow: 0 0 0 4px rgba(20, 123, 114, 0.11);
}

.voice-select,
.voice-preview {
  min-height: 42px;
  border-radius: 6px;
}

.voice-select {
  padding: 7px 10px;
  display: grid;
  justify-content: start;
  gap: 2px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.voice-select strong {
  font-size: 14px;
  line-height: 1.15;
}

.voice-select span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.voice-preview {
  width: 42px;
  padding: 0;
  border: 1px solid rgba(20, 123, 114, 0.18);
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.preview-panel {
  min-height: 0;
  padding: 20px;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: 16px;
  overflow: hidden;
  background: #171a20;
  color: #fff;
  box-shadow: var(--shadow-deep);
}

.preview-panel .eyebrow {
  color: #91d8ce;
}

.friend-options {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-content: start;
}

.friend-option {
  min-width: 0;
  min-height: 0;
  padding: 0;
  display: grid;
  grid-template-rows: auto auto;
  gap: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-align: left;
}

.friend-option.is-selected {
  border-color: #91d8ce;
  box-shadow: 0 0 0 3px rgba(145, 216, 206, 0.18);
}

.option-photo {
  min-height: 0;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: #242933;
}

.option-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.option-copy {
  min-height: 108px;
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 6px;
}

.option-copy strong {
  font-size: 16px;
  line-height: 1.12;
}

.option-copy small {
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
  line-height: 1.35;
}

.preview-copy {
  min-height: 96px;
  display: grid;
  gap: 7px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.preview-copy strong {
  display: block;
  font-size: 24px;
  line-height: 1.08;
}

.preview-copy span,
.preview-copy p {
  color: rgba(255, 255, 255, 0.72);
}

.preview-copy span {
  display: block;
  font-size: 14px;
}

.preview-copy p {
  min-height: 42px;
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.shell {
  display: grid;
  grid-template-columns: minmax(340px, 0.72fr) minmax(420px, 1fr);
  gap: 28px;
  align-items: start;
}

.friend-panel {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 18px;
  padding: 20px;
}

.portrait-wrap {
  position: relative;
  width: 100%;
  max-width: 500px;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #dfe5ea;
  box-shadow: var(--shadow-deep);
}

.portrait {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 180ms ease, transform 260ms ease;
}

.portrait-wrap[data-friend-state="thinking"] .portrait,
.portrait-wrap[data-friend-state="away"] .portrait {
  transform: scale(1.015);
}

.portrait-wrap[data-friend-state="happy"] .portrait {
  transform: scale(1.01);
}

.portrait-wrap[data-friend-state="concerned"] .portrait {
  filter: saturate(0.96);
}

.voice-ring {
  position: absolute;
  inset: 14px;
  border: 2px solid rgba(20, 123, 114, 0);
  border-radius: 8px;
  pointer-events: none;
}

.portrait-wrap.is-speaking .voice-ring {
  animation: voicePulse 1.25s ease-in-out infinite;
}

.profile-card {
  width: min(460px, 100%);
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
}

.profile-card strong {
  font-size: 26px;
  line-height: 1.1;
}

.profile-card span,
.profile-card p,
.status-row,
.counter {
  color: var(--muted);
  font-size: 14px;
}

.profile-card p {
  margin: 6px 0 0;
  line-height: 1.45;
}

.status-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 5px rgba(20, 123, 114, 0.14);
}

.status-dot.is-error {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(180, 66, 61, 0.14);
}

.voice-workspace,
.chat-workspace {
  display: grid;
  gap: 14px;
  padding: clamp(24px, 3.8vw, 42px);
}

.chat-workspace {
  grid-template-rows: minmax(280px, 1fr) auto;
  height: min(680px, calc(100vh - 132px));
  min-height: 520px;
  align-self: start;
}

.composer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

#textInput {
  min-height: 66px;
  max-height: 190px;
  background: rgba(248, 250, 251, 0.94);
}

.chat-log {
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 4px 8px 18px 4px;
  overscroll-behavior: contain;
}

.message {
  display: flex;
}

.message.is-user {
  justify-content: flex-end;
}

.message.is-friend {
  justify-content: flex-start;
}

.message-bubble {
  max-width: min(560px, 84%);
  border: 1px solid rgba(215, 221, 227, 0.86);
  border-radius: 8px;
  padding: 13px 14px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(27, 33, 39, 0.08);
}

.message.is-user .message-bubble {
  background: var(--teal);
  color: #fff;
  border-color: transparent;
}

.message-bubble p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.48;
}

.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.message-files span,
.attachment-chip {
  min-height: 30px;
  border: 1px solid rgba(215, 221, 227, 0.86);
  border-radius: 8px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  background: rgba(248, 250, 251, 0.9);
  color: var(--muted);
  font-size: 13px;
}

.message.is-user .message-files span {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.86);
}

.chat-composer {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 42px rgba(27, 33, 39, 0.12);
}

.chat-composer textarea {
  border: 0;
  padding: 8px;
  background: transparent;
  box-shadow: none;
}

.chat-composer textarea:focus {
  box-shadow: none;
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-chip {
  cursor: pointer;
}

.composer-actions,
.left-actions,
.right-actions,
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.composer-actions {
  justify-content: space-between;
}

.icon-button {
  width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
}

.icon-button.is-active {
  background: var(--coral);
  color: #fff;
  border-color: transparent;
}

.dev-only[hidden] {
  display: none !important;
}

@keyframes voicePulse {
  0% {
    border-color: rgba(20, 123, 114, 0.16);
    box-shadow: inset 0 0 0 0 rgba(20, 123, 114, 0.1);
  }

  50% {
    border-color: rgba(20, 123, 114, 0.68);
    box-shadow: inset 0 0 0 7px rgba(20, 123, 114, 0.15);
  }

  100% {
    border-color: rgba(20, 123, 114, 0.16);
    box-shadow: inset 0 0 0 0 rgba(20, 123, 114, 0.1);
  }
}

@media (max-width: 940px) {
  .setup-layout,
  .shell {
    grid-template-columns: 1fr;
  }

  .chat-workspace {
    height: min(620px, calc(100vh - 116px));
    min-height: 480px;
  }

  .setup-panel {
    order: 1;
  }

  .preview-panel {
    order: 2;
  }

  .friend-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .option-copy {
    min-height: 92px;
  }
}

@media (max-width: 560px) {
  .app-topbar {
    height: 62px;
    padding: 0 14px;
  }

  .topbar-status {
    display: none;
  }

  .locked-shell,
  .setup-shell,
  .shell {
    width: min(100vw - 24px, 1180px);
    min-height: calc(100vh - 62px);
    padding: 20px 0 28px;
  }

  .setup-panel,
  .friend-panel,
  .voice-workspace {
    padding: 18px;
  }

  .form-grid,
  .preview-panel {
    grid-template-columns: 1fr;
  }

  .friend-options {
    grid-template-columns: 1fr;
  }

  .friend-option {
    grid-template-columns: 112px minmax(0, 1fr);
    grid-template-rows: auto;
  }

  .option-photo {
    aspect-ratio: 1;
  }

  .option-copy {
    min-height: 112px;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  #textInput {
    min-height: 92px;
  }

  .chat-workspace {
    height: min(600px, calc(100vh - 94px));
    min-height: 430px;
    padding: 18px;
  }

  .message-bubble {
    max-width: 92%;
  }

  .composer-actions,
  .left-actions,
  .right-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
