:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f0f0f5);
  --text: var(--tg-theme-text-color, #15151a);
  --hint: var(--tg-theme-hint-color, #86868f);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(128, 128, 140, 0.22);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 18px rgba(0, 0, 0, 0.06);
  --radius: 18px;

  --lv1: #2fc15c;
  --lv2: #f2c200;
  --lv3: #ff9500;
  --lv4: #ff3b30;
  --lv5: #7b4bd6;

  --g1: #2fc15c;
  --g2: #ff9500;
  --g3: #ff3b30;

  --own-waiter: #cfe3e7;
  --own-manager: #dcd3ee;
  --own-director: #f0b4b4;
  --own-ink: #23232b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg2);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px calc(32px + env(safe-area-inset-bottom));
  animation: rise 0.24s ease both;
}
.screen.swap { animation: fade 0.18s ease both; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0.2; } to { opacity: 1; } }

/* Заголовки */
.brand { font-size: 13px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--hint); }
h1 { margin: 4px 0 6px; font-size: 30px; line-height: 1.12; font-weight: 800; letter-spacing: -0.02em; }
h2 { margin: 0 0 8px; font-size: 22px; line-height: 1.2; font-weight: 750; letter-spacing: -0.01em; }
.sub { margin: 0 0 18px; color: var(--hint); }
.section { margin: 26px 4px 10px; font-size: 13px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--hint); }

/* Поиск */
.search { position: relative; margin: 0 0 18px; }
.search svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; margin-top: -9px; color: var(--hint); }
.search input {
  width: 100%; height: 46px; padding: 0 40px 0 42px;
  border: 0; border-radius: 14px; outline: none;
  background: var(--bg); color: var(--text); font: inherit;
  box-shadow: var(--shadow);
}
.search input::placeholder { color: var(--hint); }
.search .clear {
  position: absolute; right: 6px; top: 6px; width: 34px; height: 34px;
  border: 0; border-radius: 10px; background: transparent; color: var(--hint); font-size: 22px; line-height: 1;
}
.search .clear[hidden] { display: none; }

/* Карточки групп */
.groups { display: grid; gap: 12px; }
.group-card {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px 16px 16px 14px;
  border: 0; border-radius: var(--radius); background: var(--bg); color: var(--text);
  text-align: left; font: inherit; box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.group-card:active { transform: scale(0.985); }
.group-card .bar { width: 6px; align-self: stretch; border-radius: 6px; background: var(--c); }
.group-card .t { flex: 1; }
.group-card .t b { display: block; font-size: 19px; font-weight: 750; }
.group-card .t span { color: var(--hint); font-size: 14px; }
.chev { width: 9px; height: 9px; border-top: 2px solid var(--hint); border-right: 2px solid var(--hint); transform: rotate(45deg); opacity: 0.7; flex: none; }

/* Списки */
.list { background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 15px 16px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text);
  text-align: left; font: inherit;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--line); }
.row .t { flex: 1; min-width: 0; }
.row small { display: block; color: var(--hint); font-size: 13px; margin-top: 1px; }

.tag { flex: none; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; color: var(--own-ink); background: var(--c); }

/* Выбор уровня */
.levels { display: grid; gap: 10px; }
.level-tile {
  display: flex; gap: 14px; width: 100%; padding: 14px 16px 14px 14px;
  border: 0; border-radius: var(--radius); background: var(--bg); color: var(--text);
  text-align: left; font: inherit; box-shadow: var(--shadow); transition: transform 0.12s ease;
}
.level-tile:active { transform: scale(0.985); }
.level-tile .n {
  flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 800; color: #fff; background: var(--c);
}
.level-tile .lv2 { color: #3a3000; }
.level-tile .t { display: block; min-width: 0; }
.level-tile .t b { display: block; font-size: 17px; font-weight: 750; margin-bottom: 2px; color: var(--text); }
.level-tile .t span { color: var(--hint); font-size: 14px; line-height: 1.4; }

/* Карточка */
.hero { margin: 0 0 14px; }
.hero .group-name { font-size: 13px; font-weight: 650; color: var(--hint); letter-spacing: 0.04em; text-transform: uppercase; }

.thermo { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; align-items: end; height: 34px; margin: 4px 0 12px; }
.thermo button {
  height: 16px; border: 0; border-radius: 8px; padding: 0;
  background: var(--c); opacity: 0.22; transition: height 0.18s ease, opacity 0.18s ease;
}
.thermo button.fill { opacity: 0.9; }
.thermo button.on { height: 34px; opacity: 1; }

.lvhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lvhead .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.lvhead h2 { margin: 0; }
.lvhead .of { color: var(--hint); font-size: 14px; }
.lvdesc { margin: 6px 0 0; color: var(--hint); font-size: 14px; }

.owner {
  display: inline-flex; align-items: center; gap: 8px; margin: 16px 0 14px; padding: 8px 14px;
  border-radius: 999px; background: var(--c); color: var(--own-ink); font-weight: 700;
}
.owner span { font-weight: 500; opacity: 0.8; }

.block {
  margin: 0 0 12px; padding: 14px 16px 14px 18px; border-radius: var(--radius);
  background: var(--bg); box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.block::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.block h3 { margin: 0 0 6px; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--hint); display: flex; justify-content: space-between; gap: 8px; }
.block h3 em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--own-ink); background: var(--c); border-radius: 999px; padding: 0 9px; font-size: 12px; }
.block p { margin: 0; white-space: pre-line; }
.block.lead { box-shadow: 0 0 0 2px var(--c), var(--shadow); }

.comp {
  margin: 16px 0 6px; padding: 16px 18px; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text);
}
.comp h3 { margin: 0 0 6px; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.8; }
.comp p { margin: 0; white-space: pre-line; font-weight: 600; }
.comp.none { background: var(--bg); color: var(--hint); box-shadow: var(--shadow); }
.comp.none p { font-weight: 500; }

.nav { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0 8px; }
.nav button, .btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 8px 12px; min-width: 0;
  border: 0; border-radius: 14px; background: var(--bg); color: var(--text); font: inherit; font-weight: 650;
  box-shadow: var(--shadow);
}
.nav button:active, .btn:active { transform: scale(0.98); }
.nav button { gap: 6px; padding: 8px 10px; font-size: clamp(13px, 3.9vw, 15px); white-space: nowrap; }
.nav .lbl { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav button:disabled { opacity: 0.35; }
.nav .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.link { margin: 10px 0 0; text-align: center; }
.link button { border: 0; background: none; color: var(--link); font: inherit; padding: 8px 12px; }

/* Прочее */
.prose { background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; white-space: pre-line; }
.empty { padding: 36px 12px; text-align: center; color: var(--hint); }
.empty b { display: block; margin-bottom: 6px; color: var(--text); font-size: 18px; }
.empty .btn { margin: 16px auto 0; max-width: 260px; }

.skeleton { display: grid; gap: 12px; }
.skeleton i { display: block; height: 70px; border-radius: var(--radius); background: var(--bg); opacity: 0.7; animation: pulse 1.2s ease-in-out infinite; }
.skeleton i:first-child { height: 46px; }
@keyframes pulse { 50% { opacity: 0.35; } }

@media (prefers-reduced-motion: reduce) {
  .screen, .screen.swap, .skeleton i { animation: none; }
  * { transition: none !important; }
}

@media (max-width: 350px) {
  .nav .dot { display: none; }
  .nav button { padding: 8px 6px; }
}
