:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #687085;
  --border: #dde1e9;
  --accent: #2f5bea;
  --accent-soft: #e8eefe;
  --ok: #188a4a;
  --ok-bg: #e3f5ea;
  --bad: #c93a3a;
  --bad-bg: #fbe8e8;
  --mask: #e3e6ee;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --card: #1b2029;
    --text: #e6e9ef;
    --muted: #949cb0;
    --border: #2c3340;
    --accent: #6d8cff;
    --accent-soft: #232c45;
    --ok: #4cc47f;
    --ok-bg: #173323;
    --bad: #ff7676;
    --bad-bg: #3a1d1f;
    --mask: #2c3340;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button { font: inherit; color: inherit; }

h1 { font-size: 1.6rem; margin: .2rem 0 .4rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
.muted { color: var(--muted); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1.2rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  background: none;
  border: 0;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--accent);
  padding: 0;
}
.header-user { display: flex; align-items: center; gap: .6rem; white-space: nowrap; }
.brand { white-space: nowrap; }
.user-name { font-weight: 600; }

main { max-width: 960px; margin: 0 auto; padding: 1.5rem 1.2rem 3rem; }
.narrow { max-width: 680px; margin: 0 auto; }

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  padding: .6rem 1.1rem;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: .3rem .7rem; font-size: .85rem; }
.btn.big { width: 100%; padding: .9rem; font-size: 1.05rem; margin-top: .8rem; }

.back {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  margin-bottom: .6rem;
}
.back:hover { color: var(--accent); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
  margin-bottom: 1rem;
}

/* Profiles */
.profiles { display: grid; gap: .6rem; margin: 1rem 0 1.5rem; }
.profile { display: flex; gap: .5rem; }
.profile-name {
  flex: 1;
  text-align: left;
  padding: .9rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-weight: 600;
  font-size: 1.05rem;
}
.profile-name:hover { border-color: var(--accent); }
.profile .icon-btn { height: auto; width: 3rem; }
.add-profile { display: flex; gap: .6rem; margin-top: 1rem; }
.add-profile input, .search {
  flex: 1;
  padding: .6rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
}

/* Home tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-top: 1.2rem;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  text-align: left;
  padding: 1.3rem;
  min-height: 140px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.tile:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.tile:disabled { cursor: default; opacity: .55; }
.tile-title { font-size: 1.2rem; font-weight: 700; }
.tile-desc { color: var(--muted); font-size: .92rem; }
.tile-meta { margin-top: auto; font-size: .85rem; font-weight: 600; color: var(--accent); }
.tile-accent { border-color: var(--accent); background: var(--accent-soft); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin: 1rem 0; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .9rem .5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat b { font-size: 1.8rem; line-height: 1.1; white-space: nowrap; }
.stat span { font-size: .85rem; color: var(--muted); text-align: center; }
.stat { min-width: 0; }
.dots { letter-spacing: .15em; color: var(--accent); white-space: nowrap; }

/* Statistics */
.home-links { margin-top: 1.2rem; display: flex; justify-content: flex-end; }
.small { font-size: .85rem; }
.stat-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem; }
.stats.four { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 560px) { .stats.four { grid-template-columns: repeat(2, 1fr); } }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; margin: .4rem 0 1.2rem; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; }
.bar span { font-size: .65rem; color: var(--muted); text-align: center; margin-top: 2px; }
.bar-a {
  background: var(--bad-bg);
  border: 1px solid var(--border);
  border-radius: 3px 3px 0 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 2px;
  overflow: hidden;
}
.bar-c { background: var(--ok); }
.lvl-row { display: flex; align-items: center; gap: .7rem; margin: .35rem 0; }
.lvl-name { width: 4.5rem; font-weight: 600; font-size: .9rem; }
.lvl-num { width: 6.5rem; text-align: right; font-size: .85rem; }
.pbar { flex: 1; height: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; overflow: hidden; display: flex; }
.pbar-l { background: var(--ok); }
.pbar-s { background: var(--accent); opacity: .45; }
.legend { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; vertical-align: middle; margin-left: .4rem; }
.legend.l, .legend.c { background: var(--ok); }
.legend.s { background: var(--accent); opacity: .45; }
.legend.a { background: var(--bad-bg); border: 1px solid var(--border); }

