/* ai-mirror — base layout & components. Brand colors live in themes.css. */

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

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f8;
  --bg-elev: #ffffff;
  --fg: #111318;
  --fg-soft: #667085;
  --border: #e4e7ec;
  --accent: #10a37f;
  --accent-fg: #ffffff;
  --user-bubble: #f2f4f7;
  --assistant-bubble: transparent;
  --brand-gradient: linear-gradient(135deg, #10a37f, #0e8c6d);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans", "Microsoft YaHei", Roboto, sans-serif;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

button, select, textarea, input {
  font: inherit;
}

button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 72%, white);
  outline-offset: 2px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elev) 94%, transparent);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 720;
  font-size: 15px;
  letter-spacing: 0;
}

.brand-copy { min-width: 0; }
.brand-copy > div:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand .glyph,
.provider-mark,
.msg .avatar {
  background: var(--brand-gradient);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.brand .glyph {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 12px;
}

.brand .sub {
  color: var(--fg-soft);
  font-weight: 520;
  font-size: 12px;
}

.spacer { flex: 1; }

.ctrl {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: 10px;
  min-height: 36px;
  padding: 0 11px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color var(--transition), background var(--transition), transform 0.15s ease;
}

.ctrl:hover {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--border));
}

.ctrl:active { transform: translateY(1px); }
.ctrl.icon { width: 38px; padding: 0; }
.ctrl.language { max-width: 122px; }

/* ---------- model picker ---------- */
.models {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  flex-shrink: 0;
  scrollbar-width: thin;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
  color: var(--fg-soft);
  transition: transform 0.15s ease, border-color var(--transition), background var(--transition);
}

.pill:hover { transform: translateY(-1px); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pill-color, #888); }
.pill .tag {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--bg-soft);
  color: var(--fg-soft);
}

.pill.active {
  color: var(--accent-fg);
  border-color: transparent;
  background: var(--brand-gradient);
}

.pill.active .dot { background: rgba(255, 255, 255, 0.9); }
.pill.active .tag { background: rgba(255, 255, 255, 0.22); color: #fff; }

/* ---------- relay ToS notice ---------- */
.notice-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 18px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--fg);
  background: color-mix(in srgb, var(--accent) 9%, var(--bg-soft));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  flex-shrink: 0;
}

.notice-bar[hidden] { display: none; }
.notice-bar span { flex: 1; min-width: 0; }

.notice-dismiss {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--fg-soft);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  transition: border-color var(--transition), color var(--transition);
}

.notice-dismiss:hover { border-color: var(--accent); color: var(--fg); }

/* ---------- selected provider panel ---------- */
.provider-panel {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 18px;
  flex-shrink: 0;
}

.provider-card {
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) minmax(210px, 280px) auto;
  gap: 14px;
  align-items: center;
}

.provider-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 13px;
}

.provider-copy { min-width: 0; }
.provider-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.provider-title-row h2 {
  font-size: 15px;
  font-weight: 760;
  letter-spacing: 0;
  white-space: nowrap;
}

.provider-copy p,
.provider-help {
  color: var(--fg-soft);
  font-size: 12px;
  line-height: 1.45;
}

.provider-help {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 780;
  white-space: nowrap;
}

.status-badge.ready, .badge.ready { background: #dcfce7; color: #166534; }
.status-badge.free, .badge.free { background: #dbeafe; color: #1e40af; }
.status-badge.byok, .badge.byok { background: #ede9fe; color: #5b21b6; }
.status-badge.needs-key, .badge.needs-key { background: #fef3c7; color: #92400e; }
.status-badge.offline, .badge.offline { background: #fee2e2; color: #991b1b; }

.provider-controls {
  display: grid;
  gap: 5px;
}

.provider-controls label {
  color: var(--fg-soft);
  font-size: 11px;
  font-weight: 700;
}

.provider-controls select,
.field input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--fg);
  padding: 0 10px;
  outline: none;
}

.provider-controls select:focus,
.field input:focus {
  border-color: var(--accent);
}

.provider-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ---------- chat area ---------- */
main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 8%, transparent), transparent 28rem),
    var(--bg);
  transition: background var(--transition);
}

