/* Verity — Apple-style: floating translucent chrome, open assistant text, instant press feedback. */

:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #aeaeb2;
  --hairline: rgba(0, 0, 0, 0.08);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-strong: rgba(118, 118, 128, 0.2);
  --accent: #5e5ce6;
  --accent-2: #7d7aff;
  --on-accent: #ffffff;
  --you-bubble: #5e5ce6;
  --code-bg: rgba(118, 118, 128, 0.1);
  --danger: #d70015;
  --material: rgba(245, 245, 247, 0.72);
  --material-edge: rgba(255, 255, 255, 0.6);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);

  /* Critically damped "spring" for things that just appear (no overshoot: nothing was flicked). */
  --spring: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 120ms;
  --t-med: 380ms;

  --bar-h: 64px;
  --composer-h: 112px;
  --measure: 760px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f5f5f7;
    --secondary: #98989d;
    --tertiary: #636366;
    --hairline: rgba(255, 255, 255, 0.1);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(118, 118, 128, 0.36);
    --accent: #7d7aff;
    --accent-2: #9a98ff;
    --you-bubble: #5e5ce6;
    --code-bg: rgba(118, 118, 128, 0.22);
    --danger: #ff453a;
    --material: rgba(22, 22, 24, 0.72);
    --material-edge: rgba(255, 255, 255, 0.08);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.47 system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.012em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
svg { display: block; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 10px; }

/* Press feedback lives on pointer-down and is instant. */
.icon-btn, .chips button, #send, .pw-go, .suggestion, .jump, .file {
  transition: transform var(--t-fast) ease-out, background-color var(--t-fast) ease-out, opacity var(--t-fast) ease-out;
}
.icon-btn:active, .chips button:active, .suggestion:active, .jump:active, .file:active { transform: scale(0.95); }
#send:active:not(:disabled), .pw-go:active { transform: scale(0.9); }

