:root {
  --spacing-1: 8px;
  --spacing-2: 12px;
  --spacing-3: 20px;
  --radius: 16px;
  --radius-sm: 12px;
  --top-right-safe: 88px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg-main: radial-gradient(1200px 800px at 50% -10%, #1b2433 0%, #0b0f17 45%, #070a10 100%);
  --bg-card: rgba(255, 255, 255, 0.03);
  --border-card: rgba(255, 255, 255, 0.08);
  --shadow: rgba(0, 0, 0, 0.45);
  --text-primary: #e6ebf2;
  --text-secondary: #9aa4b2;
  --text-muted: #6b7280;
  --accent: #4fa3ff;
  --accent-soft: #2b6cb0;
  --danger: #ff6b6b;
  --input-bg: rgba(255, 255, 255, 0.04);
  --input-border: rgba(255, 255, 255, 0.12);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-main: linear-gradient(180deg, #f7f8fb 0%, #eef1f6 100%);
  --bg-card: #ffffff;
  --border-card: #dbe1ea;
  --shadow: rgba(15, 23, 42, 0.12);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #1d4ed8;
  --danger: #dc2626;
  --input-bg: #f8fafc;
  --input-border: #cbd5e1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 900ms ease, background-color 900ms ease, color 900ms ease;
}

main {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding-inline: clamp(20px, 3vw, 48px);
  padding-right: calc(clamp(20px, 3vw, 48px) + var(--top-right-safe));
  padding-block: 24px 48px;
  position: relative;
}

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

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: var(--spacing-3);
  box-shadow: 0 16px 40px var(--shadow);
  transition: background-color 900ms ease, color 900ms ease, border-color 900ms ease, box-shadow 900ms ease, transform 180ms ease;
}

[data-motion-tier="0"] * {
  transition: none !important;
  animation: none !important;
}

[data-motion-tier="0"] .card {
  transition: none !important;
}

[data-motion-tier="2"] .card {
  box-shadow: 0 18px 46px var(--shadow);
}

.card-fixed {
  height: 340px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

@media (min-width: 901px) {
  .layout {
    grid-template-columns: repeat(2, minmax(320px, 1fr));
  }
}

@media (min-width: 1200px) {
  .layout {
    grid-template-columns: repeat(3, minmax(320px, 1fr));
  }
}

.card-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  perspective: 1200px;
}

.card-body .card-scroll {
  flex: 1;
}

.search-results-pane {
  min-height: 120px;
  overflow: auto;
  border-top: 1px solid var(--border-card);
  padding-top: 8px;
  color: var(--text-primary);
}

.search-results-pane ul {
  color: var(--text-primary);
  line-height: 1.4;
}

.card-body .stack {
  flex: 1;
  min-height: 0;
}

.stack .card-scroll {
  flex: 1;
  min-height: 0;
}

.card-expand-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-card);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.card-expand-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px var(--shadow);
  background: rgba(255, 255, 255, 0.08);
}

.card-expanded {
  grid-column: span 2;
  grid-row: span 2;
  min-height: 420px;
  box-shadow: 0 18px 46px var(--shadow);
  transform: translateZ(0);
}

@media (max-width: 900px) {
  .card-expanded {
    grid-column: span 1;
    grid-row: span 1;
    min-height: 360px;
  }
}

.card-focus {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  min-height: calc(100vh - 120px);
  z-index: 2;
}

.card-hidden {
  display: none !important;
}

@media (min-width: 901px) {
  .ai-card.card-expanded {
    min-height: calc(100vh - 140px);
  }
}

@media (max-width: 900px) {
  .card-expanded {
    grid-column: span 1;
    grid-row: span 1;
    min-height: 360px;
  }
}

.search-card .card-body {
  display: flex;
  flex-direction: column;
}

.search-card .search {
  flex: 0 0 auto;
  gap: 8px;
}

.search-card .card-view {
  position: absolute;
  inset: 0;
}

.search-card .card-view-results {
  padding-top: 6px;
}

.search-card .card-scroll {
  flex: 1;
  min-height: 0;
}

