:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1d2333;
  --muted: #6b7386;
  --line: #e2e5ee;
  --accent: #3b5bdb;
  --accent-soft: #e7ecff;
  --ok: #2b8a3e;
  --ok-soft: #e3f6e8;
  --bad: #c92a2a;
  --bad-soft: #fde8e8;
  --almost: #b7791f;
  --almost-soft: #fdf3dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .06);
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.8rem; margin: .3em 0 .5em; }
h2 { font-size: 1.2rem; margin: 0 0 .6em; }
code { background: var(--accent-soft); padding: 0 .3em; border-radius: 4px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 18px; }

main { max-width: 960px; margin: 0 auto; padding: 24px; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.error { color: var(--bad); font-weight: 600; }
form.inline { display: inline; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin: 20px 0; box-shadow: var(--shadow);
}
.banner { padding: 16px 20px; border-radius: var(--radius); font-weight: 600; margin: 16px 0; }
.banner { background: var(--accent-soft); }
.banner.success { background: var(--ok-soft); color: var(--ok); }
.badge-new { display: inline-block; margin-bottom: 10px; padding: 2px 12px; border-radius: 99px; background: var(--almost-soft); color: var(--almost); font-size: .85rem; font-weight: 600; }
tr.portion td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: #f1c0c0; }
.btn.big { padding: 14px 28px; font-size: 1.15rem; }
.btn.small { padding: 4px 10px; font-size: .875rem; }
.btn.disabled, .btn:disabled { opacity: .45; cursor: default; pointer-events: none; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 1.4rem; padding: 2px 6px; border-radius: 8px; }
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn.small { font-size: 1rem; }

input, select {
  font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
.stack.narrow { max-width: 420px; }
.narrow-field { max-width: 420px; }
.mode-groups { display: flex; gap: 20px; flex-wrap: wrap; }
.mode-groups fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; min-width: 240px; }
.mode-groups legend { color: var(--muted); font-size: .9rem; padding: 0 4px; }
.stack label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 1rem; padding: 3px 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }

table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 16px; }
table.grid th, table.grid td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.grid th { font-size: .85rem; color: var(--muted); font-weight: 600; background: #fafbfe; }
table.grid tr:last-child td { border-bottom: 0; }
tr:target td { background: var(--accent-soft); }

.tag { display: inline-block; font-size: .8rem; padding: 1px 8px; border-radius: 99px; background: var(--line); color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.portion { background: var(--accent-soft); color: var(--accent); }
.tag.new { background: var(--almost-soft); color: var(--almost); }

.atts { display: flex; flex-wrap: wrap; gap: 3px; }
.att { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; border-radius: 5px; font-size: .8rem; font-weight: 700; cursor: default; }
.att.ok { background: var(--ok-soft); color: var(--ok); }
.att.almost { background: var(--almost-soft); color: var(--almost); }
.att.bad { background: var(--bad-soft); color: var(--bad); }
.att.reset { background: var(--line); color: var(--muted); }
.legend .att { margin: 0 2px 0 10px; }

.login { max-width: 380px; margin: 8vh auto; text-align: center; }
.login .stack { text-align: left; }
.pin-input { font-size: 2rem; text-align: center; letter-spacing: .4em; padding: 12px; }
.pin-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.big-pin { font-size: 1.5rem; letter-spacing: .15em; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.tile-link {
  display: flex; flex-direction: column; gap: 10px; padding: 18px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text);
}
.tile-link:hover { border-color: var(--accent); text-decoration: none; }
.tile-title { font-weight: 600; font-size: 1.1rem; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); }
.modes { display: flex; flex-wrap: wrap; gap: 10px; }
.main-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 24px 0 36px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 36px 20px; border-radius: 18px; background: var(--accent); color: #fff; box-shadow: var(--shadow);
}
.action .muted { color: rgba(255, 255, 255, .8); }
.action:hover { filter: brightness(1.08); text-decoration: none; }
.action.disabled { background: var(--line); color: var(--muted); box-shadow: none; }
.action.disabled .muted { color: var(--muted); }
.action-title { font-size: 1.8rem; font-weight: 700; }

/* Study and quiz */
.play { max-width: 640px; margin: 0 auto; }
.quiz-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.quiz-head h1 { margin-bottom: .2em; }
.counter { color: var(--muted); text-align: center; margin: 8px 0 12px; }
.start { text-align: center; padding: 40px 0; }

.card {
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 36px 32px; text-align: center;
}
.card-word { display: flex; align-items: center; justify-content: center; gap: 8px; }
.card .en { font-size: 2.6rem; font-weight: 700; }
.card .transcription { color: var(--muted); font-size: 1.1rem; }
.card .ru { font-size: 1.6rem; margin-top: 14px; color: var(--accent); }
.card .example { margin-top: 26px; padding-top: 18px; border-top: 1px dashed var(--line); }
.card .ex-en { font-size: 1.15rem; }
.card .ex-ru { color: var(--muted); }
.nav-row { display: flex; justify-content: center; gap: 12px; margin: 20px 0; flex-wrap: wrap; }

.prompt { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 90px; margin-bottom: 20px; }
.prompt-word { font-size: 2.4rem; font-weight: 700; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.option {
  padding: 18px; font: inherit; font-size: 1.2rem; border-radius: var(--radius); border: 2px solid var(--line);
  background: var(--surface); cursor: pointer; text-align: center;
}
.option:hover { border-color: var(--accent); }
.option .key { color: var(--muted); font-size: .8rem; margin-right: 6px; }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }

.answer-form { display: flex; gap: 10px; }
.answer { flex: 1; font-size: 1.4rem; padding: 12px 16px; }
.answer.correct { border-color: var(--ok); background: var(--ok-soft); }
.answer.almost { border-color: var(--almost); background: var(--almost-soft); }
.answer.wrong { border-color: var(--bad); background: var(--bad-soft); }

.feedback { margin-top: 18px; padding: 16px 20px; border-radius: var(--radius); display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 1.1rem; }
.feedback.correct { background: var(--ok-soft); color: var(--ok); }
.feedback.almost { background: var(--almost-soft); color: var(--almost); }
.feedback.wrong { background: var(--bad-soft); color: var(--bad); }
.feedback .reveal { color: var(--text); margin-top: 4px; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.match .col { display: flex; flex-direction: column; gap: 10px; }
.tile {
  padding: 14px; font: inherit; font-size: 1.1rem; border-radius: var(--radius); border: 2px solid var(--line);
  background: var(--surface); cursor: pointer; transition: opacity .3s, background .2s;
}
.tile:hover { border-color: var(--accent); }
.tile.selected { border-color: var(--accent); background: var(--accent-soft); }
.tile.flash { border-color: var(--bad); background: var(--bad-soft); }
.tile.matched {
  border-color: var(--pair); background: color-mix(in srgb, var(--pair) 12%, var(--surface));
  color: var(--text); cursor: default;
}

.summary { text-align: center; padding: 20px 0; }
.summary h2 { font-size: 1.6rem; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: var(--ok); color: #fff; padding: 12px 22px; border-radius: 99px; font-weight: 600;
  box-shadow: var(--shadow); animation: pop .25s ease-out;
}
@keyframes pop { from { transform: translate(-50%, 12px); opacity: 0; } }
