/* «Холопы»: стиль лубка и берестяной грамоты. Mobile-first, 360–430 px. */

:root {
  --paper: #f3e6c8;
  --paper-d: #e7d3a0;
  --card-a: #fbf4df;
  --card-b: #efdcae;
  --ink: #3b2414;
  --ink-soft: #6b4b2e;
  --red: #b3261e;
  --red-d: #7d1812;
  --gold: #c9a227;
  --gold-l: #f3d87a;
  --gold-d: #8a6a12;
  --radius: 14px;
  --shadow: 0 2px 6px rgba(59, 36, 20, 0.28);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "PT Serif", Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.35) 0, transparent 40%),
    radial-gradient(circle at 88% 92%, rgba(139, 94, 40, 0.18) 0, transparent 45%),
    repeating-linear-gradient(0deg, rgba(120, 80, 30, 0.035) 0 2px, transparent 2px 5px),
    var(--paper);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: var(--tg-viewport-stable-height, 100vh);
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
}

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

.top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: linear-gradient(180deg, var(--red), var(--red-d));
  color: #fff4d6;
  border-bottom: 2px solid var(--gold);
  box-shadow: 0 3px 8px rgba(59, 36, 20, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 0 #5a140e;
}

.logo { font-size: 22px; }

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.coins {
  background: linear-gradient(#f7dd7a, var(--gold));
  color: var(--ink);
  border: 1px solid #6d5210;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.lang {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--gold-d);
  border-radius: 999px;
  padding: 2px;
}

.lang button {
  border: 0;
  background: transparent;
  color: #f3e6c8;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
}

.lang button.on {
  background: var(--gold);
  color: var(--ink);
}

/* ---------- содержимое вкладок ---------- */

.view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 12px 24px;
}

.card {
  position: relative;
  background: linear-gradient(180deg, var(--card-a), var(--card-b));
  border: 1.5px solid var(--gold-d);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  margin-bottom: 12px;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--red);
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--gold), transparent);
}

h3 {
  font-size: 14px;
  color: var(--red);
  margin: 14px 0 6px;
}

.name {
  font-weight: 700;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name.big {
  font-size: 19px;
  white-space: normal;
  word-break: break-word;
}

.title {
  font-size: 12px;
  color: var(--red);
  font-style: italic;
}

.meta {
  font-size: 12px;
  color: var(--ink-soft);
}

.meta.small { font-size: 11px; }

.center { text-align: center; }

.grow {
  flex: 1;
  min-width: 0;
}

.right {
  text-align: right;
  flex: none;
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  font-style: italic;
  padding: 14px 8px;
  margin: 0;
}

.note {
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
  margin: 0 0 10px;
}

.banner {
  background: linear-gradient(#3b2414, #2a180c);
  color: #f3e6c8;
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 12px;
  font-size: 13px;
  text-align: center;
}

.hint {
  font-size: 12px;
  color: var(--red);
  text-align: center;
  margin: 8px 0 0;
}

.reason {
  font-size: 13px;
  color: var(--red);
  text-align: center;
  padding: 8px;
  background: rgba(179, 38, 30, 0.08);
  border-radius: 10px;
  margin-bottom: 8px;
}

.price {
  font-weight: 700;
  color: var(--red);
  white-space: nowrap;
}

.income {
  font-weight: 700;
  color: #2f6b1f;
  white-space: nowrap;
}

.sentinel { height: 1px; }

/* карточка «я» */

.me-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.coins-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 10px;
}

.coins-big {
  font-size: 22px;
  font-weight: 700;
  color: var(--red);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--gold-d);
  background: #fff6dc;
  color: var(--ink);
}

