:root {
  --canvas: #111416;
  --surface: #191e21;
  --surface-raised: #22292d;
  --surface-soft: #2c3337;
  --line: #3b4549;
  --ink: #f2f4f3;
  --muted: #a9b3b3;
  --coral: #ff9878;
  --cyan: #69d5c1;
  --yellow: #e5c75f;
  --danger: #e97979;
  color-scheme: dark;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
}

.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 {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr) 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--line);
  background: #15191b;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--coral);
  color: #25130e;
  font-size: 12px;
  font-weight: 900;
}

.brand-copy {
  display: grid;
  gap: 1px;
}

.brand-copy strong {
  font-size: 16px;
}

.brand-copy small {
  color: var(--muted);
  font-size: 11px;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.connection-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--yellow);
}

.connection-dot.online {
  background: var(--cyan);
}

.connection-dot.offline {
  background: var(--danger);
}

.interaction {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 0.82fr) minmax(520px, 1.55fr);
}

.presence {
  min-width: 0;
  padding: clamp(28px, 5vw, 72px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--line);
  background: #151a1c;
}

.presence-visual {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0d1012;
}

.avatar-frame {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-placeholder {
  width: min(58%, 260px);
  height: 118px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
}

.signal {
  width: 15px;
  height: 34px;
  background: var(--coral);
  transform-origin: center;
  animation: idle-signal 1.8s ease-in-out infinite;
}

.signal-two {
  height: 68px;
  background: var(--yellow);
  animation-delay: 0.16s;
}

.signal-three {
  height: 102px;
  background: var(--cyan);
  animation-delay: 0.32s;
}

.signal-four {
  height: 62px;
  background: var(--yellow);
  animation-delay: 0.48s;
}

.signal-five {
  height: 38px;
  animation-delay: 0.64s;
}

.presence-visual.thinking .signal,
.presence-visual[data-emotion="thinking"] .signal {
  animation-duration: 0.75s;
}

.presence-visual[data-emotion="happy"] .signal,
.presence-visual[data-emotion="teasing"] .signal {
  animation-duration: 1.05s;
}

.presence-state {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  background: #131719;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.presence-state.online {
  color: var(--cyan);
  border-color: #3d786e;
}

.presence-copy {
  width: min(100%, 520px);
  padding-top: 26px;
}

.kicker,
.chat-label {
  margin: 0;
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin: 8px 0 12px;
  font-size: clamp(42px, 6vw, 76px);
  line-height: 1;
  letter-spacing: 0;
}

.presence-copy > p:last-child {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.chat {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  background: var(--surface);
}

.chat-head {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 3vw, 30px);
  border-bottom: 1px solid var(--line);
}

.session-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.quiet-button,
.tool-button,
.quick-prompts button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-raised);
  color: var(--ink);
  padding: 0 12px;
}

.quiet-button:hover:not(:disabled),
.tool-button:hover:not(:disabled),
.quick-prompts button:hover:not(:disabled) {
  border-color: var(--cyan);
}

.tool-button.active {
  border-color: var(--cyan);
  color: var(--cyan);
}

.offline-notice {
  margin: 14px clamp(16px, 3vw, 30px) 0;
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  background: #302123;
  color: #f4c6c6;
  font-size: 13px;
  line-height: 1.55;
}

.offline-notice[hidden] {
  display: none;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 22px clamp(16px, 3vw, 30px);
  scrollbar-color: var(--line) transparent;
}

.message {
  width: fit-content;
  max-width: min(720px, 88%);
}

.message.you {
  align-self: flex-end;
}

.message-body {
  border-left: 3px solid var(--coral);
  background: var(--surface-raised);
  padding: 11px 13px;
}

.message.you .message-body {
  border-left: 0;
  border-right: 3px solid var(--yellow);
  background: var(--surface-soft);
}

.message.system .message-body {
  border-color: var(--line);
  color: var(--muted);
}

.message-name {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
}

.typing .message-body {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 72px;
  min-height: 44px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.14s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.28s;
}

