:root {
  color-scheme: dark;
  --ground: #111925;
  --ground-soft: #182433;
  --surface: rgba(23, 33, 45, 0.9);
  --surface-strong: #1b2938;
  --line: rgba(198, 218, 235, 0.16);
  --line-bright: rgba(198, 218, 235, 0.3);
  --ink: #f3f5f7;
  --ink-soft: #b8c1ca;
  --ink-faint: #7f8b97;
  --silver: #c7d6e2;
  --amber: #e6b86f;
  --amber-soft: #8e6d3f;
  --mint: #72d5ba;
  --coral: #ef8278;
  --nav-height: 72px;
  --composer-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei UI", sans-serif;
  --label: "Bahnschrift", "DIN Alternate", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
}

body {
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 52% 28%, rgba(137, 167, 190, 0.23), transparent 36%),
    radial-gradient(circle at 22% 74%, rgba(94, 131, 118, 0.16), transparent 32%),
    linear-gradient(180deg, #172333 0%, #111925 54%, #101823 100%);
}

#avatar-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
  pointer-events: none;
}

.stage-atmosphere {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(8, 14, 22, 0.06) 0%, transparent 24%, transparent 54%, rgba(8, 14, 22, 0.72) 90%),
    linear-gradient(90deg, rgba(7, 12, 18, 0.22) 0%, transparent 20%, transparent 80%, rgba(7, 12, 18, 0.24) 100%);
}

.topbar {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 18px;
  right: 18px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.identity-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  background: rgba(8, 12, 18, 0.62);
}

.identity-mark svg {
  width: 18px;
  color: var(--amber);
}

.identity b,
.identity small {
  display: block;
}

.identity b {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.08em;
}

.identity small {
  margin-top: 2px;
  color: var(--ink-faint);
  font: 500 11px/1.2 var(--label);
  letter-spacing: 0.13em;
}

.presence {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 86px;
  justify-content: flex-end;
  color: var(--ink-soft);
  font: 500 11px/1 var(--label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.presence i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(230, 184, 111, 0.09);
}

.presence.is-live i {
  background: var(--mint);
  box-shadow: 0 0 0 4px rgba(114, 213, 186, 0.1);
}

.tts-mode-select {
  width: 92px;
  min-height: 32px;
  padding: 0 8px;
  color: var(--ink);
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  background: rgba(8, 12, 18, 0.72);
  font: 500 10px/1 var(--label);

.remote-install {
  position: absolute;
  top: calc(60px + env(safe-area-inset-top, 0px));
  right: 18px;
  z-index: 11;
  display: none;
  height: 32px;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid rgba(230, 184, 111, 0.4);
  border-radius: 4px;
  background: rgba(8, 12, 18, 0.86);
  color: var(--amber);
  font-size: 11px;
  text-decoration: none;
}

.remote-install svg {
  width: 15px;
  height: 15px;
}

html.needs-api-config:not(.is-native-app) .remote-install {
  display: inline-flex;
}

.companion-stage {
  position: absolute;
  inset: 82px 0 calc(var(--nav-height) + var(--composer-height) + var(--safe-bottom) + 34px);
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 22px 18px;
  pointer-events: none;
}

.mood-line {
  position: absolute;
  top: 10px;
  left: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--silver);
  font: 500 11px/1 var(--label);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mood-rule {
  width: 26px;
  height: 1px;
  background: var(--line-bright);
}

.scene-switch {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 5px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  pointer-events: auto;
}

.scene-switch svg {
  width: 14px;
  height: 14px;
  color: var(--amber);
}

.companion-copy {
  max-width: 310px;
  margin-bottom: 18px;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.58);
}

.speaker {
  margin: 0 0 8px;
  color: var(--amber);
  font: 600 11px/1 var(--label);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.companion-copy h1 {
  max-width: 11em;
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  font-weight: 550;
  line-height: 1.46;
  letter-spacing: 0;
  text-wrap: balance;
}

.voice-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  pointer-events: auto;
}

.voice-trigger {
  display: inline-flex;
  flex: 1;
  height: 46px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
  border: 1px solid rgba(230, 184, 111, 0.45);
  border-radius: 4px;
  background: rgba(11, 16, 23, 0.74);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.voice-trigger svg {
  color: var(--amber);
}

.voice-trigger:hover {
  border-color: var(--amber);
  background: rgba(20, 28, 38, 0.9);
}

.voice-trigger:active,
.voice-trigger.is-recording {
  transform: translateY(1px);
  border-color: var(--coral);
}

.voice-trigger.is-recording svg {
  color: var(--coral);
}

.round-control,
.icon-button,
.send-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(11, 16, 23, 0.74);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.round-control {
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
}

.round-control:hover,
.icon-button:hover {
  border-color: var(--line-bright);
  background: rgba(22, 31, 42, 0.92);
}

.conversation-sheet .messages {
  display: flex;
  flex-direction: column;
}

.conversation-sheet .message {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.conversation-sheet .message:last-child {
  border-bottom: 1px solid var(--line);
}

.message span {
  color: var(--amber);
  font: 500 11px/1.65 var(--label);
  letter-spacing: 0.06em;
}

.message p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.message--user span {
  color: var(--mint);
}

.message.is-pending p::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 1px;
  margin-left: 6px;
  vertical-align: middle;
  background: var(--amber);
  animation: pulse 900ms ease-in-out infinite alternate;
}

.composer {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
  z-index: 11;
  display: flex;
  height: var(--composer-height);
  align-items: flex-end;
  gap: 8px;
  padding: 9px 9px 9px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.composer textarea {
  flex: 1;
  max-height: 46px;
  min-height: 36px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  padding: 7px 0 0;
}

.composer textarea::placeholder {
  color: var(--ink-faint);
}

.send-button {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-color: rgba(230, 184, 111, 0.42);
  background: var(--amber);
  color: #17120b;
}

.send-button:hover {
  background: #efc984;
}

.send-button:disabled {
  cursor: default;
  opacity: 0.42;
}

.dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding: 6px 16px var(--safe-bottom);
  border-top: 1px solid var(--line);
  background: rgba(7, 10, 15, 0.96);
}

.dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  font-size: 11px;
  cursor: pointer;
}

.dock-item svg {
  width: 19px;
  height: 19px;
}

.dock-item.is-active {
  color: var(--amber);
}

.dock-item:hover {
  color: var(--ink);
}

.page-sheet {
  position: absolute;
  inset: 0 0 calc(var(--nav-height) + var(--safe-bottom)) 0;
  z-index: 20;
  padding: calc(24px + env(safe-area-inset-top, 0px)) 18px 24px;
  background: #080b10;
  overflow-y: auto;
}

.page-sheet:not([hidden]) {
  animation: sheet-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  max-width: 560px;
  margin: 0 auto 24px;
}

.sheet-head p {
  margin: 0 0 7px;
  color: var(--amber);
  font: 600 11px/1 var(--label);
  letter-spacing: 0.16em;
}

.sheet-head h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 560;
  line-height: 1.25;
}

