/* Мир: полка заготовок. Сталь, малярный скотч с маркером, стикеры дней недели. */

@font-face {
  font-family: "Marker";
  src: url("/static/fonts/caveat-cyrillic.woff2") format("woff2");
  font-weight: 500 700;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Marker";
  src: url("/static/fonts/caveat-latin.woff2") format("woff2");
  font-weight: 500 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}

:root {
  /* сталь стола заготовок */
  --steel: #e4e8eb;
  --steel-2: #d6dbdf;
  --surface: #f5f7f8;
  --surface-press: #e9edf0;
  --line: #c3cad0;
  --ink: #1a1d21;
  --ink-2: #48505a;
  --ink-3: #6b737d;
  /* скотч и маркер */
  --tape: #eee2bf;
  --tape-shade: #ddcc9a;
  --tape-ink: #1c1b1a;
  --tape-ink-2: #5d5440;
  /* стикеры ротации: пн–вс */
  --d1: #1f5fbf;
  --d2: #efbd1d;
  --d3: #d43939;
  --d4: #7a4a29;
  --d5: #2b9a4c;
  --d6: #ea791b;
  --d7: #26292e;
  --good: #22894a;
  --bad: #c9302f;
  --good-wash: #dcefe2;
  --bad-wash: #f7dedd;
  --focus: #1f5fbf;

  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-marker: "Marker", "Segoe Print", cursive;
  --r-s: 8px;
  --r-m: 12px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar-h: calc(58px + var(--safe-b));
  color-scheme: light;
}

:root[data-theme="dark"] {
  --steel: #1d2125;
  --steel-2: #16191c;
  --surface: #2a2f35;
  --surface-press: #333940;
  --line: #3b424a;
  --ink: #eceff2;
  --ink-2: #b2bac3;
  --ink-3: #8d96a0;
  --tape: #e2d4ab;
  --tape-shade: #c6b47f;
  --good: #47b86b;
  --bad: #ef5b55;
  --good-wash: #1f3a2a;
  --bad-wash: #43201f;
  --d7: #0f1113;
  --focus: #6d9ff0;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  background: var(--steel);
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 240px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.012) 0 2px, rgba(255, 255, 255, 0.018) 2px 4px),
    var(--steel);
  color: var(--ink);
  font: 400 16px/1.45 var(--font-ui);
  font-variant-numeric: tabular-nums;
}

::selection { background: var(--tape); color: var(--tape-ink); }

button, [role="button"], .chip, .tab {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-s);
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px calc(var(--tabbar-h) + 28px);
}
body.no-tabs #app { padding-bottom: calc(96px + var(--safe-b)); }

h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  margin: 28px 0 10px;
}

.muted { color: var(--ink-2); }
.small { font-size: 14px; }

/* --- скотч ------------------------------------------------------------------------ */

