:root {
  --bg: #0f1117;
  --sidebar-bg: #171923;
  --panel: #1e2230;
  --border: #2a2f3f;
  --text: #e8eaf0;
  --text-dim: #9aa1b5;
  --accent: #6366f1;
  --accent-hover: #4f52d8;
  --error: #f87171;
  --success: #22c55e;
  --warning: #fbbf24;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ---------- Animated background ---------- */
.bg-animation {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(135deg, #0f1117 0%, #141b33 45%, #1a1030 100%);
  animation: bg-shift 18s ease-in-out infinite alternate;
}

@keyframes bg-shift {
  0% {
    background-position: 0% 0%;
    filter: hue-rotate(0deg);
  }
  100% {
    background-position: 100% 100%;
    filter: hue-rotate(30deg);
  }
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  mix-blend-mode: screen;
  animation: float 22s ease-in-out infinite;
}

.orb-1 {
  width: 480px;
  height: 480px;
  background: #6366f1;
  top: -120px;
  left: -100px;
}

.orb-2 {
  width: 420px;
  height: 420px;
  background: #a855f7;
  bottom: -140px;
  right: -80px;
  animation-delay: -7s;
  animation-duration: 26s;
}

.orb-3 {
  width: 320px;
  height: 320px;
  background: #06b6d4;
  top: 40%;
  left: 55%;
  animation-delay: -13s;
  animation-duration: 30s;
}

@keyframes float {
  0% {
    transform: translate(0, 0) scale(1);
  }
  25% {
    transform: translate(60px, -40px) scale(1.1);
  }
  50% {
    transform: translate(-40px, 50px) scale(0.95);
  }
  75% {
    transform: translate(30px, 30px) scale(1.05);
  }
  100% {
    transform: translate(0, 0) scale(1);
  }
}

.grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
  animation: grid-drift 40s linear infinite;
}

@keyframes grid-drift {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 44px 44px;
  }
}

.layout {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
}

.sidebar,
.panel,
.main,
.topbar {
  background: rgba(15, 17, 23, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.sidebar {
  border-right-color: rgba(42, 47, 63, 0.7);
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: rgba(23, 25, 35, 0.6);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
}

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

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.nav-btn:hover {
  background: var(--panel);
  color: var(--text);
}

.nav-btn.active {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--text);
}

.word-stats {
  margin-top: 20px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 12px;
  color: var(--text-dim);
}

.word-stats p {
  display: flex;
  justify-content: space-between;
}

.word-stats p + p {
  margin-top: 4px;
}

.word-stats span {
  color: var(--text);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

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

.model-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-dim);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.topbar h2 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-dim);
}

.status {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status.hidden {
  display: none;
}

.status.thinking {
  color: var(--accent);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: none;
  flex-direction: column;
  gap: 16px;
}

.panel.active {
  display: flex;
}

/* Textareas */
.textarea-wrap {
  flex: 1;
  display: flex;
  min-height: 260px;
}

textarea {
  width: 100%;
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  padding: 16px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

textarea:focus {
  border-color: var(--accent);
}

textarea.output {
  background: rgba(99, 102, 241, 0.06);
}

.split {
  display: flex;
  gap: 16px;
  flex: 1;
  min-height: 260px;
}

.col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.col-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-lg {
  padding: 11px 22px;
  font-size: 15px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-secondary:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-dim);
}

.btn-primary,
.btn-secondary {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, opacity 0.2s;
  padding: 11px 22px;
  font-size: 15px;
}

.btn-secondary {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  padding: 10px 21px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Result card */
.result-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.result-card.hidden {
  display: none;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.verdict {
  font-size: 18px;
  font-weight: 600;
}

.score {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 16px;
}

.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--success), var(--warning), var(--error));
  transition: width 0.6s ease;
}

.reasoning {
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 14px;
}

.indicators {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.indicators li {
  font-size: 13px;
  color: var(--text);
  padding: 8px 12px;
  background: var(--bg);
  border-left: 3px solid var(--warning);
  border-radius: 6px;
}

.notes {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}

.notes.hidden {
  display: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  width: 420px;
  max-width: 90vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.modal p {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}

#key-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 16px;
}

#key-input:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn {
  padding: 9px 18px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.key-hint {
  margin-bottom: 0 !important;
  color: var(--error);
}

/* Scrollbar */
textarea::-webkit-scrollbar,
.panel::-webkit-scrollbar {
  width: 8px;
}

textarea::-webkit-scrollbar-thumb,
.panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

@media (max-width: 720px) {
  .sidebar {
    display: none;
  }
}