/* ---------- Login ---------- */
.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(60% 50% at 50% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: materialize 600ms var(--spring) both;
}
.app-icon {
  width: 88px; height: 88px; border-radius: 22px;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 35%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  display: grid; place-items: center;
  margin-bottom: 20px;
}
.app-icon svg, .avatar svg { width: 62%; height: 62%; fill: none; stroke: #fff; stroke-width: 5.5; stroke-linecap: round; stroke-linejoin: round; }
.login-card h1 { margin: 0; font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -0.03em; }
.login-sub { margin: 6px 0 28px; color: var(--secondary); font-size: 15px; letter-spacing: -0.005em; }
.pw-row {
  width: 100%;
  display: flex; align-items: center; gap: 6px;
  background: var(--surface);
  border-radius: 14px;
  padding: 5px 5px 5px 16px;
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--hairline);
}
.pw-row:focus-within { box-shadow: var(--shadow-sm), 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); }
.pw-row input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 17px; color: var(--text); padding: 9px 0;
}
.pw-row input::placeholder { color: var(--tertiary); }
.pw-go {
  width: 38px; height: 38px; flex: none; border-radius: 10px;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
}
.pw-go svg, .icon-btn svg, #send svg, .jump svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.pw-go:disabled { opacity: 0.5; }
.error { min-height: 22px; margin: 12px 0 0; color: var(--danger); font-size: 14px; }
.shake { animation: shake 360ms var(--spring); }
@keyframes shake { 20% { transform: translateX(-8px); } 45% { transform: translateX(6px); } 70% { transform: translateX(-3px); } }
@keyframes materialize { from { opacity: 0; transform: scale(0.97); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

/* ---------- App shell ---------- */
.app { position: relative; height: 100%; }
.scroller {
  position: absolute; inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-bottom: var(--composer-h);
}
.messages {
  max-width: var(--measure);
  margin: 0 auto;
  padding: calc(var(--bar-h) + env(safe-area-inset-top) + 16px) 20px calc(var(--composer-h) + env(safe-area-inset-bottom) + 24px);
  display: flex; flex-direction: column;
}

/* Floating material layers; content scrolls underneath. */
.bar {
  position: absolute; left: 0; right: 0; z-index: 5;
  background: var(--material);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
}
.bar.top {
  top: 0;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 1px 0 var(--hairline);
}
.bar.bottom {
  bottom: 0;
  padding: 10px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  box-shadow: 0 -1px 0 var(--hairline);
}
.bar.bottom > * { max-width: calc(var(--measure) - 8px); margin-left: auto; margin-right: auto; }

.who { display: flex; align-items: center; gap: 11px; min-width: 0; }
.avatar {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  display: grid; place-items: center;
}
.avatar svg { stroke-width: 6.5; }
.who-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.who-name { font-size: 17px; font-weight: 600; letter-spacing: -0.022em; }
.who-status { font-size: 12px; color: var(--secondary); letter-spacing: 0; transition: color var(--t-med) var(--spring); }
.who-status.busy { color: var(--accent); }
.bar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; color: var(--accent);
}
.icon-btn:hover { background: var(--fill); }

/* ---------- Messages ---------- */
.day {
  align-self: center;
  margin: 18px 0 10px;
  font-size: 12px; font-weight: 600; color: var(--secondary);
  letter-spacing: 0.01em;
}
.msg {
  display: flex; flex-direction: column;
  margin-top: 4px;
  animation: arrive var(--t-med) var(--spring) both;
}
.msg + .msg.you, .msg.you + .msg.verity { margin-top: 18px; }
@keyframes arrive { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.msg.you { align-items: flex-end; }
.msg.you .bubble {
  max-width: min(78%, 560px);
  background: var(--you-bubble); color: var(--on-accent);
  padding: 9px 15px; border-radius: 20px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.you.pending .bubble { opacity: 0.7; }

/* Verity speaks in open text, not bubbles: long answers, lists and code read better. */
.msg.verity .bubble { max-width: 100%; overflow-wrap: anywhere; }
.msg.verity .bubble > :first-child { margin-top: 0; }
.msg.verity .bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 10px; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 19px; line-height: 1.3; letter-spacing: -0.02em; margin: 16px 0 6px; }
.bubble ul, .bubble ol { margin: 4px 0 10px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble a { color: var(--accent); text-decoration: none; font-weight: 500; }
.bubble a:hover { text-decoration: underline; }
.msg.you .bubble a { color: inherit; text-decoration: underline; }
.bubble strong { font-weight: 600; }
.bubble code { font: 0.88em/1.4 ui-monospace, "SF Mono", Menlo, monospace; background: var(--code-bg); border-radius: 6px; padding: 2px 5px; letter-spacing: 0; }
.bubble pre { background: var(--code-bg); border-radius: 12px; padding: 12px 14px; overflow-x: auto; margin: 6px 0 10px; }
.bubble pre code { background: none; padding: 0; }
.bubble blockquote { margin: 6px 0 10px; padding: 2px 0 2px 12px; border-left: 3px solid var(--fill-strong); color: var(--secondary); }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 15px; margin: 6px 0 10px; }
.bubble th, .bubble td { padding: 6px 10px; border-bottom: 1px solid var(--hairline); text-align: left; }
.bubble hr { border: 0; height: 1px; background: var(--hairline); margin: 14px 0; }

.meta { margin-top: 5px; font-size: 11px; color: var(--tertiary); letter-spacing: 0.01em; display: flex; gap: 6px; align-items: center; }
.via { display: inline-flex; align-items: center; gap: 4px; }
.via svg { width: 12px; height: 12px; fill: currentColor; }
.msg.error-msg .bubble { color: var(--danger); }

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.file {
  display: inline-flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--text);
  background: var(--surface); border-radius: 12px; padding: 8px 12px 8px 10px;
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--hairline);
  font-size: 14px; font-weight: 500;
}
.file .ext {
  min-width: 34px; height: 26px; padding: 0 5px; border-radius: 6px;
  background: var(--fill); color: var(--secondary);
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  display: grid; place-items: center;
}

/* Thought process */
.thoughts { margin: 0 0 8px; font-size: 14px; color: var(--secondary); }
.thoughts summary {
  cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--secondary); padding: 3px 0; user-select: none;
}
.thoughts summary::-webkit-details-marker { display: none; }
.thoughts summary::before {
  content: ""; width: 6px; height: 6px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
  transform: rotate(-45deg); transition: transform var(--t-fast) ease-out; margin-right: 2px;
}
.thoughts[open] summary::before { transform: rotate(45deg); }
.steps { list-style: none; margin: 6px 0 4px; padding: 0 0 0 12px; border-left: 2px solid var(--fill-strong); display: flex; flex-direction: column; gap: 5px; }
.steps li { line-height: 1.4; overflow-wrap: anywhere; }
.steps li.think { font-style: italic; color: var(--tertiary); }

