:root {
  --spn-bg: #f7f7f8;
  --spn-surface: #ffffff;
  --spn-fg: #141414;
  --spn-muted: #6b6b6b;
  --spn-accent: #c62828;
  --spn-border: #e6e6e8;
  --spn-top: 52px;
  --spn-tabs: 58px;
  --spn-safe-b: env(safe-area-inset-bottom, 0px);
  --spn-safe-t: env(safe-area-inset-top, 0px);
  /* 3-кнопочная панель Android часто даёт safe-area=0 — минимальный запас */
  --spn-nav-fallback: 48px;
  --spn-viewer-pad-b: max(var(--spn-safe-b), var(--spn-nav-fallback));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--spn-bg);
  color: var(--spn-fg);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-x: none;
}

.spn-app {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--spn-safe-t);
  padding-bottom: calc(var(--spn-tabs) + var(--spn-safe-b));
  overscroll-behavior-x: none;
  overflow: hidden;
}

.spn-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--spn-top);
  padding: 8px 14px;
  background: var(--spn-surface);
  border-bottom: 1px solid var(--spn-border);
}

.spn-logo { border-radius: 8px; }
.spn-top-text { display: flex; flex-direction: column; line-height: 1.15; }
.spn-top-text strong { font-size: 1rem; }
.spn-top-text span { font-size: 0.78rem; color: var(--spn-muted); }

.spn-main {
  flex: 1;
  min-height: 0;
  padding: 12px 14px 18px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.spn-screen[hidden] { display: none !important; }
.spn-screen:not([hidden]) {
  min-height: 0;
}

.spn-h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 600;
}
.spn-h2--gap { margin-top: 22px; }

.spn-chips {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  background: var(--spn-surface);
  border: 1px solid var(--spn-border);
  border-radius: 12px;
}
.spn-chip {
  appearance: none;
  flex: 1;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--spn-muted);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 9px 10px;
  cursor: pointer;
}
.spn-chip.is-active {
  background: var(--spn-bg);
  color: var(--spn-fg);
  box-shadow: inset 0 0 0 1px var(--spn-border);
}

.spn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.spn-row .spn-h2 { margin: 0; }

.spn-search {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: stretch;
}
.spn-search__field {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}
.spn-search input[type="search"] {
  width: 100%;
  border: 1px solid var(--spn-border);
  border-radius: 12px;
  padding: 12px 84px 12px 14px;
  font-size: 1rem;
  background: var(--spn-surface);
}
.spn-search__tools {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
}
.spn-iconbtn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--spn-muted);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.spn-iconbtn:hover,
.spn-iconbtn.has-file,
.spn-iconbtn.is-listening {
  color: var(--spn-accent);
  background: rgba(198, 40, 40, 0.08);
}
.spn-iconbtn.is-listening {
  animation: spn-pulse 1.1s ease-in-out infinite;
}
@keyframes spn-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
.spn-attach {
  margin: 0 0 10px;
}
.spn-attach[hidden] { display: none !important; }
.spn-attach__chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  background: var(--spn-surface);
  border: 1px solid var(--spn-border);
  border-radius: 999px;
  padding: 6px 10px 6px 12px;
  font-size: 0.85rem;
}
.spn-attach__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}
.spn-attach__remove {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--spn-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.spn-voice {
  margin: 0 0 10px;
  color: var(--spn-accent);
  font-size: 0.88rem;
  font-weight: 600;
}
.spn-voice[hidden] { display: none !important; }

.spn-btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--spn-accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 16px;
  cursor: pointer;
}
.spn-btn--block { width: 100%; }
.spn-btn--ghost {
  background: #f0f0f2;
  color: var(--spn-fg);
  margin-top: 12px;
}
/* hidden не должен перебиваться display:flex у .spn-profile--embed */
#profileGuest[hidden],
#profileUser[hidden],
.spn-profile[hidden],
.spn-profile--embed[hidden] {
  display: none !important;
}
.spn-profile--embed {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin: -12px -14px -18px;
  /* Высота от flex-цепочки .spn-app → .spn-main → screen, не жёсткий calc */
  height: 100%;
}
.spn-profile-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--spn-surface);
  border-bottom: 1px solid var(--spn-border);
  flex-shrink: 0;
  align-items: center;
  min-height: 48px;
}
.spn-profile-bar[hidden] {
  display: none !important;
}
.spn-profile-bar__links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1;
}
.spn-profile-bar__links[hidden] {
  display: none !important;
}
.spn-chipbtn {
  appearance: none;
  border: 1px solid var(--spn-border);
  background: var(--spn-bg);
  color: var(--spn-fg);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.spn-chipbtn--back {
  border-color: transparent;
  background: transparent;
  padding-left: 4px;
}
.spn-chipbtn--danger {
  margin-left: auto;
  flex-shrink: 0;
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}
.spn-profile--embed.is-subpage .spn-more--embed {
  display: none;
}
.spn-profile--embed.is-subpage #profileLogoutBtn {
  display: none;
}
.spn-profile--embed.is-subpage .spn-profile-bar__links {
  display: none !important;
}
.spn-profile--embed.is-subpage .spn-profile-embed {
  flex: 1;
  min-height: 0;
}
.spn-profile-embed {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  border: 0;
  background: #fff;
  display: block;
  align-self: stretch;
}
.spn-profile-embed.is-booting {
  opacity: 0;
}
.spn-more--embed {
  margin: 0;
  border-top: 1px solid var(--spn-border);
  padding: 4px 12px 8px;
  background: var(--spn-surface);
  flex-shrink: 0;
}
/* overflow:hidden только для встроенного профиля; у гостя вкладка должна скроллиться */
html.spn-profile-embed-mode .spn-main {
  padding-bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
html.spn-profile-embed-mode .spn-screen[data-screen="profile"] {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}
html.spn-profile-embed-mode #profileUser.spn-profile--embed {
  flex: 1;
  min-height: 0;
  height: auto;
}
html.spn-profile-tab:not(.spn-profile-embed-mode) .spn-main {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.spn-more {
  margin-top: 18px;
}
.spn-more--guest {
  margin-top: 20px;
  padding-top: 4px;
}
.spn-more > summary {
  cursor: pointer;
  list-style: none;
  color: var(--spn-muted);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 12px 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  user-select: none;
}
.spn-more > summary::-webkit-details-marker { display: none; }
.spn-more > summary::after {
  content: " ▾";
  font-size: 0.75rem;
  margin-left: 4px;
}
.spn-more[open] > summary::after { content: " ▴"; }
.spn-more__links {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 0 0 10px;
}
.spn-textlink {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--spn-muted);
  font-size: 0.92rem;
  line-height: 1.4;
  padding: 10px 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.spn-textlink:hover { color: var(--spn-fg); }
.spn-linkbtn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--spn-accent);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0;
  cursor: pointer;
}

