:root {
  --bg: #f2f5fa;
  --surface: #ffffff;
  --text: #0b1f33;
  --muted: #66727f;
  --border: #e1e7ef;
  --primary: #0d4cd3;
  --primary-press: #0a3ba6;
  --on-primary: #ffffff;
  --accent: #ee3f58;
  --ok: #1a8a4a;
  --ok-bg: #e3f6ec;
  --fail: #d0283d;
  --fail-bg: #fde7ea;
  --wait: #9a5b00;
  --wait-bg: #fff1d1;
  --star: #f5a623;
  --shadow: 0 1px 2px rgba(11, 31, 51, .06), 0 4px 16px rgba(11, 31, 51, .06);
  --radius: 16px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1420;
  --surface: #1a2130;
  --text: #e8edf5;
  --muted: #93a0b4;
  --border: #2a3446;
  --primary: #4d82ff;
  --primary-press: #3a6be0;
  --on-primary: #ffffff;
  --accent: #ff5c73;
  --ok: #4ccb84;
  --ok-bg: #163327;
  --fail: #ff6b7d;
  --fail-bg: #3a1a20;
  --wait: #ffbf47;
  --wait-bg: #3a2e12;
  --star: #ffc247;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1 { font-size: 22px; line-height: 1.25; margin: 0 0 8px; }
p { margin: 0 0 12px; }
button, input, select, textarea { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); margin: 12px 0 0; }

/* --- шапка --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.back {
  border: 0;
  background: none;
  font-size: 28px;
  line-height: 1;
  padding: 0 8px 4px 0;
  color: var(--primary);
  cursor: pointer;
}

.logo { display: flex; align-items: center; gap: 10px; }

/* Логотип — фото на прозрачном фоне: в шапке показываем поясной кадр на фирменном градиенте. */
.logo-mark {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background:
    url("assets/gom1.webp") 46% 0 / 222% no-repeat,
    linear-gradient(135deg, var(--primary), var(--accent));
}

.hero-logo {
  display: block;
  width: 110px;
  height: 200px;
  margin: 0 auto 12px;
  object-fit: cover;
  object-position: 26% 0;
}

.logo-text { font-weight: 800; font-size: 20px; letter-spacing: -.3px; }
.logo-gom { color: var(--primary); }
.logo-usl { color: var(--accent); }

/* --- раскладка --- */

.container {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

.view[hidden] { display: none; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.page-title { margin: 4px 0 8px; }
.section-title { font-size: 17px; margin: 24px 0 12px; }

/* --- формы --- */

.form { display: flex; flex-direction: column; gap: 16px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.field > span, .field > legend {
  font-size: 14px;
  font-weight: 600;
  padding: 0;
  margin-bottom: 6px;
}

input:not([type]), input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 64px; }
input[type="range"] { width: 100%; accent-color: var(--primary); }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
}

.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); flex: none; }
.oath { font-weight: 600; }

/* --- кнопки --- */

.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:active { background: var(--primary-press); }
.btn.ghost { background: none; color: var(--muted); margin-top: 16px; }
.btn:disabled { opacity: .6; cursor: progress; }

/* --- личный кабинет --- */

.profile { display: flex; gap: 16px; align-items: center; }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 22px;
}

.profile-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.profile-name { font-size: 19px; font-weight: 700; overflow-wrap: anywhere; }
.profile-info .pill { align-self: flex-start; margin-top: 6px; }

.services { display: flex; flex-direction: column; gap: 10px; }

.service {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  transition: transform .1s;
}

.service:active { transform: scale(.98); }

.service-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 22px;
}

.service-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.service-text small { color: var(--muted); font-size: 13px; }
.chev { color: var(--muted); font-size: 24px; }

/* --- статусы --- */

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.fail { color: var(--fail); background: var(--fail-bg); }
.pill.wait { color: var(--wait); background: var(--wait-bg); }

/* --- результат заявления --- */

.doc { position: relative; overflow: hidden; }

.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.doc-fields { margin: 16px 0; }

.doc-fields div {
  display: grid;
  grid-template-columns: minmax(110px, 40%) 1fr;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px dashed var(--border);
}

.doc-fields dt { color: var(--muted); font-size: 14px; }
.doc-fields dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.doc-note { font-size: 14px; font-style: italic; color: var(--muted); margin: 0; padding-right: 96px; min-height: 80px; }

.stamp {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border: 3px solid currentColor;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  white-space: pre-line;
  transform: rotate(-14deg);
  opacity: .75;
}

