:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --text: #1c1b29;
  --muted: #6d6b80;
  --border: #e4e2ef;
  --accent: #534ab7;
  --accent-hover: #463ea0;
  --accent-soft: #eeedfe;
  --accent-ink: #3c3489;
  --ok: #1d9e75;
  --ok-soft: #e1f5ee;
  --ok-ink: #085041;
  --danger: #c2413a;
  --shadow: 0 1px 2px rgba(28, 27, 41, .04), 0 6px 20px rgba(28, 27, 41, .05);
  --radius: 14px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121119;
    --surface: #1c1b26;
    --text: #ecebf5;
    --muted: #9b99ad;
    --border: #2d2b3b;
    --accent: #8a82ea;
    --accent-hover: #9d96f0;
    --accent-soft: #2a2750;
    --accent-ink: #cfcbff;
    --ok: #3cc49a;
    --ok-soft: #173a30;
    --ok-ink: #a6ecd5;
    --danger: #f07a73;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }

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

.muted { color: var(--muted); }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 16px 40px;
}

/* ---------- header ---------- */

.hero { animation: rise .6s var(--ease) both; }
.hero__top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero h1 { margin: 0; font-size: clamp(26px, 5vw, 34px); line-height: 1.15; font-weight: 700; letter-spacing: -.02em; }
.hero__lead { margin: 6px 0 24px; color: var(--muted); }

.live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted);
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); white-space: nowrap;
}
.live__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); position: relative; }
.live__dot::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: var(--ok); animation: pulse 2s ease-out infinite;
}
.live.is-offline .live__dot, .live.is-offline .live__dot::after { background: var(--muted); animation: none; }

/* ---------- ask form ---------- */

.ask {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  box-shadow: var(--shadow);
  transition: border-color .2s, box-shadow .2s;
  animation: rise .6s .08s var(--ease) both;
}
.ask:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.ask.is-shake { animation: shake .4s; }

.ask textarea {
  width: 100%; resize: none; border: 0; outline: 0; background: transparent;
  min-height: 28px; max-height: 240px; padding: 2px 2px 8px; line-height: 1.5;
}
.ask textarea::placeholder { color: var(--muted); }

.ask__bar { display: flex; align-items: center; gap: 12px; }
.ask__hint { font-size: 12px; color: var(--muted); margin-right: auto; }
.ask__count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ask__count.is-near { color: var(--danger); }
.ask__error { margin: 6px 2px 0; min-height: 0; font-size: 13px; color: var(--danger); }
.ask__error:empty { display: none; }

@media (max-width: 480px) { .ask__hint { display: none; } .ask__count { margin-right: auto; } }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  padding: 8px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px;
  transition: background .2s, transform .15s var(--ease), opacity .2s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(.96); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s var(--ease); }
.btn--primary:hover svg { transform: translateX(3px); }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- toolbar ---------- */

.toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  margin: 28px 0 6px;
  animation: rise .6s .16s var(--ease) both;
}
.stats { font-size: 14px; color: var(--muted); }
.stats b { color: var(--text); font-weight: 600; }
.filters { display: flex; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: transparent; border-radius: 999px;
  padding: 4px 12px; font-size: 13px; cursor: pointer; color: var(--muted);
  transition: background .2s, color .2s, border-color .2s;
}
.chip:hover { color: var(--text); }
.chip.is-active { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---------- feed ---------- */

.day { margin-top: 22px; }
.day.is-new { animation: rise .5s var(--ease) both; }
.day__head {
  position: sticky; top: 0; z-index: 2;
  padding: 10px 2px 8px; margin: 0; line-height: 1.4;
  background: var(--bg);
  font-size: 15px; font-weight: 700;
}
.day__count { font-weight: 500; font-size: 13px; color: var(--muted); }
.day__list { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }

.q {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  transition: opacity .35s, transform .2s var(--ease), border-color .2s;
}
@media (hover: hover) {
  .q:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
}
.q.is-enter { animation: pop-in .55s var(--ease) both; }
.q.is-flash { animation: pop-in .55s var(--ease) both, flash 1.6s .2s ease-out; }

.q__num {
  flex-shrink: 0; min-width: 40px; text-align: center;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 3px 8px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent-ink);
  transition: background .3s, color .3s;
}
.q__body { flex: 1; min-width: 0; }
.q__text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; transition: color .3s; }
.q__meta { margin-top: 6px; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.q__author { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); opacity: .8; }
.avatar {
  width: 20px; height: 20px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 700; color: #fff;
}
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: var(--ok-soft); color: var(--ok-ink);
  animation: fade-in .3s var(--ease);
}