.tape {
  position: relative;
  display: block;
  background:
    repeating-linear-gradient(97deg, rgba(255, 255, 255, 0.16) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(0, 0, 0, 0.03)),
    var(--tape);
  color: var(--tape-ink);
  padding: 14px 18px 16px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12), 0 6px 14px -8px rgba(0, 0, 0, 0.35);
  /* рваные края слева и справа: маска зубцами, а не многоугольник */
  -webkit-mask:
    linear-gradient(#000 0 0) center / calc(100% - 12px) 100% no-repeat,
    conic-gradient(from -45deg at left, #000 90deg, transparent 0) left / 6px 9px repeat-y,
    conic-gradient(from 135deg at right, #000 90deg, transparent 0) right / 6px 9px repeat-y;
  mask:
    linear-gradient(#000 0 0) center / calc(100% - 12px) 100% no-repeat,
    conic-gradient(from -45deg at left, #000 90deg, transparent 0) left / 6px 9px repeat-y,
    conic-gradient(from 135deg at right, #000 90deg, transparent 0) right / 6px 9px repeat-y;
  transform: rotate(-0.6deg);
}
.tape--flat { transform: none; }
.tape--boot { margin: 40vh auto 0; width: max-content; }

.marker {
  font-family: var(--font-marker);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.01em;
}
.tape .marker { display: block; font-size: 36px; }
.tape .tape-sub {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  color: var(--tape-ink-2);
}

/* --- стикеры дней ---------------------------------------------------------------------- */

.dot {
  --c: var(--d1);
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 45%),
    var(--c);
  color: #fff;
  font: 700 11px/1 var(--font-ui);
  letter-spacing: 0.02em;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18), 0 2px 5px -2px rgba(0, 0, 0, 0.4);
  flex: none;
}
.dot[data-d="1"] { --c: var(--d1); }
.dot[data-d="2"] { --c: var(--d2); color: #2a2205; }
.dot[data-d="3"] { --c: var(--d3); }
.dot[data-d="4"] { --c: var(--d4); }
.dot[data-d="5"] { --c: var(--d5); }
.dot[data-d="6"] { --c: var(--d6); color: #2b1503; }
.dot[data-d="7"] { --c: var(--d7); }
:root[data-theme="dark"] .dot[data-d="7"] { box-shadow: inset 0 0 0 1.5px #5b636c; }
.dot--s { width: 22px; height: 22px; font-size: 9px; }
.dot--empty {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line);
  color: var(--ink-3);
}
.dot.stick { animation: stick 320ms var(--ease-out) both; }
@keyframes stick {
  0% { transform: scale(1.35) rotate(-14deg); box-shadow: 0 10px 16px -6px rgba(0, 0, 0, 0.45); }
  70% { transform: scale(0.96) rotate(1deg); }
  100% { transform: none; }
}

.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 18px;
  text-align: center;
}
.week .day { display: grid; justify-items: center; gap: 5px; }
.week .count { font-size: 15px; font-weight: 600; }
.week .count.zero { color: var(--ink-3); font-weight: 400; }
.week .when { font-size: 11px; color: var(--ink-3); margin-top: -2px; }

/* --- чипы разделов ----------------------------------------------------------------------- */

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 2px 16px 4px;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 16px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  scroll-snap-align: start;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 15px;
  white-space: nowrap;
  transition: background 120ms, transform 100ms var(--ease-out);
}
.chip:active { transform: scale(0.97); }
.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--steel);
  box-shadow: none;
}

/* --- строки разделов ---------------------------------------------------------------------- */

.rows { display: grid; gap: 2px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 4px;
  transition: background 120ms;
}
.rows > .row:first-child { border-radius: var(--r-m) var(--r-m) 4px 4px; }
.rows > .row:last-child { border-radius: 4px 4px var(--r-m) var(--r-m); }
.rows > .row:only-child { border-radius: var(--r-m); }
.row:active { background: var(--surface-press); }
.row .name { font-weight: 500; }
.row .meta { font-size: 14px; color: var(--ink-2); white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.bar {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 3px;
  background: transparent;
  position: relative;
}
.bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--w, 100%);
  border-radius: 3px;
  background: var(--steel-2);
  overflow: hidden;
}
.bar > i > b {
  display: block;
  height: 100%;
  width: var(--p, 0%);
  background: var(--ink);
  border-radius: 3px;
  transition: width 400ms var(--ease-out);
}

/* --- тренировка ---------------------------------------------------------------------------- */

