/* === Reset & base === */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  width: 100%;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  color: #303815;
  background: #f8faf0;
  overflow-y: auto;
  position: relative;
}

/* === Brand colors === */
:root {
  --brand-950: #1a1f0e;
  --brand-900: #303815;
  --brand-800: #4a5a20;
  --brand-700: #5a6a30;
  --brand-600: #6a7a40;
  --brand-500: #8a9a5c;
  --brand-400: #a8b878;
  --brand-300: #c8d9a0;
  --brand-200: #d4ddb8;
  --brand-100: #e4ecc8;
  --brand-50: #f0f4e4;
  --brand-25: #f8faf0;
  --brand-accent: #f4ffd1;
}

/* === Centered container === */
.screen {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* Auth screens are narrower and centered vertically */
#login-screen,
#signup-screen,
#verify-screen,
#forgot-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 24px;
}

.hidden { display: none !important; }

/* === Login === */
.logo {
  font-family: 'Sora', sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--brand-900);
}
.subtitle { color: var(--brand-500); font-size: 13px; }
#login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 300px;
  margin-top: 8px;
}
#login-form input {
  padding: 10px 12px;
  border: 1px solid var(--brand-200);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: #fff;
  color: var(--brand-900);
}
#login-form input:focus { border-color: var(--brand-400); box-shadow: 0 0 0 2px rgba(168,184,120,0.2); }

/* === Header === */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.logo-sm {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--brand-900);
}
.header-title { font-size: 14px; color: var(--brand-500); font-weight: 500; }

/* === Buttons === */
.btn-primary {
  padding: 10px 16px;
  background: var(--brand-900);
  color: var(--brand-accent);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--brand-800); }

.btn-accent {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 24px;
  background: var(--brand-accent);
  color: var(--brand-900);
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(48,56,21,0.12);
  transition: all 0.15s;
}
.btn-accent:hover { filter: brightness(0.95); box-shadow: 0 4px 12px rgba(48,56,21,0.18); }
.btn-accent:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--brand-50);
  color: var(--brand-800);
  border: 1px solid var(--brand-200);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--brand-100); }

.btn-ghost {
  background: none;
  border: none;
  color: var(--brand-500);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.btn-ghost:hover { background: var(--brand-50); color: var(--brand-700); }

.btn-link {
  background: none;
  border: none;
  color: var(--brand-700);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px;
}
.btn-link:hover { color: var(--brand-900); }

/* === Plan badge === */
.plan-badge {
  font-size: 9px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.plan-free { background: #f3f4f6; color: #6b7280; }
.plan-pro { background: var(--brand-accent); color: var(--brand-900); }

/* === Mode toggle === */
.mode-toggle { display: flex; gap: 6px; margin-bottom: 14px; }
.mode-btn {
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  background: var(--brand-50);
  color: var(--brand-700);
  transition: all 0.15s;
}
.mode-btn:hover { background: var(--brand-100); }
.mode-btn.active { background: var(--brand-900); color: var(--brand-accent); box-shadow: 0 1px 4px rgba(48,56,21,0.15); }

/* === Input area === */
.input-single { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 14px; }
.input-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.input-label { font-size: 12px; font-weight: 500; color: var(--brand-800); margin-bottom: 4px; display: block; }
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--brand-200);
  border-radius: 10px;
  font-size: 12px;
  color: var(--brand-900);
  background: #fff;
  resize: vertical;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
}
textarea::placeholder { color: #aaa; }
textarea:focus { border-color: var(--brand-400); box-shadow: 0 0 0 2px rgba(168,184,120,0.2); }

/* === Actions === */
.actions-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

/* === Error === */
.error-msg {
  color: #b91c1c;
  font-size: 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

/* === Results === */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--brand-100);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.results-header .results-title { flex: 1; }
.results-title { font-size: 15px; font-weight: 700; color: var(--brand-900); }
.copy-entities-wrap { position: relative; }
.copy-arrow { margin-left: 2px; opacity: 0.5; }
.copy-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--brand-50);
  border: 1px solid var(--brand-200);
  border-radius: 8px;
  overflow: hidden;
  z-index: 20;
  min-width: 120px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.copy-menu button {
  display: block;
  width: 100%;
  padding: 8px 14px;
  background: none;
  border: none;
  text-align: left;
  font-size: 12px;
  color: var(--brand-800);
  cursor: pointer;
  font-family: inherit;
}
.copy-menu button:hover { background: var(--brand-100); }

#screenshot-target { background: #fff; border-radius: 10px; padding: 16px; }

/* === Entity grid — 4 columns on desktop === */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

/* === Entity card — fixed height, uniform layout === */
.entity-card {
  border-radius: 10px;
  border: 1px solid var(--brand-200);
  padding: 10px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 110px;
  background: #fff;
  transition: box-shadow 0.15s;
  overflow: hidden;
}
.entity-card:hover { box-shadow: 0 2px 8px rgba(48,56,21,0.08); }
.entity-card.top {
  background: var(--brand-900);
  border-color: var(--brand-700);
  box-shadow: 0 2px 10px rgba(48,56,21,0.18);
  position: relative;
}
.entity-card.top::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(to right, rgba(244,255,209,0.8), rgba(244,255,209,0.3));
  border-radius: 0 0 10px 10px;
}

/* Row 1: rank + salience */
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.card-rank { font-size: 10px; font-family: monospace; flex-shrink: 0; }
.card-rank-top { color: rgba(255,255,255,0.4); }
.card-rank-normal { color: var(--brand-400); }