.thread {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 18px;
}

.msg {
  display: flex;
  gap: 12px;
  padding: 15px 0;
  animation: rise 0.22s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.msg .avatar {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
  font-size: 12px;
}

.msg.user .avatar { background: var(--fg); }
.msg.assistant .avatar { background: var(--brand-gradient); }

.message-content {
  min-width: 0;
  flex: 1;
}

.msg .body {
  line-height: 1.7;
  font-size: 15px;
  word-break: break-word;
  padding-top: 2px;
}

.msg.user .body {
  display: inline-block;
  max-width: min(100%, 680px);
  background: var(--user-bubble);
  border-radius: var(--radius);
  padding: 11px 14px;
}

.msg .body.error {
  color: #c2410c;
}

.msg .body a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.msg .body code {
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 5px;
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}

.msg .body pre {
  position: relative;
  background: color-mix(in srgb, var(--bg-soft) 90%, black 3%);
  padding: 14px 15px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
}

.msg .body pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  white-space: pre;
}

.code-lang {
  color: var(--fg-soft);
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 8px;
}

/* markdown blocks inside assistant messages */
.msg .body p { margin: 0 0 10px; }
.msg .body p:last-child { margin-bottom: 0; }

.msg .body h1,
.msg .body h2,
.msg .body h3 {
  margin: 16px 0 8px;
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--fg);
}

.msg .body h1:first-child,
.msg .body h2:first-child,
.msg .body h3:first-child { margin-top: 2px; }

.msg .body h1 { font-size: 1.32em; }
.msg .body h2 { font-size: 1.18em; }
.msg .body h3 { font-size: 1.06em; }

.msg .body ul,
.msg .body ol {
  margin: 6px 0 12px;
  padding-left: 24px;
}

.msg .body li { margin: 3px 0; }
.msg .body li::marker { color: var(--accent); }

.msg .body blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--bg-soft);
  color: var(--fg-soft);
}

.msg .body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.msg-actions button {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg-soft);
  border-radius: 8px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
}

.cursor::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* ---------- welcome ---------- */
.welcome {
  text-align: center;
  padding: 12px 0 48px;
  color: var(--fg-soft);
}

/* 3D "mirror of many minds" stage. Holds the lazy Three.js canvas, or the
   static banner image when WebGL / motion isn't available. */
.welcome-scene {
  position: relative;
  width: min(100%, 760px);
  aspect-ratio: 16 / 8;
  margin: 0 auto 24px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  background:
    radial-gradient(120% 130% at 50% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    color-mix(in srgb, var(--bg-soft) 70%, transparent);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.16);
  transition: background var(--transition), border-color var(--transition);
}

.welcome-scene .scene-canvas {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  animation: scene-in 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.05s forwards;
  touch-action: manipulation;
}

@keyframes scene-in {
  from { opacity: 0; transform: scale(1.015); }
  to { opacity: 1; transform: none; }
}

.scene-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: 0;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  color: var(--fg);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  transition: opacity 0.18s ease;
  will-change: transform;
}

.scene-tooltip.show { opacity: 1; }

.scene-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  text-align: center;
  font-size: 11px;
  color: color-mix(in srgb, var(--fg-soft) 80%, transparent);
  pointer-events: none;
  letter-spacing: 0.02em;
}

.welcome-banner {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.welcome h1 {
  font-size: clamp(28px, 5vw, 44px);
  color: var(--fg);
  margin-bottom: 10px;
  letter-spacing: 0;
  line-height: 1.08;
}

.welcome p {
  font-size: 15px;
  max-width: 620px;
  margin: 0 auto;
  line-height: 1.65;
}

.welcome-status {
  max-width: 620px;
  margin: 16px auto 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.5;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 18px auto 0;
  max-width: 700px;
}

.quick-prompts button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}

.quick-prompts button:hover { border-color: var(--accent); }

