/**
 * Тема берётся из Telegram themeParams (CSS-переменные ставит app.js),
 * поэтому приложение выглядит родным и в светлой, и в тёмной теме.
 */
:root {
  --bg: #17212b;
  --bg-2: #1d2733;
  --card: #202b36;
  --text: #f4f6f8;
  --hint: #8a97a5;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --line: #2b3947;
  --good: #31c48d;
  --warn: #f5a524;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  padding-bottom: calc(58px + var(--safe-b));
}

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100%;
}

/* шапка */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 10px;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.bar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.logo {
  font-size: 22px;
}
h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub {
  font-size: 12px;
  color: var(--hint);
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--hint);
  flex: none;
}
.dot.on {
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent);
}

main {
  padding: 0 14px 16px;
}

/* карточки */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card.tight {
  padding: 12px;
}
h2 {
  font-size: 16px;
  margin: 0 0 8px;
}
.muted {
  color: var(--hint);
  font-size: 13px;
}
.center {
  display: grid;
  place-items: center;
  min-height: 50vh;
  color: var(--hint);
  text-align: center;
}

/* таймер */
.timer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--card)), var(--card));
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.timer .label {
  font-size: 13px;
  color: var(--hint);
}
.timer .value {
  font-variant-numeric: tabular-nums;
  font-size: 24px;
  font-weight: 650;
}
.timer.urgent .value {
  color: var(--warn);
}

/* кнопки */
button,
.btn {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 46px;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
button:active {
  transform: scale(0.985);
}
button.primary,
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
a.btn {
  text-decoration: none;
  text-align: center;
  display: block;
}
button:disabled {
  opacity: 0.5;
}
.wide {
  width: 100%;
}

/* лента */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
@media (min-width: 560px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.tile {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-2);
  aspect-ratio: 1 / 1;
  border: 2px solid transparent;
}
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.tile .meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 16px 8px 6px;
  font-size: 11px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.tile.mine {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
}
.tile.selectable {
  cursor: pointer;
}
.tile.selected {
  border-color: var(--accent);
}
.tile .votes {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.tile .voted {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
}

/* загрузка */
.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  color: var(--hint);
  margin-bottom: 12px;
}
.progress {
  height: 6px;
  border-radius: 4px;
  background: var(--bg-2);
  overflow: hidden;
  margin-top: 10px;
}
.progress i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s linear;
}

/* победитель */
.winner-photo {
  width: 100%;
  border-radius: 12px;
  display: block;
  margin-bottom: 10px;
  background: var(--bg-2);
}
.signature {
  font-size: 16px;
  line-height: 1.45;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  margin: 10px 0 12px;
}

/* зал славы */
.hall-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: var(--card);
  margin-bottom: 8px;
  text-decoration: none;
  color: inherit;
}
.hall-item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  flex: none;
}
.hall-item .grow {
  min-width: 0;
  flex: 1;
}
.hall-item .name {
  font-weight: 600;
  font-size: 14px;
}
.hall-item .sig {
  font-size: 12px;
  color: var(--hint);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* нижние табы */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 6px;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  z-index: 6;
}
.tabs button {
  flex: 1;
  min-height: 40px;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--hint);
  font-size: 13px;
}
.tabs button.active {
  color: var(--text);
  background: var(--bg-2);
}

.tabs[hidden] {
  display: none;
}

/* реакции под фото: корона и комментарии */
.item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.reactions {
  display: flex;
  gap: 6px;
}
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.reaction.on {
  background: color-mix(in srgb, var(--accent) 24%, var(--bg-2));
  border-color: var(--accent);
}
.reaction .crown {
  filter: grayscale(0.75) opacity(0.75);
  transition: filter 0.12s ease, transform 0.12s ease;
}
.reaction.on .crown {
  filter: none;
  transform: scale(1.08);
}
.reaction.big {
  font-size: 16px;
  min-height: 42px;
  padding: 6px 16px;
}

/* карточка фото с комментариями */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.sheet[hidden] {
  display: none;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
}
.sheet-panel {
  position: relative;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 14px 14px calc(14px + var(--safe-b));
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.35);
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sheet-head .grow {
  flex: 1;
  min-width: 0;
}
.sheet-photo {
  width: 100%;
  max-height: 46vh;
  object-fit: contain;
  border-radius: 12px;
  background: var(--bg-2);
}
.sheet-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.comments {
  flex: 1;
  overflow-y: auto;
  max-height: 28vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
}
.comment {
  background: var(--card);
  border-radius: 10px;
  padding: 8px 10px;
}
.comment-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  color: var(--hint);
}
.comment-head b {
  color: var(--text);
  font-size: 13px;
}
.comment-body {
  font-size: 14px;
  margin-top: 3px;
  word-break: break-word;
}
.comment-form {
  display: flex;
  gap: 8px;
}
.comment-form input {
  flex: 1;
  min-width: 0;
}
.comment-form button {
  padding: 10px 16px;
  min-height: 44px;
}
.icon {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
}
.link {
  background: none;
  border: 0;
  color: var(--hint);
  font-size: 12px;
  padding: 0;
  min-height: 0;
  text-decoration: underline;
  cursor: pointer;
}

/* прочее */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + var(--safe-b));
  transform: translateX(-50%);
  max-width: 88vw;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 20;
  text-align: center;
}
.toast[hidden] {
  display: none;
}
.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}
.confetti[hidden] {
  display: none;
}
input {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  width: 100%;
  outline: none;
}
input:focus {
  border-color: var(--accent);
}