.quick-prompts {
  display: flex;
  align-items: center;
  align-content: center;
  flex-wrap: nowrap;
  gap: 8px;
  height: 50px;
  overflow-x: auto;
  padding: 0 clamp(16px, 3vw, 30px) 14px;
}

.quick-prompts[hidden] {
  display: none;
}

.quick-prompts button {
  flex: 0 0 auto;
  height: 34px;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.composer {
  padding: 14px clamp(16px, 3vw, 30px) 18px;
  border-top: 1px solid var(--line);
  background: #171c1f;
}

.camera-row {
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  margin-bottom: 12px;
}

.camera-row:not([hidden]) {
  display: grid;
}

.camera-row video {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #080a0b;
}

.camera-row p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.input-wrap {
  display: block;
}

textarea {
  width: 100%;
  min-height: 74px;
  max-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: var(--surface-raised);
  color: var(--ink);
  padding: 12px;
  line-height: 1.55;
}

textarea:focus {
  border-color: var(--cyan);
}

textarea:disabled {
  color: var(--muted);
}

.compose-actions {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.input-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.send-button {
  min-height: 42px;
  border: 1px solid var(--coral);
  border-radius: 5px;
  background: var(--coral);
  color: #28140e;
  padding: 0 18px;
  font-weight: 900;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(18px, 4vw, 56px);
  border-top: 1px solid var(--line);
  background: #15191b;
  color: var(--muted);
  font-size: 11px;
}

footer a {
  color: var(--cyan);
  text-decoration: none;
}

dialog {
  width: min(430px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 22px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

dialog h2 {
  margin: 0;
  font-size: 22px;
}

dialog p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 22px;
}

@keyframes idle-signal {
  0%,
  100% {
    transform: scaleY(0.55);
    opacity: 0.62;
  }
  50% {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes typing {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  50% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    min-height: 100dvh;
    grid-template-rows: 62px auto 38px;
  }

  .interaction {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(620px, calc(100dvh - 250px));
  }

  .presence {
    min-height: 150px;
    display: grid;
    grid-template-columns: 128px minmax(0, 1fr);
    align-items: center;
    gap: 20px;
    padding: 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .presence-visual {
    width: 128px;
    aspect-ratio: 1;
  }

  .avatar-placeholder {
    width: 82px;
    height: 66px;
    gap: 6px;
  }

  .signal {
    width: 8px;
  }

  .signal-two,
  .signal-four {
    height: 45px;
  }

  .signal-three {
    height: 62px;
  }

  .presence-state {
    top: 7px;
    left: 7px;
    padding: 3px 5px;
    font-size: 9px;
  }

  .presence-copy {
    padding: 0;
  }

  h1 {
    margin: 5px 0 7px;
    font-size: 38px;
  }

  .presence-copy > p:last-child {
    font-size: 13px;
    line-height: 1.5;
  }

  .chat {
    min-height: 620px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 0 14px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .connection {
    max-width: 145px;
    justify-content: flex-end;
    text-align: right;
    font-size: 11px;
  }

  .presence {
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 14px;
    min-height: 128px;
    padding: 14px;
  }

  .presence-visual {
    width: 92px;
  }

  .avatar-placeholder {
    width: 60px;
    height: 48px;
    gap: 4px;
  }

  .signal {
    width: 6px;
    height: 22px;
  }

  .signal-two,
  .signal-four {
    height: 34px;
  }

  .signal-three {
    height: 46px;
  }

  .kicker {
    font-size: 10px;
  }

  h1 {
    font-size: 32px;
  }

  .presence-copy > p:last-child {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .chat-head {
    min-height: 64px;
  }

  .messages {
    padding-top: 16px;
  }

  .message {
    max-width: 94%;
  }

  .compose-actions {
    align-items: flex-end;
  }

  .input-tools {
    gap: 5px;
  }

  .tool-button {
    min-height: 34px;
    padding: 0 8px;
    font-size: 12px;
  }

  .camera-row:not([hidden]) {
    grid-template-columns: 1fr;
  }

  footer {
    padding: 0 14px;
  }

  footer span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

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