.icon-button {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
}

.sheet-body {
  max-width: 560px;
  margin: 0 auto;
}

.mobile-ops {
  max-width: 560px;
  margin: 0 auto 22px;
  padding: 16px 0 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.native-only {
  display: none;
}

html.is-native-app .native-only {
  display: block;
}

html.needs-api-config .native-only {
  display: block;
}

html.is-native-app .web-only {
  display: none;
}

.apk-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 40px;
  margin-top: 10px;
  border: 1px solid rgba(114, 213, 186, 0.34);
  border-radius: 4px;
  color: var(--mint);
  font-size: 12px;
  text-decoration: none;
}

.ops-field {
  margin: 0 0 14px;
}

.ops-field span {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-faint);
  font-size: 11px;
}

.ops-field input {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  background: var(--surface-strong);
  color: var(--ink);
  font: 12px/1.4 var(--label);
}

html.is-native-app .ops-actions,
html.needs-api-config .ops-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ops-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-faint);
  font: 500 11px/1 var(--label);
  letter-spacing: 0.12em;
}

.ops-head strong {
  color: var(--mint);
  font-weight: 600;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
  margin: 18px 0;
}

.ops-grid dt {
  margin-bottom: 4px;
  color: var(--ink-faint);
  font-size: 11px;
}

.ops-grid dd {
  margin: 0;
  color: var(--ink);
  font: 500 13px/1.4 var(--label);
  overflow-wrap: anywhere;
}

.ops-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ops-actions button {
  min-height: 40px;
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 12px;
}

.ops-actions button:first-child {
  border-color: rgba(230, 184, 111, 0.42);
  color: var(--amber);
}

.ops-note {
  margin: 13px 0 0;
  color: var(--ink-faint);
  font-size: 11px;
  line-height: 1.55;
}

.empty-state {
  padding: 24px 0;
  color: var(--ink-faint);
  font-size: 13px;
  line-height: 1.7;
}

.memory-entry,
.device-entry {
  display: grid;
  grid-template-columns: 66px 1fr;
  gap: 14px;
  padding: 17px 0;
  border-top: 1px solid var(--line);
}

.memory-entry:last-child,
.device-entry:last-child {
  border-bottom: 1px solid var(--line);
}

.memory-entry time,
.device-entry .device-kind {
  color: var(--ink-faint);
  font: 500 11px/1.5 var(--label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.memory-entry p,
.device-entry p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.7;
}

.device-entry h3 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
}

.device-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  color: var(--ink-faint);
  font-size: 11px;
}

.device-state i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-faint);
}

.device-state.is-online i {
  background: var(--mint);
}

.signal-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0 20px;
  border-top: 1px solid var(--line);
}

.signal-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-faint);
  font-size: 11px;
}

.signal-hero strong {
  font: 500 64px/0.9 var(--label);
  letter-spacing: -0.03em;
}

.signal-hero small {
  margin-left: 8px;
  color: var(--ink-faint);
  font: 500 11px/1 var(--label);
  letter-spacing: 0.1em;
}

.signal-state {
  color: var(--ink-soft);
  font-size: 12px;
}

.signal-state.is-online {
  color: var(--mint);
}

.sparkline-wrap {
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

#heart-chart {
  display: block;
  width: 100%;
  height: 108px;
  overflow: visible;
}

