:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f80ed);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --line: color-mix(in srgb, var(--hint) 20%, transparent);
  --soft: color-mix(in srgb, var(--hint) 10%, transparent);
  --warn: #e8890c;
  --ok: #2fb344;
  --gift: #d6453d;
  --festive: #bf3a31;
  --primary: var(--accent);
  --primary-text: var(--accent-text);
  --radius: 14px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --column: 640px;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }
[hidden] { display: none !important; }

.view {
  max-width: var(--column);
  margin: 0 auto;
  padding: 12px 16px calc(110px + var(--safe-bottom));
  animation: fade 0.22s ease both;
}

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

h1 { font-size: 28px; line-height: 1.12; margin: 8px 4px 4px; font-weight: 700; letter-spacing: -0.02em; text-wrap: balance; }
h2 { font-size: 17px; margin: 0 0 6px; font-weight: 600; }
.lead { color: var(--hint); margin: 0 4px 16px; }

.section-title {
  margin: 20px 16px 6px;
  font-size: 13px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.section {
  background: var(--section);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.card { background: var(--section); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card p { margin: 0 0 8px; }
.card p:last-child { margin-bottom: 0; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.hint { color: var(--hint); font-size: 13px; }
.small { font-size: 13px; }
.center { text-align: center; }
.muted { color: var(--hint); }

/* Шапка экрана — крупный заголовок, как в Telegram. Главная кнопка участника зимой красная. */
body[data-area="player"] { --primary: var(--festive); --primary-text: #ffffff; }
.hero { padding: 4px 4px 6px; margin-bottom: 8px; }
.hero h1 { margin: 4px 0 4px; }
.hero .dates { color: var(--hint); font-size: 15px; line-height: 1.35; }

.cell {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  background: none;
  border: 0;
  text-align: left;
  position: relative;
}
.cell + .cell::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: 1px solid var(--line);
}
.cell .body { flex: 1; min-width: 0; }
.cell .title { display: block; overflow-wrap: anywhere; }
.cell .subtitle { display: block; color: var(--hint); font-size: 13px; overflow-wrap: anywhere; }
.cell .value { color: var(--hint); flex: none; max-width: 50%; text-align: right; overflow-wrap: anywhere; }
.cell.link { cursor: pointer; }
.cell.link:active { background: var(--soft); }
.cell.link::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--hint);
  border-top: 2px solid var(--hint);
  transform: rotate(45deg);
  opacity: 0.6;
  flex: none;
}
.badge {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  text-align: center;
  flex: none;
}

.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--soft);
  color: var(--hint);
  white-space: nowrap;
}
.chip.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.chip.accent { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.notice {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--section));
}
.notice.warn { background: color-mix(in srgb, var(--warn) 13%, var(--section)); }
.notice.danger { background: color-mix(in srgb, var(--danger) 12%, var(--section)); }
.notice.ok { background: color-mix(in srgb, var(--ok) 12%, var(--section)); }
.notice b { display: block; margin-bottom: 2px; }

.allergy {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  background: color-mix(in srgb, var(--danger) 12%, var(--section));
}
.allergy .label { color: var(--danger); font-weight: 600; margin-bottom: 2px; }

.button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 600;
  margin-bottom: 8px;
  transition: transform 0.12s, filter 0.12s;
}
.button:active { transform: scale(0.98); filter: brightness(0.94); }
.button:disabled { opacity: 0.5; cursor: default; }
.button.secondary { background: color-mix(in srgb, var(--accent) 12%, var(--section)); color: var(--accent); }
.button.danger { background: color-mix(in srgb, var(--danger) 12%, var(--section)); color: var(--danger); }
.button.plain { background: none; color: var(--link); min-height: 40px; font-weight: 500; }
.button.small { width: auto; min-height: 34px; padding: 6px 12px; font-size: 14px; display: inline-flex; margin: 0; }
.button.busy { pointer-events: none; opacity: 0.7; }
.button.busy::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .button { flex: 1; }

.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 5;
}
.bar .inner { max-width: var(--column); margin: 0 auto; }
.bar .button:last-child { margin-bottom: 0; }

.progress { height: 4px; border-radius: 2px; background: var(--line); margin: 4px 4px 14px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s ease; }
.step-label { color: var(--hint); font-size: 13px; margin: 0 4px; }