.stamp.ok { color: var(--ok); }
.stamp.fail { color: var(--fail); }
.stamp.wait { color: var(--wait); }

/* --- тапалка --- */

.tapper { text-align: center; }

.balance {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 4px 0 20px;
  font-size: 15px;
  color: var(--muted);
}

.balance b { font-size: 34px; color: var(--text); font-variant-numeric: tabular-nums; }
.balance-icon { width: 56px; height: auto; }

.tap-btn {
  display: block;
  width: 168px;
  height: 168px;
  margin: 0 auto;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd86b, #f5a623 55%, #c97a00);
  box-shadow: 0 8px 0 #9c5f00, 0 14px 28px rgba(201, 122, 0, .35);
  color: #4a2a00;
  font-size: 40px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .06s, box-shadow .06s;
}

.tap-btn:active {
  transform: translateY(6px) scale(.97);
  box-shadow: 0 2px 0 #9c5f00, 0 6px 14px rgba(201, 122, 0, .35);
}

.rain {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
  pointer-events: none;
}

.bill {
  position: absolute;
  top: -90px;
  width: 84px;
  animation: fall var(--dur, 1.6s) linear forwards;
}

@keyframes fall {
  to { transform: translateY(calc(100vh + 140px)) rotate(var(--rot, 180deg)); }
}

.plus {
  position: absolute;
  font-size: 22px;
  font-weight: 900;
  color: var(--star);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transform: translate(-50%, -50%);
  animation: plus .7s ease-out forwards;
}

@keyframes plus {
  to { transform: translate(-50%, -160%); opacity: 0; }
}

/* --- вкладки --- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 14px;
  background: var(--border);
}

.tab {
  flex: 1;
  padding: 9px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.tab-panel[hidden] { display: none; }

/* --- лидерборд --- */

.leader-me {
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 12px;
  background: var(--wait-bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.leader-me:empty { display: none; }

.leaders { list-style: none; margin: 0; padding: 0; }

.leader {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-top: 1px solid var(--border);
}

.leader:first-child { border-top: 0; }
.leader.me { background: var(--ok-bg); border-radius: 10px; padding-inline: 10px; }
.leader-rank { flex: none; width: 28px; text-align: center; font-weight: 700; color: var(--muted); }
.leader-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.leader-count { font-variant-numeric: tabular-nums; }
.leaders .empty { padding: 16px 0; }

/* --- Гом TV: корпус телевизора тёмный в любой теме --- */

.tv {
  padding: 14px;
  border-radius: 22px;
  background: #1d1f24;
  box-shadow: var(--shadow);
}

.tv-screen {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 14px;
  background: #000;
  cursor: pointer;
}

.tv-screen video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tv-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.tv-live { color: #ff4d5e; }

/* Помехи при переключении канала. */
.tv-static {
  position: absolute;
  inset: 0;
  background: #777 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: tv-static .12s steps(2) infinite;
}

.tv-static[hidden] { display: none; }

/* Кнопка ▶, если устройство запретило автозапуск. */
.tv-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 88px;
  height: 88px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 36px;
  cursor: pointer;
}

.tv-play[hidden] { display: none; }

@keyframes tv-static {
  50% { background-position: -37px 23px; }
  100% { background-position: 19px -41px; }
}

.tv-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.tv-btn {
  flex: none;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: #2d3038;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  touch-action: manipulation;
}

.tv-btn:active { background: #3d414b; }

.tv-name {
  flex: 1;
  min-width: 0;
  text-align: center;
  color: #fff;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.tv-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.tv-thumb {
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
}

.tv-thumb.active { border-color: var(--primary); }

.tv-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--border);
}

.tv-thumb span {
  display: block;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- гостевая книга --- */

.reviews { display: flex; flex-direction: column; gap: 12px; }
.review { margin: 0; padding: 16px; }
.review.mine { box-shadow: inset 3px 0 0 var(--primary), var(--shadow); }

.review-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.review-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: hsl(var(--hue, 220) 55% 48%);
  color: #fff;
  font-weight: 700;
}

.review-who { display: flex; flex-direction: column; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.review-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* Новые записи из автообновления на секунду подсвечиваются. */
.review.fresh { animation: fresh 1.6s ease-out; }

@keyframes fresh {
  from { background: var(--ok-bg); }
}

#reviewsMore[hidden] { display: none; }

/* --- подвал и тост --- */

.footer {
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.footer b { color: var(--text); }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: 528px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  .service, .tap-btn { transition: none; }
  .review.fresh { animation: none; }
}