.q.is-answered { opacity: .62; }
.q.is-answered .q__num { background: var(--ok-soft); color: var(--ok-ink); }
.q.is-answered .q__text { color: var(--muted); }

/* checkbox */
.check { position: relative; flex-shrink: 0; width: 28px; height: 28px; cursor: pointer; }
.check input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.check__box {
  position: absolute; inset: 2px; border-radius: 8px;
  border: 2px solid var(--border); background: var(--surface);
  display: grid; place-items: center;
  transition: background .2s, border-color .2s, transform .15s var(--ease);
}
.check:hover .check__box { border-color: var(--ok); }
.check input:focus-visible + .check__box { box-shadow: 0 0 0 3px var(--ok-soft); }
.check__box svg { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 22; stroke-dashoffset: 22; transition: stroke-dashoffset .3s .05s var(--ease); }
.check input:checked + .check__box { background: var(--ok); border-color: var(--ok); animation: check-pop .35s var(--ease); }
.check input:checked + .check__box svg { stroke-dashoffset: 0; }
.check input:disabled { cursor: wait; }

/* ---------- empty / footer ---------- */

.empty { text-align: center; color: var(--muted); padding: 48px 0; animation: fade-in .5s both; }
.empty__icon {
  width: 56px; height: 56px; margin: 0 auto 8px; border-radius: 16px;
  display: grid; place-items: center; font-size: 28px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent-ink);
  animation: float 3s ease-in-out infinite;
}

.feed-note { text-align: center; color: var(--muted); padding: 32px 0; animation: fade-in .3s both; }

.footer {
  margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  font-size: 13px; color: var(--muted);
}
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 13px; }
.link:hover { text-decoration: underline; }

/* ---------- modal & toast ---------- */

.modal {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 16px;
  background: rgba(15, 14, 25, .45);
  animation: fade-in .2s both;
}
.modal[hidden] { display: none; }
.modal__card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  animation: pop-in .3s var(--ease) both;
}
.modal__card h2 { margin: 0 0 4px; font-size: 18px; }
.modal__card p { margin: 0 0 14px; font-size: 14px; }
.modal__card input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); outline: 0;
}
.modal__card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  transition: opacity .25s, transform .3s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- phones ---------- */

@media (max-width: 560px) {
  body { -webkit-tap-highlight-color: transparent; }
  .page {
    padding: calc(20px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
             calc(24px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .hero__top { align-items: flex-start; }
  .hero__lead { font-size: 15px; margin-bottom: 16px; }
  .live { margin-top: 4px; }

  .ask { padding: 12px 12px 10px; border-radius: 16px; }
  .ask textarea { font-size: 16px; max-height: 40vh; }
  .ask__bar .btn { min-height: 44px; padding: 10px 18px; }

  .toolbar { flex-direction: column; align-items: stretch; margin-top: 20px; }
  .filters {
    overflow-x: auto; scrollbar-width: none;
    margin: 0 -12px; padding: 0 12px;
  }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; padding: 8px 14px; font-size: 14px; }

  .day { margin-top: 16px; }
  .day__head { font-size: 14px; padding: 10px 2px 8px; }
  .day__list { gap: 8px; }

  .q { gap: 10px; padding: 12px; border-radius: 12px; }
  .q__num { min-width: 34px; padding: 2px 6px; font-size: 12px; }
  .q__text { font-size: 15px; }
  .q__meta { font-size: 12px; }
  /* Палец не мышь: область нажатия галочки — 44×44. */
  .check { width: 44px; height: 44px; margin: -8px -8px -8px -4px; }
  .check__box { inset: 9px; }

  .footer { flex-direction: column-reverse; align-items: flex-start; margin-top: 32px; }
  .link { padding: 8px 0; font-size: 14px; }

  .modal { place-items: end center; padding: 0; }
  .modal__card {
    max-width: none; border-radius: 20px 20px 0 0; border-bottom: 0;
    padding: 22px 16px calc(16px + env(safe-area-inset-bottom));
    animation: sheet-up .3s var(--ease) both;
  }
  .modal__card input { font-size: 16px; padding: 12px; }
  .modal__actions .btn { flex: 1; justify-content: center; min-height: 44px; }

  .toast {
    left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateY(20px); text-align: center;
  }
  .toast.is-visible { transform: none; }
}

/* ---------- keyframes ---------- */

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-10px) scale(.97); }
  to { opacity: 1; transform: none; }
}
@keyframes flash { from { box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); } to { box-shadow: var(--shadow); } }
@keyframes check-pop { 0% { transform: scale(1); } 45% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes pulse { from { transform: scale(1); opacity: .7; } to { transform: scale(2.6); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes float { 50% { transform: translateY(-6px); } }

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