:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --border: #e6e1d8;
  --text: #1f1d1a;
  --muted: #6b6862;
  --accent: #2b6cb0;
  --accent-text: #ffffff;
  --chip: #f0ece4;
  --danger: #b3261e;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --surface: #211e18;
    --border: #34302a;
    --text: #f2efe9;
    --muted: #a8a39a;
    --accent: #5b9bd5;
    --accent-text: #0b1622;
    --chip: #2c2820;
    --danger: #f0938c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

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

header.app-bar h1 { font-size: 19px; margin: 0; font-weight: 600; }
header.app-bar .sub { font-size: 13px; color: var(--muted); }

a.back { color: var(--accent); text-decoration: none; font-size: 14px; }

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

textarea {
  width: 100%;
  font-size: 17px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  font-family: inherit;
}

.row { display: flex; align-items: center; gap: 12px; margin: 16px 0; }
.row label { font-size: 13px; color: var(--muted); white-space: nowrap; }
input[type=range] { flex: 1; accent-color: var(--accent); }
.rate-val { font-size: 13px; font-weight: 600; min-width: 38px; text-align: right; }

.is-hidden { display: none; }

select {
  flex: 1;
  font-size: 15px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}
select:disabled { opacity: 0.5; cursor: default; }

.mode-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 4px 0 16px;
}
.mode-toggle button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
}
.mode-toggle button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.buttons { display: flex; gap: 10px; }
button.primary, button.icon {
  border: none; border-radius: 10px; cursor: pointer;
  font-size: 16px; padding: 13px 16px;
}
button.primary {
  flex: 1; background: var(--accent); color: var(--accent-text);
  font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px;
}
button.icon { width: 52px; background: var(--chip); color: var(--text); }
button:disabled { opacity: 0.5; cursor: default; }

.status { font-size: 13px; color: var(--muted); margin: 12px 0 0; min-height: 18px; }
.status.error { color: var(--danger); }

.section-label { font-size: 13px; color: var(--muted); margin: 22px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 14px; padding: 8px 12px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--chip); color: var(--text);
  cursor: pointer;
}

.tile-list { display: flex; flex-direction: column; gap: 12px; }
.tile {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  text-decoration: none; color: var(--text); font-size: 17px; font-weight: 500;
}
.tile .arrow { color: var(--muted); }
.tile.disabled { opacity: 0.5; pointer-events: none; }
.tile .tag { font-size: 12px; color: var(--muted); font-weight: 400; }

.install-hint {
  font-size: 12px; color: var(--muted); margin-top: 20px; text-align: center;
}

/* ---- grammar analysis (Wortarten) ---- */
button.secondary {
  width: 100%; margin-top: 12px;
  border: 1px solid var(--border); background: var(--chip); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 15px; cursor: pointer;
}
button.secondary:disabled { opacity: 0.6; cursor: default; }

.analysis {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;     /* cards in the same row share a height -> tidy */
  gap: 8px;
  margin-top: 16px;
}
.analysis .tok {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  flex: 0 1 auto;           /* size to content: German compounds can be long */
  min-width: 80px;
  max-width: 190px;
  min-height: 78px;
  padding: 8px 10px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--c) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  overflow-wrap: anywhere;  /* last resort: wrap a very long word instead of overflowing */
}
.analysis .tok .w { font-size: 16px; color: var(--text); line-height: 1.2; }
.analysis .tok .cat { font-size: 11px; font-weight: 600; color: var(--c); margin-top: 3px; line-height: 1.25; }
.analysis .tok .feat { font-size: 10px; color: var(--muted); margin-top: 2px; letter-spacing: 0.2px; }
.analysis .tok .art { font-size: 11px; font-weight: 700; color: var(--art); margin-bottom: 1px; }
.analysis .tok .vinfo { font-size: 10px; color: var(--c); margin-top: 3px; line-height: 1.3; }
.analysis .tok .vnote { font-size: 9px; color: var(--muted); font-style: italic; margin-top: 2px; line-height: 1.25; overflow-wrap: anywhere; }

/* Tappable analysis cards -> the real card lifts into a centered overlay. */
.analysis .tok {
  cursor: pointer;
  -webkit-user-select: none; user-select: none;   /* tap = expand, never a stray text selection */
  -webkit-touch-callout: none;
}

.tok-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(10, 9, 7, 0.46);
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease;
}
.tok-overlay.is-open { opacity: 1; pointer-events: auto; }

/* The real card, lifted into the overlay: enlarged, solid, text-selectable.
   It leaves `.analysis`, so the `.analysis .tok` flex-column layout no longer
   applies — re-declare it here, or the word/category/features collapse onto one
   line. */
.tok.tok--promoted {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  position: relative; z-index: 1;
  max-width: min(360px, 88vw);
  min-height: 0;
  padding: 24px 28px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.28);
  cursor: auto;
  -webkit-user-select: text; user-select: text;   /* selecting inside the popup is fine */
  -webkit-touch-callout: default;
}
.tok.tok--promoted .w     { font-size: 26px; }
.tok.tok--promoted .art   { font-size: 14px; }
.tok.tok--promoted .cat   { font-size: 15px; margin-top: 8px; }
.tok.tok--promoted .feat  { font-size: 14px; margin-top: 8px; }
.tok.tok--promoted .vinfo { font-size: 14px; margin-top: 10px; line-height: 1.4; }
.tok.tok--promoted .vnote { font-size: 13px; margin-top: 8px; line-height: 1.4; }

/* Invisible stand-in that holds the card's grid slot so nothing reflows. */
.tok-placeholder { flex: 0 0 auto; visibility: hidden; }