.train-top {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}
.icon-btn:active { background: var(--surface-press); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

.ticks { display: flex; gap: 3px; }
.ticks i {
  flex: 1;
  height: 6px;
  border-radius: 2px;
  background: var(--steel-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
.ticks i.ok { background: var(--good); box-shadow: none; }
.ticks i.no { background: var(--bad); box-shadow: none; }
.ticks i.now { background: var(--ink); box-shadow: none; }
.ticks i.extra { flex: 0.6; }
.counter { font-size: 15px; color: var(--ink-2); min-width: 44px; text-align: right; }

.q .tape { padding: 14px 18px 18px; }
.q .q-meta { font-size: 13px; color: var(--tape-ink-2); display: flex; gap: 6px; flex-wrap: wrap; }
.q .q-meta .retry { color: var(--bad); font-weight: 600; }
.q .q-text { font-family: var(--font-marker); font-weight: 700; font-size: 30px; line-height: 1.08; margin-top: 6px; text-wrap: balance; }
.q .q-text i {
  display: block;
  font: 400 17px/1.4 var(--font-ui);
  color: var(--tape-ink);
  margin-top: 10px;
  font-style: normal;
}

.options { display: grid; gap: 8px; margin-top: 22px; }
.opt {
  display: grid;
  grid-template-columns: 1fr 24px;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 13px 14px 13px 16px;
  text-align: left;
  background: var(--surface);
  border-radius: var(--r-m);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 17px;
  line-height: 1.3;
  transition: background 120ms, transform 100ms var(--ease-out), box-shadow 120ms;
}
.opt:active { transform: scale(0.985); background: var(--surface-press); }
.opt svg { opacity: 0; width: 22px; height: 22px; stroke-width: 2.2; }
.opt[disabled] { cursor: default; }
.opt[disabled]:active { transform: none; }
.opt.is-right { background: var(--good-wash); box-shadow: inset 0 0 0 2px var(--good); }
.opt.is-right svg { opacity: 1; color: var(--good); }
.opt.is-wrong { background: var(--bad-wash); box-shadow: inset 0 0 0 2px var(--bad); }
.opt.is-wrong svg { opacity: 1; color: var(--bad); }
.opt.is-dim { opacity: 0.55; }

.verdict {
  margin-top: 18px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  animation: rise 220ms var(--ease-out) both;
}
.verdict .v-title { font-weight: 600; font-size: 17px; }
.verdict .v-title.good { color: var(--good); }
.verdict .v-title.bad { color: var(--bad); }
.verdict .v-sub { font-size: 15px; color: var(--ink-2); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* --- карточка позиции ------------------------------------------------------------------------ */

.item { margin-top: 18px; animation: rise 220ms var(--ease-out) both; }
.item .tape .marker { font-size: 32px; }
.facts {
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px 16px;
  font-size: 16px;
}
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; }
.prices { display: grid; gap: 2px; }
.prices span { display: flex; justify-content: space-between; gap: 12px; }
.recipe { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
.recipe-head { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.tag {
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--steel-2);
  font-size: 14px;
}
.ingr { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ingr li { display: flex; justify-content: space-between; gap: 12px; }
.ingr li span:last-child { color: var(--ink-2); white-space: nowrap; }
.steps { color: var(--ink-2); font-size: 15px; margin: 12px 0 0; max-width: 65ch; }

/* ступени знания: фиксированная шкала размеров точек */
.ladder { display: inline-flex; align-items: center; gap: 3px; }
.ladder i { border-radius: 50%; background: var(--line); }
.ladder i:nth-child(1) { width: 4px; height: 4px; }
.ladder i:nth-child(2) { width: 5px; height: 5px; }
.ladder i:nth-child(3) { width: 6px; height: 6px; }
.ladder i:nth-child(4) { width: 7px; height: 7px; }
.ladder i:nth-child(5) { width: 8px; height: 8px; }
.ladder i.on { background: var(--ink); }
.ladder.learned i.on { background: var(--good); }

/* --- меню ---------------------------------------------------------------------------------- */

.search {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: -14px -16px 0;
  padding: 12px 16px 10px;
  background: var(--steel);
}
.search label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--r-m);
  box-shadow: inset 0 0 0 1px var(--line);
  padding: 0 12px;
}
.search svg { color: var(--ink-3); width: 20px; height: 20px; }
.search input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 16px var(--font-ui);
  padding: 12px 0;
  outline: none;
  min-width: 0;
}
.search input::placeholder { color: var(--ink-3); }
.search .chips { margin-top: 10px; }

.mi {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 4px;
}
.rows > .mi:first-child { border-radius: var(--r-m) var(--r-m) 4px 4px; }
.rows > .mi:last-child { border-radius: 4px 4px var(--r-m) var(--r-m); }
.rows > .mi:only-child { border-radius: var(--r-m); }
.mi:active { background: var(--surface-press); }
.mi .name { font-weight: 500; }
.mi .price { font-weight: 500; white-space: nowrap; }
.mi .sub {
  font-size: 14px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mi .ladder { justify-self: end; }
.note { font-size: 14px; color: var(--ink-2); margin: -4px 0 8px; }
.empty { padding: 32px 4px; color: var(--ink-2); text-align: center; }

/* --- прогресс и настройки ------------------------------------------------------------------- */

.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 46px;
  height: 28px;
  border-radius: 14px;
  background: var(--steel-2);
  box-shadow: inset 0 0 0 1px var(--line);
  position: relative;
  margin: 0;
  flex: none;
  cursor: pointer;
  transition: background 160ms;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 160ms var(--ease-out);
}
.switch:checked { background: var(--good); box-shadow: none; }
.switch:checked::after { transform: translateX(18px); }
.switch:disabled { opacity: 0.5; }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 4px;
}
.rows > .setting:first-child { border-radius: var(--r-m) var(--r-m) 4px 4px; }
.rows > .setting:last-child { border-radius: 4px 4px var(--r-m) var(--r-m); }
.rows > .setting:only-child { border-radius: var(--r-m); }
.setting .s-text { display: grid; gap: 2px; }
.setting .s-sub { font-size: 14px; color: var(--ink-2); }
.badge { font-size: 13px; color: var(--ink-2); padding: 3px 8px; border-radius: 6px; background: var(--steel-2); white-space: nowrap; }
select {
  font: 16px var(--font-ui);
  color: var(--ink);
  background: var(--steel-2);
  border: 0;
  border-radius: var(--r-s);
  padding: 8px 10px;
}
.link {
  color: var(--focus);
  font-weight: 500;
  padding: 6px 0;
}

.roles { display: grid; gap: 8px; margin-top: 20px; }
.role {
  text-align: left;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--r-m);
  box-shadow: inset 0 0 0 1px var(--line);
  display: grid;
  gap: 4px;
}
.role:active { background: var(--surface-press); }
.role .r-name { font-weight: 600; font-size: 17px; }
.role .r-sub { font-size: 14px; color: var(--ink-2); }
.role[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--ink); }

