:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #eef4f2;
  --ink: #12211f;
  --muted: #5b6f6b;
  --line: #dbe6e3;
  --accent: #0f766e;
  --accent-strong: #0b5d56;
  --accent-soft: #dcf1ed;
  --user: #0f766e;
  --warning: #b45309;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(15, 48, 44, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', 'Apple SD Gothic Neo', Roboto,
    'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

body {
  overscroll-behavior-y: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: 0 0 40px rgba(15, 48, 44, 0.06);
}

.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;
}

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #fbfdfc);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: none;
}

.brand-text {
  min-width: 0;
}

h1 {
  font-size: 1.02rem;
  line-height: 1.15;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tagline {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.market {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  flex: none;
}

.market-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.market-btn span {
  font-weight: 500;
  opacity: 0.75;
}

.market-btn.is-active {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(15, 48, 44, 0.12);
}

/* Read-aloud toggle */
.options {
  display: flex;
  justify-content: flex-end;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfc;
}

.tts-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}

.tts-toggle svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.tts-toggle[aria-pressed='true'] {
  background: var(--accent-soft);
  border-color: #b7ded8;
  color: var(--accent-strong);
}

.tts-toggle .slash {
  display: none;
}

.tts-toggle[aria-pressed='false'] .wave {
  display: none;
}

.tts-toggle[aria-pressed='false'] .slash {
  display: inline;
}

.speech-btn.is-playing {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Chat log */
.chat {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.welcome {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.welcome h2 {
  margin: 0 0 6px;
  font-size: 0.98rem;
}

.welcome p {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--muted);
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.suggestion {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: left;
}

.suggestion:active {
  background: var(--accent-soft);
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 92%;
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-bot {
  align-self: flex-start;
}

.bubble {
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 0.92rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.msg-user .bubble {
  background: var(--user);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg-bot .bubble {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.bubble p {
  margin: 0 0 8px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul {
  margin: 4px 0 8px;
  padding-left: 18px;
}

.bubble a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-user .bubble a {
  color: #fff;
}

.bubble strong {
  font-weight: 650;
}

.msg.user-transcript .bubble::before {
  content: '🎙 ';
}

.products {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.product {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 9px 11px;
  font-size: 0.8rem;
  text-decoration: none;
  color: var(--ink);
}

.product:active {
  background: var(--accent-soft);
}

.product-name {
  font-weight: 600;
}

.product-price {
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.msg-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-left: 2px;
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent-strong);
  border-radius: 999px;
  font: inherit;
  font-size: 0.76rem;
  padding: 5px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn:active {
  background: var(--accent-soft);
}

.meta {
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0 2px;
}

.msg-error .bubble {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #7c2d12;
}

/* Typing */
.typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 18px 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.dots {
  display: inline-flex;
  gap: 3px;
}

.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: blink 1.1s infinite;
}

.dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  position: relative;
}

#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 14px;
  padding: 11px 12px;
  font: inherit;
  font-size: 1rem;
  line-height: 1.35;
  max-height: 120px;
  color: var(--ink);
  min-height: 44px;
}

#input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#input::placeholder {
  color: #8ba19c;
}

.mic,
.send {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent-strong);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.1s, background 0.15s;
}

.mic svg,
.send svg {
  width: 22px;
  height: 22px;
}

.send {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.mic.is-recording {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
  transform: scale(1.04);
  animation: pulse 1.2s infinite;
}

.mic.is-waiting {
  opacity: 0.6;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.25);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(220, 38, 38, 0);
  }
}

.record-state {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(100% + 8px);
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1f2d2b;
  color: #fff;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 0.8rem;
  box-shadow: var(--shadow);
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ef4444;
  animation: blink 1s infinite;
  flex: none;
}

.rec-hint {
  margin-left: auto;
  opacity: 0.7;
  font-size: 0.72rem;
}

.record-state.is-limit {
  background: #7c2d12;
}

.disclaimer {
  padding: 0 14px calc(8px + env(safe-area-inset-bottom));
  text-align: center;
}

.disclaimer p {
  margin: 0 0 6px;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--muted);
}

@media (max-width: 430px) {
  .market-btn span {
    display: none;
  }
  .market-btn {
    padding: 7px 9px;
  }
  .top {
    padding-left: 12px;
    padding-right: 12px;
    gap: 8px;
  }
  .brand {
    gap: 8px;
  }
}

@media (min-width: 700px) {
  .app {
    margin-top: 12px;
    margin-bottom: 12px;
    height: calc(100dvh - 24px);
    border-radius: 18px;
    overflow: hidden;
  }
  .msg {
    max-width: 78%;
  }
  .chat {
    padding: 20px 22px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
