:root {
  --color-primary: #00E5A0;
  --color-primary-hover: #00CC8E;
  --color-secondary: #58A6FF;
  --color-warning: #D29922;
  --color-error: #F85149;
  --color-success: #3FB950;
  --bg: #0D1117;
  --surface: #161B22;
  --border: #30363D;
  --text-primary: #E6EDF3;
  --text-secondary: #8B949E;
  --text-tertiary: #484F58;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
  --max-width: 960px;
  --radius: 8px;
}

[data-theme="light"] {
  --bg: #FFFFFF;
  --surface: #F6F8FA;
  --border: #D0D7DE;
  --text-primary: #1F2328;
  --text-secondary: #656D76;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: 100;
  padding: 0.5rem 1rem;
  background: var(--color-primary);
  color: #0D1117;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius);
}

.skip-link:focus {
  position: fixed;
  top: 1rem;
  left: 1rem;
  width: auto;
  height: auto;
  overflow: visible;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Nav */
nav {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wordmark {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.25rem;
}

.accent {
  color: var(--color-primary);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.pro-badge {
  background: var(--color-primary);
  color: #0D1117;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.375rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease;
}

#theme-toggle:hover {
  border-color: var(--text-secondary);
}

/* Show sun in dark mode, moon in light mode */
.icon-moon {
  display: none;
}

[data-theme="light"] .icon-sun {
  display: none;
}

[data-theme="light"] .icon-moon {
  display: block;
}

/* Main */
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px 48px;
}

.hero {
  padding-top: 2rem;
  margin-bottom: 2rem;
}

.hero h1 {
  margin: 0 0 0.25rem;
  font-size: 2rem;
}

.hero p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 1.125rem;
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.upload-zone:hover,
.upload-zone:focus-visible {
  border-color: var(--color-primary);
  color: var(--text-primary);
}

.upload-zone.drag-over {
  border-color: var(--color-primary);
  background: rgba(0, 229, 160, 0.05);
}

.upload-zone span {
  font-size: 0.875rem;
}

/* Character count */
.char-count {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-align: right;
}

/* Input */
.input-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#text-input {
  width: 100%;
  min-height: 200px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#text-input::placeholder {
  color: var(--text-tertiary);
}

#text-input:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 229, 160, 0.2);
}

#analyze-btn {
  background: var(--color-primary);
  color: #0D1117;
  padding: 0.75rem 2rem;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  align-self: flex-start;
  transition: background 0.15s ease;
}

#analyze-btn:hover {
  background: var(--color-primary-hover);
}

#analyze-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Results */
#results {
  margin-top: 2rem;
}

/* Score card */
.score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.score-meter {
  position: relative;
  width: 200px;
  margin: 0 auto;
}

.meter-svg {
  width: 100%;
  height: auto;
}

.score-value {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.score-label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.score-interpretation {
  font-size: 1rem;
  margin-top: 1rem;
  color: var(--text-secondary);
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-primary);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* Recommendation */
.recommendation {
  background: var(--surface);
  border-left: 3px solid var(--color-primary);
  padding: 1rem 1.5rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 1.5rem;
  color: var(--text-secondary);
}

/* Footer */
footer {
  text-align: center;
  padding: 32px 24px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

footer a:hover {
  color: var(--text-primary);
}

/* Pro section */
.pro-section {
  position: relative;
}

/* Pro teaser — blurred when locked */
.pro-teaser {
  position: relative;
  max-height: 300px;
  overflow: hidden;
  filter: blur(4px);
  opacity: 0.5;
  pointer-events: none;
  user-select: none;
  margin-top: 1rem;
}

.pro-teaser::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(transparent, var(--bg));
  pointer-events: none;
}

.pro-teaser.hidden {
  filter: none;
  opacity: 1;
  pointer-events: auto;
  user-select: auto;
  max-height: none;
  overflow: visible;
}

.pro-teaser.hidden::after {
  display: none;
}

/* Paywall banner — sits between free results and blurred pro content */
.paywall-banner {
  background: var(--surface);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 2rem;
  margin-top: 1.5rem;
  text-align: center;
}

.paywall-banner.hidden {
  display: none;
}

.paywall-content {
  max-width: 500px;
  margin: 0 auto;
}

.paywall-content h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--text-primary);
}

.paywall-content > p {
  color: var(--text-secondary);
  margin: 0 0 1.5rem;
  font-size: 0.9375rem;
  line-height: 1.5;
}

/* Pricing options */
.pricing-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.btn-pro {
  display: inline-block;
  background: var(--color-primary);
  color: #0D1117;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  transition: background 0.2s;
}

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

.btn-pro-secondary {
  display: inline-block;
  background: transparent;
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
  padding: calc(0.75rem - 2px) calc(1.5rem - 2px);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}

.btn-pro-secondary:hover {
  background: var(--color-primary);
  color: #0D1117;
}

.save-tag {
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.8;
}

