:root {
  --ink: #101413;
  --ink-2: #171d1b;
  --panel: rgba(22, 29, 27, 0.86);
  --line: rgba(220, 211, 190, 0.16);
  --paper: #f5efe2;
  --muted: #a99f8c;
  --bronze: #73b79c;
  --bronze-2: #2e6f61;
  --cinnabar: #c94c32;
  --gold: #d3ad6c;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.36);
  --radius: 8px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(115, 183, 156, 0.12), transparent 28rem),
    linear-gradient(140deg, #0f1514 0%, #171411 52%, #0d1110 100%);
  color: var(--paper);
  min-height: 100dvh;
  overflow-x: hidden;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar > div:first-child {
  min-width: 0;
  margin-right: auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: clamp(28px, 4vw, 46px);
  font-weight: 760;
  line-height: 1;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(245, 239, 226, 0.06);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(245, 239, 226, 0.06);
}

.status.connecting,
.status.listening {
  color: var(--gold);
}

.status.listening .status-dot {
  animation: breathe 1.2s ease-in-out infinite;
}

.status.responding {
  color: var(--bronze);
}

.status.error,
.status.closed {
  color: #ff8a72;
}

@keyframes breathe {
  50% {
    transform: scale(1.3);
    opacity: 0.52;
  }
}

.call-stage {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(380px, 0.92fr) minmax(420px, 1.08fr);
  gap: 16px;
}

.video-panel,
.conversation-panel {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.video-panel {
  min-height: 560px;
  isolation: isolate;
}

.video-panel video {
  width: 100%;
  height: 100%;
  min-height: 560px;
  object-fit: cover;
  display: block;
  background: #050606;
}

.hidden {
  display: none;
}

.video-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.34), transparent 30%),
    linear-gradient(0deg, rgba(0, 0, 0, 0.58), transparent 42%);
  pointer-events: none;
  z-index: 1;
}

.video-meta {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: rgba(245, 239, 226, 0.82);
  font-size: 12px;
}

.video-meta span {
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid rgba(245, 239, 226, 0.18);
  border-radius: 999px;
  background: rgba(16, 20, 19, 0.54);
  backdrop-filter: blur(12px);
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(245, 239, 226, 0.18);
  border-radius: 50%;
  background: rgba(16, 20, 19, 0.58);
  color: var(--paper);
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: transform 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
}

.icon-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(245, 239, 226, 0.38);
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.camera-switch {
  position: absolute;
  right: 16px;
  top: 16px;
  z-index: 3;
}

.settings-trigger span,
.settings-head .icon-btn span {
  font-size: 20px;
  line-height: 1;
}

.camera-switch span {
  font-size: 24px;
  line-height: 1;
}

.conversation-panel {
  min-height: 560px;
}

.conversation-panel::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: linear-gradient(180deg, var(--cinnabar), var(--gold), var(--bronze-2));
  opacity: 0.95;
}

.dialogue {
  height: 100%;
  max-height: calc(100dvh - 156px);
  overflow-y: auto;
  padding: 22px 22px 22px 28px;
  scrollbar-color: rgba(211, 173, 108, 0.5) transparent;
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
}

.seal {
  width: 54px;
  height: 54px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid rgba(115, 183, 156, 0.58);
  color: var(--bronze);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 18px;
  font-weight: 800;
}

.empty-state p {
  margin: 0;
  font-size: 14px;
}

.turn {
  display: flex;
  flex-direction: column;
  margin: 0 0 14px;
}

.turn.user {
  align-items: flex-end;
}

.turn.ai,
.turn.system {
  align-items: flex-start;
}

.msg {
  max-width: min(82%, 560px);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  line-height: 1.62;
  font-size: 15px;
  word-break: break-word;
}

.msg.user {
  background: linear-gradient(135deg, rgba(115, 183, 156, 0.2), rgba(46, 111, 97, 0.28));
  color: #f8fff9;
  border-color: rgba(115, 183, 156, 0.42);
}

.msg.ai {
  background: rgba(245, 239, 226, 0.08);
  color: var(--paper);
}

.msg.system {
  background: rgba(201, 76, 50, 0.12);
  color: #ffd7c8;
  border-color: rgba(201, 76, 50, 0.28);
  font-size: 13px;
}

.msg.current::after {
  content: " ▌";
  color: var(--gold);
  animation: cursor-blink 0.8s infinite;
}

@keyframes cursor-blink {
  50% {
    opacity: 0;
  }
}

