/* Snowball Fight — интерфейс. Палитра: морозное небо, тёплый снег, коралловый акцент. */
:root {
  --sky: #CFE8FF;
  --sky2: #E9F4FF;
  --snow: #F7FBFF;
  --lav: #B9C4E8;
  --ink: #1E2A4A;
  --ink2: #4A587A;
  --muted: #7D8AA8;
  --coral: #FF6B5A;
  --coral-d: #E04D3D;
  --teal: #3FD0D4;
  --teal-d: #1FA9AD;
  --red: #E8434F;
  --gold: #FFC23D;
  --gold-d: #E29A0B;
  --green: #2DBE8C;
  --card: #FFFFFF;
  --line: #E1E8F5;
  --shadow: 0 8px 24px rgba(30, 42, 74, .10);
  --r: 18px;
  --font: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --num: "Rubik", "Nunito", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font: 15px/1.4 var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, var(--sky2) 55%, var(--snow) 100%);
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; user-select: text; -webkit-user-select: text; }

#snowfx { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#app { position: relative; z-index: 1; height: 100%; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; }

.screen { display: none; flex: 1; flex-direction: column; min-height: 0; animation: fadeIn .25s ease; }
.screen.on { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px calc(16px + var(--safe-b)); }

/* ---------- верхняя панель ---------- */
.topbar { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.topbar .who { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.avatar { width: 42px; height: 42px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; flex: none; overflow: hidden; }
.avatar svg { width: 38px; height: 38px; }
.who .nm { font-weight: 900; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .lv { font-size: 12px; color: var(--ink2); font-weight: 700; }
.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--card); border-radius: 999px; padding: 5px 10px 5px 6px; font: 700 14px var(--num); box-shadow: 0 3px 10px rgba(30,42,74,.08); white-space: nowrap; }
.chip svg { width: 20px; height: 20px; }
.back { width: 40px; height: 40px; border-radius: 14px; border: 0; background: var(--card); box-shadow: var(--shadow); font-size: 20px; font-weight: 900; cursor: pointer; flex: none; }
.ttl { font-size: 20px; font-weight: 900; flex: 1; }

/* ---------- кнопки ---------- */
.btn { border: 0; border-radius: 16px; padding: 13px 18px; font-weight: 900; font-size: 16px; cursor: pointer; transition: transform .08s, filter .15s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { transform: translateY(2px); }
.btn:disabled { filter: grayscale(.7) opacity(.6); cursor: default; transform: none; }
.btn.primary { background: var(--coral); color: #fff; box-shadow: 0 4px 0 var(--coral-d); }
.btn.primary:active { box-shadow: 0 2px 0 var(--coral-d); }
.btn.teal { background: var(--teal); color: #fff; box-shadow: 0 4px 0 var(--teal-d); }
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 var(--gold-d); }
.btn.ghost { background: #EAF1FC; color: var(--ink); }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 12px; }
.btn.wide { width: 100%; }
.btn svg { width: 20px; height: 20px; }
.btn.primary svg path, .btn.teal svg path { stroke: #fff; }

/* ---------- карточки ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 17px; }
.muted { color: var(--muted); }
.sm { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.num { font-family: var(--num); font-weight: 700; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: #EEF3FC; font-size: 12px; font-weight: 800; color: var(--ink2); }
.badge.coral { background: #FFE6E2; color: var(--coral-d); }
.badge.teal { background: #DDF8F8; color: #10888C; }
.badge.gold { background: #FFF2D2; color: #9A6500; }

/* ---------- городок ---------- */
.town-hero { position: relative; margin: 4px 14px 10px; border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); background: linear-gradient(#9FD0FF, #DDF0FF); height: 150px; flex: none; }
.town-hero svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.town-hero .hello { position: absolute; left: 12px; top: 12px; font-weight: 900; font-size: 14px; color: var(--ink); background: rgba(255,255,255,.88); padding: 6px 12px; border-radius: 999px; box-shadow: 0 3px 10px rgba(30,42,74,.12); }
.town-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bld { position: relative; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); border: 0; padding: 10px 10px 12px; text-align: left; cursor: pointer; transition: transform .1s; overflow: hidden; }
.bld:active { transform: scale(.97); }
.bld .pic { height: 86px; display: grid; place-items: center; border-radius: 16px; margin-bottom: 8px; }
.bld .pic svg { height: 80px; width: auto; }
.bld .nm { font-weight: 900; font-size: 16px; }
.bld .ds { font-size: 12px; color: var(--muted); line-height: 1.25; margin-top: 2px; }
.bld.big { grid-column: span 2; display: flex; align-items: center; gap: 12px; }
.bld.big .pic { width: 120px; height: 90px; margin: 0; flex: none; }
.bld .lock { position: absolute; top: 10px; right: 10px; }
.bg-sky { background: linear-gradient(#DDEFFF, #F2F8FF); }
.bg-coral { background: linear-gradient(#FFE3DE, #FFF4F1); }
.bg-teal { background: linear-gradient(#D6F6F6, #F0FCFC); }
.bg-gold { background: linear-gradient(#FFF0C8, #FFF9EA); }
.bg-lav { background: linear-gradient(#E4E8FA, #F5F6FE); }

/* ---------- инвентарь ---------- */
.invbar { flex: none; padding: 10px 14px calc(12px + var(--safe-b)); background: rgba(255,255,255,.75); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid rgba(255,255,255,.9); }
.invbar .lbl { font-size: 12px; font-weight: 800; color: var(--ink2); margin-bottom: 6px; display: flex; justify-content: space-between; }
.slots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.slot { position: relative; aspect-ratio: 1; border-radius: 14px; background: #EEF3FC; border: 2px dashed #CBD6EC; display: grid; place-items: center; cursor: pointer; padding: 0; }
.slot.full { background: var(--card); border: 2px solid var(--line); box-shadow: 0 3px 8px rgba(30,42,74,.08); }
.slot.sel { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(255,107,90,.25); }
.slot svg { width: 72%; height: 72%; }
.slot .q { position: absolute; right: 3px; bottom: 1px; font: 800 13px var(--num); color: var(--ink); text-shadow: 0 0 3px #fff, 0 0 3px #fff; }

/* ---------- магазин ---------- */
.shop-head { display: flex; align-items: center; gap: 12px; padding: 4px 4px 12px; }
.shop-head svg { width: 72px; height: 72px; flex: none; }
.item { display: flex; gap: 12px; align-items: center; }
.item .ic { width: 64px; height: 64px; border-radius: 16px; background: linear-gradient(#F2F7FF, #E6EEFB); display: grid; place-items: center; flex: none; }
.item .ic svg { width: 50px; height: 50px; }
.item .nm { font-weight: 900; font-size: 16px; }
.item .ds { font-size: 13px; color: var(--ink2); }
.price { display: inline-flex; align-items: center; gap: 4px; font: 700 15px var(--num); }
.price svg { width: 18px; height: 18px; }

/* ---------- районы ---------- */
.dist { display: flex; gap: 12px; align-items: center; position: relative; overflow: hidden; }
.dist .ill { width: 92px; height: 70px; border-radius: 14px; flex: none; overflow: hidden; }
.dist .ill svg { width: 100%; height: 100%; }
.dist.locked { opacity: .55; }
.prog { height: 8px; border-radius: 99px; background: #EAF0FA; overflow: hidden; margin-top: 6px; }
.prog > i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), #6BE3C4); border-radius: 99px; }

/* ---------- PvP ---------- */
.league { display: grid; place-items: center; text-align: center; padding: 18px 10px; }
.league svg { width: 96px; height: 96px; }
.league .r { font: 800 34px var(--num); margin-top: 6px; }
.searching { display: grid; place-items: center; gap: 10px; padding: 16px 0; }
.spinner { width: 72px; height: 72px; border-radius: 50%; border: 7px solid #E3EDFB; border-top-color: var(--coral); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- кланы ---------- */
.tabs { display: flex; gap: 6px; background: #E6EEFA; padding: 4px; border-radius: 14px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 11px; font-weight: 800; cursor: pointer; color: var(--ink2); }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 2px 6px rgba(30,42,74,.1); }
.member { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; }
.chat { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; padding: 4px 0 8px; }
.msg { background: #F1F5FC; border-radius: 14px; padding: 7px 11px; align-self: flex-start; max-width: 88%; }
.msg.me { background: #FFE9E5; align-self: flex-end; }
.msg.sys { background: transparent; align-self: center; color: var(--muted); font-size: 12px; padding: 2px; }
.msg b { font-size: 12px; color: var(--ink2); display: block; }
.field { width: 100%; border: 2px solid var(--line); border-radius: 14px; padding: 11px 13px; background: #FBFDFF; outline: none; }
.field:focus { border-color: var(--teal); }
label.f { display: block; font-weight: 800; font-size: 13px; margin: 10px 0 4px; color: var(--ink2); }

/* ---------- рейтинг ---------- */
.lb-row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.lb-row:last-child { border-bottom: 0; }
.lb-row.me { background: #FFF4EC; border-radius: 12px; }
.place { width: 30px; text-align: center; font: 800 15px var(--num); color: var(--ink2); flex: none; }
.place.p1 { color: #D89A00; } .place.p2 { color: #8C9AB8; } .place.p3 { color: #C0743A; }

/* ---------- вход ---------- */
.auth { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 20px 18px calc(24px + var(--safe-b)); }
.logo { text-align: center; margin-bottom: 18px; }
.logo svg { width: 230px; max-width: 80%; height: auto; }
.logo .sub { font-weight: 800; color: var(--ink2); margin-top: 2px; }

/* ---------- бой ---------- */
#battle { position: fixed; inset: 0; z-index: 20; background: #BFDDF7; display: none; touch-action: none; }
#battle.on { display: block; }
#battle canvas { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); touch-action: none; }
#battle .pausebtn { position: absolute; top: calc(8px + env(safe-area-inset-top, 0px)); right: 8px; z-index: 2; width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.85); font-weight: 900; font-size: 16px; cursor: pointer; box-shadow: 0 3px 10px rgba(30,42,74,.15); }

/* ---------- модальные окна и уведомления ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20, 30, 60, .45); display: none; align-items: center; justify-content: center; padding: 18px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal.on { display: flex; animation: fadeIn .2s ease; }
.modal .box { background: var(--card); border-radius: 26px; width: 100%; max-width: 380px; padding: 20px; box-shadow: 0 20px 60px rgba(20,30,60,.35); max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 6px; font-size: 24px; text-align: center; }
.res-ic { display: grid; place-items: center; margin: 4px 0 8px; }
.res-ic svg { width: 110px; height: 110px; }
.res-list { display: grid; gap: 8px; margin: 12px 0 16px; }
.res-list .r { display: flex; align-items: center; gap: 10px; background: #F3F7FD; border-radius: 14px; padding: 9px 12px; font-weight: 800; }
.res-list .r svg { width: 24px; height: 24px; }
.res-list .r .v { margin-left: auto; font-family: var(--num); }
.btn-col { display: grid; gap: 10px; }

#toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 14px; font-weight: 700; box-shadow: 0 10px 30px rgba(20,30,60,.3); animation: toastIn .25s ease; text-align: center; }
.toast.ok { background: #138A64; }
.toast.err { background: #C93441; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.empty { text-align: center; color: var(--muted); padding: 20px 8px; }
.debug { border: 2px dashed var(--gold); }
.hint { font-size: 13px; color: var(--muted); }
.rot-hint { display: none; }
@media (min-width: 900px) {
  #app { padding-top: 12px; }
}