.spn-status, .spn-muted, .spn-meta {
  color: var(--spn-muted);
  font-size: 0.92rem;
  line-height: 1.45;
}
.spn-answer {
  background: var(--spn-surface);
  border: 1px solid var(--spn-border);
  border-radius: 14px;
  padding: 14px;
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 0.98rem;
}
.spn-meta { margin-top: 10px; }

.spn-sources {
  margin-top: 12px;
  background: var(--spn-surface);
  border: 1px solid var(--spn-border);
  border-radius: 14px;
  padding: 0 12px;
}
.spn-sources[hidden] { display: none !important; }
.spn-sources > summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 0;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--spn-fg);
}
.spn-sources > summary::-webkit-details-marker { display: none; }
.spn-sources > summary::after {
  content: "▾";
  float: right;
  color: var(--spn-muted);
}
.spn-sources[open] > summary::after { content: "▴"; }
.spn-sources__list {
  list-style: none;
  margin: 0;
  padding: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.spn-sources__list button {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 10px;
  background: var(--spn-bg);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.spn-sources__list button strong {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--spn-fg);
  line-height: 1.3;
}
.spn-sources__list button span {
  font-size: 0.75rem;
  color: var(--spn-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spn-media {
  margin-top: 12px;
}
.spn-media[hidden] { display: none !important; }
.spn-media__title {
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.spn-media__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.spn-media__card {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--spn-surface);
  border: 1px solid var(--spn-border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  text-align: left;
  min-width: 0;
}
.spn-media__thumb {
  position: relative;
  aspect-ratio: 1;
  background: #ececef;
  overflow: hidden;
}
.spn-media__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.spn-media__duration {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 4px;
}
.spn-media__label {
  padding: 6px 7px;
  font-size: 0.68rem;
  line-height: 1.25;
  color: var(--spn-fg);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.spn-error { color: #b00020; font-size: 0.9rem; }

.spn-list, .spn-cards, .spn-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.spn-item, .spn-cardbtn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--spn-surface);
  border: 1px solid var(--spn-border);
  border-radius: 14px;
  padding: 12px 14px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.spn-item strong, .spn-cardbtn strong {
  display: block;
  margin-bottom: 4px;
}
.spn-item span, .spn-cardbtn span {
  color: var(--spn-muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.spn-toolcard {
  position: relative;
}
.spn-toolcard .spn-cardbtn {
  padding-right: 48px;
}
.spn-favbtn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.spn-favbtn svg {
  width: 20px;
  height: 20px;
}
.spn-favbtn.is-on {
  color: #eab308;
}
.spn-favbtn.is-on svg {
  fill: currentColor;
}

.spn-answer-actions {
  margin: 8px 0 4px;
}
.spn-answer-actions__row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.spn-actbtn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--spn-border);
  background: var(--spn-surface);
  color: var(--spn-fg);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.spn-actbtn.is-active.spn-actbtn--like {
  background: #ecfdf5;
  border-color: #10b981;
  color: #047857;
}
.spn-actbtn.is-active.spn-actbtn--dislike {
  background: #fef2f2;
  border-color: #ef4444;
  color: #dc2626;
}

.spn-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 16px;
  padding-bottom: calc(16px + var(--spn-safe-b));
}
.spn-modal[hidden] { display: none !important; }
.spn-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.spn-modal__dialog {
  position: relative;
  width: min(420px, 100%);
  background: var(--spn-surface);
  border-radius: 16px;
  padding: 18px 16px 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.spn-modal__title {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 6px;
}
.spn-modal__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.spn-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--spn-tabs) + var(--spn-safe-b) + 16px);
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90vw, 360px);
  padding: 10px 14px;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.spn-toast[hidden] { display: none !important; }

.spn-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0;
}
.spn-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--spn-muted);
}
.spn-form input {
  border: 1px solid var(--spn-border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  color: var(--spn-fg);
}

.spn-tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  min-height: var(--spn-tabs);
  padding: 6px 4px calc(6px + var(--spn-safe-b));
  background: var(--spn-surface);
  border-top: 1px solid var(--spn-border);
}
.spn-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--spn-muted);
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.15;
  padding: 6px 2px;
  cursor: pointer;
  white-space: normal;
}
.spn-tab.is-active { color: var(--spn-accent); }

