:root {
  --paper: #faf6f3;
  --paper-deep: #e9dcc4;
  --panel: #fff9ed;
  --panel-soft: #f8efdd;
  --ink: #453d5e;
  --ink-soft: #8a7f95;
  --indigo: #4b3f72;
  --indigo-deep: #342b55;
  --amber: #d99a4e;
  --amber-deep: #a86e2c;
  --line: #e2d3b4;
  --line-dark: #cdb78e;
  --success: #6e8665;
  --danger: #a85656;
  --shadow: 3px 3px 0 rgba(75, 63, 114, 0.1);
  color-scheme: light;
  font-family: Inter, ui-rounded, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  min-width: 320px;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 250, 235, 0.8), transparent 26rem),
    #faf6f3;
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(217, 154, 78, 0.5);
  outline-offset: 2px;
}

button:disabled {
  cursor: default;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-shell {
  position: relative;
  width: min(100%, 460px);
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  overflow: hidden;
  background:
    linear-gradient(rgba(243, 234, 217, 0.9), rgba(243, 234, 217, 0.96)),
    repeating-linear-gradient(0deg, rgba(86, 70, 59, 0.025) 0 1px, transparent 1px 4px);
  box-shadow: 0 0 42px rgba(55, 43, 69, 0.2);
}

.page-stack {
  position: absolute;
  inset: 0 0 calc(70px + env(safe-area-inset-bottom));
  overflow: hidden;
}

.page {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top)) 16px 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-dark) transparent;
}