.stats-line { display: flex; gap: 20px; margin-top: 14px; flex-wrap: wrap; }
.stats-line div { display: grid; }
.stats-line b { font-size: 20px; font-weight: 600; }
.stats-line span { font-size: 13px; color: var(--ink-2); }

/* --- нижняя навигация и запасная кнопка вне Telegram ----------------------------------------- */

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: var(--tabbar-h);
  padding-bottom: var(--safe-b);
  background: var(--steel-2);
  box-shadow: 0 -1px 0 var(--line);
}
.tabbar[hidden] { display: none; }
.tab {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  font-size: 12px;
  color: var(--ink-3);
}
.tab[aria-current="page"] { color: var(--ink); font-weight: 600; }
.tab:active svg { transform: scale(0.92); }

.fallback-main {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 6;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: linear-gradient(180deg, transparent, var(--steel) 30%);
}
body:not(.no-tabs) .fallback-main { bottom: var(--tabbar-h); padding-bottom: 10px; }
.btn-main {
  display: block;
  width: 100%;
  max-width: 528px;
  margin: 0 auto;
  min-height: 52px;
  border-radius: var(--r-m);
  background: var(--d1);
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  transition: transform 100ms var(--ease-out), filter 120ms;
}
.btn-main:active { transform: scale(0.985); filter: brightness(0.92); }
.btn-ghost {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border-radius: var(--r-m);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 500;
}

.error {
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: var(--r-m);
  background: var(--bad-wash);
  color: var(--ink);
}

@media (hover: hover) and (pointer: fine) {
  .row:hover, .mi:hover, .opt:not([disabled]):hover, .role:hover { background: var(--surface-press); }
  .chip:hover { box-shadow: inset 0 0 0 1px var(--ink-3); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

.due {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--tape);
  color: var(--tape-ink);
  padding: 2px 8px;
  border-radius: 4px;
}

:root[data-theme="dark"] body {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.008) 0 2px, rgba(0, 0, 0, 0.02) 2px 4px),
    var(--steel);
}
