:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #111);
  --hint: var(--tg-theme-hint-color, #888);
  --link: var(--tg-theme-link-color, #2a7);
  --btn: var(--tg-theme-button-color, #2ea6ff);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --sec-bg: var(--tg-theme-secondary-bg-color, #f3f3f5);
  --card: var(--tg-theme-bg-color, #fff);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Атрибут hidden должен побеждать любые display из классов (.modal-wrap, .toast). */
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0; background: var(--sec-bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px;
}
body { padding-bottom: env(safe-area-inset-bottom); }

#appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; background: var(--bg);
  border-bottom: 1px solid rgba(128,128,128,.15);
}
#title { font-size: 18px; margin: 0; font-weight: 700; }
.iconbtn {
  border: none; background: none; color: var(--link);
  font-size: 30px; line-height: 1; padding: 0 6px; cursor: pointer;
}

#screen { padding: 14px; max-width: 620px; margin: 0 auto; }
.loader { text-align: center; color: var(--hint); padding: 40px 0; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.muted { color: var(--hint); font-size: 14px; }
.muted small { font-size: 12px; }
h2 { font-size: 17px; margin: 2px 0 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; }

/* Home grid */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--card); border-radius: var(--radius); border: none;
  padding: 20px 12px; text-align: center; cursor: pointer; color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.06); font: inherit;
}
.tile .emoji { font-size: 30px; display: block; margin-bottom: 6px; }
.tile .lbl { font-size: 14px; font-weight: 600; }
.tile.wide { grid-column: 1 / -1; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; border: none; border-radius: 12px; padding: 13px 14px;
  background: var(--btn); color: var(--btn-text); font: inherit; font-weight: 600;
  cursor: pointer; margin-top: 8px;
}
.btn.secondary { background: var(--sec-bg); color: var(--text); }
.btn.danger { background: #e5484d; color: #fff; }
.btn.ghost { background: transparent; color: var(--link); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-top: 8px; }

/* List rows */
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; background: var(--card); border-radius: 12px;
  margin-bottom: 8px; cursor: pointer; border: 1px solid transparent;
}
.row.locked { opacity: .55; cursor: default; }
.row.next { border-color: var(--btn); }
.row .ic { font-size: 20px; width: 24px; text-align: center; }
.row .main { flex: 1; min-width: 0; }
.row .ttl { font-weight: 600; }
.row .sub { font-size: 13px; color: var(--hint); }
.row .chev { color: var(--hint); font-size: 22px; }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--sec-bg); color: var(--hint); }
.pill { display:inline-block; font-size:12px; padding:2px 8px; border-radius:20px; background: var(--sec-bg); color: var(--hint); margin-left:6px; }

.stat { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid rgba(128,128,128,.12); }
.stat:last-child { border-bottom: none; }
.stat b { font-variant-numeric: tabular-nums; }

/* Exercise detail */
.tech li { margin-bottom: 4px; }
.kv { margin: 8px 0; }
.kv .k { color: var(--hint); font-size: 13px; }
.note-box { white-space: pre-wrap; }
.eximg { width: 100%; border-radius: 12px; margin-top: 10px; }

.field-label { font-size: 13px; color: var(--hint); margin: 10px 0 4px; }
input[type=text], input[type=number], textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; font: inherit;
  border: 1px solid rgba(128,128,128,.3); background: var(--bg); color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }

.rpe-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 6px; }
.rpe-grid button {
  padding: 10px 0; border-radius: 8px; border: 1px solid rgba(128,128,128,.3);
  background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
}
.rpe-grid button.sel { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }

/* Chat */
.chat-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble { padding: 10px 13px; border-radius: 14px; max-width: 85%; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--btn); color: var(--btn-text); }
.bubble.bot { align-self: flex-start; background: var(--card); }
.typing { color: var(--hint); font-style: italic; }

/* Modal */
.modal-wrap {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal {
  background: var(--bg); width: 100%; max-width: 620px;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.modal-title { font-weight: 700; font-size: 16px; margin-bottom: 12px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px; border-radius: 20px;
  z-index: 60; font-size: 14px; max-width: 90%;
}

.knowledge-body { line-height: 1.5; }
.knowledge-body b { font-weight: 700; }
.deload-banner { background: #ffefc2; color: #6b4e00; border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; font-size: 14px; }
