:root,
:root[data-theme="light"] {
  --ty-bg:           #ffffff;
  --ty-bg-elev:      #ffffff;
  --ty-bg-soft:      #f1f3f4;
  --ty-bg-hover:     #f6f8fa;
  --ty-line:         #e4e7eb;
  --ty-line-strong:  #d2d7dc;
  --ty-text:         #1f1f1f;
  --ty-text-soft:    #444746;
  --ty-text-muted:   #80868b;
  --ty-accent:       #1a73e8;
  --ty-accent-soft:  #e8f0fe;
  --ty-accent-strong:#1967d2;
  --ty-on-accent:    #ffffff;
  --ty-good:         #1e8e3e;
  --ty-bad:          #d93025;
  --ty-shadow-pill:  0 1px 6px rgba(32, 33, 36, .08);
  --ty-shadow-pill-hover: 0 2px 8px rgba(32, 33, 36, .15);
  --ty-mono:         "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --ty-bg:           #131314;
  --ty-bg-elev:      #1e1f20;
  --ty-bg-soft:      #1e1f20;
  --ty-bg-hover:     #2a2b2d;
  --ty-line:         #2a2b2d;
  --ty-line-strong:  #3c4043;
  --ty-text:         #e8eaed;
  --ty-text-soft:    #c4c7c5;
  --ty-text-muted:   #9aa0a6;
  --ty-accent:       #8ab4f8;
  --ty-accent-soft:  rgba(138, 180, 248, 0.16);
  --ty-accent-strong:#a8c7fa;
  --ty-on-accent:    #062147;
  --ty-good:         #81c995;
  --ty-bad:          #f28b82;
  --ty-shadow-pill:  0 1px 4px rgba(0, 0, 0, .35);
  --ty-shadow-pill-hover: 0 2px 8px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--ty-bg);
  color: var(--ty-text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#app, .ty-shell { height: 100%; }

.ty-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--ty-bg);
}

/* ───── header ───────────────────────────────────────────────────── */
.ty-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  background: transparent;
  position: relative;
  z-index: 2;
}

.ty-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: inherit;
}
.ty-brand-mark {
  width: 28px; height: 28px;
  display: inline-block;
  line-height: 0;
}
.ty-brand-mark svg { width: 100%; height: 100%; display: block; }
.ty-brand-name {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.1px;
  color: var(--ty-text);
}
.ty-brand-ai {
  font-weight: 700;
  color: #ed2939;
}

.ty-header-actions { display: flex; align-items: center; gap: 4px; }

.ty-icon-btn {
  background: transparent;
  border: none;
  color: var(--ty-text-soft);
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  width: 36px; height: 36px;
  transition: background 120ms ease, color 120ms ease;
}
.ty-icon-btn:hover {
  background: var(--ty-bg-hover);
  color: var(--ty-text);
}
.ty-icon-btn svg { width: 18px; height: 18px; display: block; }
.ty-icon-btn .ty-icon-moon { display: none; }
.ty-icon-btn .ty-icon-sun  { display: block; }
:root[data-theme="dark"] .ty-icon-btn .ty-icon-sun  { display: none; }
:root[data-theme="dark"] .ty-icon-btn .ty-icon-moon { display: block; }

/* ───── main / chat ──────────────────────────────────────────────── */
.ty-main {
  flex: 1;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.ty-chat {
  width: min(720px, 100%);
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0 24px;
}

/* In Empty-Mode wandert das Input + Hero in die Mitte — wie Google. */
.ty-chat.is-empty .ty-chat-log { display: flex; align-items: center; justify-content: center; }
.ty-chat.is-empty .ty-input-zone { padding-bottom: 14vh; }

/* ───── empty / hero ─────────────────────────────────────────────── */
.ty-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.ty-chat-empty {
  text-align: center;
  color: var(--ty-text-muted);
}
.ty-hero-svg {
  display: block;
  width: clamp(280px, 42vw, 440px);
  height: auto;
  margin: 0 auto 8px;
}
.ty-hero-wordmark-text { fill: var(--ty-text); }
.ty-tagline {
  font-size: 16px;
  margin: 0;
  color: var(--ty-text-muted);
  letter-spacing: -0.1px;
}

/* ───── messages ─────────────────────────────────────────────────── */
.ty-turn { display: flex; gap: 12px; align-items: flex-start; }
.ty-turn.is-user { flex-direction: row-reverse; }
.ty-turn.is-user .ty-bubble {
  background: var(--ty-accent-soft);
  color: var(--ty-text);
  border-color: transparent;
}
.ty-turn.is-assistant .ty-bubble {
  background: transparent;
  border: none;
  padding: 4px 0;
  box-shadow: none;
  max-width: 100%;
}
.ty-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--ty-bg-soft);
  color: var(--ty-text-soft);
  font-size: 10.5px;
  font-weight: 600;
  flex-shrink: 0;
}
.ty-turn.is-assistant .ty-avatar {
  background: var(--ty-accent);
  color: var(--ty-on-accent);
}
.ty-bubble {
  background: var(--ty-bg-soft);
  border: 1px solid transparent;
  border-radius: 18px;
  padding: 10px 14px;
  max-width: 78%;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ty-bubble-text { display: block; white-space: pre-wrap; }

.ty-code {
  background: var(--ty-bg-soft);
  border: 1px solid var(--ty-line);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: var(--ty-mono);
  font-size: 12.5px;
  line-height: 1.45;
}
.ty-code code { color: var(--ty-text); white-space: pre; }

.ty-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.ty-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ty-accent);
  animation: ty-bounce 1.2s infinite ease-in-out;
}
.ty-typing span:nth-child(2) { animation-delay: 0.2s; }
.ty-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ty-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1;   }
}

