/* ===========================================================================
   kamal.agent — minimalist agent-chat interface
   =========================================================================== */

:root {
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", "Cascadia Code",
          "Fira Code", "Roboto Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius: 16px;
  --gap: clamp(14px, 3.5vw, 22px);
  --tap: 40px;
}

html[data-theme="dark"] {
  --bg:        #08090b;
  --panel:     #0e1013;
  --panel-2:   #14171c;
  --border:    #23262d;
  --text:      #eceef1;
  --muted:     #888f9b;
  --user-bg:   #1a1e26;
  --accent:    #45d68b;
  --accent-2:  #5eead4;
  --accent-soft: rgba(69, 214, 139, 0.13);
  --shadow:    0 24px 60px -28px rgba(0, 0, 0, 0.85);
  --glow:      none;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg:        #f4f5f7;
  --panel:     #ffffff;
  --panel-2:   #f1f3f6;
  --border:    #e4e6eb;
  --text:      #14161b;
  --muted:     #6b7280;
  --user-bg:   #eef1f6;
  --accent:    #0f9d58;
  --accent-2:  #0d9488;
  --accent-soft: rgba(15, 157, 88, 0.10);
  --shadow:    0 24px 60px -34px rgba(20, 22, 30, 0.30);
  --glow:      none;
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(1100px 540px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.72;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0px, 3vw, 40px);
}

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

.noscript {
  max-width: 620px; margin: auto; padding: 28px;
  font-family: var(--mono); line-height: 1.7;
}
.noscript a { color: var(--accent); }

/* ---------- shell ---------------------------------------------------------- */

.app {
  width: min(820px, 100%);
  height: min(880px, 100dvh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.app__bar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(var(--panel-2), var(--panel));
  font-family: var(--mono);
  font-size: 13px;
}
.app__id { display: flex; align-items: center; gap: 9px; min-width: 0; }
.diamond { color: var(--accent); font-size: 12px; }
.app__avatar {
  width: 28px; height: 28px; border-radius: 50%;
  object-fit: cover; display: block;
  border: 1px solid var(--border);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.app__name { letter-spacing: 0.04em; }
.app__status {
  color: var(--muted); font-size: 11px; letter-spacing: 0.06em;
  padding-left: 11px; position: relative;
}
.app__status::before {
  content: ""; position: absolute; left: 0; top: 50%;
  width: 6px; height: 6px; margin-top: -3px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 0 var(--accent-2);
  animation: pulse 2.6s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-2) 55%, transparent); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.app__tools { display: flex; align-items: center; gap: 14px; }
.iconbtn {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--muted); cursor: pointer; font-size: 14px;
  display: grid; place-items: center;
  transition: color .18s, border-color .18s, transform .18s;
}
.iconbtn:hover { color: var(--text); border-color: var(--accent); }
.iconbtn:active { transform: scale(0.92); }
.dots { display: flex; gap: 6px; }
.dots i {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1px solid var(--border); display: block;
}

/* ---------- stream --------------------------------------------------------- */

.stream {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--gap) var(--gap) 6px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  scroll-behavior: smooth;
}
.stream::-webkit-scrollbar { width: 9px; }
.stream::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 99px;
  border: 2px solid var(--panel);
}

.msg { display: flex; flex-direction: column; gap: 7px; max-width: 100%; }
.msg__role {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.09em;
  text-transform: lowercase; color: var(--muted);
  display: flex; align-items: center; gap: 7px;
}

.msg--user { align-items: flex-end; animation: rise .32s ease both; }
.msg--user .msg__role { padding-right: 2px; }
.msg--user .bubble {
  background: var(--user-bg);
  border: 1px solid var(--border);
  padding: 11px 16px; border-radius: 14px 14px 4px 14px;
  max-width: 85%; font-size: 15px;
}

.msg--agent { align-items: flex-start; animation: rise .32s ease both; }
.msg--agent .msg__role::before { content: "◆"; color: var(--accent); }
.msg--agent .body { max-width: 100%; }
.msg--agent .body p { margin: 0 0 10px; }
.msg--agent .body p:last-child { margin-bottom: 0; }
.msg--agent .body strong { color: var(--text); font-weight: 650; }
.msg--agent .body a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  transition: color .15s, border-color .15s;
}
.msg--agent .body a:hover { color: var(--accent); border-color: var(--accent); }

@keyframes rise { from { opacity: 0; transform: translateY(9px); } }

/* typewriter caret + thinking indicator */
.caret {
  display: inline-block; width: 0.5em; height: 1.05em;
  background: var(--accent); margin-left: 2px;
  vertical-align: -0.18em; animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.thinking { display: inline-flex; gap: 5px; padding: 4px 0; }
.thinking i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); animation: think 1.1s ease-in-out infinite;
}
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .30s; }
@keyframes think {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- timeline (experience) ----------------------------------------- */

.timeline { list-style: none; margin: 14px 0 2px; padding: 0; }
.timeline li {
  position: relative; padding: 0 0 16px 22px;
  border-left: 1px solid var(--border);
}
.timeline li:last-child { padding-bottom: 0; border-color: transparent; }
.timeline li::before {
  content: ""; position: absolute; left: -4.5px; top: 7px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--panel); border: 1.5px solid var(--accent);
}
.timeline .where { font-weight: 600; color: var(--text); }
.timeline .what { color: var(--muted); font-size: 14px; }