.card-salience {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.card-salience-top { background: var(--brand-accent); color: var(--brand-900); }
.card-salience-normal { background: var(--brand-100); color: var(--brand-800); }
.card-salience-low { background: #f3f4f6; color: #6b7280; }

/* Row 2: entity name — clamped to 2 lines */
.card-name {
  font-weight: 700;
  font-size: 12px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  align-self: center;
}
.card-name-top { color: #fff; }
.card-name-normal { color: var(--brand-900); }

/* Row 3: type + mentions — always at bottom */
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  gap: 4px;
}

.card-type {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 9px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 65%;
  flex-shrink: 1;
}
.card-type-top { background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.8); }
.type-dot { width: 4px; height: 4px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.type-dot-top { background: rgba(255,255,255,0.6); }

/* Type colors */
.type-PERSON { background: #dbeafe; color: #1d4ed8; }
.type-PERSON .type-dot { background: #3b82f6; }
.type-LOCATION { background: #fef3c7; color: #b45309; }
.type-LOCATION .type-dot { background: #f59e0b; }
.type-ORGANIZATION { background: #ede9fe; color: #6d28d9; }
.type-ORGANIZATION .type-dot { background: #8b5cf6; }
.type-EVENT { background: #ffe4e6; color: #be123c; }
.type-EVENT .type-dot { background: #f43f5e; }
.type-OTHER { background: #f3f4f6; color: #4b5563; }
.type-OTHER .type-dot { background: #9ca3af; }
.type-CONSUMER_GOOD { background: #ccfbf1; color: #0f766e; }
.type-CONSUMER_GOOD .type-dot { background: #14b8a6; }
.type-WORK_OF_ART { background: #fce7f3; color: #be185d; }
.type-WORK_OF_ART .type-dot { background: #ec4899; }

.card-mentions { font-size: 9px; white-space: nowrap; flex-shrink: 0; }
.card-mentions-top { color: rgba(255,255,255,0.5); }
.card-mentions-normal { color: #9ca3af; }

/* Wikipedia link */
.card-wiki {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  border-radius: 3px;
  font-size: 8px;
  font-weight: 700;
  text-decoration: none;
  margin-left: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}
.card-wiki-top { background: rgba(255,255,255,0.2); color: rgba(255,255,255,0.8); }
.card-wiki-top:hover { background: rgba(255,255,255,0.35); }
.card-wiki-normal { background: #e4ecc8; color: #4a5a20; }
.card-wiki-normal:hover { background: #c8d9a0; }

/* === Toggle row === */
.toggle-row { text-align: center; margin-top: 10px; }

/* === Compare layout — side-by-side on desktop === */
.compare-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.compare-col { min-width: 0; }
.col-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brand-700);
  margin-bottom: 4px;
}
.count-badge { font-size: 10px; color: #9ca3af; margin-bottom: 10px; display: block; }

/* Compare entity grid — 2 columns per panel (4 total across page) */
.compare-col .entity-grid { grid-template-columns: repeat(2, 1fr); }

/* === Loading === */
#loading {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(248,250,240,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 100;
  color: var(--brand-700);
  font-weight: 500;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--brand-200);
  border-top-color: var(--brand-700);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Auth screens === */
.auth-link { text-align: center; font-size: 11px; color: #888; margin-top: 8px; }
.auth-link a { color: #5a6a30; text-decoration: underline; cursor: pointer; }
.verify-message { text-align: center; padding: 16px 0; font-size: 12px; line-height: 1.5; }
.verify-message strong { color: #303815; }
.success-msg { color: #2d6a2e; font-size: 12px; background: #f0fdf4; border: 1px solid #bbf7d0; padding: 8px 12px; border-radius: 8px; margin-top: 8px; text-align: center; }
#verify-screen .resend-btn { width: 100%; max-width: 300px; padding: 8px; border: 1px solid #d4ddb8; background: #fff; color: #303815; border-radius: 6px; cursor: pointer; font-size: 12px; }
#verify-screen .resend-btn:hover { background: #f4ffd1; }
#verify-screen .resend-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#signup-form, #forgot-form { display: flex; flex-direction: column; gap: 0; width: 300px; }
#signup-form input, #forgot-form input { width: 100%; padding: 8px 10px; border: 1px solid #d4ddb8; border-radius: 6px; font-size: 12px; box-sizing: border-box; margin-bottom: 8px; }
#signup-form input:focus, #forgot-form input:focus { outline: none; border-color: #5a6a30; }

/* === Billing bar === */
.billing-bar { padding: 8px 12px; background: #f4ffd1; border-radius: 8px; margin-bottom: 10px; }
.billing-status { font-size: 11px; color: #303815; margin-bottom: 6px; }
.billing-actions { display: flex; gap: 6px; }
.billing-actions button { flex: 1; padding: 5px 8px; font-size: 10px; border-radius: 4px; cursor: pointer; border: 1px solid #d4ddb8; background: #fff; color: #303815; }
.billing-actions button:hover { background: #e4ecc8; }
.billing-actions .btn-accent { background: #303815; color: #f4ffd1; border-color: #303815; }
.billing-actions .btn-accent:hover { background: #4a5a20; }

/* === Responsive === */
@media (max-width: 768px) {
  .screen { padding: 20px 16px; }

  /* Entity grid: 2 columns on tablet */
  .entity-grid { grid-template-columns: repeat(2, 1fr); }

  /* Compare side-by-side becomes stacked */
  .compare-row { grid-template-columns: 1fr; gap: 20px; }
  .compare-col .entity-grid { grid-template-columns: repeat(2, 1fr); }

  /* Input area compare: stacked on mobile */
  .input-compare { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  /* Entity grid: 1 column on small mobile */
  .entity-grid { grid-template-columns: 1fr; }
  .compare-col .entity-grid { grid-template-columns: 1fr; }

  #login-form { width: 100%; }
  #signup-form, #forgot-form { width: 100%; }
  #verify-screen .resend-btn { width: 100%; max-width: none; }
}
