:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #efece3;
  --text: #1d2420;
  --muted: #66706a;
  --border: #e0dcd0;
  --accent: #0f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe6;
  --gold: #e5b82a;
  --again: #c8423b;
  --hard: #c7792a;
  --good: #1f8a5b;
  --easy: #2f63b8;
  --shadow: 0 1px 2px rgb(20 30 25 / 6%), 0 8px 24px rgb(20 30 25 / 7%);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1b211e;
    --surface-2: #232a26;
    --text: #e9eeea;
    --muted: #97a39c;
    --border: #2f3833;
    --accent: #3fb68a;
    --accent-ink: #08130e;
    --accent-soft: #1f3b30;
    --again: #e0675f;
    --hard: #e09a4f;
    --good: #45b884;
    --easy: #6a96e4;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
}
button:hover, .button:hover { border-color: var(--muted); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 8px 10px; }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.danger { color: var(--again); }
button.wide { width: 100%; padding: 16px; font-size: 1.05rem; }

kbd {
  font: 600 0.72rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid currentColor;
  opacity: 0.6;
}

input[type="text"], input[type="email"], input[type="number"], input[type="search"], select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Layout ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand span { color: var(--accent); }
.tabs { display: flex; gap: 4px; }
.tabs button { border: none; background: transparent; padding: 8px 12px; color: var(--muted); font-weight: 500; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }
.view.narrow { max-width: 520px; margin: 0 auto; }
h1 { font-size: 1.9rem; line-height: 1.2; letter-spacing: -0.02em; margin: 8px 0 12px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
.lead { font-size: 1.08rem; color: var(--muted); margin: 0 0 24px; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.9rem; margin: -4px 0 4px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.form { display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-weight: 500; }
.form label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.form label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 8px; }

.banner {
  max-width: 760px;
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--again) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--again) 40%, transparent);
}
.banner code { font-size: 0.9em; }

.translate-progress {
  max-width: 760px;
  margin: 12px auto 0;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--muted);
}
.translate-progress .track { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.translate-progress .fill { height: 100%; width: 0; background: var(--accent); transition: width 0.4s ease; }

/* --- Dashboard --------------------------------------------------------- */

.hero { margin-bottom: 20px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 1.9rem; line-height: 1.1; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 0.88rem; }
.stat.new b { color: var(--easy); }
.stat.learn b { color: var(--hard); }
.stat.review b { color: var(--good); }

.overall { margin-bottom: 20px; }
.overall .meter { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; display: flex; margin: 10px 0 6px; }
.overall .meter i { display: block; height: 100%; }
.overall .meter .known { background: var(--accent); }
.overall .meter .started { background: var(--gold); }
.overall .legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.86rem; color: var(--muted); }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

.upcoming { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  padding: 5px 11px;
  border-radius: 99px;
  background: var(--surface-2);
  font-size: 0.9rem;
}
.chip small { color: var(--muted); margin-right: 4px; }

.done { text-align: center; padding: 28px 20px; }
.done .big { font-size: 2.6rem; }

/* --- Studiekort ---------------------------------------------------------- */

.session-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.counts { display: flex; gap: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.count.new { color: var(--easy); }
.count.learn { color: var(--hard); }
.count.review { color: var(--good); }
.count.current { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; }

.card {
  min-height: 340px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 20px 22px 26px;
}
.card-meta { display: flex; justify-content: space-between; align-items: center; font-size: 0.82rem; color: var(--muted); }
.dir-badge { padding: 4px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.card-body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 6px; padding: 16px 0 4px; }
.term { font-size: clamp(2.1rem, 7vw, 3rem); font-weight: 750; letter-spacing: -0.02em; line-height: 1.15; overflow-wrap: anywhere; }
.term-row { display: flex; align-items: center; justify-content: center; gap: 10px; }
.forms { color: var(--muted); font-size: 0.95rem; }
.clue { font-style: italic; color: var(--muted); }
.answer { width: 100%; border-top: 1px dashed var(--border); margin-top: 18px; padding-top: 18px; display: grid; gap: 8px; justify-items: center; }
.answer .term { font-size: clamp(1.7rem, 5.5vw, 2.3rem); color: var(--accent); }
.example { margin-top: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); width: 100%; text-align: left; display: grid; gap: 2px; }
.example .pt { display: flex; align-items: flex-start; gap: 8px; font-weight: 550; }
.example .tr { color: var(--muted); }
.speak {
  width: 38px; height: 38px; padding: 0; flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}
.speak.small { width: 28px; height: 28px; }
.speak svg { width: 55%; height: 55%; }

.typed { width: 100%; max-width: 360px; margin-top: 14px; text-align: center; font-size: 1.1rem; }
.verdict { font-weight: 600; padding: 4px 12px; border-radius: 99px; }
.verdict.right { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.verdict.close { color: var(--hard); background: color-mix(in srgb, var(--hard) 14%, transparent); }
.verdict.wrong { color: var(--again); background: color-mix(in srgb, var(--again) 14%, transparent); }

.actions { margin-top: 16px; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade { flex-direction: column; gap: 2px; padding: 12px 6px; border-width: 2px; }
.grade small { color: var(--muted); font-size: 0.8rem; }
.grade.again { border-color: color-mix(in srgb, var(--again) 55%, transparent); color: var(--again); }
.grade.hard { border-color: color-mix(in srgb, var(--hard) 55%, transparent); color: var(--hard); }
.grade.good { border-color: color-mix(in srgb, var(--good) 55%, transparent); color: var(--good); }
.grade.easy { border-color: color-mix(in srgb, var(--easy) 55%, transparent); color: var(--easy); }
.shortcuts { text-align: center; font-size: 0.8rem; color: var(--muted); margin-top: 18px; }

/* --- Ordlista ------------------------------------------------------------ */

.list-tools { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 8px; }
.list-tools select { width: auto; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.word-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.word-table th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--surface-2); padding: 10px 12px; }
.word-table td { padding: 10px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.word-table td:first-child { color: var(--muted); font-variant-numeric: tabular-nums; width: 3.5em; }
.word-table .pt { font-weight: 650; cursor: pointer; }
.word-table .pt small { display: block; font-weight: 400; color: var(--muted); }
.word-table .pending { color: var(--muted); font-style: italic; }
.status { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.status span { font-size: 0.76rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.status span.on { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .brand { font-size: 1.05rem; }
  .tabs button { padding: 7px 9px; font-size: 0.92rem; }
  main { padding-top: 16px; }
  .stats { gap: 8px; }
  .stat { padding: 12px; }
  .stat b { font-size: 1.5rem; }
  .card { min-height: 300px; padding: 16px 16px 22px; }
  .grades { gap: 6px; }
  .shortcuts { display: none; }
  .word-table th:nth-child(4), .word-table td:nth-child(4) { display: none; }
}