.eyebrow {
  color: var(--amber-deep);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.home-page {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.home-header,
.simple-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.home-header h1,
.simple-header h1 {
  margin-top: 3px;
  font-size: clamp(22px, 7vw, 29px);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.icon-button:active {
  transform: translateY(1px);
  box-shadow: none;
}

.icon-button svg,
.header-action svg,
.tab-button svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.companion-card {
  position: relative;
  min-height: 230px;
  overflow: hidden;
  padding: 26px 22px 22px;
  border: 2px solid rgba(205, 183, 142, 0.78);
  border-radius: 24px 8px 24px 8px;
  background:
    radial-gradient(circle at 80% 20%, rgba(235, 198, 132, 0.34), transparent 30%),
    linear-gradient(145deg, #51456f 0%, #3c3459 63%, #332d4d 100%);
  box-shadow: 5px 6px 0 rgba(75, 63, 114, 0.13);
  color: #f7eedc;
  isolation: isolate;
}

.companion-card::before,
.companion-card::after {
  position: absolute;
  z-index: -1;
  content: "";
  border-radius: 50%;
  background: rgba(243, 225, 188, 0.12);
}

.companion-card::before {
  width: 180px;
  height: 180px;
  right: -72px;
  top: -82px;
}

.companion-card::after {
  width: 95px;
  height: 95px;
  right: 54px;
  bottom: -58px;
}

.companion-glow {
  position: absolute;
  right: 23px;
  top: 20px;
  width: 116px;
  height: 116px;
  border: 1px solid rgba(243, 225, 188, 0.3);
  border-radius: 50%;
  box-shadow:
    0 0 0 12px rgba(243, 225, 188, 0.04),
    0 0 42px rgba(236, 183, 104, 0.15);
}

.companion-avatar {
  position: absolute;
  right: 33px;
  top: 30px;
  width: 96px;
  height: 96px;
  border: 3px solid rgba(247, 238, 220, 0.68);
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
  box-shadow: 0 6px 20px rgba(20, 14, 33, 0.25);
}

.companion-copy {
  width: calc(100% - 112px);
}

.companion-kicker {
  color: #e8c98f;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.companion-copy h2 {
  margin-top: 9px;
  font-size: clamp(21px, 6vw, 27px);
  line-height: 1.2;
}

.companion-copy p:last-child {
  max-width: 210px;
  margin-top: 9px;
  color: #d8cde1;
  font-size: 12px;
  line-height: 1.6;
}

.primary-button {
  position: absolute;
  left: 22px;
  bottom: 22px;
  min-width: 122px;
  padding: 10px 18px;
  border: 1px solid rgba(255, 243, 217, 0.55);
  border-radius: 6px;
  background: #f3e7ce;
  box-shadow: 3px 3px 0 rgba(18, 12, 31, 0.25);
  color: var(--indigo-deep);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.primary-button:active {
  transform: translateY(2px);
  box-shadow: none;
}

.home-section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 2px 3px 0;
}

.home-section-heading h2 {
  font-size: 17px;
}

.home-section-heading span {
  color: var(--ink-soft);
  font-size: 10px;
}

.entry-card {
  display: flex;
  min-height: 108px;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 24px 15px 30px;
  border: 0;
  background: url("/assets/ui/home/entry-card.png") center / 100% 100% no-repeat;
  color: var(--ink);
  text-align: left;
}

.entry-card:active {
  transform: translateY(1px);
}

.entry-emblem {
  width: 54px;
  height: 58px;
  flex: none;
  object-fit: contain;
  image-rendering: pixelated;
}

.entry-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.entry-copy strong {
  font-size: 15px;
}

.entry-copy small {
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-arrow {
  width: 17px;
  height: 18px;
  margin-left: auto;
  object-fit: contain;
}

.entry-badge {
  margin-left: auto;
  padding: 4px 7px;
  border: 1px solid var(--line-dark);
  border-radius: 999px;
  color: var(--amber-deep);
  font-size: 10px;
}

.chat-page {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: max(8px, env(safe-area-inset-top)) 0 0;
}

.chat-header {
  display: grid;
  grid-template-columns: 68px 1fr 68px;
  align-items: center;
  min-height: 66px;
  padding: 8px 10px 10px;
  border-bottom: 2px solid var(--line);
  background: rgba(255, 249, 237, 0.92);
  backdrop-filter: blur(10px);
}

.header-action {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 5px 2px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 10px;
}

.header-action svg {
  width: 23px;
  height: 23px;
}

.new-conversation {
  justify-self: end;
}

.chat-peer {
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 8px;
}

.chat-peer img {
  width: 38px;
  height: 38px;
  border: 2px solid var(--line-dark);
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
}

.chat-peer h1 {
  font-size: 15px;
  line-height: 1.1;
}

.chat-peer p {
  max-width: 118px;
  margin-top: 3px;
  overflow: hidden;
  color: var(--amber-deep);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-panel {
  position: absolute;
  z-index: 8;
  inset: 0;
  overflow-y: auto;
  padding: max(22px, env(safe-area-inset-top)) 16px 24px;
  background:
    linear-gradient(rgba(243, 234, 217, 0.98), rgba(243, 234, 217, 0.99)),
    repeating-linear-gradient(0deg, rgba(86, 70, 59, 0.03) 0 1px, transparent 1px 4px);
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.history-heading h2 {
  margin-top: 4px;
  font-size: 24px;
}

.conversation-list {
  display: grid;
  gap: 10px;
}

.conversation-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: left;
}

.conversation-item[aria-current="true"] {
  border-color: var(--amber);
  background: #fff6df;
}

.conversation-item img {
  width: 42px;
  height: 42px;
  border: 2px solid var(--line-dark);
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
}

.conversation-copy {
  min-width: 0;
}

.conversation-copy strong,
.conversation-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-copy strong {
  font-size: 14px;
}

.conversation-copy small {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 11px;
}

.conversation-time {
  color: var(--amber-deep);
  font-size: 9px;
}

.history-empty {
  padding: 24px 14px;
  border: 2px dashed var(--line-dark);
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

.chat-empty {
  display: grid;
  flex: 1;
  place-items: center;
  align-content: center;
  padding: 24px 44px;
  text-align: center;
}

.chat-empty img {
  width: 76px;
  height: 76px;
  border: 3px solid var(--line);
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
}

.chat-empty h2 {
  margin-top: 14px;
  font-size: 18px;
}

.chat-empty p {
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.65;
}

.chat-messages {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  padding: 22px 12px 14px;
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  animation: message-in 180ms ease-out both;
}

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

.message-assistant,
.message-error {
  justify-content: flex-start;
}

.message-note {
  position: relative;
  max-width: min(78%, 290px);
  min-width: 74px;
  border-style: solid;
  border-color: transparent;
}

.message-assistant .message-note,
.message-error .message-note {
  padding: 2px 8px 1px;
  border-width: 14px 20px;
  border-image: url("/assets/ui/chat/bubble-assistant.png") 135 108 22 72 fill / 60px 48px 10px 32px stretch;
}

.message-user .message-note {
  padding: 4px 8px 2px;
  border-width: 18px 24px 12px 14px;
  border-image: url("/assets/ui/chat/bubble-user.png") 128 98 18 20 fill / 58px 44px 8px 9px stretch;
}

.message-text {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.62;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-user .message-text {
  color: #f5ecd9;
  transform: translateY(3px);
}

.message-time {
  display: block;
  margin-top: 5px;
  color: #a99a7e;
  font-size: 9px;
  text-align: right;
}

.message-user .message-time {
  color: #b7abd1;
}

.message-pending .message-text {
  color: var(--ink-soft);
  font-style: italic;
}

.message-error .message-text {
  color: var(--danger);
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-composer {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 76%, rgba(243, 234, 217, 0));
}

.input-note {
  display: flex;
  min-width: 0;
  height: 54px;
  flex: 1;
  align-items: center;
  border: 6px solid transparent;
  border-width: 6px 30px 10px 28px;
  border-image: url("/assets/ui/chat/input-note.png") 27 135 46 125 fill / 6px 30px 10px 28px stretch;
}

.input-note textarea {
  width: 100%;
  max-height: 68px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
}

.input-note textarea::placeholder {
  color: #aa9b87;
}

.send-button {
  position: relative;
  top: -2px;
  width: 52px;
  height: 52px;
  flex: none;
  background: transparent;
}

.send-button img {
  position: absolute;
  inset: 0;
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.send-ready {
  opacity: 0;
}

.send-button:not(:disabled) .send-ready {
  opacity: 1;
}

.send-button:not(:disabled) .send-idle {
  opacity: 0;
}

.send-button:not(:disabled):active {
  transform: translateY(2px);
}

.placeholder-page {
  display: flex;
  flex-direction: column;
}

.simple-header {
  min-height: 62px;
}

.with-back {
  justify-content: flex-start;
  gap: 14px;
}

.back-button {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 6px 2px;
  background: transparent;
  color: var(--amber-deep);
  font-size: 11px;
}

.back-button img {
  width: 18px;
  transform: scaleX(-1);
}

.placeholder-card {
  display: grid;
  flex: 1;
  max-height: 330px;
  place-items: center;
  align-content: center;
  margin: 24px 0;
  padding: 34px 28px;
  border: 2px dashed var(--line-dark);
  border-radius: 24px 8px 24px 8px;
  background: rgba(255, 249, 237, 0.72);
  text-align: center;
}

.placeholder-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 2px solid var(--line-dark);
  border-radius: 50%;
  color: var(--amber-deep);
  font-size: 25px;
}

.placeholder-card h2 {
  margin-top: 17px;
  color: var(--indigo);
  font-size: 18px;
}

.placeholder-card p {
  max-width: 260px;
  margin-top: 9px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.7;
}

.tab-bar {
  position: absolute;
  z-index: 10;
  inset: auto 0 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: calc(70px + env(safe-area-inset-bottom));
  padding: 7px 8px env(safe-area-inset-bottom);
  border-top: 2px solid rgba(205, 183, 142, 0.8);
  background: rgba(255, 249, 237, 0.96);
  box-shadow: 0 -8px 24px rgba(75, 63, 114, 0.08);
  backdrop-filter: blur(14px);
}

.tab-button {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-width: 0;
  border-radius: 10px;
  background: transparent;
  color: #9d9187;
  font-size: 10px;
}

.tab-button::after {
  position: absolute;
  bottom: 1px;
  width: 16px;
  height: 3px;
  border-radius: 999px;
  background: var(--amber);
  content: "";
  opacity: 0;
  transform: scaleX(0.2);
  transition: 160ms ease;
}

.tab-button svg {
  width: 25px;
  height: 25px;
}

.tab-button.active {
  color: var(--indigo);
  font-weight: 700;
}

.tab-button.active::after {
  opacity: 1;
  transform: scaleX(1);
}

.toast {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 9px 14px;
  border: 1px solid rgba(255, 243, 217, 0.4);
  border-radius: 999px;
  background: rgba(52, 43, 85, 0.94);
  box-shadow: 0 8px 24px rgba(31, 24, 48, 0.24);
  color: #fff4df;
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  transform: translateX(-50%);
}

@media (min-width: 700px) {
  .app-shell {
    height: min(900px, calc(100dvh - 32px));
    margin-top: 16px;
    border: 1px solid rgba(75, 63, 114, 0.15);
    border-radius: 30px;
  }
}

@media (max-height: 680px) {
  .companion-card {
    min-height: 200px;
  }

  .companion-avatar {
    width: 82px;
    height: 82px;
  }

  .entry-card {
    min-height: 92px;
  }
}

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

.login-gate {
  display: grid;
  width: 100%;
  min-height: 100dvh;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 248, 226, 0.88), transparent 22rem),
    linear-gradient(155deg, #e7dac2, #d6c8b1);
}

.login-card {
  display: grid;
  width: min(100%, 390px);
  justify-items: center;
  padding: 34px 26px 28px;
  border: 2px solid var(--line-dark);
  border-radius: 28px 10px 28px 10px;
  background:
    linear-gradient(rgba(255, 249, 237, 0.96), rgba(248, 239, 221, 0.98)),
    repeating-linear-gradient(0deg, rgba(86, 70, 59, 0.03) 0 1px, transparent 1px 4px);
  box-shadow: 7px 8px 0 rgba(75, 63, 114, 0.12);
  text-align: center;
}

.login-avatar {
  width: 84px;
  height: 84px;
  margin-bottom: 18px;
  border: 3px solid var(--line-dark);
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
  box-shadow: 0 8px 22px rgba(55, 43, 69, 0.18);
}

.offline-card {
  min-height: 390px;
  align-content: center;
}

.offline-icon {
  width: 104px;
  height: 104px;
  margin-bottom: 18px;
  border: 2px solid #292824;
  border-radius: 24px;
  object-fit: cover;
}

.retry-button {
  margin-top: 22px;
  padding: 8px 22px;
}

.update-banner {
  position: fixed;
  z-index: 50;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  display: flex;
  width: min(calc(100% - 24px), 420px);
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 11px 10px 15px;
  border: 1px solid rgba(250, 246, 243, 0.35);
  border-radius: 10px;
  background: #292824;
  box-shadow: 0 8px 28px rgba(41, 40, 36, 0.28);
  color: #faf6f3;
  font-size: 12px;
  transform: translateX(-50%);
}

.update-banner button {
  flex: none;
  padding: 7px 11px;
  border-radius: 6px;
  background: #faf6f3;
  color: #292824;
  font-size: 12px;
  font-weight: 800;
}

.login-card h1 {
  margin-top: 5px;
  color: var(--indigo-deep);
  font-size: 28px;
}

.login-copy {
  max-width: 290px;
  margin-top: 11px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.7;
}

.login-field {
  display: grid;
  width: 100%;
  gap: 7px;
  margin-top: 24px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.login-field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 2px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #fffaf0;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.login-field input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(217, 154, 78, 0.16);
}

.login-button,
.logout-button {
  min-height: 44px;
  border: 1px solid var(--indigo-deep);
  border-radius: 7px;
  background: var(--indigo);
  box-shadow: 3px 3px 0 rgba(52, 43, 85, 0.2);
  color: #fff4df;
  font-weight: 800;
}

.login-button {
  width: 100%;
  margin-top: 15px;
}

.login-button:disabled {
  opacity: 0.62;
}

.login-status {
  min-height: 18px;
  margin-top: 10px;
  color: var(--danger);
  font-size: 11px;
}

.logout-button {
  align-self: center;
  min-width: 156px;
  margin: 0 auto 14px;
  padding: 8px 18px;
  background: transparent;
  color: var(--indigo);
}
