@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600&family=IBM+Plex+Mono:wght@400;600&display=swap');

:root {
  --bg: #ffffff;
  --text: #202124;
  --muted: #5f6368;
  --border: #dadce0;
  --accent: #62346d;
  --accent-hover: #4a2857;
  --accent-bg: #f3f0f7;
  --danger: #d93025;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden {
  display: none !important;
}

.page {
  min-height: 100vh;
}

/* Home view */
.home {
  --logo-height: 150px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform: translateY(calc(var(--logo-height) / -2));
  background: var(--bg);
}

.logo {
  height: var(--logo-height);
  width: auto;
  max-width: 400px;
  margin-bottom: 8px;
  pointer-events: none;
}

.search-container {
  position: relative;
  width: 720px;
  max-width: 90%;
}

.search-input {
  width: 100%;
  padding: 16px 60px 16px 24px;
  font-family: inherit;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 28px;
  outline: none;
  background: var(--bg);
  transition: box-shadow 0.2s;
}

.search-input:hover,
.search-input:focus {
  box-shadow: 0 1px 6px rgba(32, 33, 36, 0.28);
  border-color: transparent;
}

.search-input::placeholder {
  color: #bbb;
}

.submit-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.submit-btn:hover {
  background: var(--accent-hover);
}

.tagline {
  margin-top: 24px;
  font-size: 14px;
  color: var(--muted);
}

/* REPL link */
.repl-link {
  position: fixed;
  top: 16px;
  left: 16px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, opacity 0.3s;
  z-index: 20;
  opacity: 0;
  animation: fadeInRepl 1.0s ease-out 1s forwards;
}

@keyframes fadeInRepl {
  to { opacity: 1; }
}

.repl-link:hover {
  background: var(--accent);
  color: #fff;
}

/* Model picker */
.model-picker {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20;
}

.model-picker-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f1f3f4;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.model-picker-btn:hover {
  background: #e8eaed;
  border-color: #ccc;
}

.model-picker-btn svg {
  transition: transform 0.2s;
}

.model-picker.open .model-picker-btn svg {
  transform: rotate(180deg);
}

.model-picker-btn.unavailable {
  color: #aaa;
  border-color: #ddd;
}

.model-picker-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  min-width: 180px;
  overflow: hidden;
}

.model-picker-menu {
  max-height: 300px;
  overflow-y: auto;
  padding: 6px 0;
}

.model-picker-more {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  height: 50px;
  color: var(--muted);
  font-size: 10px;
  gap: 4px;
  background: linear-gradient(transparent, var(--bg) 50%);
  pointer-events: none;
}

.model-picker-more svg {
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2px); }
}

.model-picker-group {
  padding: 6px 12px 4px;
  font-size: 10px;
  font-weight: 500;
  color: #adb5bd;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.model-picker-option {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}

.model-picker-option:hover {
  background: #f1f3f4;
}

.model-picker-option.selected {
  color: var(--accent);
  font-weight: 500;
}

.model-picker-option.unavailable {
  color: #aaa;
}

.model-picker-option.unavailable::after {
  content: ' ⃠';
  font-size: 10px;
  opacity: 0.6;
}

/* Results view */
.results-view {
  min-height: 100vh;
  background: var(--bg);
  padding-bottom: 48px;
}

.results-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.logo-link {
  flex-shrink: 0;
  cursor: pointer;
}

.logo-small {
  height: 60px;
  width: auto;
  flex-shrink: 0;
  object-fit: contain;
  pointer-events: none;
}

.search-container-mini {
  position: relative;
  flex: 1;
}

.search-input-mini {
  width: 100%;
  padding: 10px 44px 10px 16px;
  font-family: inherit;
  font-size: 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  outline: none;
}

.search-input-mini:focus {
  border-color: var(--accent);
}

.submit-btn-mini {
  width: 32px;
  height: 32px;
  right: 5px;
}

.status-indicator {
  position: fixed;
  top: 16px;
  font-size: 13px;
  color: var(--muted);
  padding: 8px 14px;
  background: #f1f3f4;
  border-radius: 20px;
  white-space: nowrap;
  z-index: 20;
}

.status-indicator.error {
  color: var(--danger);
  background: #fce8e6;
}

.status-indicator.running {
  color: var(--accent);
  background: var(--accent-bg);
}

.status-indicator.done {
  color: #188038;
  background: #e6f4ea;
}

/* Results area */
.results {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: grid;
  gap: 16px;
}

.block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.step {
  border-left: 3px solid var(--accent);
}

.step .explain {
  margin: 6px 0 12px;
  color: var(--muted);
}

.expr {
  margin: 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: #f1f3f4;
  border: 1px solid var(--border);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-x: auto;
}

.expr code,
.expr code[class*="language-"] {
  font-family: inherit;
  font-size: 14px;
  background: transparent;
  padding: 0;
  text-shadow: none;
}

.expr .token.keyword {
  color: var(--accent);
}

.expr .token.builtin {
  color: #2563eb;
}

.expr .token.function {
  color: #0891b2;
}

.expr .token.number {
  color: #059669;
}

.expr .token.string {
  color: #b45309;
}

.expr .token.operator {
  color: #64748b;
  background: none;
}

.expr .token.comment {
  color: #94a3b8;
  font-style: italic;
}

.step-results {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.block h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.block p {
  margin: 0;
  line-height: 1.6;
  overflow-wrap: break-word;
}

.latex {
  font-size: 18px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.table th,
.table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}

.table th {
  background: #f1f3f4;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 40px;
}

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

.error-block {
  border-left: 3px solid var(--danger);
  background: #fce8e6;
}

/* Spinner */
.spinner {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0%, var(--accent) 100%);
  animation: spin 0.5s linear infinite, pulse 1.0s ease-in-out infinite;
  margin: -16px auto 0;
}

.spinner::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--bg);
}

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

