/* Falar — веб-версия. Токены из DESIGN_SPEC.md (Claude design language). */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
::-webkit-scrollbar { width: 0; height: 0; }

:root {
  --page: #C6C3BA; --canvas: #FAF9F5; --surface: #FFFFFF; --sunk: #F0EEE6; --border: #E8E5DC;
  --t1: #1F1E1B; --t2: #6B6862; --t3: #9B978D;
  --accent: #D97757; --accent-press: #C25E3F; --accent-sunk: #F5E6DF;
  --success: #4F7A52; --success-sunk: #E5EFE3; --error: #C2553D; --error-sunk: #F7E4DE;
  --warning: #C99A3F; --lock: #B8B4A8;
  --shadow: 0 4px 16px rgba(31,30,27,.06); --shadow-lg: 0 10px 34px rgba(31,30,27,.12);
}
[data-theme="dark"] {
  --page: #100F0E; --canvas: #1B1A17; --surface: #26241F; --sunk: #1F1E1A; --border: #36332C;
  --t1: #F2F0E9; --t2: #A8A398; --t3: #7E7A70;
  --accent: #E08763; --accent-press: #C9714F; --accent-sunk: #3A2B24;
  --success: #7FA67F; --success-sunk: #28332A; --error: #D77A62; --error-sunk: #3A2622;
  --warning: #D2A85A; --lock: #5C584F;
  --shadow: none; --shadow-lg: none;
}

html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, "Segoe UI", system-ui, sans-serif;
  background: var(--page); color: var(--t1);
  transition: background .3s;
  touch-action: manipulation;          /* без двойного тапа на зум по всему сайту */
}
.serif { font-family: Lora, Georgia, serif; }

#app {
  max-width: 430px; margin: 0 auto; height: 100dvh;
  background: var(--canvas); display: flex; flex-direction: column;
  position: relative; transition: background .3s;
}
@media (min-width: 480px) {
  #app { margin: 24px auto; height: calc(100dvh - 48px); border-radius: 36px; box-shadow: var(--shadow-lg); overflow: hidden; }
}

.screen { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 20px 110px; animation: fadeup .3s ease-out; }
.screen.no-tab { padding-bottom: 30px; }
@keyframes fadeup { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes reveal { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.18); opacity: .7; } }
@keyframes ping { 0% { transform: scale(.7); opacity: .65; } 100% { transform: scale(1.7); opacity: 0; } }
@keyframes toastup { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

h1 { font-family: Lora, Georgia, serif; font-weight: 600; font-size: 28px; line-height: 1.15; margin: 0; }
h2 { font-family: Lora, Georgia, serif; font-weight: 500; font-size: 18px; margin: 0; }
.sub { font-size: 14px; color: var(--t2); margin-top: 4px; line-height: 1.45; }

/* ---------- базовые компоненты ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 18px; box-shadow: var(--shadow);
}
.tappable { cursor: pointer; transition: transform .12s; user-select: none; }
.tappable:active { transform: scale(.985); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 54px; width: 100%; border-radius: 14px; border: none; cursor: pointer;
  font: 600 16px Inter, sans-serif; transition: transform .12s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn, .icon-btn, .tappable, .gword, .seg button, .chip { touch-action: manipulation; }
/* видимый фокус для клавиатурной навигации (доступность) */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
/* видимое только для скринридеров (доступные имена иконочных кнопок) */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.w1k-opt:focus-visible, .tile:focus-visible, .chip:focus-visible { outline-offset: 1px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-press); }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--t1); }
.btn-success { background: var(--success); color: #fff; }
.btn-text { background: none; color: var(--accent); }
.btn[disabled] { background: var(--sunk); color: var(--t3); cursor: default; }
.btn[disabled]:active { transform: none; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 99px; background: var(--sunk);
  border: none; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--t1); flex: none;
}
.icon-btn:active { transform: scale(.94); }

.pill {
  height: 26px; padding: 0 11px; border-radius: 99px; font-size: 12.5px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
}
.pill-accent { background: var(--accent-sunk); color: var(--accent); }
.pill-sunk { background: var(--sunk); color: var(--t2); }

