:root {
  --bg:         #0b0f19;
  --surface:    #0f172a;
  --surface2:   #1e293b;
  --border:     #1e293b;
  --border2:    #334155;
  --blue:       #2563eb;
  --blue-lt:    #60a5fa;
  --blue-dim:   #1e3a5f;
  --text:       #f0f4ff;
  --text2:      #94a3b8;
  --text3:      #475569;
  --green:      #4ade80;
  --green-dim:  #052e16;
  --green-bdr:  #166534;
  --yellow:     #fbbf24;
  --yellow-dim: #1c1400;
  --yellow-bdr: #92400e;
  --orange:     #fb923c;
  --orange-dim: #1c0a00;
  --orange-bdr: #7c2d12;
  --red:        #f87171;
  --red-dim:    #1c0000;
  --red-bdr:    #7f1d1d;
  --radius:     14px;
  --radius-sm:  9px;
  --font:       'DM Sans', sans-serif;
  --mono:       'DM Mono', monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --surface2:   #f1f5f9;
  --border:     #e2e8f0;
  --border2:    #cbd5e1;
  --blue-lt:    #2563eb;
  --blue-dim:   #dbeafe;
  --text:       #0f172a;
  --text2:      #475569;
  --text3:      #94a3b8;
  --green:      #16a34a;
  --green-dim:  #dcfce7;
  --green-bdr:  #86efac;
  --yellow:     #ca8a04;
  --yellow-dim: #fef9c3;
  --yellow-bdr: #fde047;
  --orange:     #ea580c;
  --orange-dim: #ffedd5;
  --orange-bdr: #fed7aa;
  --red:        #dc2626;
  --red-dim:    #fee2e2;
  --red-bdr:    #fca5a5;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ── Header ─────────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text3);
  text-decoration: none;
  font-family: var(--mono);
  transition: color 0.15s;
}

.back-link:hover { color: var(--blue-lt); }

.header-divider {
  width: 1px;
  height: 18px;
  background: var(--border2);
}

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

.logo-icon {
  width: 30px;
  height: 30px;
  background: var(--blue);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
}

.logo-text {
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
  letter-spacing: -0.3px;
}

.logo-text b {
  color: var(--blue-lt);
  font-weight: 600;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.theme-toggle:hover { background: var(--border2); color: var(--text); transform: scale(1.08) rotate(12deg); }

/* ── Hero ───────────────────────────────────────────────── */
.hero {
  text-align: center;
  padding: 52px 24px 40px;
  max-width: 900px;
  margin: 0 auto;
}

.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--blue-lt);
  background: var(--blue-dim);
  border-radius: 20px;
  padding: 4px 14px;
  margin-bottom: 16px;
  font-family: var(--mono);
}

h1 {
  font-size: 40px;
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -1px;
  margin-bottom: 12px;
  color: var(--text);
}

.accent { color: var(--blue-lt); }

.hero-sub {
  font-size: 15px;
  color: var(--text2);
  max-width: 420px;
  margin: 0 auto 32px;
  font-weight: 300;
  line-height: 1.65;
}

/* ── Form bar ───────────────────────────────────────────── */
.form-bar {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 680px;
  margin: 0 auto;
  text-align: left;
}

.error-banner {
  background: var(--red-dim);
  border: 1px solid var(--red-bdr);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  margin-bottom: 14px;
  display: none;
}

.error-banner.visible { display: block; }

.form-row {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 12px;
  margin-bottom: 12px;
  align-items: start;
}

.form-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text3);
  margin-bottom: 6px;
}

.form-label-hint {
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--text3);
  font-size: 11px;
}