@keyframes pulse {
  0%, 100% {
    scale: 0.7;
    opacity: 0.6;
    filter: drop-shadow(0 0 0 transparent);
  }
  50% {
    scale: 1;
    opacity: 1;
    filter: drop-shadow(0 0 8px rgba(98, 52, 109, 0.5));
  }
}

/* GitHub link */
.github-link {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.github-link svg {
  width: 24px;
  height: 24px;
}

.github-link:hover {
  background: var(--text);
  color: var(--bg);
}

/* Settings */
.settings-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.settings-btn:hover {
  background: #f1f3f4;
  color: var(--text);
}

.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.settings-content {
  background: var(--bg);
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.settings-content h3 {
  margin: 0 0 16px;
  font-size: 18px;
}

.settings-content label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.settings-content input {
  width: 100%;
  padding: 10px 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}

.settings-content input:focus {
  outline: none;
  border-color: var(--accent);
}

.settings-close {
  width: 100%;
  padding: 10px;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.settings-close:hover {
  background: #333;
}

/* Bridge overlay */
.bridge-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.bridge-overlay-content {
  text-align: center;
  max-width: 540px;
  padding: 32px;
  background: var(--bg);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.bridge-logo {
  height: 80px;
  width: auto;
  pointer-events: none;
}

.bridge-overlay-content .bridge-intro {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.bridge-intro a {
  color: var(--accent);
  text-decoration: none;
}

.bridge-intro a:hover {
  text-decoration: underline;
}

.bridge-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

.bridge-overlay-content h2 {
  margin: 0 0 16px;
  font-size: 20px;
  color: var(--text);
}

.bridge-overlay-content p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.bridge-command-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 0 16px;
  width: 100%;
}

.bridge-command {
  flex: 1;
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 14px 48px;
  border-radius: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  margin: 0;
  text-align: center;
}

.copy-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.copy-btn:hover {
  color: #d4d4d4;
  background: rgba(255, 255, 255, 0.1);
}

.copy-btn.copied {
  color: #4ade80;
}

.copy-btn .check-icon {
  display: none;
}

.copy-btn.copied .copy-icon {
  display: none;
}

.copy-btn.copied .check-icon {
  display: block;
}

.copy-tooltip {
  position: absolute;
  top: 50%;
  right: calc(100% + 8px);
  transform: translateY(-50%);
  background: #1e1e1e;
  color: #4ade80;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.copy-btn.copied .copy-tooltip {
  opacity: 1;
}

.bridge-url-input {
  width: 100%;
  padding: 14px 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  text-align: center;
}

.bridge-url-input:focus {
  outline: none;
  border-color: var(--accent);
}

.bridge-retry {
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.bridge-retry:hover:not(:disabled) {
  background: var(--accent-hover);
}

.bridge-retry:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.bridge-popup-hint {
  margin-top: 16px;
  padding-top: 16px;
  font-size: 13px;
  color: var(--danger);
}

.bridge-popup-hint a {
  color: var(--accent);
  text-decoration: underline;
}

/* Gemini auth overlay */
.gemini-auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.gemini-auth-link {
  display: inline-flex;
  align-items: center;
  padding: 12px 24px;
  background: #f2f2f2;
  color: #3c4043;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 500;
  border: 1px solid #dadce0;
  transition: background 0.15s, box-shadow 0.15s;
}

.gemini-auth-link:hover {
  background: #e8e8e8;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.overlay-cancel {
  -webkit-appearance: none;
  appearance: none;
  margin-top: 12px;
  padding: 9px 23px;
  background: #fce8e6;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.overlay-cancel:hover {
  background: #f8d7da;
}

/* Responsive */
@media (max-width: 600px) {
  .home {
    --logo-height: 100px;
  }

  .search-container {
    width: 100%;
  }

  .results-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .search-container-mini {
    order: 3;
    width: 100%;
  }
}
