:root {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --again: #dc2626;
  --hard: #d97706;
  --good: #16a34a;
  --easy: #2563eb;
  /* German genders: der / die / das */
  --g-m: #2563eb;
  --g-f: #db2777;
  --g-n: #16a34a;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1b1e26;
    --text: #eceef2;
    --muted: #9aa1ad;
    --border: #2a2e38;
    --accent: #818cf8;
    --accent-soft: #26293d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}
input, textarea {
  user-select: text;
  -webkit-user-select: text;
}
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 16px calc(16px + env(safe-area-inset-bottom));
}

button {
  font: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}
input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { resize: vertical; min-height: 72px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0 10px;
}
.topbar h1 {
  font-size: 19px;
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.iconbtn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  display: grid;
  place-items: center;
  font-size: 19px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.pill {
  font-size: 12.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* study header counters */
.pill-learn, .pill-due, .pill-new {
  font-size: 13.5px;
  font-weight: 700;
  min-width: 30px;
  text-align: center;
  padding: 4px 8px;
  border-radius: 9px;
}
.pill-learn { color: var(--again); background: color-mix(in srgb, var(--again) 14%, transparent); }
.pill-due  { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.pill-new  { color: var(--easy); background: color-mix(in srgb, var(--easy) 14%, transparent); }
.pill-learn.empty, .pill-due.empty, .pill-new.empty { color: var(--muted); background: transparent; opacity: 0.5; }

/* deck list */
.deck-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 15px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgb(0 0 0 / 4%);
}
.deck-row .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.deck-row .counts { display: flex; gap: 10px; font-size: 15px; font-weight: 700; }
.count-new { color: var(--easy); }
.count-due { color: var(--good); }
.count-zero { color: var(--muted); font-weight: 500; }

.actions { display: flex; gap: 10px; margin-top: 8px; }
.actions button {
  flex: 1;
  padding: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
}
.primary { background: var(--accent) !important; color: #fff !important; border: none !important; }

.statline { color: var(--muted); font-size: 13.5px; text-align: center; margin: 14px 0 4px; }

/* study */
.study { flex: 1; display: flex; flex-direction: column; }
.card-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 20px;
  margin: 6px 0 14px;
  overflow-y: auto;
  text-align: center;
  font-size: 23px;
  line-height: 1.45;
  word-break: break-word;
}
.card-area.clickable { cursor: pointer; }
.card-area hr { border: none; border-top: 1px solid var(--border); margin: 18px 10%; }
.card-front { font-size: 26px; font-weight: 600; }
.card-back { font-size: 20px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 18%; }

.show-btn { padding: 18px; font-size: 17px; font-weight: 700; }
.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ratings button {
  padding: 11px 4px 9px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}
.ratings small { font-weight: 500; font-size: 11.5px; opacity: 0.85; }
.r1 { background: var(--again); }
.r2 { background: var(--hard); }
.r3 { background: var(--good); }
.r4 { background: var(--easy); }

.speak {
  margin: 18px auto 0;
  font-size: 21px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
}
.speak:active { transform: scale(0.92); }

.done { text-align: center; margin-top: 30vh; }
.done .big { font-size: 44px; }

/* browse */
.card-item {
  width: 100%;
  text-align: left;
  padding: 13px 15px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  font-size: 14.5px;
}
.card-item .f { font-weight: 600; margin-bottom: 3px; }
.card-item .b { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-item .meta { font-size: 12px; color: var(--muted); margin-top: 5px; }

.form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: -6px; }

/* login */
.login { margin-top: 24vh; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login .logo { width: 88px; height: 88px; margin: 0 auto; image-rendering: pixelated; }
.login h1 { margin: 0; }

.error { color: var(--again); font-size: 14px; text-align: center; margin: 8px 0; }
.notice { color: var(--muted); font-size: 13.5px; }

/* import */
.import-deck {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.import-deck input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.import-deck .name { flex: 1; font-weight: 600; word-break: break-word; }
progress { width: 100%; accent-color: var(--accent); }

.filebtn { padding: 40px 20px; border: 2px dashed var(--border); text-align: center; color: var(--muted); font-weight: 600; width: 100%; }

/* stats */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.tile-n { font-size: 27px; font-weight: 700; letter-spacing: -0.5px; }
.tile-unit { font-size: 16px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.tile-l { font-size: 13px; color: var(--muted); margin-top: 2px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  margin-bottom: 10px;
}
.panel h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; color: var(--muted); }

.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.grid { stroke: var(--border); stroke-width: 1; }
.grid.strong { stroke: var(--muted); opacity: 0.5; }
.axis { font-size: 9px; fill: var(--muted); }
.xlabels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }
.charttip {
  position: absolute;
  top: -6px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

.rrow { display: flex; align-items: center; gap: 10px; margin: 7px 0; }
.rlabel { width: 46px; font-size: 13px; color: var(--muted); }
.rbar-track { flex: 1; height: 12px; }
.rbar { display: block; height: 100%; min-width: 2px; border-radius: 0 3px 3px 0; }
.rcount { width: 42px; text-align: right; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.stack { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; }
.seg { display: block; min-width: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; }
.chip { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.chip b { color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* collocation map */
.nexus-chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.nexus-chip b { color: var(--accent); margin-left: 3px; }
.nexus-chip.active { background: var(--accent); color: #fff; border-color: transparent; }
.nexus-chip.active b { color: #fff; opacity: 0.8; }

.mindmap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
}
.mmlines { position: absolute; inset: 0; width: 100%; height: 100%; }
.mmlines line { stroke: var(--border); stroke-width: 1.5; }
.mmleaf {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 7px 11px;
  font-size: 13.5px;
  max-width: 150px;
  text-align: center;
  cursor: pointer;
  line-height: 1.3;
  z-index: 1;
}
.mmleaf.flipped { border-color: var(--accent); color: var(--muted); font-style: italic; }
.mmnexus {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  padding: 10px 18px;
  border: none;
  border-radius: 99px;
  z-index: 2;
  cursor: default;
  max-width: 190px;
}

.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 99px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 25%);
  z-index: 10;
  white-space: nowrap;
}
