:root {
  --paper: #f6f8fd;
  --grid: #dde5f6;
  --sheet: #ffffff;
  --ink: #16213e;
  --muted: #5b6685;
  --line: #cbd3e8;
  --blue: #2f4fd8;
  --blue-dark: #2340b8;
  --marker: #ffe45c;
  --danger: #c62f3b;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  /* клетчатая тетрадная бумага */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.25rem; margin-bottom: 0.25rem; }
p { margin: 0; }

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

:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* Бренд: строка, обведённая маркером */
.brand {
  display: inline-block;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  padding: 0.05em 0.4em;
  background: var(--marker);
  color: var(--ink);
  transform: rotate(-1.5deg);
  border-radius: 3px;
}
.brand-big { font-size: 2.1rem; }

/* Верхняя панель */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--ink);
  padding-top: env(safe-area-inset-top);
}
.top-inner {
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem;
}
.me-btn {
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%; padding: 0; background: none; cursor: pointer;
  min-width: 44px; min-height: 44px; display: grid; place-items: center;
}
.me-btn:focus-visible { outline-color: var(--marker); }

/* Баланс лицей-коинов в шапке (ведёт на страницу игры /farm/) */
.coin-chip {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-weight: 700; font-size: 0.95rem;
  background: var(--marker); color: var(--ink);
  border-radius: 999px; padding: 0.25rem 0.7rem;
  text-decoration: none; white-space: nowrap; min-height: 32px;
}
.coin-chip b { font-weight: 800; }
.coin-chip:hover { background: #fff08a; }
.top-inner .me-btn { margin-left: 0.6rem; }

.page { max-width: 640px; margin: 0 auto; padding: 1rem; }

/* Листы бумаги */
.sheet {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  display: grid;
  gap: 0.85rem;
}

/* Формы */
label { display: grid; gap: 0.3rem; font-weight: 600; font-size: 0.95rem; }
label small { font-weight: 400; color: var(--muted); }

input, textarea {
  font: inherit;
  font-size: 1rem; /* 16px, чтобы iOS не увеличивал страницу при фокусе */
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  min-height: 44px;
  width: 100%;
}
textarea { resize: vertical; min-height: 5.5rem; }
input:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(47, 79, 216, 0.2); }

.btn {
  font: inherit; font-weight: 700;
  min-height: 44px; padding: 0.6rem 1.1rem;
  border: 2px solid var(--blue); border-radius: 8px;
  background: var(--blue); color: #fff;
  cursor: pointer; text-align: center;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-ghost { background: transparent; color: var(--blue); }
.btn-ghost:hover { background: rgba(47, 79, 216, 0.08); color: var(--blue-dark); }

.link {
  font: inherit; background: none; border: 0; padding: 0.4rem 0;
  color: var(--blue); text-decoration: underline; cursor: pointer; min-height: 44px;
}
.link.danger, .danger { color: var(--danger); }

.error { color: var(--danger); font-weight: 600; font-size: 0.95rem; }

/* Вход */
.auth { display: grid; gap: 1rem; padding-top: 1.5rem; }
.auth-title { margin-bottom: 0.25rem; }
.auth-lead { color: var(--muted); }
.switch { color: var(--muted); font-size: 0.95rem; }
.switch .link { min-height: 0; padding: 0; }

/* Лента */
.feed-view { display: grid; gap: 1rem; }
.composer-row { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: space-between; }
.composer-row .btn { flex: 1 1 9rem; }
.preview { display: grid; gap: 0.25rem; justify-items: start; }
.preview img { max-width: 100%; max-height: 240px; border-radius: 8px; border: 1px solid var(--line); }

.feed { display: grid; gap: 1rem; }
.post { padding: 0.9rem 1rem; }
.post-head { display: flex; align-items: center; gap: 0.7rem; }
.who { display: grid; min-width: 0; }
.who strong { overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 0.85rem; }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.post-img { width: 100%; max-height: 520px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--grid); }
.post-foot { display: flex; justify-content: flex-end; }
.post-foot .link { min-height: 36px; font-size: 0.9rem; }

.empty { text-align: center; color: var(--muted); padding: 1.5rem 0; background: var(--paper); }
.more { justify-self: center; }