.btn-lifetime {
  display: inline-block;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: calc(0.75rem - 1px) calc(1.5rem - 1px);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9375rem;
  text-decoration: none;
  transition: border-color 0.2s;
}

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

/* Paywall footer */
.paywall-footer {
  margin-top: 0.75rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 0.8125rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

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

/* Paywall message */
.paywall-message {
  padding: 0.5rem 1rem;
  border-radius: calc(var(--radius) / 2);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.paywall-message.success {
  background: rgba(63, 185, 80, 0.15);
  color: var(--color-success);
}

.paywall-message.error {
  background: rgba(248, 81, 73, 0.15);
  color: var(--color-error);
}

/* Restore purchase form */
.restore-form {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.restore-form input[type="email"] {
  background: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) / 2);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  width: 100%;
  max-width: 280px;
}

.restore-form input[type="email"]:focus {
  border-color: var(--color-primary);
  outline: none;
}

.restore-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn-sm {
  font-size: 0.8125rem;
  padding: 0.375rem 0.75rem;
}

.btn.btn-sm {
  background: var(--color-primary);
  color: #0D1117;
  border: none;
  border-radius: calc(var(--radius) / 2);
  font-weight: 600;
  cursor: pointer;
}

.btn.btn-sm:disabled {
  opacity: 0.5;
}

/* Pro cards */
.pro-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.pro-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 1rem 0;
  line-height: 1.3;
}

/* Formula grid (readability table) */
.formula-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.formula-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-radius: calc(var(--radius) / 2);
  border: 1px solid var(--border);
}

.formula-name {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.formula-grade {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.125rem;
}

/* Consensus value */
.consensus-value {
  font-size: 3rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-primary);
  text-align: center;
  margin: 1rem 0;
}

/* Sentiment display */
.sentiment-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.sentiment-label {
  font-size: 1.25rem;
  font-weight: 600;
  text-transform: capitalize;
}

.sentiment-score {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.sentiment-confidence {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.sentiment-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin: 1rem 0;
}

.sentiment-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.word-lists {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.word-list h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.word-tag {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  margin: 0.125rem;
  border-radius: 4px;
  font-size: 0.8125rem;
}

.word-tag.positive {
  background: rgba(63, 185, 80, 0.15);
  color: var(--color-success);
}

.word-tag.negative {
  background: rgba(248, 81, 73, 0.15);
  color: var(--color-error);
}

/* Keywords */
.keyword-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.keyword-item:last-child {
  border-bottom: none;
}

.keyword-word {
  font-weight: 600;
  min-width: 100px;
}

.keyword-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.keyword-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 3px;
}

.keyword-count {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-secondary);
  min-width: 50px;
  text-align: right;
}

/* SEO display */
.seo-score-big {
  font-size: 3rem;
  font-weight: 700;
  font-family: var(--font-mono);
  text-align: center;
  margin: 1rem 0;
}

.seo-grade {
  font-size: 1.25rem;
  color: var(--text-secondary);
  text-align: center;
}

.seo-details {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.seo-detail {
  text-align: center;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: calc(var(--radius) / 2);
}

.seo-detail-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.25rem;
}

.seo-detail-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.seo-issues,
.seo-suggestions {
  margin-top: 1rem;
}

.seo-issues h3,
.seo-suggestions h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.seo-issues li {
  color: var(--color-error);
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
}

.seo-suggestions li {
  color: var(--color-success);
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
}

/* Summary */
.summary-text {
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.8;
}

.summary-ratio {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  margin-top: 0.75rem;
}

/* Results transition */
#results {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Tablet+ */
@media (min-width: 768px) {

  #text-input {
    min-height: 300px;
  }

  .score-card {
    padding: 2.5rem;
  }

  .score-meter {
    width: 240px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .formula-grid {
    grid-template-columns: 1fr 1fr;
  }

  .seo-details {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 767px) {
  .actions-bar {
    flex-direction: column;
  }

  .actions-bar .btn-secondary {
    width: 100%;
    justify-content: center;
  }

  .pricing-options {
    flex-direction: column;
    align-items: center;
  }

  .pricing-options a {
    width: 100%;
    max-width: 280px;
    text-align: center;
  }
}

@media (min-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .history-panel {
    max-height: 500px;
  }
}

/* Actions bar */
.actions-bar {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

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

/* History panel */
.history-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 1.5rem;
  max-height: 400px;
  overflow-y: auto;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.history-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}

.btn-icon:hover {
  color: var(--text-primary);
}

.history-item {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  cursor: default;
}

.history-item:last-child {
  border-bottom: none;
}

.history-preview {
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.5rem;
}

.history-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.history-actions {
  display: flex;
  gap: 0.5rem;
}

.history-load,
.history-delete {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  border: none;
}

.history-load {
  background: var(--color-primary);
  color: #0D1117;
}

.history-delete {
  background: transparent;
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

.history-delete:hover {
  background: rgba(248, 81, 73, 0.15);
}

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