.ty-trace-collapsed {
  background: var(--ty-bg-soft);
  border: 1px solid var(--ty-line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
}
.ty-trace-collapsed summary { color: var(--ty-text-muted); cursor: pointer; user-select: none; }
.ty-trace { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.ty-trace-step {
  display: grid; grid-template-columns: 100px 1fr 60px;
  gap: 10px;
  padding: 5px 8px;
  background: var(--ty-bg);
  border: 1px solid var(--ty-line);
  border-radius: 6px;
  font-family: var(--ty-mono);
  font-size: 12px;
}
.ty-trace-stage { color: var(--ty-text-muted); }
.ty-trace-weight { color: var(--ty-accent); text-align: right; }

/* ───── input zone (pill + chips + tiny status) ─────────────────── */
.ty-input-zone {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 0 16px;
  background: var(--ty-bg);
}

.ty-chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ty-bg-elev);
  border: 1px solid var(--ty-line);
  border-radius: 999px;
  padding: 4px 6px 4px 18px;
  box-shadow: var(--ty-shadow-pill);
  transition: box-shadow 160ms ease, border-color 160ms ease;
}
.ty-chat-input:hover { box-shadow: var(--ty-shadow-pill-hover); }
.ty-chat-input:focus-within {
  border-color: var(--ty-accent);
  box-shadow: var(--ty-shadow-pill-hover);
}
.ty-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--ty-text);
  padding: 12px 0;
  font-size: 15px;
  font-family: inherit;
}
.ty-input::placeholder { color: var(--ty-text-muted); }
.ty-input:focus { outline: none; }
.ty-input:disabled { opacity: 0.6; }

.ty-send {
  background: var(--ty-accent);
  color: var(--ty-on-accent);
  border: none;
  border-radius: 50%;
  width: 38px; height: 38px;
  display: inline-grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 120ms ease, transform 120ms ease;
}
.ty-send:hover:not(:disabled) { background: var(--ty-accent-strong); }
.ty-send:disabled {
  background: var(--ty-bg-soft);
  color: var(--ty-text-muted);
  cursor: not-allowed;
}
.ty-send svg { width: 18px; height: 18px; display: block; }
.ty-send-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--ty-text-muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: ty-spin 0.75s linear infinite;
}
@keyframes ty-spin { to { transform: rotate(360deg); } }

.ty-prompts {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.ty-prompt {
  background: var(--ty-bg-elev);
  border: 1px solid var(--ty-line);
  color: var(--ty-text-soft);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.ty-prompt:hover {
  background: var(--ty-bg-hover);
  border-color: var(--ty-line-strong);
  box-shadow: var(--ty-shadow-pill);
}

.ty-chat-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px;
  color: var(--ty-text-muted);
  justify-content: center;
  padding: 2px 8px;
}
.ty-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ty-text-muted);
  flex-shrink: 0;
}
.ty-dot.is-on { background: var(--ty-good); }
.ty-dot.is-busy { background: var(--ty-accent); animation: ty-pulse 1.6s infinite; }
.ty-dot.is-off { background: var(--ty-bad); }
.ty-status-text { color: var(--ty-text-muted); }
.ty-status-sub em { color: var(--ty-text-soft); font-style: normal; font-weight: 500; }

@keyframes ty-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(26,115,232,0.35); }
  70%  { box-shadow: 0 0 0 7px rgba(26,115,232,0); }
  100% { box-shadow: 0 0 0 0 rgba(26,115,232,0); }
}