.field { display: block; padding: 10px 16px; position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.field > span { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  padding: 2px 0;
  font-size: 16px;
}
.field textarea { resize: vertical; min-height: 84px; line-height: 1.4; }
.field select { appearance: none; -webkit-appearance: none; }
.field input:disabled, .field textarea:disabled, .field select:disabled { opacity: 0.55; }
.field .error { display: block; color: var(--danger); font-size: 13px; margin-top: 4px; }
.field.invalid > span { color: var(--danger); }
.field .counter { position: absolute; right: 16px; top: 10px; font-size: 12px; color: var(--hint); }
.field .counter.over { color: var(--danger); }

.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 16px;
  cursor: pointer;
  position: relative;
}
.check + .check::before, .field + .check::before, .check + .field::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: 1px solid var(--line);
}
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--hint);
  flex: none;
  display: grid;
  place-items: center;
  margin-top: 1px;
  transition: background 0.15s, border-color 0.15s;
}
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after {
  content: "";
  width: 6px;
  height: 11px;
  border: solid var(--accent-text);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.choice {
  border: 1.5px solid var(--line);
  background: none;
  border-radius: 12px;
  padding: 8px 14px;
  min-height: 40px;
}
.choice.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 600; }

.summary dt { color: var(--hint); font-size: 13px; margin-top: 10px; }
.summary dt:first-child { margin-top: 0; }
.summary dd { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.summary .edit { float: right; font-size: 13px; }

.messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bubble {
  max-width: 86%;
  padding: 8px 12px 6px;
  border-radius: 16px;
  background: var(--section);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.out { align-self: flex-end; background: color-mix(in srgb, var(--accent) 16%, var(--section)); border-bottom-right-radius: 6px; }
.bubble.in { align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble .from { display: block; font-size: 13px; font-weight: 600; color: var(--gift); margin-bottom: 2px; }
.bubble .meta { display: flex; gap: 10px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--hint); margin-top: 2px; }
.bubble .meta button { border: 0; background: none; color: var(--hint); padding: 0; font-size: 11px; text-decoration: underline; }
.bubble.hidden-msg { font-style: italic; color: var(--hint); }

.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  border: 0;
  border-radius: 20px;
  padding: 11px 14px;
  background: var(--section);
  outline: none;
  resize: none;
  line-height: 1.35;
}
.composer button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--primary);
  color: var(--primary-text);
  display: grid;
  place-items: center;
  flex: none;
}
.composer button:disabled { opacity: 0.4; }
.composer svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.composer-hint { display: flex; justify-content: space-between; font-size: 12px; color: var(--hint); margin: 6px 6px 0; }
.composer-hint .over { color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--section); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--hint); }

.stepper { display: flex; gap: 4px; margin: 4px 0 12px; }
.stepper div { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.stepper div.done { background: var(--accent); }
.stepper div.now { background: color-mix(in srgb, var(--accent) 55%, transparent); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .choice { flex: none; min-height: 34px; padding: 5px 12px; font-size: 14px; }

.search {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: var(--section);
  padding: 10px 14px;
  outline: none;
  margin-bottom: 10px;
  font-size: 16px;
}

.pair { padding: 10px 16px; position: relative; }
.pair + .pair::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.pair .arrow { color: var(--hint); margin: 0 6px; }

.journal-entry { padding: 10px 16px; position: relative; font-size: 14px; }
.journal-entry + .journal-entry::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.journal-entry code { font-size: 12px; color: var(--hint); word-break: break-all; display: block; margin-top: 2px; }

.empty { text-align: center; padding: 48px 20px; color: var(--hint); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

.skeleton { height: 56px; border-radius: var(--radius); background: var(--section); margin-bottom: 10px; opacity: 0.7; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  padding: 10px 16px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--text) 88%, transparent);
  color: var(--bg);
  font-size: 14px;
  z-index: 30;
  animation: fade 0.2s ease both;
}
.toast.error { background: var(--danger); color: #fff; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%;
  max-width: var(--column);
  background: var(--bg-2);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  animation: up 0.24s ease both;
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet h2 { margin: 0 4px 6px; }
.sheet p { margin: 0 4px 12px; color: var(--hint); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv span:nth-child(odd) { color: var(--hint); }

.split { display: grid; grid-template-columns: 1fr 1fr; position: relative; }
.split::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.split .field + .field::before { top: 10px; bottom: 10px; left: 0; right: auto; border-top: 0; border-left: 1px solid var(--line); }
.hint.block { display: block; }
.button.plain.danger-text { color: var(--danger); }

/* Снег поверх экрана и иней на карточке подопечного */
#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }
.reveal-card {
  position: relative;
  overflow: hidden;
  display: grid;
  align-content: center;
  gap: 3px;
  min-height: 116px;
  margin: 16px 0 12px;
  padding: 18px 16px;
  border-radius: var(--radius);
  background: var(--section);
}
.reveal-card small { color: var(--hint); font-size: 13px; }
.reveal-card b { font-size: 22px; line-height: 1.15; letter-spacing: -0.01em; }
.reveal-card span { color: var(--hint); font-size: 15px; }
.frost { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; transition: opacity 0.45s; }
.frost-hint { position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; color: rgba(55, 72, 98, 0.8); pointer-events: none; transition: opacity 0.3s; }
@media (prefers-reduced-motion: reduce) {
  .button, .frost, .frost-hint { transition: none; }
}
