:root {
  --paper: #f7f4ec;
  --panel: #fffdf7;
  --ink: #16201c;
  --muted: #6e756e;
  --line: #d7d2c4;
  --lime: #c7f04d;
  --mint: #1f9d84;
  --orange: #f2893d;
  --blue: #3c7fb7;
  --danger: #b92f2f;
  --shadow: 0 18px 50px rgba(22, 32, 28, 0.14);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(199, 240, 77, 0.18), transparent 36%),
    linear-gradient(315deg, rgba(60, 127, 183, 0.14), transparent 34%),
    var(--paper);
  color: var(--ink);
  font-family: Avenir Next, PingFang SC, Hiragino Sans GB, Microsoft YaHei, sans-serif;
  font-size: 16px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  background: rgba(255, 253, 247, 0.84);
  box-shadow: var(--shadow);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid rgba(215, 210, 196, 0.74);
  background: rgba(255, 253, 247, 0.92);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--mint);
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
}

.ghost-button,
.send-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ghost-button {
  width: 40px;
  height: 40px;
  background: var(--panel);
  color: var(--ink);
}

.image-panel {
  padding: 10px 12px 0;
  background: linear-gradient(180deg, rgba(255, 253, 247, 0.95), rgba(247, 244, 236, 0.8));
}

.image-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.image-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.image-frame img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

.target-box {
  position: absolute;
  z-index: 2;
  border: 2px solid #ff2d2d;
  border-radius: 6px;
  background: rgba(255, 45, 45, 0.18);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(255, 45, 45, 0.7), 0 0 12px rgba(255, 45, 45, 0.78);
  pointer-events: none;
  transform-origin: center;
  animation: target-pulse 0.95s ease-in-out infinite;
}

.target-box::after {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 28px;
  padding: 3px 6px;
  border-radius: 999px;
  background: #ff2d2d;
  box-shadow: 0 2px 10px rgba(22, 32, 28, 0.36);
  color: #fff;
  content: attr(data-label);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}

@keyframes target-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(255, 45, 45, 0.68), 0 0 10px rgba(255, 45, 45, 0.76);
  }

  50% {
    box-shadow: 0 0 0 2px #fff, 0 0 0 6px rgba(255, 45, 45, 0.48), 0 0 16px rgba(255, 45, 45, 0.9);
  }
}

.chat-panel {
  min-height: 0;
  padding: 8px 12px 12px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  max-height: calc(100dvh - 390px);
  min-height: 180px;
  overflow-y: auto;
  padding: 2px 2px 12px;
  scroll-behavior: smooth;
}

.app-shell.is-keyboard-open {
  height: var(--keyboard-viewport-height, 100dvh);
  max-height: var(--keyboard-viewport-height, 100dvh);
  min-height: var(--keyboard-viewport-height, 100dvh);
  overflow: hidden;
}

.app-shell.is-keyboard-open .image-panel {
  padding: 8px 10px 0;
}

.app-shell.is-keyboard-open .image-toolbar {
  margin-bottom: 6px;
}

.app-shell.is-keyboard-open .image-frame {
  width: min(100%, clamp(220px, calc((var(--keyboard-viewport-height, 100dvh) - 294px) * 1.1), 360px));
  margin-inline: auto;
}

.app-shell.is-keyboard-open .chat-panel {
  padding: 6px 10px 8px;
}

.app-shell.is-keyboard-open .messages {
  min-height: 96px;
  max-height: none;
  padding-bottom: 8px;
}

.app-shell.is-keyboard-open .composer {
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}

.message {
  width: fit-content;
  max-width: min(86%, 420px);
  padding: 11px 12px;
  border-radius: 8px;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

.message--assistant {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: var(--panel);
}

.message--user {
  align-self: flex-end;
  background: var(--ink);
  color: white;
}

.message--result {
  min-width: min(76%, 320px);
  padding: 10px;
  border-color: rgba(31, 157, 132, 0.34);
  background: #f4fff7;
}

.message--warning {
  border-color: rgba(242, 137, 61, 0.34);
  background: #fff8ed;
}

.message--error {
  border-color: rgba(185, 47, 47, 0.34);
  background: #fff1f1;
  color: var(--danger);
}

.result-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 0;
}

.result-meta div {
  min-width: 0;
  padding: 8px 6px;
  border: 1px solid rgba(31, 157, 132, 0.22);
  border-radius: 8px;
  background: white;
  text-align: center;
}

.result-meta dt {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 11px;
}

.result-meta dd {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
}

.typing-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 3px;
  border-radius: 50%;
  background: var(--mint);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(215, 210, 196, 0.74);
  background: rgba(255, 253, 247, 0.94);
  backdrop-filter: blur(14px);
}

.composer input {
  min-width: 0;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: white;
  color: var(--ink);
}

.composer input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(31, 157, 132, 0.14);
}

.send-button {
  width: 44px;
  height: 44px;
  background: var(--lime);
  color: var(--ink);
}

.send-button:disabled {
  cursor: wait;
  opacity: 0.54;
}

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

@media (min-width: 700px) {
  body {
    padding: 18px 0;
  }

  .app-shell {
    min-height: calc(100dvh - 36px);
    border: 1px solid rgba(215, 210, 196, 0.72);
    border-radius: 8px;
    overflow: hidden;
  }
}

@media (max-height: 760px) {
  .messages {
    max-height: calc(100dvh - 330px);
  }
}

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