.references {
  width: min(82%, 560px);
  margin-top: 7px;
  display: grid;
  gap: 7px;
}

.reference-card {
  border: 1px solid rgba(211, 173, 108, 0.24);
  border-radius: var(--radius);
  background: rgba(10, 13, 12, 0.42);
  overflow: hidden;
}

.reference-card summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  color: var(--paper);
  cursor: pointer;
  font-size: 13px;
}

.reference-card summary::-webkit-details-marker {
  display: none;
}

.reference-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.reference-title strong {
  font-weight: 650;
}

.reference-count {
  color: var(--gold);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  white-space: nowrap;
}

.reference-body {
  padding: 0 12px 12px;
  display: grid;
  gap: 8px;
}

.reference-item {
  padding: 10px;
  border-left: 2px solid rgba(211, 173, 108, 0.58);
  background: rgba(245, 239, 226, 0.05);
}

.reference-item h4 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 650;
  color: var(--paper);
}

.reference-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.reference-meta span {
  padding: 2px 6px;
  border: 1px solid rgba(245, 239, 226, 0.12);
  border-radius: 999px;
}

.reference-text {
  margin: 0;
  color: rgba(245, 239, 226, 0.86);
  font-size: 13px;
  line-height: 1.55;
}

.control-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding-bottom: env(safe-area-inset-bottom);
}

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 20px;
  background: rgba(5, 7, 7, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.settings-panel.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-card {
  width: min(520px, 100%);
  border: 1px solid rgba(245, 239, 226, 0.16);
  border-radius: var(--radius);
  background: rgba(17, 22, 21, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  padding: 18px;
  transform: translateY(12px);
  transition: transform 0.18s ease;
}

.settings-panel.open .settings-card {
  transform: translateY(0);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.settings-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 14px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.setting-row strong,
.setting-row small {
  display: block;
}

.setting-row strong {
  color: var(--paper);
  font-size: 14px;
}

.setting-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.setting-row output {
  min-width: 58px;
  justify-self: end;
  color: var(--gold);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  text-align: right;
}

.setting-row input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--bronze);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.ghost-btn {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(245, 239, 226, 0.18);
  border-radius: 999px;
  background: rgba(245, 239, 226, 0.05);
  color: var(--paper);
  cursor: pointer;
}

.ghost-btn:hover {
  border-color: rgba(245, 239, 226, 0.36);
}

.call-btn {
  min-width: 148px;
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.call-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.call-btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.call-btn.start {
  background: linear-gradient(135deg, var(--bronze-2), var(--bronze));
  box-shadow: 0 18px 44px rgba(46, 111, 97, 0.28);
}

.call-btn.end {
  background: linear-gradient(135deg, #9d3325, var(--cinnabar));
  box-shadow: 0 18px 44px rgba(201, 76, 50, 0.22);
}

.btn-icon {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  line-height: 1;
}

@media (max-width: 820px) {
  .app-shell {
    padding: max(12px, env(safe-area-inset-top)) 12px 12px;
    gap: 10px;
  }

  .topbar {
    align-items: flex-start;
    gap: 10px;
  }

  h1 {
    font-size: 30px;
  }

  .call-stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 42dvh) minmax(0, 1fr);
  }

  .video-panel,
  .conversation-panel {
    min-height: 0;
  }

  .video-panel video {
    min-height: 0;
    height: 100%;
  }

  .conversation-panel {
    height: calc(58dvh - 118px);
  }

  .dialogue {
    max-height: none;
    padding: 18px 16px 18px 22px;
  }

  .msg,
  .references {
    max-width: 92%;
  }

  .control-bar {
    position: sticky;
    bottom: 0;
    padding-top: 4px;
    background: linear-gradient(180deg, transparent, rgba(15, 21, 20, 0.84) 35%);
  }

  .call-btn {
    min-width: 0;
    flex: 1;
  }

  .settings-panel {
    align-items: end;
    padding: 10px;
  }
}

@media (max-width: 430px) {
  .eyebrow {
    display: none;
  }

  .status {
    min-height: 30px;
    padding: 0 10px;
    font-size: 12px;
  }

  .settings-trigger {
    width: 40px;
    height: 40px;
  }

  .call-stage {
    grid-template-rows: minmax(245px, 38dvh) minmax(0, 1fr);
  }

  .conversation-panel {
    height: calc(62dvh - 108px);
  }

  .video-meta {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .camera-switch {
    top: 12px;
    right: 12px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