/* ---------- research cards ------------------------------------------------- */

.cards { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.card {
  display: grid;
  grid-template-columns: 152px 1fr;
  gap: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 14px;
  transition: border-color .2s, transform .2s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.card__media {
  width: 152px; height: 110px; border-radius: 8px; overflow: hidden;
  background: var(--bg); border: 1px solid var(--border);
}
.card__media img,
.card__media video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.card__body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.card__title {
  font-size: 15px; font-weight: 650; line-height: 1.35; color: var(--text);
}
.card__venue {
  display: inline-block; align-self: flex-start;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.05em;
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  padding: 1px 7px; border-radius: 999px; margin: 2px 0 1px;
}
.card__desc { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.card__authors {
  font-size: 11.5px; color: var(--muted); font-style: italic; opacity: .8;
}
.card__authors b { font-style: normal; color: var(--text); opacity: 1; }
.card__links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.card__links a {
  font-family: var(--mono); font-size: 11.5px;
  color: var(--text); text-decoration: none;
  border: 1px solid var(--border); border-radius: 7px;
  padding: 3px 9px; transition: border-color .15s, color .15s, background .15s;
}
.card__links a:hover {
  color: var(--accent); border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- news / videos -------------------------------------------------- */

.vidgrid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 6px;
}
.vid {
  position: relative; border: 1px solid var(--border); border-radius: 11px;
  overflow: hidden; background: var(--bg); aspect-ratio: 16 / 9;
  cursor: pointer; text-decoration: none; color: var(--text); display: block;
}
.vid img, .vid iframe {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; border: 0; display: block;
}
.vid__play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 46px; height: 46px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 88%, black);
  color: #fff; display: grid; place-items: center; font-size: 17px;
  box-shadow: 0 6px 22px -6px rgba(0,0,0,.7); transition: transform .18s;
}
.vid:hover .vid__play { transform: translate(-50%, -50%) scale(1.1); }
.vid__meta {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 22px 12px 9px; font-size: 12px; line-height: 1.4;
  background: linear-gradient(transparent, rgba(0,0,0,.82));
  color: #f3f4f6;
}
.vid__meta b {
  display: block; font-family: var(--mono); font-size: 10.5px;
  letter-spacing: .05em; color: var(--accent-2); margin-bottom: 2px;
}
.vid--x .vid__play { background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); }

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

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: linear-gradient(var(--panel), var(--panel-2));
  padding: 12px var(--gap) calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 11px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--mono); font-size: 12.5px;
  color: var(--muted); background: transparent;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 13px; cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.chip::before { content: "/"; color: var(--accent); margin-right: 5px; opacity: .7; }
.chip:hover, .chip:focus-visible {
  color: var(--text); border-color: var(--accent);
  background: var(--accent-soft); outline: none;
}

.prompt {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 4px 4px 14px;
  transition: border-color .18s, box-shadow .18s;
}
.prompt:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.prompt__mark { color: var(--accent); font-family: var(--mono); font-size: 16px; }
.prompt__input {
  flex: 1 1 auto; min-width: 0;
  background: transparent; border: 0; outline: 0;
  color: var(--text); font-family: var(--mono); font-size: 14px;
  padding: 10px 0;
}
.prompt__input::placeholder { color: var(--muted); }
.prompt__send {
  flex: 0 0 auto;
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 9px; cursor: pointer;
  background: var(--accent); color: #fff;
  font-size: 16px; display: grid; place-items: center;
  transition: transform .15s, filter .15s;
}
html[data-theme="light"] .prompt__send { color: #fff; }
.prompt__send:hover { filter: brightness(1.08); }
.prompt__send:active { transform: scale(0.9); }

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

/* ---------- responsive ----------------------------------------------------- */

@media (max-width: 600px) {
  body { padding: 0; }
  .app {
    width: 100%; height: 100dvh;
    border: 0; border-radius: 0; box-shadow: none;
  }
  .card {
    grid-template-columns: 1fr;
  }
  .card__media { width: 100%; height: 168px; }
  .vidgrid { grid-template-columns: 1fr; }
}

/* ---------- motion preferences --------------------------------------------- */

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

/* ---------- 404 page ------------------------------------------------------- */

.nf-body { padding: 24px; }
.nf {
  width: min(520px, 100%); background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 30px;
}
.nf .role {
  font-family: var(--mono); font-size: 11px; letter-spacing: .09em;
  color: var(--muted); margin-bottom: 10px;
}
.nf .role::before { content: "◆ "; color: var(--accent); }
.nf p { margin: 0 0 14px; }
.nf code {
  font-family: var(--mono); font-size: 13px;
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 6px; color: var(--accent);
}
.nf a {
  font-family: var(--mono); font-size: 13px; color: var(--text);
  text-decoration: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 13px; display: inline-block;
  transition: border-color .15s, color .15s;
}
.nf a:hover { color: var(--accent); border-color: var(--accent); }
