:root {
  color-scheme: light;
  --page: oklch(96.5% 0.012 91);
  --panel: oklch(99% 0.008 88);
  --panel-strong: oklch(94% 0.018 92);
  --ink: oklch(24% 0.035 77);
  --ink-soft: oklch(36% 0.03 75);
  --muted: oklch(50% 0.026 73);
  --soft: oklch(74% 0.032 78);
  --accent: oklch(58% 0.135 151);
  --accent-strong: oklch(45% 0.12 153);
  --accent-soft: oklch(89% 0.06 151);
  --blue: oklch(54% 0.12 245);
  --blue-soft: oklch(90% 0.045 245);
  --danger: oklch(54% 0.16 25);
  --warn: oklch(72% 0.13 70);
  --shadow: 0 24px 70px oklch(32% 0.035 75 / 14%);
  --shadow-soft: 0 12px 30px oklch(32% 0.035 75 / 8%);
  --ring: 0 0 0 4px oklch(58% 0.135 151 / 18%);
  --radius: 22px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, oklch(88% 0.08 151 / 45%), transparent 34rem),
    radial-gradient(circle at 85% 12%, oklch(88% 0.07 245 / 38%), transparent 28rem),
    linear-gradient(135deg, var(--page), oklch(94% 0.018 72));
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ------------------------------------------------------------------ */
/* Top bar */
/* ------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: oklch(99% 0.008 88 / 80%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid oklch(86% 0.02 75 / 60%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: oklch(58% 0.18 30);
  color: white;
  font-weight: 800;
  letter-spacing: 0.05em;
  font-size: 13px;
}

.brand-divider {
  color: var(--soft);
}

.brand-label {
  color: var(--ink-soft);
}

.profile-form {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.profile-form label {
  color: var(--muted);
  font-weight: 500;
}

.profile-form input,
.profile-form select {
  width: 320px;
  padding: 8px 12px;
  border: 1px solid oklch(86% 0.02 75);
  border-radius: 999px;
  background: var(--panel);
  outline: none;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.profile-form input:focus-visible,
.profile-form select:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--ring);
}

#view-profile-button {
  padding: 8px 16px;
  border: 1px solid oklch(86% 0.02 75);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

#view-profile-button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

#reload-button {
  padding: 8px 18px;
  border: none;
  border-radius: 999px;
  background: var(--ink);
  color: var(--page);
  font-weight: 600;
  transition: background 0.2s ease, transform 0.2s ease;
}

#reload-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

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

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 96px;
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.block {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.block-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.block-personal {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--accent-strong);
  text-transform: none;
  font-weight: 500;
}

.block-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.filter-chips[hidden] {
  display: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 9px;
  border-radius: 999px;
  background: oklch(93% 0.035 151);
  color: var(--accent-strong);
  border: 1px solid oklch(84% 0.045 151);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------------ */
/* Status card */
/* ------------------------------------------------------------------ */

.status-card {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid oklch(89% 0.025 75);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.status-card.fade-out {
  opacity: 0;
  transform: translateY(-6px);
}

.status-card[data-tone="error"] {
  border-color: oklch(80% 0.13 28);
  background: oklch(96% 0.04 30);
}

.status-card[data-tone="done"] {
  border-color: var(--accent-soft);
  background: oklch(96% 0.04 151);
}

.status-orbit {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.status-orbit span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  animation: spin 1.6s linear infinite;
}

.status-orbit span:nth-child(2) {
  inset: 5px;
  border-top-color: var(--blue);
  animation-duration: 2.1s;
  animation-direction: reverse;
}

.status-orbit span:nth-child(3) {
  inset: 10px;
  border-top-color: var(--warn);
  animation-duration: 2.6s;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.status-eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.status-text {
  margin: 2px 0 0;
  font-weight: 500;
  color: var(--ink);
}

/* ------------------------------------------------------------------ */
/* Shimmer / skeletons */
/* ------------------------------------------------------------------ */

.shimmer {
  position: relative;
  background: linear-gradient(
    90deg,
    oklch(92% 0.018 80),
    oklch(96% 0.015 80),
    oklch(92% 0.018 80)
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.shimmer.wide { height: 18px; width: 70%; }
.shimmer.block { height: 120px; width: 100%; border-radius: 14px; }

/* ------------------------------------------------------------------ */
/* Tiles */
/* ------------------------------------------------------------------ */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid oklch(90% 0.02 75);
  box-shadow: var(--shadow-soft);
  min-height: 200px;
  color: var(--ink);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.tile-shortcut {
  background: linear-gradient(150deg, var(--panel), oklch(95% 0.025 151));
  text-decoration: none;
}

.tile-shortcut:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--accent-soft);
}

.tile-personal-line {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
  font-weight: 600;
}

.tile-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
}

.tile-emoji {
  font-size: 30px;
  line-height: 1;
}

.tile-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.tile-query {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-filter-chips {
  margin-top: auto;
}

.tile-filter-chips .filter-chip {
  background: var(--panel-strong);
  border-color: oklch(86% 0.025 75);
  color: var(--muted);
}

.tile-cta {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--accent-strong);
  color: white;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.2s ease, transform 0.2s ease;
}

.tile-shortcut:hover .tile-cta {
  background: var(--accent);
  transform: translateX(2px);
}

/* Tile skeleton */
.tile-skeleton {
  pointer-events: none;
}

.tile-skeleton .tile-emoji {
  width: 40px;
  height: 40px;
  border-radius: 12px;
}

.tile-skeleton .tile-line {
  height: 12px;
  width: 50%;
}

.tile-skeleton .tile-title {
  height: 22px;
}

.tile-skeleton .tile-cta {
  margin-top: auto;
  height: 30px;
  width: 140px;
  background: transparent;
  padding: 0;
  color: transparent;
}

/* ------------------------------------------------------------------ */
/* Chat tile */
/* ------------------------------------------------------------------ */

.chat-tile {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 22px 26px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, oklch(94% 0.04 248), oklch(96% 0.03 200));
  border: 1px solid oklch(86% 0.05 240);
  box-shadow: var(--shadow-soft);
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  width: 100%;
  color: var(--ink);
  font: inherit;
}