.seg { display: flex; background: var(--sunk); border-radius: 12px; padding: 4px; gap: 3px; }
.seg button {
  flex: 1; height: 38px; border: none; border-radius: 10px; background: transparent;
  color: var(--t2); font: 500 13.5px Inter, sans-serif; cursor: pointer; white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: var(--shadow); }

.progressbar { flex: 1; height: 8px; border-radius: 99px; background: var(--sunk); overflow: hidden; }
.progressbar > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s ease-out; }

.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- таббар ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; padding: 7px 24px calc(10px + env(safe-area-inset-bottom));
}
@media (min-width: 480px) { .tabbar { bottom: 24px; border-radius: 0 0 36px 36px; } }
.tabbar button {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 4px 0; color: var(--t3); font: 500 11px Inter, sans-serif;
}
.tabbar button.on { color: var(--accent); }

/* ---------- урок / дорожка ---------- */
.lesson-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.lesson-card.locked { opacity: .6; }
.lesson-card.current { border: 1.5px solid var(--accent); }
.lesson-num {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; background: var(--sunk); color: var(--t2);
}
.status-dot { width: 26px; height: 26px; border-radius: 99px; display: flex; align-items: center; justify-content: center; flex: none; }
.miniprog { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.miniprog .bar { flex: 1; height: 5px; border-radius: 99px; background: var(--sunk); overflow: hidden; }
.miniprog .bar > div { height: 100%; border-radius: 99px; background: var(--accent); }
.miniprog span { font-size: 11px; color: var(--t3); }

/* ---------- теория ---------- */
.note-block {
  background: var(--accent-sunk); border-radius: 14px; padding: 13px 15px;
  font-size: 14.5px; line-height: 1.5; color: var(--t1); margin: 12px 0;
}
.vtable { display: grid; grid-template-columns: 34px 1fr 1fr 1fr; gap: 6px; align-items: stretch; }
.vtable .head { font-size: 11px; color: var(--t3); font-weight: 500; text-align: center; align-self: center; }
.vtable .sign {
  width: 26px; height: 26px; border-radius: 8px; background: var(--sunk); color: var(--t2);
  font-weight: 600; font-size: 14px; display: flex; align-items: center; justify-content: center; align-self: center;
}
.vcell {
  background: var(--sunk); color: var(--t1); border: none; border-radius: 11px;
  padding: 11px 4px; text-align: center; font: 500 13.5px Inter, sans-serif;
  cursor: pointer; transition: all .18s;
}
.vcell.on { background: var(--accent); color: #fff; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 13px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border);
  font: 500 14px Inter, sans-serif; color: var(--t1); cursor: pointer;
}
.chip:active { transform: scale(.95); }

/* ---------- учебные таблицы урока (RU) ---------- */
.tbl-card { padding: 14px; }
.tbl-title { font: 600 15px Lora, serif; color: var(--accent); text-align: center; margin-bottom: 12px; }
.tbl-note { margin-top: 10px; line-height: 1.45; }
.tbl { display: grid; gap: 6px; align-items: stretch; }
.tbl .thd { font-size: 11px; color: var(--t3); font-weight: 600; text-align: center; align-self: center; padding-bottom: 2px; }
.tbl .tlbl { font-size: 13px; color: var(--t2); align-self: center; display: flex; align-items: center; }
.tcell {
  background: var(--sunk); color: var(--t1); border: none; border-radius: 11px;
  padding: 11px 8px; text-align: center; font: 500 14.5px Inter, sans-serif;
  cursor: pointer; transition: all .18s;
}
.tcell:active { transform: scale(.96); }
.tcell.on { background: var(--accent); color: #fff; font-weight: 600; }
.tbl-compare { grid-template-columns: auto 1fr 1fr; }
.tbl-paradigm { grid-template-columns: auto 1fr; max-width: 280px; margin: 0 auto; }
.tbl-list { gap: 8px; }
.tbl-list .litem { display: flex; flex-direction: column; gap: 3px; }
.tbl-list .litem-pt { padding: 9px 6px; }
.tbl-list .litem-ru { font-size: 12px; color: var(--t3); text-align: center; }

/* ---------- разбор ошибки в плитках (RU) ---------- */
.diff-sentence {
  font-size: 21px; line-height: 1.5;
  display: flex; flex-wrap: wrap; gap: 6px 8px; justify-content: center;
  padding: 14px; border-radius: 14px; background: var(--sunk);
}
.diff-ok { color: var(--success); font-weight: 600; }
.diff-missing { color: var(--error); font-weight: 600; }
.diff-extra { color: var(--error); text-decoration: line-through; opacity: .7; }
.diff-legend { margin-top: 10px; font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: center; }
.diff-explain {
  margin-top: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--accent-sunk); color: var(--t1); font-size: 14.5px; line-height: 1.5;
}

/* ---------- режим «1000 слов» (RU) ---------- */
.w1k-opts { display: flex; flex-direction: column; gap: 10px; margin-top: 26px; }
.w1k-opt {
  width: 100%; padding: 15px 16px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--t1); font: 500 17px Inter, sans-serif;
  text-align: center; cursor: pointer; transition: all .16s;
}
.w1k-opt:active { transform: scale(.98); }
.w1k-opt[disabled] { cursor: default; }
.w1k-opt.ok { background: var(--success-sunk); border-color: var(--success); color: var(--success); font-weight: 700;
  animation: optPop .42s cubic-bezier(.34,1.56,.64,1) both; box-shadow: 0 0 0 3px var(--success); }
