body.ai-app-page {
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 7% 9%, rgba(248, 206, 96, 0.34) 0 150px, transparent 151px),
    radial-gradient(circle at 95% 91%, rgba(170, 212, 188, 0.42) 0 190px, transparent 191px),
    #e9e1d4;
}

.ai-app-page .site-header,
.ai-app-page .site-footer,
.ai-app-page .app-tabbar,
.ai-app-page .global-ai-launcher {
  display: none;
}

.ai-page {
  display: grid;
  min-height: 100dvh;
  padding: 16px;
  place-items: center;
}

.ai-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto;
  width: min(780px, 100%);
  height: min(900px, calc(100dvh - 32px));
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 26px;
  background: #f6f1e8;
  box-shadow: 9px 10px 0 rgba(75, 56, 42, 0.12);
}

.ai-head {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 62px;
  padding: 10px 13px;
  border-bottom: 1px solid rgba(75, 56, 42, 0.12);
  background: rgba(255, 250, 240, 0.97);
}

.ai-back,
.ai-head-actions button,
.ai-attach,
.ai-send {
  display: grid;
  width: 38px;
  height: 38px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  place-items: center;
}

.ai-back:hover,
.ai-head-actions button:hover,
.ai-attach:hover {
  background: rgba(75, 56, 42, 0.08);
}

.ai-back svg,
.ai-head-actions svg,
.ai-attach svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.ai-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.ai-avatar {
  display: grid;
  width: 39px;
  height: 39px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-radius: 13px;
  background: var(--honey-light);
  place-items: center;
}

.ai-avatar img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.ai-identity > div {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.ai-identity h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
}

.ai-identity small {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #7f766e;
  font-size: 8px;
}

.ai-identity small i,
.ai-local-strip i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #5ca86a;
  box-shadow: 0 0 0 3px rgba(92, 168, 106, 0.12);
}

.ai-head-actions {
  display: flex;
  gap: 1px;
}

.ai-local-strip {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 15px;
  border-bottom: 1px solid rgba(75, 56, 42, 0.1);
  color: #837970;
  background: #fffdf8;
  font-size: 8px;
}

.ai-local-strip > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.ai-local-strip button {
  padding: 3px 7px;
  border: 0;
  border-radius: 999px;
  color: #72594a;
  background: #f5ebdb;
  cursor: pointer;
  font-size: 8px;
}

.ai-strip-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.ai-local-strip .ai-sound-toggle.is-enabled,
.ai-local-strip #aiSoundToggle.is-enabled {
  color: #2e6d3d;
  background: #e5f3e3;
}

.ai-local-strip .ai-sound-toggle:not(.is-enabled),
.ai-local-strip #aiSoundToggle:not(.is-enabled) {
  color: #7a6b61;
  background: #eee7dc;
}

.ai-local-strip #aiModelMode.is-enabled {
  color: #fff;
  background: #6f4b37;
}

.ai-local-strip #aiWebToggle.is-enabled,
.ai-local-strip #aiMemoryToggle.is-enabled {
  color: #2e6d3d;
  background: #e5f3e3;
}

.ai-messages {
  display: flex;
  flex-direction: column;
  gap: 13px;
  min-height: 0;
  padding: 18px clamp(12px, 3vw, 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    linear-gradient(rgba(255, 251, 242, 0.78), rgba(249, 239, 221, 0.8)),
    radial-gradient(circle at 2px 2px, rgba(113, 85, 61, 0.13) 1px, transparent 1.2px);
  background-size: cover, 21px 21px;
}

.ai-message {
  display: flex;
  max-width: 84%;
  align-items: flex-start;
  gap: 8px;
}

.ai-message.is-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-message-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(75, 56, 42, 0.62);
  border-radius: 10px;
  background: var(--honey-light);
  place-items: center;
}

.ai-message-avatar img {
  width: 30px;
  height: 30px;
}

.ai-message > div {
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid rgba(88, 67, 51, 0.1);
  border-radius: 13px 13px 13px 4px;
  background: #fffdf8;
  box-shadow: 0 1px 2px rgba(75, 56, 42, 0.09);
}