.chat-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.chat-ai-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  font-weight: 800;
  letter-spacing: 0.06em;
  font-size: 12px;
  flex-shrink: 0;
}

.chat-tile-body {
  flex: 1;
  min-width: 0;
}

.chat-tile-eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.chat-tile-topic {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.chat-tile-question {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.chat-tile-cta {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-tile-skeleton {
  pointer-events: none;
}

.chat-tile-skeleton .chat-topic {
  height: 22px;
  width: 60%;
  border-radius: 8px;
}

.chat-tile-skeleton .chat-question {
  height: 14px;
  width: 80%;
  border-radius: 8px;
}

/* ------------------------------------------------------------------ */
/* Feed */
/* ------------------------------------------------------------------ */

.feed {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.feed-card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid oklch(90% 0.02 75);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.feed-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.feed-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: oklch(88% 0.02 80);
  background-size: cover;
  background-position: center;
}

.feed-image.missing {
  background: repeating-linear-gradient(45deg, oklch(88% 0.02 80), oklch(88% 0.02 80) 10px, oklch(91% 0.018 80) 10px, oklch(91% 0.018 80) 20px);
}

.feed-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px 18px;
}

.feed-card-title {
  margin: 0;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.feed-card-meta {
  margin: 0;
  font-size: 13px;
  color: var(--accent-strong);
  font-weight: 500;
}

.feed-card-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.feed-skeleton .feed-image {
  background-image: linear-gradient(90deg, oklch(92% 0.018 80), oklch(96% 0.015 80), oklch(92% 0.018 80));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.feed-title-line { height: 16px; }
.feed-meta-line { height: 12px; width: 60%; }
.feed-desc-line { height: 12px; width: 90%; }

.feed-loader {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}

.feed-end {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 18px;
}

.feed-sentinel {
  height: 1px;
}

/* ------------------------------------------------------------------ */
/* Typing dots */
/* ------------------------------------------------------------------ */

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

.dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing 1.1s ease-in-out infinite;
}

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

@keyframes typing {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.6; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* ------------------------------------------------------------------ */
/* Inline chat (beneath the chat tile) */
/* ------------------------------------------------------------------ */

.chat-inline {
  margin-top: 14px;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid oklch(89% 0.025 75);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-inline.open {
  opacity: 1;
  transform: translateY(0);
}

.chat-inline .chat-thread {
  max-height: 360px;
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: oklch(98% 0.012 88);
}

.chat-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-msg p {
  margin: 0;
}

.chat-msg h4 {
  margin: 2px 0 6px;
  font-size: 14px;
  font-weight: 700;
}

.chat-msg ul,
.chat-msg ol {
  margin: 4px 0 0;
  padding-left: 18px;
}

.chat-msg li + li {
  margin-top: 4px;
}

.chat-msg code {
  padding: 1px 5px;
  border-radius: 6px;
  background: oklch(90% 0.018 80);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.chat-msg pre {
  margin: 6px 0 0;
  padding: 10px 12px;
  overflow-x: auto;
  border-radius: 10px;
  background: oklch(88% 0.018 80);
}

.chat-msg pre code {
  padding: 0;
  background: transparent;
}

.chat-msg a {
  color: var(--blue);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--panel-strong);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--blue);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg.typing {
  padding: 12px 14px;
}

.chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid oklch(89% 0.025 75);
  background: var(--panel);
}

.chat-input input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid oklch(86% 0.02 75);
  border-radius: 999px;
  background: var(--panel-strong);
  outline: none;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.chat-input input:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px oklch(54% 0.12 245 / 18%);
}

#chat-send {
  padding: 10px 18px;
  border-radius: 999px;
  border: none;
  background: var(--blue);
  color: white;
  font-weight: 600;
}

#chat-send:hover {
  background: oklch(46% 0.14 245);
}

/* ------------------------------------------------------------------ */
/* Responsive */
/* ------------------------------------------------------------------ */

@media (max-width: 900px) {
  .tiles {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .profile-form input,
  .profile-form select {
    width: 100%;
    min-width: 0;
  }
  .profile-form {
    width: 100%;
  }
}