/* Cloud: sign-in, devices, access */
.signin { text-align: center; padding: 2rem 1.5rem; }
.list { list-style: none; padding: 0; margin: .3rem 0 1rem; }
.list li {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}
.list li > span:first-child { flex: 1; }
.list li:last-child { border-bottom: 0; }
.inline { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
code { background: var(--bg); padding: .1rem .3rem; border-radius: 4px; }

/* Setup fields */
.field { margin: 1.1rem 0; }
.field-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: .4rem;
}
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 4.2rem;
  padding: .5rem .9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-weight: 600;
}
.seg-btn small { font-weight: 400; font-size: .75rem; color: var(--muted); }
.seg-btn:hover:not(:disabled) { border-color: var(--accent); }
.seg-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.seg-btn:disabled { opacity: .45; cursor: default; }

.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.2rem; }
.actions .btn { flex: 1; min-width: 140px; padding: .8rem; }

/* Quiz */
.quiz-top { display: flex; align-items: center; gap: 1rem; margin-bottom: .5rem; }
.quiz-title { font-weight: 700; flex: 1; }
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 1.2rem; }
.progress > div { height: 100%; background: var(--accent); transition: width .2s; }

.question { text-align: center; padding: 1.8rem 1.2rem; }
.q-label { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.q-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .7rem;
  font-size: 2rem;
  font-weight: 700;
  margin: .5rem 0 .2rem;
  word-break: break-word;
}
.q-sub { color: var(--muted); }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
@media (max-width: 560px) {
  .options { grid-template-columns: 1fr; }
  .q-prompt { font-size: 1.5rem; }
}
.option {
  display: flex;
  align-items: center;
  gap: .8rem;
  text-align: left;
  padding: 1rem;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-size: 1.05rem;
  transition: border-color .12s, background .12s;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled { cursor: default; }
.option .key {
  flex-shrink: 0;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  background: var(--bg);
  color: var(--muted);
}
.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.correct .key { background: var(--ok); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option.wrong .key { background: var(--bad); color: #fff; }
.option.dim { opacity: .55; }

.feedback {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .7rem;
  min-height: 2.6rem;
  margin: 1rem 0 .4rem;
}
.feedback .info { color: var(--muted); }
.next-row { display: flex; justify-content: flex-end; }
.next-row .btn { min-width: 160px; }
.hint { font-size: .8rem; color: var(--muted); text-align: center; margin-top: 1rem; }

.ok { color: var(--ok); }
.bad { color: var(--bad); }

/* Summary */
.score { text-align: center; }
.score-pct { font-size: 3rem; font-weight: 800; }
.mistakes { list-style: none; padding: 0; margin: 0; }
.mistakes li {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}
.mistakes li:last-child { border-bottom: 0; }
.mistakes .arrow { color: var(--muted); }

/* Verb table */
.table-tools { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; margin: 1rem 0; }
.toggles { display: flex; flex-wrap: wrap; gap: .8rem; font-size: .9rem; }
.toggles label { display: inline-flex; align-items: center; gap: .3rem; cursor: pointer; }
.table-wrap { overflow-x: auto; }
table.verbs { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.verbs th, .verbs td { padding: .55rem .8rem; text-align: left; border-bottom: 1px solid var(--border); }
.verbs th {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: var(--bg);
  position: sticky;
  top: 0;
}
.verbs td.en { font-weight: 600; }
.verbs td.masked {
  color: transparent;
  background: var(--mask);
  cursor: pointer;
  user-select: none;
}
.verbs td.lvl { color: var(--muted); font-size: .85rem; }
.verbs td.done { color: var(--ok); font-weight: 700; width: 1.5rem; }
.verbs .icon-btn { width: 1.8rem; height: 1.8rem; }