/* ───── responsive ───────────────────────────────────────────────── */
@media (max-width: 720px) {
  body { font-size: 14px; }

  .ty-header { padding: 8px 14px; }
  .ty-brand-name { font-size: 15px; }

  .ty-chat { padding: 0 14px; }
  .ty-chat.is-empty .ty-input-zone { padding-bottom: 6vh; }

  .ty-hero { font-size: clamp(48px, 16vw, 72px); letter-spacing: -1.5px; }

  .ty-turn { gap: 8px; }
  .ty-bubble { max-width: 88%; padding: 9px 12px; border-radius: 16px; }
  .ty-avatar { width: 26px; height: 26px; font-size: 10px; }

  .ty-code { font-size: 11.5px; padding: 9px 10px; }

  .ty-trace-step {
    grid-template-columns: 72px 1fr 48px;
    gap: 6px;
    font-size: 11px;
    padding: 4px 6px;
  }

  .ty-chat-input { padding: 4px 6px 4px 14px; }
  .ty-input { padding: 11px 0; font-size: 16px; }
  .ty-send { width: 36px; height: 36px; }
  .ty-prompt { padding: 6px 12px; font-size: 12.5px; }
  .ty-input-zone {
    padding: 10px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

/* ===========================================================
   Header navigation
   =========================================================== */
.ty-nav {
  display: flex;
  gap: 4px;
  margin-left: 24px;
  flex: 1;
}

.ty-nav-link {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--ty-text-muted, #6b7280);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.ty-nav-link:hover {
  background: var(--ty-bg-soft, rgba(0, 0, 0, 0.05));
  color: var(--ty-text, #111827);
}

.ty-nav-link.active {
  background: var(--ty-bg-soft, rgba(0, 0, 0, 0.06));
  color: var(--ty-text, #111827);
}

/* ===========================================================
   Training dashboard
   =========================================================== */
.ty-training {
  width: min(1200px, 100%);
  height: 100%;
  overflow-y: auto;
  padding: 24px 32px 64px;
  box-sizing: border-box;
  color: var(--ty-text, #111827);
}

.ty-training-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.ty-training-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.ty-training-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.ty-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-transform: uppercase;
}

.ty-pill-ok { background: #dcfce7; color: #166534; }
.ty-pill-warn { background: #fef3c7; color: #92400e; }
.ty-pill-err { background: #fee2e2; color: #991b1b; }

.ty-muted { color: var(--ty-text-muted, #6b7280); }
.ty-ok { color: #16a34a; font-weight: 600; }
.ty-warn { color: #d97706; font-weight: 600; }

/* Status cards grid */
.ty-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.ty-card {
  padding: 16px 18px;
  border-radius: 12px;
  background: var(--ty-bg-soft, rgba(0, 0, 0, 0.03));
  border: 1px solid var(--ty-border, rgba(0, 0, 0, 0.06));
}

.ty-card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ty-text-muted, #6b7280);
  margin-bottom: 6px;
}

.ty-card-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
  margin-bottom: 4px;
}

.ty-card-sub {
  font-size: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Loss sparkline */
.ty-chart-block {
  background: var(--ty-bg-soft, rgba(0, 0, 0, 0.03));
  border: 1px solid var(--ty-border, rgba(0, 0, 0, 0.06));
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 24px;
}

.ty-chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ty-text-muted, #6b7280);
  margin-bottom: 12px;
}

.ty-sparkline {
  width: 100%;
  height: 180px;
  color: #E30613;
  display: block;
}

.ty-chart-axis {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  margin-top: 6px;
}

/* AutoTune section */
.ty-autotune {
  background: var(--ty-bg-soft, rgba(0, 0, 0, 0.03));
  border: 1px solid var(--ty-border, rgba(0, 0, 0, 0.06));
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 24px;
}

.ty-autotune-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}

.ty-autotune-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.ty-phase-list {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px;
}

.ty-phase {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--ty-bg, rgba(255, 255, 255, 0.5));
  border: 1px solid var(--ty-border, rgba(0, 0, 0, 0.06));
  font-size: 12px;
}

.ty-phase.is-done {
  opacity: 0.55;
}

.ty-phase.is-done .ty-phase-idx::before { content: "✓ "; }

.ty-phase.is-active {
  border-color: #E30613;
  background: rgba(227, 6, 19, 0.06);
  font-weight: 600;
}

.ty-phase-idx {
  font-variant-numeric: tabular-nums;
  color: var(--ty-text-muted, #6b7280);
  font-size: 11px;
  width: 18px;
}

.ty-phase-name {
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.ty-autotune-health {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  font-size: 12px;
}

.ty-autotune-health > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Workers table */
.ty-workers {
  margin-bottom: 24px;
}

.ty-workers h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
}

.ty-worker-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.ty-worker-table th,
.ty-worker-table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--ty-border, rgba(0, 0, 0, 0.06));
}

.ty-worker-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ty-text-muted, #6b7280);
}

.ty-worker-table code {
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--ty-bg-soft, rgba(0, 0, 0, 0.04));
  padding: 2px 6px;
  border-radius: 4px;
}

@media (max-width: 768px) {
  .ty-training { padding: 16px; }
  .ty-training-header h1 { font-size: 22px; }
  .ty-card-value { font-size: 22px; }
  .ty-nav { margin-left: 12px; }
  .ty-nav-link { padding: 6px 10px; font-size: 13px; }
}