.w1k-opt.bad { background: var(--error-sunk); border-color: var(--error); color: var(--error); font-weight: 600;
  animation: optShake .5s cubic-bezier(.36,.07,.19,.97) both; box-shadow: 0 0 0 2px var(--error); }
.w1k-opt.dim { opacity: .4; transition: opacity .25s; }
@keyframes optPop { 0% { transform: scale(.9); } 45% { transform: scale(1.08); } 70% { transform: scale(.98); } 100% { transform: scale(1); } }
@keyframes optShake { 0%,100% { transform: translateX(0); } 12% { transform: translateX(-10px); } 28% { transform: translateX(9px); } 44% { transform: translateX(-7px); } 60% { transform: translateX(5px); } 76% { transform: translateX(-3px); } 90% { transform: translateX(2px); } }
/* уважение системной настройки «уменьшить движение»: убираем тряску/«поп» и резкие переходы */
@media (prefers-reduced-motion: reduce) {
  .w1k-opt.ok, .w1k-opt.bad { animation: none; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
.sdots { display: inline-flex; gap: 5px; flex: none; align-items: center; }
.sdot { width: 9px; height: 9px; border-radius: 99px; background: var(--sunk); border: 1px solid var(--border); transition: background .2s; }
.sdot.on { background: var(--success); border-color: var(--success); }
.btn-relearn { flex: none; padding: 7px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--accent); font: 500 13px Inter, sans-serif; cursor: pointer; }
.btn-relearn:active { transform: scale(.96); }

/* ---------- прогресс и аккаунт ---------- */
.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 99px; margin-right: 7px; vertical-align: middle; flex: none; }
.sync-dot.ok { background: var(--success); }
.sync-dot.warn { background: var(--warning); }
.sync-dot.off { background: var(--t3); }
.rc-box {
  font: 700 18px/1.3 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 1px;
  background: var(--accent-sunk); color: var(--accent); border-radius: 12px;
  padding: 14px; text-align: center; user-select: all; word-break: break-all;
}
.ac-input {
  width: 100%; box-sizing: border-box; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--t1);
  font: 500 16px Inter, sans-serif;
}
.ac-input:focus { outline: none; border-color: var(--accent); }
.vblank { color: var(--accent); border-bottom: 2px dashed var(--accent); padding: 0 14px; letter-spacing: 2px; }
.vf-block { margin-bottom: 14px; }
.vf-tense { font: 600 12px Inter, sans-serif; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.vf-pron { color: var(--t3); font-size: 13px; }

/* ---------- практика ---------- */
.phrase-ru { font-size: 23px; line-height: 1.35; font-weight: 400; }
.phrase-pt { font-size: 27px; line-height: 1.3; font-weight: 500; letter-spacing: .01em; }
.hint { font-size: 13px; color: var(--t3); }

.tile {
  padding: 10px 14px; border-radius: 11px; font: 500 17px Inter, sans-serif;
  cursor: grab; border: 1px solid var(--border); background: var(--surface); color: var(--t1);
  touch-action: none;                  /* нужно для перетаскивания плиток */
  user-select: none;
}
.tile:active { transform: scale(.95); }
.tile.dragging { opacity: .3; }
.drag-clone {
  position: fixed; z-index: 100; pointer-events: none; cursor: grabbing;
  box-shadow: var(--shadow-lg); margin: 0;
}
.ins-caret {
  width: 3px; align-self: stretch; min-height: 34px; flex: none;
  background: var(--accent); border-radius: 2px; margin: 0 -3px;
}
.tile.in-slot { background: var(--accent-sunk); color: var(--accent); border-color: transparent; }
.tile.ok { background: var(--success-sunk); color: var(--success); border-color: transparent; }
.tile.bad { background: var(--error-sunk); color: var(--error); border-color: transparent; }
.tile.ghost { background: var(--sunk); color: transparent; border-color: transparent; pointer-events: none; }

.histbar { height: 10px; border-radius: 99px; background: var(--sunk); overflow: hidden; }
.slotzone {
  min-height: 58px; border-radius: 14px; background: var(--sunk);
  border: 1.5px dashed var(--border); padding: 10px;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
}
.bankzone { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 16px; }

.bigbtn {
  width: 96px; height: 96px; border-radius: 99px; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.bigbtn:active { transform: scale(.95); }

.word-ok { color: var(--success); font: 500 22px Inter, sans-serif; }
.word-bad { color: var(--error); font: 500 22px Inter, sans-serif; }
.word-dim { color: var(--t3); font: 500 22px Inter, sans-serif; text-decoration: line-through; }

.playing { animation: pulse .9s ease-in-out infinite; }

/* ---------- разное ---------- */
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.statgrid .card { padding: 16px; }
.statnum { font-family: Lora, Georgia, serif; font-size: 26px; font-weight: 600; }
.statlabel { font-size: 12.5px; color: var(--t2); margin-top: 2px; }

.settings-group { border-radius: 18px; overflow: hidden; padding: 0; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 15px 18px; border-bottom: 1px solid var(--border); font-size: 15px;
}
.settings-row:last-child { border-bottom: none; }
.settings-col { padding: 15px 18px; border-bottom: 1px solid var(--border); }
.settings-col:last-child { border-bottom: none; }
.group-label { font-size: 13px; color: var(--t3); font-weight: 500; padding: 0 4px 8px; }

.toggle { width: 46px; height: 28px; border-radius: 99px; border: none; cursor: pointer; position: relative; background: var(--border); flex: none; }
.toggle.on { background: var(--accent); }
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 99px; background: #fff; transition: left .18s;
}
.toggle.on::after { left: 21px; }

select, input[type="range"] { accent-color: var(--accent); }
select {
  background: var(--sunk); border: none; border-radius: 10px; padding: 8px 10px;
  font: 500 13px Inter, sans-serif; color: var(--t1); max-width: 190px;
}

.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: var(--t1); color: var(--canvas); padding: 11px 18px; border-radius: 99px;
  font-size: 14px; z-index: 99; animation: toastup .25s ease-out; max-width: 86vw; text-align: center;
}

.overlay {
  position: fixed; inset: 0; background: rgba(20,18,15,.45); z-index: 80;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 430px; background: var(--surface);
  border-radius: 28px 28px 0 0; padding: 12px 24px calc(34px + env(safe-area-inset-bottom));
  animation: reveal .3s ease-out;
}
.sheet-handle { width: 40px; height: 5px; border-radius: 99px; background: var(--border); margin: 0 auto 20px; }

.gword { cursor: pointer; border-bottom: 1px dashed var(--t3); padding-bottom: 1px; }
.gword:active { color: var(--accent); border-bottom-color: var(--accent); }
.gloss-pop {
  position: fixed; z-index: 95; background: var(--t1); color: var(--canvas);
  padding: 7px 8px 7px 13px; border-radius: 12px; font: 600 17px Inter, sans-serif;
  display: flex; align-items: center; gap: 6px; box-shadow: var(--shadow-lg); max-width: 84vw;
}
.gloss-pop .gloss-spk {
  background: none; border: none; color: var(--canvas); cursor: pointer;
  padding: 4px; display: flex; opacity: .75; touch-action: manipulation;
}

.ring-wrap { position: relative; display: inline-block; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
