:root {
  color-scheme: light;
  --ink: #2d2725;
  --muted: #746a64;
  --paper: #f6f0e5;
  --paper-deep: #e9dfcf;
  --red: #7b1f2b;
  --red-dark: #58151e;
  --red-soft: #f2e2e1;
  --gold: #b98b45;
  --jade: #46756b;
  --white: #fffdf9;
  --shadow: 0 20px 50px rgb(72 39 23 / 12%);
  --radius-lg: 28px;
  --radius-md: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { background: #dcd2c2; scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -10%, rgb(185 139 69 / 14%), transparent 32%),
    linear-gradient(180deg, #f9f5ed 0%, var(--paper) 55%, #eee5d8 100%);
}

button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgb(70 117 107 / 45%); outline-offset: 3px; }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 99;
  padding: 10px 14px;
  transform: translateY(-140%);
  color: white;
  background: var(--ink);
  border-radius: 10px;
}
.skip-link:focus { transform: none; }

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

.app-shell {
  position: relative;
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: calc(96px + var(--safe-bottom));
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent 49.8%, rgb(123 31 43 / 3%) 50%, transparent 50.2%),
    transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 14px;
  background: rgb(249 245 237 / 88%);
  border-bottom: 1px solid rgb(123 31 43 / 8%);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #fff8e9;
  font-family: "Songti SC", serif;
  font-size: 23px;
  font-weight: 800;
  background: var(--red);
  border: 1px solid rgb(255 255 255 / 35%);
  border-radius: 14px 14px 14px 4px;
  box-shadow: 0 6px 20px rgb(123 31 43 / 22%);
}
.brand strong, .brand small { display: block; }
.brand strong { font-family: "Songti SC", serif; font-size: 18px; letter-spacing: .08em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 10px; letter-spacing: .04em; }

.install-button {
  padding: 9px 13px;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
  background: var(--white);
  border: 1px solid rgb(123 31 43 / 15%);
  border-radius: 999px;
}

main { padding: 16px 18px 34px; }