.ps-select {
  width: 100%;
  padding: 10px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.ps-select:focus { border-color: var(--blue); }

.ps-textarea {
  width: 100%;
  min-height: 110px;
  padding: 10px 12px;
  font-size: 13.5px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  font-family: var(--font);
  resize: vertical;
  line-height: 1.6;
  outline: none;
  transition: border-color 0.15s;
}

.ps-textarea:focus { border-color: var(--blue); }
.ps-textarea::placeholder { color: var(--text3); }

.char-count {
  font-size: 11.5px;
  color: var(--text3);
  text-align: right;
  margin-top: 5px;
}

.char-count.warn { color: var(--orange); }

/* Privacy note */
.privacy-note {
  font-size: 11.5px;
  color: var(--text3);
  margin-bottom: 10px;
  margin-top: 2px;
  line-height: 1.5;
}

.ps-btn {
  width: 100%;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: -0.2px;
  transition: background 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

.ps-btn:hover { background: #1d4ed8; }
.ps-btn:active { transform: scale(0.99); }
.ps-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.kbd-hint {
  font-size: 12px;
  color: var(--text3);
  margin-top: 10px;
  text-align: center;
}

kbd {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: var(--mono);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Results ─────────────────────────────────────────────── */
.results-section {
  display: none;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 24px 0;
  animation: fadeUp 0.35s ease;
}

.results-section.visible { display: block; }

/* Visually hidden heading — present for screen readers and focus target */
.results-heading {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.score-strip {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 22px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 14px;
}

.score-left { min-width: 160px; }

.score-display {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
}

.score-num {
  font-size: 52px;
  font-weight: 600;
  line-height: 1;
  font-family: var(--mono);
  letter-spacing: -2px;
  transition: color 0.3s;
}

.score-of {
  font-size: 18px;
  color: var(--text3);
  font-family: var(--mono);
}

.score-bar-track {
  height: 4px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}

.score-bar-fill {
  height: 4px;
  border-radius: 4px;
  width: 0%;
  transition: width 0.6s ease, background 0.3s;
}

.score-right { flex: 1; }

.score-label {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: -0.3px;
  transition: color 0.3s;
}

.score-badge {
  display: inline-flex;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--blue-dim);
  color: var(--blue-lt);
}

/* Feedback grid */
.feedback-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.fb-block {
  border-radius: var(--radius-sm);
  padding: 16px;
  border: 1px solid;
}

.fb-block.str { background: var(--green-dim); border-color: var(--green-bdr); }
.fb-block.wk  { background: var(--red-dim);   border-color: var(--red-bdr); }
.fb-block.ms  { background: var(--orange-dim); border-color: var(--orange-bdr); }
.fb-block.tp  { background: var(--blue-dim);   border-color: #1e40af; }

.fb-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 10px;
}

.fb-block.str .fb-title { color: var(--green); }
.fb-block.wk  .fb-title { color: var(--red); }
.fb-block.ms  .fb-title { color: var(--orange); }
.fb-block.tp  .fb-title { color: var(--blue-lt); }

.fb-block ul { list-style: none; display: flex; flex-direction: column; gap: 5px; }

.fb-block ul li {
  font-size: 13px;
  line-height: 1.5;
  padding-left: 16px;
  position: relative;
}

.fb-block.str li { color: #86efac; }
.fb-block.wk  li { color: #fca5a5; }
.fb-block.ms  li { color: #fdba74; }
.fb-block.tp  li { color: #93c5fd; }

[data-theme="light"] .fb-block.str li { color: #166534; }
[data-theme="light"] .fb-block.wk  li { color: #7f1d1d; }
[data-theme="light"] .fb-block.ms  li { color: #7c2d12; }
[data-theme="light"] .fb-block.tp  li { color: #1e3a5f; }

.fb-block li::before { content: '—'; position: absolute; left: 2px; opacity: 0.4; }

/* Rewrites */
.rewrites-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
  margin-bottom: 10px;
  font-family: var(--mono);
}

.rewrites-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.rw-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 16px;
}

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

.rw-type {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--blue-lt);
}

.copy-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.copy-btn:hover { background: var(--blue-dim); color: var(--blue-lt); border-color: var(--blue); }
.copy-btn.copied { background: var(--green-dim); color: var(--green); border-color: var(--green-bdr); }
.copy-btn.error  { background: var(--red-dim);   color: var(--red);   border-color: var(--red-bdr); font-size: 10px; width: auto; padding: 0 8px; }

.rw-text {
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text2);
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--mono);
  margin-bottom: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}

.rw-exp {
  font-size: 12px;
  color: var(--text3);
  line-height: 1.5;
  padding-left: 16px;
  position: relative;
}

.rw-exp::before { content: '↳'; position: absolute; left: 0; color: var(--blue-lt); opacity: 0.6; }

/* ── Feed ───────────────────────────────────────────────── */
.feed-section {
  max-width: 900px;
  margin: 24px auto 0;
  padding: 0 24px 56px;
}

.feed-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
  margin-bottom: 10px;
  font-family: var(--mono);
}

.feed-empty {
  text-align: center;
  color: var(--text3);
  font-size: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.feed-list { display: flex; flex-direction: column; gap: 6px; }

.feed-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.15s;
}

.feed-item:hover { border-color: var(--border2); }

.feed-score {
  font-size: 16px;
  font-weight: 500;
  min-width: 36px;
  font-family: var(--mono);
}

.feed-divider { width: 1px; height: 22px; background: var(--border2); flex-shrink: 0; }

.feed-info { flex: 1; min-width: 0; }

.feed-preview {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feed-time { font-size: 11px; color: var(--text3); margin-top: 2px; }

.feed-model {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.feed-claude  { background: #2e1065; color: #c4b5fd; }
.feed-chatgpt { background: #022c22; color: #6ee7b7; }

[data-theme="light"] .feed-claude  { background: #ede9fe; color: #7c3aed; }
[data-theme="light"] .feed-chatgpt { background: #d1fae5; color: #065f46; }

.feed-gemini  { background: #082f49; color: #7dd3fc; }
[data-theme="light"] .feed-gemini  { background: #e0f2fe; color: #0369a1; }

/* ── Footer ─────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border);
  padding: 18px 24px;
}

.footer-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text3);
  gap: 16px;
}

.footer-back {
  color: var(--blue-lt);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
}

.footer-back:hover { color: var(--text2); }
.footer-inner a { color: var(--blue-lt); text-decoration: none; }

.footer-impressum {
  white-space: nowrap;
  color: var(--text3) !important;
  font-family: var(--mono);
}

.footer-impressum:hover { color: var(--text2) !important; }

/* ── Feedback popup ─────────────────────────────────────── */
.feedback-popup {
  position: fixed;
  right: 24px;
  bottom: 24px;
  left: auto;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: 12px 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  z-index: 1000;
  width: auto;
  min-width: 0;
  max-width: min(92vw, 420px);
  display: none;
  align-items: center;
  gap: 10px;
  animation: popIn 0.3s cubic-bezier(0.4,0,0.2,1) both;
}

.feedback-popup.visible { display: flex; }

@keyframes popIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.feedback-close {
  position: static;
  background: none;
  border: none;
  color: var(--text3);
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  margin-left: 2px;
}

.feedback-close:hover { color: var(--text); }

.feedback-question {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.feedback-stars {
  display: flex;
  gap: 2px;
}

.star-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--border2);
  cursor: pointer;
  padding: 0;
  transition: color 0.12s, transform 0.1s;
  line-height: 1;
}

.star-btn:hover,
.star-btn.active { color: var(--yellow); }

.star-btn:hover { transform: scale(1.15); }

.feedback-thanks {
  font-size: 12px;
  color: var(--green);
  display: none;
  white-space: nowrap;
}

.feedback-thanks.visible { display: block; }

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Prevent horizontal scroll — contain everything to viewport width */
  main, .header, .footer { max-width: 100vw; overflow: hidden; }

  .hero {
    padding: 32px 16px 24px;
  }

  h1 { font-size: 28px; letter-spacing: -0.5px; }
  .hero-sub { font-size: 14px; }

  .form-bar {
    padding: 14px;
    margin: 0 12px;
    max-width: calc(100% - 24px);
  }

  .form-row { grid-template-columns: 1fr; }

  .results-section { padding: 16px 12px 0; }

  .score-strip {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 16px;
  }

  .score-left { min-width: 0; width: 100%; }

  /* Feedback blocks stack vertically on mobile */
  .feedback-grid { grid-template-columns: 1fr; }
  .rewrites-grid { grid-template-columns: 1fr; }

  /* Prevent long rewrite text from overflowing */
  .rw-text {
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
  }

  .feed-section { padding: 0 12px 40px; }

  .footer-inner {
    flex-direction: column;
    text-align: center;
    gap: 8px;
    padding: 14px 16px;
  }

  /* Feedback popup on iOS:
     position:fixed + overflow-x:hidden on body = broken touch events.
     Solution: keep overflow off body, use safe left/right anchoring, no transform. */
  .feedback-popup {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: env(safe-area-inset-bottom, 16px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    width: auto;
    max-width: none;
    border-radius: 999px;
    padding: 12px 16px;
    gap: 10px;
    z-index: 9999;
    /* No transform — transforms break fixed positioning touch on iOS */
    transform: none !important;
    -webkit-transform: none !important;
  }

  /* Larger touch targets for stars — minimum 44×44px per Apple HIG */
  .star-btn {
    font-size: 24px;
    padding: 8px 4px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .feedback-stars { gap: 0; }

  .feedback-question {
    font-size: 12px;
    white-space: normal;
    flex: 1;
    min-width: 0;
  }

  .feedback-thanks { white-space: normal; }

  /* Dismiss button — bigger tap target */
  .feedback-close {
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
  }

  .header-inner { padding: 12px 16px; }
}

/* ── Collapsible blocks (mobile only) ───────────────────── */
.fb-toggle {
  display: none;
}

@media (max-width: 640px) {
  .fb-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    opacity: 0.7;
    transition: transform 0.22s ease, opacity 0.15s;
    transform: rotate(0deg);
  }

  .fb-title {
    display: flex;
    align-items: center;
    width: 100%;
  }

  /* Collapsed state — hide content, rotate chevron */
  .fb-collapsed > ul,
  .fb-collapsed > .rw-text,
  .fb-collapsed > .rw-exp {
    display: none;
  }

  .fb-collapsed .fb-toggle,
  .fb-collapsed .rw-toggle {
    transform: rotate(-90deg);
    opacity: 0.5;
  }

  /* Rewrite card toggle */
  .rw-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    background: none;
    border: none;
    color: var(--blue-lt);
    font-size: 18px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    opacity: 0.7;
    transition: transform 0.22s ease, opacity 0.15s;
  }
}
