:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #14181d;
  --muted: #6a7280;
  --line: #dce0e7;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #171c22;
    --surface-2: #1f252d;
    --text: #e8ecf1;
    --muted: #8b949e;
    --line: #2a313a;
    --accent: #4f8bff;
    --danger: #ff6b5e;
  }
}

* {
  box-sizing: border-box;
}

/* Form controls don't inherit the body font on their own, and the `font` shorthand can't
   take `inherit` as its family, so set the family here and use longhands everywhere else. */
button,
input,
select,
textarea {
  font-family: inherit;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* Standalone mode has no browser chrome, so the app owns the notch and home-indicator gaps. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  overscroll-behavior: none;
}

/* --- header ------------------------------------------------------------------------------ */

.bar {
  display: flex;
  /* Top-aligned so the ⚙ stays level with the first row of language buttons when they wrap. */
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.langs {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

/* The language list is user-configurable, so the buttons have to wrap rather than shrink below
   a usable tap target. A grid keeps every cell the same width across rows — with flex-wrap a
   short final row stretches its buttons to fill the space. */
.lang-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(46px, 1fr));
  gap: 6px;
}

/* Matching the button height keeps these level with the first row when the grid wraps. */
.native,
.swap {
  line-height: 40px;
  color: var(--muted);
}

.native {
  font-weight: 700;
  font-size: 15px;
}

.swap {
  font-size: 13px;
}

.lang {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.lang.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
}

/* --- feed -------------------------------------------------------------------------------- */

.feed {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty {
  margin: auto;
  max-width: 22em;
  text-align: center;
  color: var(--muted);
}

.card {
  /* .feed is a column flexbox, so a card would otherwise inherit flex-shrink: 1 and get
     compressed once the feed overflows — and `overflow: hidden` below would silently clip the
     tail of the response rather than scrolling it. */
  flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  /* Keeps the header's background inside the rounded corners. */
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.tag {
  flex: none;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.03em;
}

.src {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.copy {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}

.card-body {
  padding: 4px 14px 12px;
}

.card-body h3,
.card-body h4,
.card-body h5 {
  margin: 14px 0 4px;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
}

.card-body p {
  margin: 8px 0;
}

.card-body ul {
  margin: 8px 0;
  padding-left: 20px;
}

.card-body li {
  margin: 4px 0;
}

/* Which model answered — ambient provenance, not a notification. Quiet enough to ignore,
   and still there when scrolling back through old cards. */
.card-foot {
  padding: 0 14px 10px;
  text-align: right;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--muted);
  opacity: 0.75;
}

.card-body code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  font-size: 0.92em;
}

/* --- composer ---------------------------------------------------------------------------- */

.composer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 8px 12px 10px;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

#input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  /* 16px minimum, otherwise iOS zooms the viewport on focus. */
  font-size: 16px;
  line-height: 1.4;
  resize: none;
}

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

.round {
  flex: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.round.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.round:disabled {
  opacity: 0.45;
}

.round.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}

@media (prefers-reduced-motion: reduce) {
  .round.recording {
    animation: none;
  }
}

.hint {
  margin: 6px 2px 0;
  min-height: 1.2em;
  font-size: 13px;
  color: var(--muted);
}

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

/* --- settings sheet ---------------------------------------------------------------------- */

.sheet {
  width: min(94vw, 420px);
  /* The prompt editor makes this tall enough to need its own scroll on a phone. */
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  /* No top padding: the sticky header supplies its own, so it can pin flush to the scrollport
     instead of leaving a strip for content to scroll through above it. */
  padding: 0 18px 18px;
}

.sheet::backdrop {
  background: rgb(0 0 0 / 0.45);
}

/* Pinned to the top of the scrolling sheet: the prompt editor makes this tall enough that
   hunting for the button at the bottom is a chore, so a way out is always in reach. The
   negative margins bleed it over the sheet's padding so scrolled content cannot show beside it. */
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -18px 14px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.sheet h2 {
  margin: 0;
  font-size: 18px;
}

.sheet label {
  display: block;
  margin: 12px 0 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.sheet input,
.sheet select,
.sheet textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  /* Also 16px to stop iOS zooming when a field is focused. */
  font-size: 16px;
  line-height: 1.3;
}

.sheet textarea {
  /* Proportional, not monospace: the instruction is prose, and monospace at 16px wraps
     every other word at phone width. */
  line-height: 1.45;
  resize: vertical;
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.label-row label {
  margin-bottom: 5px;
}

#prompt-state {
  font-weight: 400;
  text-transform: none;
}

.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.note.warn {
  color: var(--danger);
}

.note {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.sheet-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
}

.sheet-actions button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.sheet-actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.sheet-actions .ghost {
  color: var(--danger);
}