.badge.chain { border-color: #5b5b5b; background: #e6e6e6; }
.badge.immune { border-color: #2a6fb0; background: #dcebfa; color: #1d4f80; }
.badge.boost { border-color: #2f8a2f; background: #dff3d8; color: #1f5f1f; }

/* строки списков */

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.35);
  border: 1px solid rgba(138, 106, 18, 0.35);
  margin-bottom: 8px;
}

.row.link { cursor: pointer; }
.row.link:active { background: rgba(255, 255, 255, 0.6); }
.row.me {
  border-color: var(--gold);
  background: rgba(243, 216, 122, 0.35);
}

.mk {
  cursor: pointer;
}

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

.mk .btn { margin-top: 8px; }

.rank {
  width: 30px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
  color: var(--red);
  flex: none;
}

.rank-me {
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  margin: -2px 0 10px;
}

/* амбар */

.bar {
  height: 12px;
  border-radius: 7px;
  background: #e3d1a0;
  border: 1px solid var(--gold-d);
  overflow: hidden;
  margin: 6px 0 8px;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #b8891a, var(--gold-l));
  border-radius: 7px;
  transition: width 0.9s ease;
}

/* сегменты */

.seg {
  display: flex;
  gap: 3px;
  background: var(--paper-d);
  border: 1px solid var(--gold-d);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 10px;
}

.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
  padding: 8px 2px;
  border-radius: 9px;
  color: var(--ink);
  cursor: pointer;
}

