:root {
  --bg: #0a0e1a;
  --card: #121a2e;
  --card-2: #18223b;
  --line: #243050;
  --text: #e8edff;
  --muted: #94a0c2;
  --accent: #9ca3af;
  --accent-glow: rgba(156, 163, 175, 0.45);
  --accent-soft: rgba(156, 163, 175, 0.14);
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 16px;
  --gutter: 16px;
  --nav-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

.panel {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right))
    calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
  background:
    radial-gradient(120% 50% at 50% 0%, var(--accent-soft), transparent 70%);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-title { margin: 0 0 10px; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.card-head .card-title { margin: 0; }
.muted { color: var(--muted); margin: 0 0 6px; }
.badge { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent); white-space: nowrap; }

/* герой */
.hero-card { text-align: center; border-color: var(--accent); box-shadow: 0 0 28px -6px var(--accent-glow); }
.hero-frame {
  width: min(220px, 72%); aspect-ratio: 2 / 3; margin: 4px auto 14px; border-radius: 24px; overflow: hidden;
  border: 2px solid var(--accent); box-shadow: 0 0 22px var(--accent-glow); background: var(--card-2);
}
.hero-img { display: block; width: 100%; height: 100%; object-fit: cover; }
.hero-ph { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 72px; font-weight: 700; color: var(--accent); background: var(--accent-soft); }
.hero-name { margin: 0; font-size: 24px; line-height: 1.2; overflow-wrap: anywhere; }
.hero-sub { margin: 4px 0 14px; color: var(--accent); font-weight: 600; }
.hero-xp { display: flex; justify-content: space-between; gap: 8px; margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.streak { color: var(--warn); }
.celebrate { margin: 12px 0 0; padding: 8px 12px; border-radius: 12px; background: var(--accent-soft); border: 1px solid var(--accent); }

@media (prefers-reduced-motion: no-preference) {
  .hero-card { animation: glow 4s ease-in-out infinite; }
  @keyframes glow {
    0%, 100% { box-shadow: 0 0 22px -6px var(--accent-glow); }
    50% { box-shadow: 0 0 36px -2px var(--accent-glow); }
  }
  .toast { transition: opacity 0.2s, transform 0.2s; }
}

/* полосы */
.bar { height: 10px; border-radius: 999px; background: var(--card-2); overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }

/* сейчас */
.quest-line { display: flex; align-items: baseline; gap: 10px; margin: 0 0 6px; flex-wrap: wrap; }
.quest-time { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }
.quest-title { font-size: 18px; font-weight: 600; flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.quest-xp { color: var(--ok); font-weight: 600; white-space: nowrap; }
.quest-text { margin: 0 0 14px; color: var(--muted); overflow-wrap: anywhere; }
.mode-note { margin: 0; color: var(--accent); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
  min-height: 44px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); font: inherit; font-size: 15px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { grid-column: 1 / -1; background: var(--accent); border-color: var(--accent); color: #0a0e1a; font-weight: 700; font-size: 17px; min-height: 48px; }

/* дайджест */
.digest { list-style: none; margin: 0; padding: 0; }
.digest-item { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 0; border-top: 1px solid var(--line); }
.digest-item:first-child { border-top: 0; }
.digest-icon { width: 24px; text-align: center; flex: none; }
.digest-time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.digest-title { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.st-sent .digest-title { font-weight: 700; color: var(--accent); }
.st-done .digest-title { color: var(--text); }
.st-plan .digest-title, .st-skip .digest-title, .st-skip .digest-time { color: var(--muted); }
.st-late .digest-title { color: var(--warn); }

/* навык, характеристики */
.skill-name { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.attr { margin-top: 12px; }
.attr-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: 15px; }
.attr-val { color: var(--muted); font-variant-numeric: tabular-nums; }

/* баннер, тост, заглушки */
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px;
  border-radius: var(--radius); background: #3a1620; border: 1px solid #7f2a3d; }
.placeholder { text-align: center; padding: 40px 16px; }
/* заглушка на время первого запроса вкладки */
.loading { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.loading-text { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.skel { height: 14px; margin-top: 10px; border-radius: 7px; background: var(--card-2); }
.skel-wide { height: 56px; margin-top: 0; border-radius: 12px; }
.skel-short { width: 60%; }
@media (prefers-reduced-motion: no-preference) {
  .skel { animation: skel-pulse 1.3s ease-in-out infinite; }
}
@keyframes skel-pulse { 50% { opacity: 0.45; } }
.standalone { margin-top: 30vh; text-align: center; font-size: 18px; }
.standalone p { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px); width: max-content; max-width: min(90vw, 420px); padding: 12px 16px; border-radius: 16px;
  white-space: pre-line; text-align: left; line-height: 1.4;
  background: var(--card-2); border: 1px solid var(--accent); color: var(--text); opacity: 0; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* нижняя панель */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom); background: rgba(10, 14, 26, 0.96); border-top: 1px solid var(--line);
}
.tabbar[hidden] { display: none; }
.tab {
  flex: 1 1 0; max-width: 120px; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 12px;
  -webkit-tap-highlight-color: transparent;
}
.tab-icon { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: 0.7; }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active .tab-icon { filter: none; opacity: 1; }

/* общее: группы-<details>, формы */
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
.group-sum {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.group-sum::after { content: "▾"; color: var(--muted); flex: none; transition: transform 0.15s; }
details:not([open]) > .group-sum::after { transform: rotate(-90deg); }
.group-sum > span:first-child { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.group-sum:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.input {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); font: inherit; font-size: 16px;
}
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
select.input { appearance: none; -webkit-appearance: none; }
.field { display: block; margin-bottom: 12px; }
.field-label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.form-error { margin: 0 0 12px; padding: 8px 12px; border-radius: 12px; background: #3a1620; border: 1px solid #7f2a3d; }
.form-error[hidden] { display: none; }
.btn-primary-lite { border-color: var(--accent); }

/* навыки */
.skill-row { padding: 10px 0; border-top: 1px solid var(--line); }
.skill-row:first-of-type { border-top: 0; padding-top: 0; }
.skill-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.skill-title { font-size: 17px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.branch { border-top: 1px solid var(--line); }
.branch:first-of-type { border-top: 0; }
.branch-sum { color: var(--accent); font-size: 17px; }
.school { margin: 0 0 4px 8px; border-left: 2px solid var(--line); padding-left: 10px; }
.school > .group-sum { font-weight: 500; font-size: 15px; }
.skill-list { list-style: none; margin: 0 0 8px; padding: 0; }
.skill-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 8px 0; border-top: 1px solid var(--line); align-items: center; }
.skill-item:first-child { border-top: 0; }
.skill-item-name { grid-column: 1 / -1; font-size: 15px; overflow-wrap: anywhere; }
.skill-item-rank { font-size: 13px; color: var(--muted); text-align: right; white-space: nowrap; }
.skill-item.unrated .skill-item-rank { grid-column: 1 / -1; text-align: left; font-style: italic; }
.rank-bar { display: flex; gap: 4px; }
.rank-seg { width: 100%; max-width: 28px; flex: 1 1 0; height: 8px; border-radius: 4px; background: var(--card-2); border: 1px solid var(--line); }
.rank-seg.on { background: var(--accent); border-color: var(--accent); }

/* подборка */
.rec-list { display: flex; flex-direction: column; gap: 14px; }
.add-card { padding: 4px 16px; }
.add-card[open] { padding-bottom: 16px; }
.add-form { padding-top: 8px; }
.add-form .btn-primary { width: 100%; }
.rec-head { display: flex; gap: 12px; align-items: flex-start; }
.rec-icon { font-size: 26px; line-height: 1.2; flex: none; width: 32px; text-align: center; }
.rec-main { min-width: 0; flex: 1 1 auto; }
.rec-title { margin: 0; font-size: 17px; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
.rec-by { margin: 2px 0 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.rec-why { margin: 10px 0 0; font-size: 15px; overflow-wrap: anywhere; }
.rec-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.rec-xp { color: var(--ok); font-weight: 600; }
.rec-status { color: var(--accent); font-weight: 600; }
.rec-st-done .rec-title { color: var(--muted); }
.xp-flash { margin: 10px 0 0; padding: 6px 12px; border-radius: 12px; background: var(--accent-soft); border: 1px solid var(--ok);
  color: var(--ok); font-weight: 700; width: max-content; max-width: 100%; }
.rec-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.rec-actions .btn { flex: 1 1 96px; }
.rec-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; color: var(--accent); font-weight: 600; }

/* меню */
.day-card.today { border-color: var(--accent); box-shadow: 0 0 18px -8px var(--accent-glow); }
.meal { display: grid; grid-template-columns: 76px 1fr; gap: 8px; margin: 0; padding: 6px 0; border-top: 1px solid var(--line); }
.card-head + .meal { border-top: 0; }
.meal-label { color: var(--muted); font-size: 14px; }
.meal-text { overflow-wrap: anywhere; min-width: 0; }
.meal-text.empty { color: var(--muted); font-style: italic; }
.shop-list { list-style: none; margin: 0; padding: 0; }
.shop-row { border-top: 1px solid var(--line); }
.shop-row:first-child { border-top: 0; }
.shop-label { display: flex; align-items: center; gap: 14px; min-height: 48px; cursor: pointer; }
.shop-box { width: 24px; height: 24px; flex: none; accent-color: var(--accent); margin: 0; }
.shop-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.shop-row.bought .shop-name { text-decoration: line-through; color: var(--muted); }
