/* Living Off AI v3 "Macchina": graphite field, cream type, valentine red used sparingly. */
:root {
  --bg: #0B0C0E;
  --surface: #101114;
  --raised: #16171B;
  --line: #1E2024;
  --line-strong: #2A2C30;
  --ghost: #3A3D42;
  --fg: #F2EDE3;
  --muted: #A9ACB2;
  --subtle: #7A7D83;
  --red: #E8442E;
  --red-300: #F26A50;
  --err-text: #F58A73;
  --err-bg: rgba(242, 106, 80, 0.12);
  --err-border: #B93524;
  --verde: #00894C;
  --ouro: #E2B33C;
  --sans: "Space Grotesk", "Avenir Next", "Helvetica Neue", system-ui, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--red-300); outline-offset: 2px; }

.app {
  display: flex;
  flex-direction: column;
  height: var(--app-h, 100dvh);
  max-width: 760px;
  margin: 0 auto;
}

/* Header */
.top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.mark {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 18%;
  background: #17181C;
  box-shadow: inset 0 0 0 1px rgba(242, 237, 227, 0.08), 0 2px 0 rgba(0, 0, 0, 0.45);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 700; font-size: 13px; line-height: 0.95; letter-spacing: -0.02em;
}
.mark .ai { color: var(--red); }
.titles { min-width: 0; }
h1 {
  margin: 0;
  font-weight: 700;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.sub {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
}

/* Conversation */
.log {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 16px 8px;
}
.msg {
  max-width: 88%;
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 16px;
  overflow-wrap: anywhere;
}
.msg.assistant {
  background: var(--raised);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.msg.user {
  margin-left: auto;
  background: var(--fg);
  color: var(--bg);
  border-top-right-radius: 4px;
  white-space: pre-wrap;
}
.msg.error {
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  color: var(--err-text);
}
.msg p { margin: 0 0 8px; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 4px 0 8px; padding-left: 20px; }
.msg li { margin: 2px 0; }
.msg strong { font-weight: 700; }
.msg code { font-family: var(--mono); font-size: 0.88em; background: rgba(242, 237, 227, 0.07); padding: 1px 4px; border-radius: 4px; }
.msg a { color: inherit; text-decoration: underline; text-decoration-color: var(--subtle); text-underline-offset: 2px; }
.msg.user a { text-decoration-color: currentColor; }
.msg .thumb { display: block; max-width: 200px; max-height: 200px; border-radius: 10px; margin: 0 0 6px auto; }
.msg .tag {
  display: block; margin-bottom: 4px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.7;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 16px; }
.chip {
  font: 500 14px/1.2 var(--sans);
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--ghost);
  border-radius: 999px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.chip:hover { border-color: var(--muted); }
.chip:active { transform: scale(0.98); }

.typing { display: inline-flex; gap: 5px; align-items: center; padding: 14px 16px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* Composer */
.composer {
  flex: none;
  border-top: 1px solid var(--line);
  padding: 10px 12px calc(6px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.row { display: flex; align-items: flex-end; gap: 8px; }
textarea {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  margin: 0;
  padding: 11px 16px;
  font: 16px/1.35 var(--sans);
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
}
textarea::placeholder { color: var(--subtle); }
.icon-btn, .send {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}
.icon-btn { background: transparent; color: var(--fg); border: 1px solid var(--ghost); }
.icon-btn:hover { border-color: var(--muted); }
.send { background: var(--red); color: var(--fg); border: 0; }
.send:active, .icon-btn:active { transform: scale(0.98); }
.send:disabled { background: var(--line-strong); color: var(--subtle); cursor: default; }
.preview { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; }
.preview img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line-strong); }
.preview-label { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.preview-remove {
  margin-left: auto; min-height: 36px; padding: 0 14px;
  font: 500 13px var(--sans); color: var(--fg); background: transparent;
  border: 1px solid var(--ghost); border-radius: 999px; cursor: pointer;
}
.foot {
  margin: 8px 4px 0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.4;
  color: var(--subtle);
  text-align: center;
}
.foot a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line-strong); }

/* Closed state */
.closed {
  flex: none;
  margin: 0 16px calc(16px + env(safe-area-inset-bottom));
  padding: 20px 20px 0;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 16px;
  overflow: hidden;
}
.closed .label {
  margin: 0 0 6px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--subtle);
}
.closed h2 { margin: 0 0 8px; font-size: 22px; line-height: 1.15; letter-spacing: -0.03em; font-weight: 700; }
.closed p { margin: 0 0 10px; color: var(--muted); }
.closed-links a { color: var(--fg); text-decoration: none; border-bottom: 1px solid var(--line-strong); line-height: 2; }
.heritage {
  height: 3px; margin: 16px -20px 0;
  background: linear-gradient(90deg, var(--verde) 0 33.34%, var(--red) 33.34% 66.67%, var(--ouro) 66.67% 100%);
}

@media (min-width: 640px) {
  h1 { font-size: 26px; }
  .sub { font-size: 12px; }
  .log { padding: 24px 24px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