/* Аватар */
.avatar {
  --s: 44px; --h: 220;
  width: var(--s); height: var(--s);
  flex: none;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  overflow: hidden;
  font-weight: 700; font-size: calc(var(--s) * 0.38);
  background: hsl(var(--h) 65% 88%);
  color: hsl(var(--h) 50% 22%);
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Галочка верифицированного ученика */
.verified {
  width: 1em; height: 1em;
  margin-left: 0.3em;
  vertical-align: -0.12em;
  display: inline-block;
  flex: none;
}
.name { overflow-wrap: anywhere; }

/* Статус верификации в профиле */
.profile-name { font-weight: 700; font-size: 1.05rem; }
.verify-status { font-size: 0.9rem; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 0.1rem; }
.status.ok { color: var(--blue-dark); font-weight: 600; }
.status .verified { margin-left: 0; }

/* Профиль */
.dialog {
  border: 0; padding: 0; background: transparent;
  width: min(480px, calc(100% - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  overflow: auto;
}
.dialog::backdrop { background: rgba(22, 33, 62, 0.55); }
.avatar-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }


/* Вкладки */
.tabs { max-width: 640px; margin: 0 auto; display: flex; padding: 0 0.5rem; }
.tab {
  flex: 1; min-height: 46px; padding: 0 0.5rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  font: inherit; font-weight: 700; cursor: pointer;
  color: rgba(255, 255, 255, 0.72);
  background: none; border: 0; border-bottom: 3px solid transparent;
  text-decoration: none;
}
.tab:hover { color: #fff; }
.tab[aria-current="page"] { color: #fff; border-bottom-color: var(--marker); }
.tab:focus-visible { outline-color: var(--marker); outline-offset: -3px; }

.badge {
  display: inline-block; min-width: 1.4rem; padding: 0 0.4rem;
  border-radius: 999px; background: var(--marker); color: var(--ink);
  font-size: 0.8rem; font-weight: 800; line-height: 1.4rem; text-align: center;
}

/* Действия под постом */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.5rem; margin: 0 -0.25rem; }
.act {
  font: inherit; font-size: 0.95rem; font-weight: 600;
  min-height: 44px; padding: 0 0.6rem;
  color: var(--muted); background: none; border: 0; border-radius: 8px; cursor: pointer;
}
.act:hover { background: rgba(47, 79, 216, 0.08); color: var(--blue-dark); }
.act:disabled { opacity: 0.6; }
.act.like[aria-pressed="true"] { color: var(--danger); }
.act.danger { color: var(--danger); }
.act.danger:hover { background: rgba(198, 47, 59, 0.08); color: var(--danger); }
.act.push { margin-left: auto; }

/* Комментарии */
.comments { display: grid; gap: 0.75rem; border-top: 1px dashed var(--line); padding-top: 0.75rem; }
.comment-list { display: grid; gap: 0.75rem; }
.comment { display: flex; gap: 0.6rem; align-items: flex-start; }
.comment-main { min-width: 0; flex: 1; }
.comment-head { display: flex; flex-wrap: wrap; gap: 0 0.5rem; align-items: baseline; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.link.small { font-size: 0.85rem; min-height: 32px; padding: 0.2rem 0; }
.comment-form { display: grid; gap: 0.4rem; }
.comment-row { display: flex; gap: 0.5rem; }
.comment-row input { flex: 1; min-width: 0; }
#imga {
    display: none
}

/* Сообщения */
.conv-view { display: grid; gap: 1rem; }
.section-title { font-size: 1.05rem; margin: 0.25rem 0 0; }
.list { display: grid; gap: 0.5rem; }
.row {
  display: flex; align-items: center; gap: 0.75rem; width: 100%;
  min-height: 60px; padding: 0.5rem 0.75rem; text-align: left;
  font: inherit; color: inherit; cursor: pointer;
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius);
}
.row:hover { border-color: var(--blue); }
.row-main { display: grid; min-width: 0; flex: 1; }
.row-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thread { padding: 0; gap: 0; overflow: hidden; }
.thread-head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.25rem 0.75rem; border-bottom: 1px solid var(--line);
}
.thread-who { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.thread-body {
  display: flex; flex-direction: column; gap: 0.5rem;
  height: 50vh; height: 50dvh; min-height: 260px; overflow-y: auto;
  padding: 0.75rem; background: var(--paper);
}
.bubble {
  max-width: 80%; padding: 0.5rem 0.75rem; border-radius: 14px;
  display: grid; gap: 0.1rem;
}
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble time { font-size: 0.75rem; opacity: 0.7; justify-self: end; }
.bubble.theirs { align-self: flex-start; background: var(--sheet); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.mine { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.thread-form { display: grid; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid var(--line); }
.thread-form textarea { min-height: 3.5rem; }

@media (min-width: 700px) {
  .page { padding: 1.5rem 1rem 3rem; }
  .sheet { padding: 1.25rem; }
  .brand-big { font-size: 2.6rem; }
}

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