.ai-message.is-user > div {
  color: #fffdf8;
  background: #7a5240;
  border-radius: 13px 13px 4px 13px;
}

.ai-message > div > strong {
  display: block;
  margin-bottom: 3px;
  color: #806b5d;
  font-size: 8px;
}

.ai-message.is-user > div > strong {
  color: #f4ded2;
}

.ai-message p {
  margin: 0;
  color: #29221d;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-message.is-user p {
  color: #fffdf8;
}

.ai-message p + p {
  margin-top: 7px;
}

.ai-answer-heading {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 5px;
  padding-bottom: 4px;
  border-bottom: 1px dashed rgba(117, 79, 55, 0.22);
  color: #5b402f;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.35;
}

.ai-answer-heading:first-child {
  margin-top: 0;
}

.ai-answer-heading::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f4bf3f;
  box-shadow: 0 0 0 3px rgba(244, 191, 63, 0.16);
  content: "";
}

.ai-message p strong {
  color: #5f4435;
  font-weight: 800;
}

.ai-message.is-user p strong {
  color: #fff;
}

.ai-message ul,
.ai-message ol {
  margin: 5px 0 0;
  padding-left: 18px;
}

.ai-message li {
  margin: 2px 0;
  font-size: 13px;
  line-height: 1.55;
}

.ai-message.is-user li {
  font-size: 13px;
}

.ai-message.is-thinking p::after {
  display: inline-block;
  margin-left: 4px;
  content: "•••";
  letter-spacing: 2px;
  animation: aiThinking 1.1s ease-in-out infinite;
}

.ai-message.is-thinking > div {
  border-color: rgba(118, 81, 64, 0.24);
  background:
    linear-gradient(100deg, #fffdf8 20%, #fff1d5 42%, #fffdf8 65%);
  background-size: 220% 100%;
  animation: thinkingShimmer 1.8s linear infinite;
}

.ai-message.is-thinking .ai-message-avatar {
  animation: thinkingBear 1.25s ease-in-out infinite;
}

@keyframes thinkingShimmer {
  from { background-position: 110% 0; }
  to { background-position: -110% 0; }
}

@keyframes thinkingBear {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-3px) rotate(2deg); }
}

@keyframes aiThinking {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.ai-message-image {
  display: block;
  width: min(240px, 60vw);
  max-height: 220px;
  margin-bottom: 7px;
  border-radius: 9px;
  object-fit: cover;
}

.ai-message-link {
  display: inline-flex;
  margin-top: 7px;
  padding: 5px 9px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--honey);
  font-size: 9px;
  font-weight: 800;
}

.ai-message-sources {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed rgba(75, 56, 42, 0.18);
}

.ai-message-sources span {
  color: #8b7d72;
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.ai-message-sources a {
  overflow: hidden;
  color: #77513f;
  font-size: 9px;
  line-height: 1.45;
  text-decoration: underline;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-underline-offset: 2px;
}

.ai-message.is-user .ai-message-sources a {
  color: #fff1e6;
}

.ai-image-preview {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  margin: 0 13px 7px;
  padding: 7px;
  border: 1px dashed rgba(75, 56, 42, 0.25);
  border-radius: 13px;
  background: #fffaf1;
}

.ai-image-preview[hidden] {
  display: none;
}

.ai-image-preview img {
  width: 54px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}

.ai-image-preview > div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.ai-image-preview strong {
  overflow: hidden;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-image-preview small {
  color: var(--muted);
  font-size: 8px;
}

.ai-image-preview > button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--wine-dark);
  background: #f3eadc;
  cursor: pointer;
  font-size: 17px;
}

.ai-suggestions {
  display: flex;
  gap: 6px;
  padding: 3px 13px 7px;
  overflow-x: auto;
  background: #fffaf1;
  scrollbar-width: none;
}

.ai-suggestions::-webkit-scrollbar {
  display: none;
}

