:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --text: #16202e;
  --muted: #5b6676;
  --border: #dde3ec;
  --accent: #0a66d8;
  --accent-text: #ffffff;
  --hero-from: #0a3d8f;
  --hero-to: #0a66d8;
  --ok: #138a4b;
  --warn: #b25e00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141c;
    --surface: #161e29;
    --text: #e7edf5;
    --muted: #9aa7b8;
    --border: #2a3646;
    --accent: #4d9bff;
    --accent-text: #0b1420;
    --hero-from: #0b2a5c;
    --hero-to: #12408a;
    --ok: #4cc98a;
    --warn: #f0a24a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: 1.5rem; margin-top: 2.5rem; }
h3 { font-size: 1.1rem; }

code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }

.hero {
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  color: #fff;
  padding: 72px 0 64px;
}
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .8rem; opacity: .85; margin: 0 0 .75rem; }
.lead { font-size: 1.15rem; max-width: 640px; opacity: .95; }

.btn {
  display: inline-block;
  background: #fff;
  color: var(--hero-from);
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  margin-top: .5rem;
}
.btn.small { background: var(--accent); color: var(--accent-text); padding: 8px 14px; margin: 0; }
.btn:disabled { opacity: .6; cursor: wait; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.muted { color: var(--muted); }

.live { margin-top: -32px; position: relative; box-shadow: 0 8px 30px rgba(0,0,0,.12); }
.live h2 { margin-top: 0; }
.live-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 16px 0 0;
}
.grid div { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.grid dt { font-size: .8rem; color: var(--muted); }
.grid dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

.note { margin: 12px 0 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 4px; }

.flow { list-style: none; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.flow li { display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.flow span {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 700;
}
.flow p { margin: 0; }

.cols { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.cols .muted { margin-top: -.5em; font-size: .9rem; }

.pros { padding-left: 1.2em; }
.pros li { margin-bottom: .4em; }

footer { padding: 48px 16px 32px; font-size: .9rem; }

section.card { margin-top: 24px; }
section.card h2 { margin-top: 0; }

.hero-stats { display: flex; flex-wrap: wrap; gap: 24px; margin: 24px 0 8px; }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats span { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.hero-stats small { opacity: .85; max-width: 220px; }

.cols.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.form { display: grid; gap: 12px; margin: 16px 0; }
.form label { display: grid; gap: 4px; font-weight: 600; font-size: .9rem; }
.form input, .form textarea {
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
.form textarea { resize: vertical; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  font-size: .85rem;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
}

.answer {
  white-space: pre-wrap;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  background: var(--bg);
  border-radius: 4px;
}

.entries { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.entries li { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.entries p { margin: 4px 0 0; overflow-wrap: anywhere; }
.entry-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.entry-head .muted { font-size: .85rem; }

.bars { display: flex; align-items: flex-end; gap: 2px; height: 80px; margin-top: 16px; }
.bars:empty { display: none; }
.bars span { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-width: 2px; }
.bars span.fail { background: var(--warn); }

a { color: var(--accent); }

.banner {
  background: var(--accent);
  color: var(--accent-text);
  text-align: center;
  font-weight: 600;
  padding: 10px 16px;
}

.generated { margin: 16px 0 0; }
.generated img { display: block; width: 100%; max-width: 512px; border-radius: 12px; border: 1px solid var(--border); }
.generated figcaption { margin-top: 6px; font-size: .9rem; }

/* Charts */
.chart { position: relative; }
.chart-title { margin-top: 20px; }
.tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  white-space: nowrap;
  background: var(--text);
  color: var(--bg);
  font-size: .85rem;
  padding: 4px 8px;
  border-radius: 6px;
}

.hbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center; padding: 3px 0; outline-offset: 2px; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.hbar-track { height: 14px; }
.hbar-fill { display: block; height: 100%; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbar-value { font-size: .9rem; font-variant-numeric: tabular-nums; color: var(--muted); }

.vbars-max { font-size: .8rem; }
.vbars { display: flex; align-items: flex-end; gap: 2px; height: 160px; border-bottom: 1px solid var(--border); }
.vbar-col { flex: 1; height: 100%; display: flex; align-items: flex-end; outline-offset: 2px; }
.vbar { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.vbar-col:hover .vbar, .vbar-col:focus .vbar, .hbar:hover .hbar-fill, .hbar:focus .hbar-fill { filter: brightness(1.15); }
.vbars-axis { display: flex; gap: 2px; font-size: .7rem; color: var(--muted); }
.vbars-axis span { flex: 1; text-align: center; overflow: visible; white-space: nowrap; }

.table-view { margin-top: 12px; font-size: .9rem; }
.table-view table { border-collapse: collapse; margin-top: 8px; }
.table-view td, .table-view th { padding: 2px 16px 2px 0; text-align: left; }

/* Admin */
.admin-bar { background: var(--surface); border-bottom: 1px solid var(--border); }
.admin-bar-inner { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; align-items: center; padding-top: 12px; padding-bottom: 12px; }
.admin-bar nav { display: flex; gap: 16px; align-items: center; }
.link-btn { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.danger-text { color: var(--warn); margin-left: auto; }
.btn.danger { background: var(--warn); }
.login { max-width: 420px; margin: 48px auto; }
.dash-title { margin-top: 24px; font-size: 1.8rem; }
.tiles dd { font-size: 1.6rem; }
.switch { display: flex !important; grid-template-columns: none; gap: 8px !important; align-items: center; font-weight: 400 !important; }
.switch input { width: auto !important; }

/* ---------- Animations ---------- */

/* Hero: moving gradient and drifting clouds */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(120deg, var(--hero-from), var(--hero-to), #5b3fd6, var(--hero-from));
  background-size: 300% 300%;
  animation: gradientShift 18s ease infinite;
}
.hero-inner { position: relative; z-index: 1; }
.hero-inner > * { animation: fadeUp .8s cubic-bezier(.2, .7, .2, 1) both; }
.hero-inner > :nth-child(2) { animation-delay: .1s; }
.hero-inner > :nth-child(3) { animation-delay: .2s; }
.hero-inner > :nth-child(4) { animation-delay: .3s; }
.hero-inner > :nth-child(5) { animation-delay: .4s; }
.hero-inner > :nth-child(6) { animation-delay: .5s; }

.sky { position: absolute; inset: 0; pointer-events: none; }
.cloud {
  position: absolute;
  left: -260px;
  width: 220px;
  height: 64px;
  border-radius: 64px;
  background: rgba(255, 255, 255, .12);
  animation: drift linear infinite;
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: inherit;
}
.cloud::before { width: 96px; height: 96px; left: 30px; top: -48px; }
.cloud::after { width: 70px; height: 70px; left: 110px; top: -32px; }
.c1 { top: 22%; animation-duration: 46s; }
.c2 { top: 62%; animation-duration: 64s; animation-delay: -30s; transform: scale(.7); }
.c3 { top: 40%; animation-duration: 80s; animation-delay: -55s; transform: scale(1.3); opacity: .7; }
.c4 { top: 82%; animation-duration: 54s; animation-delay: -12s; transform: scale(.5); }

.ad-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  padding: 6px 14px;
  border-radius: 999px;
  color: #fff;
  font-size: .85rem;
  text-decoration: none;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .3);
  backdrop-filter: blur(6px);
  transition: background .2s, transform .2s;
}
.ad-badge:hover { background: rgba(255, 255, 255, .24); transform: translateY(-1px); }

.banner { animation: slideDown .5s ease-out both; }

/* Scroll reveal */
.reveal { opacity: 0; transform: translateY(28px); transition: opacity .7s ease, transform .7s cubic-bezier(.2, .7, .2, 1); }
.reveal.visible { opacity: 1; transform: none; }
.cols > .reveal:nth-child(2), .flow li:nth-child(2) { transition-delay: .1s; }
.cols > .reveal:nth-child(3), .flow li:nth-child(3) { transition-delay: .2s; }
.cols > .reveal:nth-child(4), .flow li:nth-child(4) { transition-delay: .3s; }

/* Hover lift */
.btn { transition: transform .2s, box-shadow .2s, filter .2s; }
.btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0, 0, 0, .18); }
.btn:active:not(:disabled) { transform: translateY(0); }
.cols .card { transition: transform .25s, box-shadow .25s, border-color .25s; }
.cols .card:hover { transform: translateY(-4px); box-shadow: 0 10px 28px rgba(0, 0, 0, .12); border-color: var(--accent); }
.chip { transition: background .2s, color .2s; }
.chip:hover:not(:disabled) { background: var(--accent); color: var(--accent-text); }

/* Live status dot */
.dot { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; background: var(--muted); vertical-align: middle; }
.dot.on { background: var(--ok); animation: pulse 2s ease-out infinite; }
.dot.off { background: var(--warn); }

/* Data flowing through the steps */
.flow span { animation: flowPulse 4s ease-in-out infinite; }
.flow li:nth-child(2) span { animation-delay: 1s; }
.flow li:nth-child(3) span { animation-delay: 2s; }
.flow li:nth-child(4) span { animation-delay: 3s; }

/* Growing bars */
.vbar, .bars span { transform-origin: bottom; animation: growY .7s cubic-bezier(.2, .7, .2, 1) both; }
.hbar-fill { transform-origin: left; animation: growX .8s cubic-bezier(.2, .7, .2, 1) both; }

/* AI typing caret and image loading */
.typing::after { content: "▍"; margin-left: 2px; animation: blink .8s steps(1) infinite; }
.shimmer {
  width: 100%;
  max-width: 512px;
  aspect-ratio: 1;
  margin-top: 16px;
  border-radius: 12px;
  background: linear-gradient(100deg, var(--bg) 30%, var(--border) 50%, var(--bg) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
.generated img { opacity: 0; filter: blur(16px); transform: scale(.97); transition: opacity .8s, filter .8s, transform .8s; }
.generated img.loaded { opacity: 1; filter: none; transform: none; }

/* TiTech Cloud ad */
@property --angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; }
.ad {
  margin-top: 24px;
  padding: 3px;
  border-radius: 18px;
  background: conic-gradient(from var(--angle), #4d9bff, #a46bff, #38e1c4, #4d9bff);
  animation: spin 6s linear infinite;
}
.ad-inner {
  position: relative;
  overflow: hidden;
  border-radius: 15px;
  padding: 28px 24px;
  color: #fff;
  background: radial-gradient(circle at 85% 15%, #3b2a8f 0, transparent 55%), linear-gradient(135deg, #0b1d4a, #12286b);
}
.ad h2 { margin: 8px 0 2px; font-size: 2rem; }
.ad-label { font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; opacity: .7; }
.ad-tagline { margin: 0 0 12px; font-size: 1.15rem; font-weight: 600; background: linear-gradient(90deg, #8ec5ff, #c9a8ff, #7ff0d8); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ad-logo { position: absolute; right: 24px; top: 20px; width: 72px; height: 72px; color: #8ec5ff; animation: float 4s ease-in-out infinite; filter: drop-shadow(0 6px 18px rgba(77, 155, 255, .5)); }
.ad-logo svg { width: 100%; height: 100%; }
.ad-features { list-style: none; padding: 0; margin: 16px 0 20px; display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.ad-features li { padding: 8px 12px; border-radius: 8px; background: rgba(255, 255, 255, .07); }
.ad-features span { margin-right: 6px; }
.ad-cta { position: relative; overflow: hidden; color: #0b1d4a; }
.ad-cta::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .7) 50%, transparent 70%);
  transform: translateX(-100%);
  animation: shine 3.5s ease-in-out infinite;
}
.ad-cta span { display: inline-block; transition: transform .2s; }
.ad-cta:hover span { transform: translateX(4px); }
@media (max-width: 520px) { .ad-logo { width: 48px; height: 48px; right: 16px; } }

@keyframes gradientShift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes drift { to { left: 110%; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: none; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }
@keyframes flowPulse { 0%, 20%, 100% { transform: scale(1); box-shadow: none; } 10% { transform: scale(1.18); box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 25%, transparent); } }
@keyframes growY { from { transform: scaleY(0); } }
@keyframes growX { from { transform: scaleX(0); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes spin { to { --angle: 360deg; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes shine { 0%, 60% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
  .generated img { opacity: 1; filter: none; transform: none; }
}