/* Thinking indicator */
.typing { flex-direction: column !important; align-items: flex-start; }
.typing .dots { display: flex; gap: 5px; padding: 6px 0; }
.typing .live { list-style: none; margin: 4px 0 0; padding: 0 0 0 12px; border-left: 2px solid var(--fill-strong); display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--secondary); }
.typing .live li { animation: arrive var(--t-med) var(--spring) both; overflow-wrap: anywhere; }
.typing .live li.think { font-style: italic; color: var(--tertiary); }
.typing .live li:last-child { color: var(--text); }

/* Live screen sheet: anchored to the Screen button, materializes from there. */
.screen-sheet {
  position: absolute; z-index: 20; top: calc(var(--bar-h) + env(safe-area-inset-top) + 8px); right: 12px;
  width: min(720px, calc(100vw - 24px));
  background: var(--material);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  border-radius: 20px; box-shadow: var(--shadow-lg), 0 0 0 1px var(--hairline);
  transform-origin: top right;
  animation: sheet-in 420ms var(--spring) both;
  overflow: hidden;
}
@keyframes sheet-in { from { opacity: 0; transform: scale(0.92); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }
.screen-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 16px; font-size: 15px; font-weight: 600; letter-spacing: -0.015em; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #ff453a; margin-right: 8px; vertical-align: 1px; animation: breathe 2s ease-in-out infinite; }
.screen-body { padding: 0 10px 10px; }
.screen-body iframe { width: 100%; aspect-ratio: 4 / 3; border: 0; border-radius: 12px; background: #111; display: block; }
.screen-note { margin: 8px 4px 0; font-size: 12px; color: var(--secondary); }

.typing { flex-direction: row; gap: 5px; padding: 10px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--tertiary);
  animation: breathe 1.4s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes breathe { 0%, 100% { opacity: 0.3; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1); } }

/* Empty state */
.hello { padding: 9vh 0 16px; animation: arrive 600ms var(--spring) both; }
.hello h2 {
  margin: 0; font-size: clamp(30px, 6vw, 40px); line-height: 1.08; font-weight: 700; letter-spacing: -0.035em;
}
.hello p { margin: 10px 0 26px; color: var(--secondary); font-size: 17px; max-width: 30em; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.suggestion {
  text-align: left;
  background: var(--surface);
  border-radius: 16px; padding: 14px 16px;
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--hairline);
  display: flex; flex-direction: column; gap: 3px;
}
.suggestion:hover { background: color-mix(in srgb, var(--surface) 92%, var(--accent)); }
.suggestion b { font-size: 15px; font-weight: 600; letter-spacing: -0.015em; }
.suggestion span { font-size: 13px; color: var(--secondary); letter-spacing: -0.005em; }

/* ---------- Composer ---------- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 0 10px;
  scrollbar-width: none;
  mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none;
  background: var(--fill); color: var(--text);
  border-radius: 999px; padding: 6px 13px;
  font-size: 14px; font-weight: 500; letter-spacing: -0.01em;
}
.chips button:hover { background: var(--fill-strong); }
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface);
  border-radius: 22px;
  padding: 5px 5px 5px 16px;
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--hairline);
}
.composer:focus-within { box-shadow: var(--shadow-sm), 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent); }
textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 17px; line-height: 1.4; color: var(--text);
  padding: 7px 0; max-height: 180px;
}
textarea::placeholder { color: var(--tertiary); }
#send {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
}
#send:disabled { background: var(--fill-strong); color: var(--tertiary); cursor: default; }

.jump {
  position: absolute; z-index: 6; left: 50%;
  bottom: calc(var(--composer-h) + env(safe-area-inset-bottom) + 8px);
  transform: translateX(-50%);
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--material); color: var(--text);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  display: grid; place-items: center;
  animation: arrive var(--t-med) var(--spring) both;
}
.jump:active { transform: translateX(-50%) scale(0.92); }

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .msg, .hello, .login-card, .jump { animation: fade 200ms ease both !important; }
  .typing span { animation: none !important; opacity: 0.6; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
}
@media (prefers-reduced-transparency: reduce) {
  .bar, .jump { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --hairline: rgba(127, 127, 127, 0.6); --secondary: var(--text); --tertiary: var(--text); }
  .bar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (max-width: 520px) {
  body { font-size: 16px; }
  .messages { padding-left: 16px; padding-right: 16px; }
  .msg.you .bubble { max-width: 85%; }
  .suggestions { grid-template-columns: 1fr 1fr; }
  .suggestion { padding: 12px 13px; }
}

/* The container shows focus for these fields; no second ring inside it. */
.composer textarea:focus-visible, .pw-row input:focus-visible { outline: none; }