.ai-suggestions button {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid #e5d9c8;
  border-radius: 999px;
  color: #6f5d50;
  background: #fffdf8;
  cursor: pointer;
  font-size: 9px;
}

.ai-suggestions button:hover {
  border-color: var(--wine-dark);
  background: var(--honey-light);
}

.ai-composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 7px 10px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(75, 56, 42, 0.12);
  background: #fffaf1;
}

.ai-attach {
  width: 39px;
  height: 42px;
  flex: 0 0 auto;
  color: var(--wine-dark);
}

.ai-composer textarea {
  flex: 1;
  min-height: 42px;
  max-height: 118px;
  padding: 10px 11px;
  border: 1px solid rgba(75, 56, 42, 0.14);
  border-radius: 12px;
  outline: 0;
  color: var(--ink);
  background: #fff;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.35;
  resize: none;
  -webkit-appearance: none;
}

.ai-composer textarea:focus {
  border-color: rgba(118, 81, 64, 0.55);
}

.ai-send {
  width: 43px;
  height: 42px;
  flex: 0 0 auto;
  color: #fffdf8;
  background: var(--wine-dark);
  font-size: 19px;
}

.ai-send:hover {
  background: #573725;
}

.ai-voice-panel {
  max-height: 45vh;
  padding: 14px 15px calc(14px + env(safe-area-inset-bottom));
  overflow-y: auto;
  border-top: 1px solid rgba(75, 56, 42, 0.14);
  background: #fff8eb;
}

.ai-voice-panel[hidden] {
  display: none;
}

.ai-voice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-voice-head > div {
  display: grid;
  gap: 1px;
}

.ai-voice-head span {
  color: var(--wine-dark);
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.ai-voice-head strong {
  font-family: var(--serif);
  font-size: 18px;
}

.ai-voice-head > button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #f0e5d7;
  cursor: pointer;
  font-size: 17px;
}

.ai-voice-panel > p,
.ai-voice-panel > small {
  color: var(--muted);
  font-size: 8px;
  line-height: 1.6;
}

.ai-voice-record-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 10px;
  margin: 10px 0;
}

.ai-voice-record-row button,
.ai-voice-actions button {
  min-height: 32px;
  padding: 0 11px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  color: var(--ink);
  background: var(--honey);
  cursor: pointer;
  font-size: 9px;
  font-weight: 800;
}

.ai-voice-record-row button.is-recording {
  color: #fff;
  background: var(--wine-dark);
}

.ai-voice-record-row strong {
  font-size: 10px;
}

.ai-voice-record-row span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 8px;
}

.ai-voice-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 9px;
  font-size: 10px;
  font-weight: 700;
}

.ai-voice-toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--wine-dark);
}

.ai-voice-panel > label:not(.ai-voice-toggle) {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 8px;
}

.ai-voice-panel > label > span {
  display: flex;
  justify-content: space-between;
}

.ai-voice-panel input[type="range"] {
  width: 100%;
  accent-color: var(--wine-dark);
}

.ai-voice-panel select {
  width: 100%;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  font-size: 16px;
}

.ai-voice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.ai-voice-actions button:last-child {
  background: var(--cream-light);
}

@media (max-width: 620px) {
  .ai-page {
    padding: 0;
  }

  .ai-shell {
    width: 100%;
    height: var(--ai-viewport-height, 100dvh);
    max-height: var(--ai-viewport-height, 100dvh);
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .ai-head {
    min-height: 56px;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  }

  .ai-avatar {
    width: 35px;
    height: 35px;
    border-radius: 11px;
  }

  .ai-avatar img {
    width: 30px;
    height: 30px;
  }

  .ai-identity h1 {
    font-size: 16px;
  }

  .ai-messages {
    padding: 13px 9px;
  }

  .ai-message {
    max-width: 88%;
  }

  .ai-message p {
    font-size: 14px;
  }

  .ai-image-preview {
    margin-right: 8px;
    margin-left: 8px;
  }

  .ai-composer {
    padding-right: 8px;
    padding-left: 8px;
  }
}