/* Полноценный экран раздела (лента/входящие) — между шапкой и табами, не оверлей */
.spn-fullscreen {
  position: fixed;
  top: calc(var(--spn-safe-t) + var(--spn-top));
  left: 0;
  right: 0;
  bottom: calc(var(--spn-tabs) + var(--spn-safe-b));
  z-index: 25;
  display: flex;
  flex-direction: column;
  background: #fff;
  overscroll-behavior-x: none;
}
.spn-fullscreen[hidden] { display: none !important; }
.spn-fullscreen__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--spn-border);
  background: #fff;
  flex-shrink: 0;
}
.spn-fullscreen__title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spn-fullscreen__frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
  display: block;
}
.spn-fullscreen__frame.is-booting {
  opacity: 0;
}

.spn-viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: #fff;
  padding-top: var(--spn-safe-t);
  /* Не уезжать под системные клавиши Android */
  padding-bottom: var(--spn-viewer-pad-b);
  overscroll-behavior-x: none;
}
.spn-viewer[hidden] { display: none !important; }
.spn-viewer.is-game {
  /* Игры: только реальный safe-area, без лишнего «поля» */
  padding-bottom: var(--spn-safe-b);
  background: #0e1116;
  /* Режем горизонтальный edge-gesture «назад» */
  touch-action: pan-y;
  overscroll-behavior-x: none;
}
.spn-viewer.is-game .spn-viewer__frame {
  touch-action: pan-y;
  overscroll-behavior-x: none;
}
.spn-viewer.is-game .spn-viewer__bar {
  background: #151820;
  border-bottom-color: #2a3140;
}
.spn-viewer.is-game .spn-viewer__title {
  color: #e8eaed;
}
.spn-viewer.is-game #viewerBack {
  background: #1e2633;
  border-color: #35485f;
  color: #f3f0ea;
}
/* 2048 — светлая оболочка */
.spn-viewer.is-game-light {
  background: #faf8ef;
}
.spn-viewer.is-game-light .spn-viewer__bar {
  background: #faf8ef;
  border-bottom-color: #e0d8c8;
}
.spn-viewer.is-game-light .spn-viewer__title {
  color: #3d3a36;
}
.spn-viewer.is-game-light #viewerBack {
  background: #f3f0ea;
  border-color: #d6cfc0;
  color: #3d3a36;
}
.spn-viewer__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--spn-border);
  background: #fff;
  flex-shrink: 0;
}
.spn-viewer__title {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spn-viewer__frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
  overscroll-behavior-x: none;
}
.spn-viewer__frame.is-booting {
  opacity: 0;
  pointer-events: none;
}

/* Сервисы на главном экране — убраны (неудобно для пользователя) */

/* Онбординг */
.spn-onboard {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 20, 20, 0.45);
  padding: 16px;
}
.spn-onboard[hidden] { display: none !important; }
.spn-onboard__panel {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 18px 18px 14px 14px;
  padding: 20px 16px calc(16px + var(--spn-safe-b));
  box-shadow: 0 -8px 28px rgba(0,0,0,.18);
}
.spn-onboard__dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}
.spn-onboard__dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d0d0d4;
}
.spn-onboard__dots span.is-active { background: var(--spn-accent); }
.spn-onboard__slide h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  text-align: center;
}
.spn-onboard__slide p {
  margin: 0 0 16px;
  color: var(--spn-muted);
  text-align: center;
  line-height: 1.45;
  font-size: 0.95rem;
}
.spn-onboard__actions {
  display: flex;
  gap: 8px;
}
.spn-onboard__actions .spn-btn { flex: 1; }

/* Офлайн */
.spn-offline {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(247, 247, 248, 0.96);
  padding: 24px;
}
.spn-offline[hidden] { display: none !important; }
.spn-offline__card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--spn-border);
  border-radius: 16px;
  padding: 22px 18px;
}
.spn-offline__card h2 { margin: 0 0 8px; font-size: 1.2rem; }
.spn-offline__card p {
  margin: 0 0 16px;
  color: var(--spn-muted);
  line-height: 1.45;
}