.seg button.on {
  background: linear-gradient(#d9443a, var(--red));
  color: #fff6dc;
  box-shadow: 0 1px 3px rgba(59, 36, 20, 0.35);
}

/* ---------- аватары и рамки ---------- */

.av {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(#f3dc94, #b8891a);
  border: 2px solid var(--gold-d);
  position: relative;
}

.av img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.av-letter {
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
}

.av-lg { width: 76px; height: 76px; }
.av-lg .av-letter { font-size: 30px; }
.av-sm { width: 36px; height: 36px; }
.av-sm .av-letter { font-size: 15px; }

.frame-gold {
  border: 3px solid #f5c542;
  animation: glowGold 2.4s ease-in-out infinite alternate;
}

.frame-fire {
  border: 3px solid #ff6a1a;
  animation: glowFire 1.4s ease-in-out infinite alternate;
}

.frame-ice {
  border: 3px solid #8fe0ff;
  animation: glowIce 2.2s ease-in-out infinite alternate;
}

@keyframes glowGold {
  from { box-shadow: 0 0 0 2px #fff3c4, 0 0 6px 1px rgba(245, 197, 66, 0.5); }
  to   { box-shadow: 0 0 0 2px #fff3c4, 0 0 14px 4px rgba(245, 197, 66, 0.95); }
}

@keyframes glowFire {
  from { box-shadow: 0 0 0 2px #fff0d0, 0 0 6px 1px rgba(255, 106, 26, 0.5); }
  to   { box-shadow: 0 0 0 2px #fff0d0, 0 0 16px 5px rgba(255, 80, 20, 0.95); }
}

@keyframes glowIce {
  from { box-shadow: 0 0 0 2px #eaf9ff, 0 0 6px 1px rgba(143, 224, 255, 0.5); }
  to   { box-shadow: 0 0 0 2px #eaf9ff, 0 0 14px 4px rgba(143, 224, 255, 0.95); }
}

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

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  background: linear-gradient(#d9443a, var(--red));
  color: #fff6dc;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25), 0 2px 4px rgba(59, 36, 20, 0.3);
  cursor: pointer;
  transition: transform 0.08s ease;
}

.btn:active { transform: translateY(1px); }

.btn[disabled] {
  background: #c2b596;
  color: #7d6f57;
  box-shadow: none;
  cursor: default;
}

.btn.wide {
  display: block;
  width: 100%;
  margin-top: 8px;
}

.btn-gold {
  background: linear-gradient(#f3d87a, #b8891a);
  color: var(--ink);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18), 0 2px 4px rgba(59, 36, 20, 0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--red);
  border: 1.5px solid var(--red);
  box-shadow: none;
}

.btn-ghost[disabled] {
  background: transparent;
  border-color: #c2b596;
  color: #8a7d64;
}

.mon {
  margin-top: 4px;
  padding: 0 4px 8px;
}

.mon .btn { margin-top: 6px; }

/* лента событий */

.ev {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 7px 0;
  border-bottom: 1px dashed rgba(138, 106, 18, 0.35);
  font-size: 14px;
  line-height: 1.35;
}

.ev:last-child { border-bottom: 0; }

.ev-ic {
  width: 26px;
  text-align: center;
  font-size: 18px;
  flex: none;
}

.ev-body {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

/* лавка */

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

.shop-ic {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 12px;
  background: linear-gradient(#f3dc94, #d9b55a);
  border: 1px solid var(--gold-d);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.shop-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.shop-actions .btn {
  flex: 1;
  margin: 0;
}

.owned {
  font-size: 13px;
  font-weight: 700;
  color: #2f6b1f;
}

/* ---------- тосты ---------- */

.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(10px + var(--safe-t));
  width: min(92vw, 420px);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(#4a2a16, #2a180c);
  color: #fbf0d2;
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  font-size: 14px;
  line-height: 1.35;
  animation: toastIn 0.25s ease both;
  transition: opacity 0.35s ease;
}

.toast span { flex: 1; }
.toast.out { opacity: 0; }

.toast-btn {
  flex: none;
  border: 0;
  border-radius: 9px;
  background: var(--gold);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 7px 10px;
  cursor: pointer;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- шторки ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 22, 10, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.2s ease both;
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 88%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, #fbf3dc, #eedcae);
  border: 2px solid var(--gold);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  padding: 18px 14px calc(18px + var(--safe-b));
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.35);
  animation: sheetUp 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.grab {
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: var(--gold-d);
  opacity: 0.6;
  margin: 0 auto 10px;
}

.sheet-x {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  background: transparent;
  font-size: 18px;
  color: var(--ink-soft);
  padding: 4px 8px;
  cursor: pointer;
}

.sheet-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  padding-right: 24px;
}

.sheet-title {
  font-size: 18px;
  color: var(--red);
  text-align: center;
  margin: 4px 0 8px;
}

.sheet-text {
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  margin: 0 0 10px;
}

.welcome-ic {
  font-size: 44px;
  text-align: center;
}

.rules {
  padding-left: 18px;
  margin: 8px 0 4px;
  font-size: 14px;
  line-height: 1.5;
}

.job-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid var(--gold-d);
  background: rgba(255, 255, 255, 0.45);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 6px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.job-btn.on {
  background: linear-gradient(#f3d87a, #d9b55a);
  font-weight: 700;
}

.job-ic {
  width: 28px;
  text-align: center;
  font-size: 20px;
}

/* ---------- нижняя навигация ---------- */

.nav {
  flex: none;
  display: flex;
  background: linear-gradient(#5a140e, #3e0d09);
  border-top: 2px solid var(--gold);
  padding: 6px 6px calc(6px + var(--safe-b));
}

.nav button {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #e9d6a4;
  font: inherit;
  font-size: 11px;
  padding: 4px 2px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}

.nav button .ic {
  font-size: 20px;
  line-height: 1;
}

.nav button.on {
  color: #fff4d6;
  background: rgba(201, 162, 39, 0.25);
  box-shadow: inset 0 0 0 1px var(--gold);
}

/* ---------- загрузка ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
}

.boot-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 0 24px;
}

.boot-logo {
  font-size: 56px;
  animation: bob 1.6s ease-in-out infinite;
}

#boot-text {
  font-size: 16px;
  color: var(--red);
}

/* ---------- анимации ---------- */

.rise {
  animation: rise 0.45s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: none; }
}

@keyframes bob {
  50% { transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}

@media (min-width: 431px) {
  .view { padding-left: 16px; padding-right: 16px; }
}