.card-swap .card-body {
  position: relative;
}

.card-view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 160ms ease, transform 160ms ease;
}

.card-view-controls {
  position: relative;
}

.card-view.is-hidden {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 400ms ease;
}

.card.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}

.face.back {
  transform: rotateY(180deg);
}

.card-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-scroll {
  overflow: auto;
  flex: 1;
  min-height: 0;
  padding-right: 4px;
}

.card-scroll::-webkit-scrollbar {
  width: 6px;
}

.card-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.card-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.ai-card {
  display: flex;
  flex-direction: column;
  height: 340px;
}

.ai-card .ai-stack {
  flex: 1;
  min-height: 0;
  gap: 10px;
}

.ai-chat {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  line-height: 1.4;
  min-height: 0;
}

.ai-chat-empty {
  color: var(--text-muted);
}

.chat-message {
  padding: 8px 10px;
  border-radius: 10px;
  max-width: 100%;
  word-wrap: break-word;
}

.chat-message.user {
  align-self: flex-end;
  background: rgba(79, 163, 255, 0.18);
  border: 1px solid var(--accent);
  color: var(--text-primary);
}

.chat-message.ai {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-card);
  color: var(--text-primary);
}

.chat-message.error {
  border-color: var(--danger);
  color: var(--danger);
}

.chat-message.pending {
  opacity: 0.9;
  font-style: italic;
}

.ai-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-input {
  flex: 0 0 auto;
  min-height: 64px;
  max-height: 120px;
}

.ai-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-actions .button {
  padding: 8px 14px;
  font-size: 14px;
}

.ai-actions .notice {
  min-height: 18px;
  max-height: 54px;
  overflow: auto;
}

.ai-disclaimer {
  flex: 0 0 auto;
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-muted);
  white-space: normal;
}

.subtitle {
  margin: -6px 0 10px 0;
  color: var(--text-secondary);
  font-size: 14px;
  letter-spacing: 0.2px;
}

h2 {
  margin: 0 0 12px 0;
}

h1 {
  margin: 0 0 16px 0;
  font-size: 32px;
  letter-spacing: 0.5px;
}

.section-title {
  margin: 0 0 12px 0;
  font-size: 20px;
  letter-spacing: 0.3px;
}

.search {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-1);
}

.search label {
  font-size: 12px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.search input,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 16px;
  transition: background-color 750ms ease, color 750ms ease, border-color 750ms ease;
}

textarea {
  min-height: 110px;
  resize: vertical;
  font-size: 15px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2);
}

.disclaimer,
.notice {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.notice {
  min-height: 16px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--spacing-2);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-1);
}

.muted {
  color: var(--text-muted);
  font-size: 12px;
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.subhead {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin: 0 0 8px 0;
}

.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
}

.hidden {
  display: none;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

.card:focus-within {
  transform: translateY(-3px);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }

  .card:hover,
  .card:focus-within {
    transform: none;
    box-shadow: 0 16px 40px var(--shadow);
  }

  body,
  .card,
  .card *,
  .face {
    transition: none !important;
  }
}

@media (min-width: 901px) and (max-width: 1200px) {
  body {
    display: flex;
    align-items: center;
  }

  main {
    width: 100%;
  }

  .layout {
    grid-template-columns: repeat(2, minmax(320px, 1fr));
  }
}

@media (min-width: 1201px) and (max-width: 1800px) {
  body {
    display: flex;
    align-items: center;
  }

  main {
    width: 100%;
  }

  .layout {
    grid-template-columns: repeat(3, minmax(320px, 1fr));
  }
}

@media (min-width: 1801px) {
  body {
    display: flex;
    align-items: center;
  }

  main {
    width: 100%;
  }

  .layout {
    grid-template-columns: repeat(4, minmax(320px, 1fr));
  }
}
[data-motion-tier="0"] * {
  transition: none !important;
  animation: none !important;
}

[data-motion-tier="0"] .card {
  transition: none !important;
}

[data-motion-tier="2"] .card {
  box-shadow: 0 18px 46px var(--shadow);
}