.welcome-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- composer ---------- */
footer {
  flex-shrink: 0;
  padding: 14px 18px 18px;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.composer {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elev);
  padding: 9px 9px 9px 15px;
  box-shadow: 0 10px 35px rgba(15, 23, 42, 0.06);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 14px 45px color-mix(in srgb, var(--accent) 14%, transparent);
}

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--fg);
  font-size: 15px;
  line-height: 1.55;
  max-height: 180px;
  padding: 6px 0;
}

.send {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: var(--brand-gradient);
  color: #fff;
  font-size: 17px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.15s ease;
}

.send:disabled { opacity: 0.42; cursor: not-allowed; }
.send:not(:disabled):active { transform: translateY(1px); }

.foot-note {
  max-width: 820px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--fg-soft);
}

/* ---------- modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  display: none;
  place-items: center;
  z-index: 50;
  padding: 20px;
}

.overlay.open { display: grid; }

.modal {
  position: relative;
  background: var(--bg-elev);
  color: var(--fg);
  border-radius: 18px;
  padding: 24px;
  max-width: 560px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--fg-soft);
  cursor: pointer;
  font-size: 18px;
}

.modal h2 {
  font-size: 20px;
  margin-bottom: 6px;
  letter-spacing: 0;
}

.modal .desc,
.note-warn,
.field-hint {
  font-size: 13px;
  color: var(--fg-soft);
  line-height: 1.5;
}

.modal .desc { margin: 0 36px 18px 0; }

.field {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.field:last-child { border-bottom: none; }

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 760;
}

.field-sub-label {
  margin: 10px 0 6px;
  color: var(--fg-soft);
}

.field input {
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}

.field-hint { margin-top: 6px; font-size: 12px; }

.key-row { position: relative; }

.key-row input { padding-right: 40px; }

.key-eye {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-soft);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.key-eye:hover { color: var(--fg); background: var(--bg-soft); }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  padding: 0 14px;
}

.btn.primary { background: var(--brand-gradient); color: #fff; }
.btn.ghost { background: var(--bg-soft); color: var(--fg); border: 1px solid var(--border); }
.btn.compact { min-height: 36px; font-size: 13px; }
.modal-actions .btn { flex: 1; }

.btn.danger {
  width: 100%;
  margin-top: 12px;
  background: transparent;
  color: #dc2626;
  border: 1px solid color-mix(in srgb, #dc2626 38%, var(--border));
  font-size: 13px;
  min-height: 38px;
  transition: background var(--transition), border-color var(--transition);
}

.btn.danger:hover {
  background: color-mix(in srgb, #dc2626 9%, transparent);
  border-color: #dc2626;
}

.note-warn {
  background: var(--bg-soft);
  padding: 11px 12px;
  border-radius: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  background: #111827;
  color: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 16px 45px rgba(15, 23, 42, 0.24);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 70;
}

.toast.open {
  opacity: 1;
  pointer-events: auto; /* hovering pauses auto-dismiss */
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .provider-card {
    grid-template-columns: 42px minmax(0, 1fr);
  }
  .provider-controls,
  .provider-actions {
    grid-column: 1 / -1;
  }
  .provider-actions { justify-content: stretch; }
  .provider-actions .btn { flex: 1; }
}

@media (max-width: 640px) {
  .topbar { gap: 8px; padding: 10px 12px; }
  .brand .sub { display: none; }
  .brand-copy > div:first-child { max-width: 132px; }
  .ctrl { min-height: 34px; padding: 0 9px; }
  #settingsLabel { display: none; }
  .models { padding: 8px 12px; }
  .provider-panel { padding: 10px 12px; }
  main { padding: 16px 0; }
  .thread, .composer, .foot-note { max-width: 100%; }
  .welcome { padding-top: 0; }
  .welcome-scene { border-radius: 14px; margin-bottom: 18px; aspect-ratio: 4 / 3; }
  .welcome h1 { font-size: 29px; }
  .welcome-actions { flex-direction: column; }
  .welcome-actions .btn { width: 100%; }
  footer { padding: 12px; }
  .toast { width: calc(100% - 28px); text-align: center; border-radius: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