.companion-card {
  position: relative;
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 16px;
  min-height: 172px;
  padding: 24px 22px;
  overflow: hidden;
  color: #fffaf0;
  background:
    radial-gradient(circle at 9% 16%, rgb(255 255 255 / 13%) 0 4%, transparent 4.5%),
    radial-gradient(circle at 93% 110%, rgb(185 139 69 / 40%) 0 28%, transparent 29%),
    linear-gradient(135deg, var(--red-dark), var(--red) 60%, #8f3e3b);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgb(88 21 30 / 23%);
}
.companion-card::after {
  position: absolute;
  right: -20px;
  top: -45px;
  width: 150px;
  height: 150px;
  content: "";
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 50%;
  box-shadow: 0 0 0 24px rgb(255 255 255 / 3%), 0 0 0 48px rgb(255 255 255 / 3%);
}

.avatar-wrap { position: relative; align-self: center; height: 92px; }
.avatar-halo {
  position: absolute;
  inset: 7px;
  background: rgb(255 251 238 / 14%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 36% 64% 55% 45%;
  animation: orbit 8s linear infinite;
}
.avatar {
  position: relative;
  z-index: 1;
  display: grid;
  width: 76px;
  height: 76px;
  margin: 8px;
  place-items: center;
  font-size: 44px;
  background: linear-gradient(145deg, #fff7dc, #f2d79d);
  border: 3px solid rgb(255 255 255 / 50%);
  border-radius: 32px 32px 32px 12px;
  box-shadow: 0 14px 28px rgb(48 8 14 / 28%);
  transition: transform .25s ease;
}
.avatar[data-emotion="listening"] { animation: listen 1s ease-in-out infinite; }
.avatar[data-emotion="thinking"] { animation: think 1.2s ease-in-out infinite; }
.avatar[data-emotion="speaking"] { animation: speak .55s ease-in-out infinite alternate; }

.companion-copy { position: relative; z-index: 2; align-self: center; }
.eyebrow { margin: 0 0 7px; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.companion-card .eyebrow { color: #e7c98e; }
.companion-copy h1 { margin: 0; font-family: "Songti SC", serif; font-size: clamp(23px, 6vw, 30px); letter-spacing: .03em; }
.companion-copy > p:not(.eyebrow) { margin: 8px 0 12px; color: rgb(255 250 240 / 74%); font-size: 13px; line-height: 1.55; }

.status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mode-badge, .sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 6px 10px;
  color: rgb(255 252 244 / 86%);
  font-size: 10px;
  font-weight: 700;
  background: rgb(255 255 255 / 9%);
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 999px;
}
.mode-badge i { width: 7px; height: 7px; background: #8ed1a6; border-radius: 50%; box-shadow: 0 0 0 4px rgb(142 209 166 / 12%); }
.mode-badge.is-demo i { background: #e7c98e; }
.mode-badge.is-error i { background: #ff958f; }
.sound-toggle { cursor: pointer; }
.sound-toggle[aria-pressed="false"] { opacity: .62; }

.notice {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin: 16px 4px 25px;
  padding: 12px 14px;
  color: #5e524a;
  background: rgb(255 253 249 / 60%);
  border: 1px solid rgb(185 139 69 / 20%);
  border-radius: 16px;
}
.notice > span { color: var(--gold); }
.notice p { margin: 0; font-size: 12px; line-height: 1.55; }

.tab-panel { animation: panelIn .28s ease both; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; margin: 0 4px 16px; }
.section-heading h2 { margin: 0; font-family: "Songti SC", serif; font-size: 26px; letter-spacing: .03em; }
.step-label { color: rgb(123 31 43 / 16%); font-family: Georgia, serif; font-size: 37px; font-weight: 800; line-height: 1; }

.camera-card {
  position: relative;
  min-height: 390px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 35%, rgb(185 139 69 / 16%), transparent 26%),
    linear-gradient(145deg, #302b29, #151313);
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 30px;
  box-shadow: var(--shadow);
}
.camera-card video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.camera-placeholder { position: absolute; inset: 0; z-index: 2; display: grid; align-content: center; justify-items: center; padding: 30px; color: #f9f1e5; text-align: center; }
.camera-placeholder h3 { margin: 24px 0 7px; font-family: "Songti SC", serif; font-size: 22px; }
.camera-placeholder p { max-width: 270px; margin: 0; color: rgb(249 241 229 / 55%); font-size: 12px; line-height: 1.7; }
.viewfinder { position: relative; display: grid; width: 150px; height: 150px; place-items: center; }
.viewfinder b { font-size: 48px; filter: sepia(.2); }
.viewfinder span { position: absolute; width: 42px; height: 42px; border-color: #d4ae6c; border-style: solid; }
.viewfinder span:nth-child(1) { left: 0; top: 0; border-width: 2px 0 0 2px; border-radius: 13px 0 0; }
.viewfinder span:nth-child(2) { right: 0; top: 0; border-width: 2px 2px 0 0; border-radius: 0 13px 0 0; }
.viewfinder span:nth-child(3) { right: 0; bottom: 0; border-width: 0 2px 2px 0; border-radius: 0 0 13px; }
.viewfinder span:nth-child(4) { left: 0; bottom: 0; border-width: 0 0 2px 2px; border-radius: 0 0 0 13px; }
.camera-live-label { position: absolute; z-index: 4; top: 16px; left: 16px; padding: 8px 10px; color: white; font-size: 11px; background: rgb(24 21 20 / 58%); border-radius: 999px; backdrop-filter: blur(10px); }
.camera-live-label i { display: inline-block; width: 7px; height: 7px; margin-right: 4px; background: #ff766c; border-radius: 50%; animation: pulse 1.2s infinite; }
.camera-shade { position: absolute; z-index: 3; inset: auto 0 0; height: 30%; pointer-events: none; background: linear-gradient(transparent, rgb(0 0 0 / 42%)); }

.camera-actions { display: grid; grid-template-columns: 1fr 1.18fr; gap: 10px; margin-top: 12px; }
.button { min-height: 54px; padding: 13px 16px; font-weight: 800; border-radius: 18px; cursor: pointer; transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease; }
.button:not(:disabled):active { transform: scale(.98); }
.button:disabled { cursor: not-allowed; opacity: .42; }
.button-secondary { color: var(--red); background: var(--white); border: 1px solid rgb(123 31 43 / 12%); }
.button-primary { color: #fff8eb; background: linear-gradient(135deg, var(--red), #963a3b); border: 1px solid transparent; box-shadow: 0 13px 26px rgb(123 31 43 / 22%); }

.artifact-result { display: grid; grid-template-columns: 72px 1fr; gap: 16px; margin-top: 18px; padding: 20px; background: var(--white); border: 1px solid rgb(123 31 43 / 8%); border-radius: 24px; box-shadow: var(--shadow); }
.artifact-symbol { display: grid; width: 72px; height: 72px; place-items: center; font-size: 35px; background: var(--paper); border: 1px solid rgb(185 139 69 / 18%); border-radius: 23px 23px 23px 8px; }
.result-meta { display: flex; gap: 7px; margin-bottom: 5px; }
.result-meta span { padding: 4px 8px; color: var(--jade); font-size: 9px; font-weight: 800; background: rgb(70 117 107 / 9%); border-radius: 999px; }
.artifact-result h3 { margin: 0; font-family: "Songti SC", serif; font-size: 20px; }
.artifact-result p { margin: 7px 0 10px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.text-button { padding: 0; color: var(--red); font-size: 12px; font-weight: 800; background: none; border: 0; cursor: pointer; }

.current-artifact { display: flex; align-items: center; gap: 11px; margin-bottom: 12px; padding: 11px 13px; background: var(--white); border: 1px solid rgb(185 139 69 / 20%); border-radius: 18px; }
.current-artifact > span { font-size: 26px; }
.current-artifact div { flex: 1; }
.current-artifact small, .current-artifact strong { display: block; }
.current-artifact small { color: var(--muted); font-size: 9px; }
.current-artifact strong { margin-top: 2px; font-family: "Songti SC", serif; }
.current-artifact button { width: 32px; height: 32px; color: var(--muted); background: var(--paper); border: 0; border-radius: 50%; }

.chat-card { overflow: hidden; background: var(--white); border: 1px solid rgb(123 31 43 / 8%); border-radius: 28px; box-shadow: var(--shadow); }
.messages { display: flex; flex-direction: column; gap: 14px; height: min(52vh, 430px); min-height: 330px; padding: 20px 17px; overflow-y: auto; scroll-behavior: smooth; }
.message { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 8px; align-items: flex-start; max-width: 92%; animation: messageIn .25s ease both; }
.message.is-user { grid-template-columns: minmax(0, 1fr); align-self: flex-end; }
.message-avatar { display: grid; width: 32px; height: 32px; place-items: center; background: var(--paper); border-radius: 12px 12px 12px 4px; }
.message-bubble { padding: 11px 13px; font-size: 13px; line-height: 1.65; background: var(--paper); border-radius: 4px 17px 17px 17px; }
.message.is-user .message-bubble { color: #fff8ed; background: var(--red); border-radius: 17px 4px 17px 17px; }
.message-meta { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; }
.typing-dots { display: flex; gap: 4px; padding: 5px 0; }
.typing-dots i { width: 6px; height: 6px; background: var(--gold); border-radius: 50%; animation: typing 1s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .16s; }
.typing-dots i:nth-child(3) { animation-delay: .32s; }

.quick-prompts { display: flex; gap: 7px; padding: 0 16px 11px; overflow-x: auto; scrollbar-width: none; }
.quick-prompts button { flex: 0 0 auto; padding: 8px 11px; color: var(--red); font-size: 10px; font-weight: 700; background: var(--red-soft); border: 0; border-radius: 999px; cursor: pointer; }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) 42px 42px; gap: 7px; align-items: end; margin: 0 12px 9px; padding: 7px 7px 7px 14px; background: var(--paper); border: 1px solid rgb(123 31 43 / 9%); border-radius: 22px; }
.chat-form textarea { width: 100%; max-height: 100px; padding: 10px 0 7px; resize: none; color: var(--ink); background: transparent; border: 0; outline: 0; }
.mic-button, .send-button { display: grid; width: 42px; height: 42px; place-items: center; border: 0; border-radius: 16px; cursor: pointer; }
.mic-button { background: var(--white); }
.mic-button.is-listening { color: white; background: var(--jade); animation: pulseSoft 1s infinite; }
.send-button { color: white; font-size: 21px; font-weight: 800; background: var(--red); }
.chat-hint { margin: 0; padding: 0 16px 13px; color: #998d84; font-size: 9px; text-align: center; }

.artifact-grid { display: grid; gap: 12px; }
.artifact-card { display: grid; grid-template-columns: 72px minmax(0, 1fr) 24px; gap: 13px; align-items: center; padding: 16px; text-align: left; background: var(--white); border: 1px solid rgb(123 31 43 / 8%); border-radius: 22px; box-shadow: 0 12px 35px rgb(72 39 23 / 8%); cursor: pointer; }
.artifact-card .art-emoji { display: grid; width: 72px; height: 72px; place-items: center; font-size: 32px; background: linear-gradient(145deg, var(--paper), #efe2cf); border-radius: 22px 22px 22px 7px; }
.artifact-card small { color: var(--gold); font-size: 9px; font-weight: 800; letter-spacing: .08em; }
.artifact-card h3 { margin: 3px 0 5px; font-family: "Songti SC", serif; font-size: 18px; }
.artifact-card p { margin: 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.artifact-card .arrow { color: var(--red); font-size: 22px; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  bottom: 0;
  left: 50%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 720px);
  padding: 8px 14px calc(8px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgb(255 253 249 / 92%);
  border-top: 1px solid rgb(123 31 43 / 8%);
  backdrop-filter: blur(20px);
  box-shadow: 0 -12px 40px rgb(72 39 23 / 8%);
}
.nav-item { display: grid; gap: 1px; min-height: 58px; place-items: center; align-content: center; color: #8e827a; background: transparent; border: 0; border-radius: 18px; cursor: pointer; }
.nav-item > span { font-size: 25px; line-height: 1; }
.nav-item small { font-size: 10px; font-weight: 800; }
.nav-item.is-active { color: var(--red); background: var(--red-soft); }

.candidate-dialog { width: min(calc(100% - 28px), 560px); max-height: 84vh; padding: 0; color: var(--ink); background: transparent; border: 0; }
.candidate-dialog::backdrop { background: rgb(35 24 22 / 62%); backdrop-filter: blur(5px); }
.dialog-card { position: relative; padding: 26px 20px 20px; background: var(--white); border-radius: 28px; box-shadow: 0 30px 80px rgb(0 0 0 / 28%); }
.dialog-card h2 { margin: 0; font-family: "Songti SC", serif; }
.dialog-description { margin: 8px 0 18px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.dialog-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; color: var(--muted); background: var(--paper); border: 0; border-radius: 50%; }
.candidate-list { display: grid; gap: 9px; }
.candidate-option { display: grid; grid-template-columns: 46px 1fr auto; gap: 10px; align-items: center; width: 100%; padding: 12px; text-align: left; background: var(--paper); border: 1px solid transparent; border-radius: 17px; cursor: pointer; }
.candidate-option:hover { border-color: rgb(123 31 43 / 24%); }
.candidate-option > span:first-child { font-size: 27px; }
.candidate-option strong, .candidate-option small { display: block; }
.candidate-option small { margin-top: 3px; color: var(--muted); font-size: 9px; }

.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(90px + var(--safe-bottom)); width: max-content; max-width: calc(100% - 36px); padding: 11px 15px; transform: translateX(-50%); color: white; font-size: 12px; background: rgb(45 39 37 / 92%); border-radius: 13px; box-shadow: var(--shadow); }

@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes listen { 50% { transform: scale(1.06) rotate(-2deg); } }
@keyframes think { 50% { transform: translateY(-4px) rotate(3deg); } }
@keyframes speak { to { transform: scale(1.05) translateY(-2px); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes pulseSoft { 50% { box-shadow: 0 0 0 7px rgb(70 117 107 / 14%); } }
@keyframes typing { 50% { transform: translateY(-3px); opacity: .5; } }
@keyframes panelIn { from { transform: translateY(8px); opacity: 0; } }
@keyframes messageIn { from { transform: translateY(5px); opacity: 0; } }

@media (min-width: 700px) {
  body { padding: 24px 0; }
  .app-shell { min-height: calc(100vh - 48px); background-color: rgb(255 253 249 / 36%); border: 1px solid rgb(123 31 43 / 8%); border-radius: 36px; box-shadow: 0 25px 90px rgb(72 39 23 / 14%); }
  .topbar { border-radius: 36px 36px 0 0; }
  .bottom-nav { bottom: 24px; width: 688px; border: 1px solid rgb(123 31 43 / 8%); border-radius: 0 0 36px 36px; }
  main { padding-inline: 28px; }
  .camera-card { min-height: 470px; }
}

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