#heart-chart polyline {
  fill: none;
  stroke: var(--coral);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

#heart-caption {
  margin: 8px 0 0;
  color: var(--ink-faint);
  font-size: 11px;
  line-height: 1.5;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  margin: 0;
}

.metric-grid div {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.metric-grid div:nth-child(odd) {
  padding-right: 18px;
  border-right: 1px solid var(--line);
}

.metric-grid div:nth-child(even) {
  padding-left: 18px;
}

.metric-grid dt {
  color: var(--ink-faint);
  font-size: 11px;
}

.metric-grid dd {
  margin: 6px 0 0;
  font: 500 18px/1 var(--label);
}

.call-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
  padding: calc(28px + env(safe-area-inset-top, 0px)) 24px calc(28px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(circle at 50% 28%, rgba(92, 135, 151, 0.3), transparent 34%),
    linear-gradient(180deg, rgba(20, 31, 44, 0.92), rgba(13, 20, 29, 0.98));
  backdrop-filter: blur(18px);
}

.call-overlay[hidden] {
  display: none;
}

.call-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.call-head span,
.call-head time {
  color: var(--ink-faint);
  font: 500 11px/1 var(--label);
  letter-spacing: 0.12em;
}

.call-head h2 {
  margin: 7px 0 0;
  font-size: 26px;
  font-weight: 560;
}

.call-presence {
  align-self: end;
  padding-bottom: 24px;
}

.call-presence i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 5px rgba(114, 213, 186, 0.12);
}

.call-presence strong {
  color: var(--mint);
  font: 600 13px/1.2 var(--label);
  letter-spacing: 0.08em;
}

.call-mode-badge {
  display: inline-block;
  margin-right: 7px;
  padding: 3px 6px;
  border: 1px solid rgba(114, 213, 186, 0.42);
  border-radius: 4px;
  color: var(--mint);
  font: 600 10px/1 var(--label);
  letter-spacing: 0.04em;
}

.call-presence p {
  max-width: 260px;
  margin: 12px 0 0 15px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.65;
}

.call-controls {
  display: grid;
  grid-template-columns: 1fr 1.45fr 1fr;
  gap: 12px;
  align-items: end;
}

.call-controls button {
  display: grid;
  min-height: 58px;
  place-items: center;
  gap: 5px;
  border: 1px solid var(--line-bright);
  border-radius: 8px;
  background: rgba(19, 29, 41, 0.82);
  color: var(--ink-soft);
  font-size: 11px;
  touch-action: none;
}

.call-controls button.is-active {
  border-color: var(--amber);
  color: var(--amber);
}

.call-talk {
  min-height: 82px !important;
  background: linear-gradient(145deg, #e8bd7a, #c99143) !important;
  color: #1b140b !important;
  font-weight: 650 !important;
}

.call-talk.is-recording {
  background: linear-gradient(145deg, #f19c8f, #d9685f) !important;
}

.call-end {
  border-color: rgba(239, 130, 120, 0.5) !important;
  color: #ffc1bb !important;
}

@media (max-width: 380px) {
  .call-controls { grid-template-columns: 1fr 1.25fr 1fr; gap: 8px; }
  .call-controls button span { font-size: 10px; }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--composer-height) + var(--safe-bottom) + 24px);
  z-index: 40;
  max-width: calc(100vw - 48px);
  padding: 10px 14px;
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error {
  border-color: rgba(239, 130, 120, 0.52);
  color: #ffc1bb;
}

.tts-dialog {
  width: calc(100vw - 32px);
  max-width: 410px;
  padding: 0;
  color: var(--ink);
  border: 1px solid var(--line-bright);
  border-radius: 8px;
  background: var(--surface-strong);
}

.tts-dialog::backdrop {
  background: rgba(4, 7, 10, 0.72);
  backdrop-filter: blur(6px);
}

.tts-dialog-body {
  padding: 22px;
}

.tts-dialog-kicker {
  color: var(--amber);
  font: 600 10px/1 var(--label);
  letter-spacing: 0.13em;
}

.tts-dialog h2 {
  margin: 12px 0 8px;
  font-size: 21px;
}

.tts-dialog p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.7;
}

.tts-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  gap: 16px;
  justify-items: center;
  background: var(--ground);
  transition: opacity 320ms ease, visibility 320ms ease;
}

.loading.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-ring {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line-bright);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 820ms linear infinite;
}

.loading p {
  margin: 0;
  color: var(--ink-faint);
  font: 500 11px/1 var(--label);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  from { opacity: 0.25; transform: scaleX(0.55); }
  to { opacity: 1; transform: scaleX(1); }
}

@media (min-width: 720px) {
  .app-shell {
    width: min(100vw, 460px);
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  body {
    background: #05070a;
  }
}

@media (max-height: 700px) {
  .companion-copy {
    margin-bottom: 12px;
  }

  .companion-copy h1 {
    font-size: 21px;
  }

  .conversation-veil {
    display: none;
  }
}

@media (max-height: 560px) {
  .mood-line,
  .companion-copy,
  .voice-actions {
    display: none;
  }
}

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