:root {
  --bg: #12141c;
  --panel: rgba(22, 25, 36, .86);
  --panel-solid: #1a1d29;
  --panel-2: #232737;
  --line: rgba(255, 255, 255, .08);
  --text: #eef0f5;
  --muted: #8d93a5;
  --accent: #e8871e;
  --accent-2: #ffad42;
  --cream: #f3ead8;
  --cream-ink: #2b2620;
  --good: #2ecc71;
  --bad: #e74c3c;
  --gold: #f1c40f;
  --radius: 10px;
  --font-display: 'Oswald', 'Arial Narrow', Impact, sans-serif;
  --font-ui: 'Inter', -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font-ui);
}
button, input, select { font-family: inherit; font-size: 14px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }

#backdrop {
  position: fixed; inset: -40px; width: calc(100% + 80px); height: calc(100% + 80px);
  filter: blur(6px) saturate(.8);
  z-index: 0;
  animation: backdropPan 60s ease-in-out infinite alternate;
}
@keyframes backdropPan {
  from { transform: translate(0, 0) scale(1.05); }
  to   { transform: translate(-30px, -20px) scale(1.1); }
}
#backdropShade {
  position: fixed; inset: 0; z-index: 1;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(18, 20, 28, .35), rgba(18, 20, 28, .88) 75%),
    linear-gradient(180deg, rgba(18, 20, 28, .2), rgba(18, 20, 28, .7));
}

/* dvh — высота без панели адреса мобильного браузера (иначе низ экрана уезжает) */
.screen { position: relative; z-index: 2; width: 100vw; height: 100vh; height: 100dvh; }
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }

/* Кнопки-инструменты: звук, музыка, установка, полный экран */
.tool-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; min-width: 34px; padding: 0 9px; border-radius: 8px;
  background: rgba(0,0,0,.35); color: var(--text); border: 1px solid var(--line);
  font-size: 15px; font-weight: 600; transition: background .15s, opacity .15s;
}
.tool-btn:hover { background: rgba(255,255,255,.1); }
.tool-btn span { font-size: 13px; }
.tool-btn.off { opacity: .45; text-decoration: line-through; }
#installBtn { background: var(--accent); border-color: transparent; color: #fff; }
.touch-only { display: none !important; }
body.touch .touch-only { display: inline-flex !important; }

/* ---------- «Поверните телефон» ---------- */
#rotateOverlay {
  display: none; position: fixed; inset: 0; z-index: 900;
  flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; text-align: center;
  background: radial-gradient(ellipse at 50% 35%, #23283a, #0d0f16 75%);
}
@media (orientation: portrait) {
  body.touch.need-land #rotateOverlay { display: flex; }
}
.rot-phone {
  width: 64px; height: 108px; border: 4px solid #fff; border-radius: 14px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  box-shadow: 0 0 0 6px rgba(232,135,30,.25);
  animation: rotPhone 2.4s ease-in-out infinite;
}
@keyframes rotPhone { 0%, 20% { transform: rotate(0); } 45%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
.rot-title { font-family: var(--font-display); font-size: 26px; letter-spacing: 1px; text-transform: uppercase; color: var(--accent-2); }
.rot-text { max-width: 300px; font-size: 14px; line-height: 1.5; color: #c8ccd8; }
#rotateOverlay .btn-ghost { margin-top: 8px; }
.ios-share { display: inline-block; padding: 0 6px; border-radius: 4px; background: #2b6cff; color: #fff; font-weight: 700; }

/* ---------- Кнопки ---------- */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 12px 28px; border-radius: 8px;
  font-family: var(--font-display); font-size: 18px; font-weight: 600;
  letter-spacing: 1.5px; text-transform: uppercase;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 4px 0 #a35a0c;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #a35a0c; }
.btn-primary:disabled { opacity: .45; box-shadow: none; }
.btn-primary.wide { width: 100%; margin-top: 18px; }

.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--line); padding: 11px 22px; border-radius: 8px;
  font-weight: 600;
}
.btn-ghost:hover { background: rgba(255,255,255,.06); }

.icon-btn {
  background: rgba(255,255,255,.06); color: var(--text); border: none;
  width: 28px; height: 28px; border-radius: 6px; font-size: 14px;
}
.icon-btn:hover { background: rgba(255,255,255,.14); }

.chip-btn {
  background: rgba(255,255,255,.06); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; font-weight: 600;
}
.chip-btn:hover:not(:disabled) { background: rgba(255,255,255,.12); }
.chip-btn:disabled { opacity: .4; }

.small-btn {
  background: transparent; color: var(--muted);
  padding: 3px 9px; font-size: 12px; border: 1px solid #3a3f52; border-radius: 6px;
}
.small-btn:hover { background: #2b3042; color: #fff; }

input {
  background: #0f1220; color: #fff; width: 100%;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; font-size: 16px; outline: none;
}
input:focus { border-color: var(--accent); }

.level-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 20px; padding: 0 6px; border-radius: 5px;
  font-size: 11px; font-weight: 800; color: #111;
  font-variant-numeric: tabular-nums;
  border: 1px solid rgba(0,0,0,.3);
  background: #95a5a6;
}
.rank, .rank-slot { display: inline-flex; align-items: center; cursor: help; }
.rank-svg { display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.55)); }
.tooltip {
  position: fixed; z-index: 1000; pointer-events: none;
  white-space: pre; line-height: 1.45;
  background: #0d0f18; color: var(--text);
  border: 1px solid rgba(255,255,255,.14); border-radius: 8px;
  padding: 7px 11px; font-size: 12px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.6);
  opacity: 0; transition: opacity .12s;
}
.tooltip.show { opacity: 1; }

/* изменение рейтинга: тёмная капсула, число и треугольник */
.rdelta {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  background: rgba(8,10,18,.75); border: 1px solid rgba(255,255,255,.08); font-variant-numeric: tabular-nums; line-height: 1.2;
}
.rdelta i { font-style: normal; font-size: 12px; color: #c9cfdd; }
.rdelta b { font-family: var(--font-display); font-size: 15px; color: #fff; }
.rdelta svg { flex-shrink: 0; }
.rdelta.up svg { color: #7dff5a; filter: drop-shadow(0 0 4px rgba(125,255,90,.7)); }
.rdelta.down svg { color: #ff4d6a; filter: drop-shadow(0 0 4px rgba(255,77,106,.7)); }
.rdelta.flat svg { color: #8a90a2; }
.rdelta.big { padding: 5px 14px; gap: 7px; }
.rdelta.big b { font-size: 22px; }
.rdelta.big svg { width: 15px; height: 15px; }
.host-badge, .spec-badge {
  font-size: 10px; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: 700;
  letter-spacing: .5px;
}
.host-badge { background: var(--accent); }
.spec-badge { background: #3498db; }
.bot-badge { background: #6c7386; }

/* ---------- Логотип ---------- */
.logo { display: flex; justify-content: center; }
.logo svg { height: 46px; width: auto; filter: drop-shadow(0 4px 14px rgba(0,0,0,.6)); }
.logo-modal svg { height: 56px; max-width: 100%; }

/* ---------- Модальные окна ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5, 6, 10, .78);
  display: none; align-items: center; justify-content: center;
  z-index: 400; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--panel-solid); border-radius: 14px;
  border: 1px solid var(--line);
  max-width: 920px; width: 100%; max-height: 90vh;
  overflow-y: auto; padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.8);
}
.modal-small { max-width: 420px; text-align: center; }
.modal-small h3 { margin: 14px 0; }
.modal-box h3 { font-family: var(--font-display); font-size: 24px; letter-spacing: 1px; margin: 0 0 12px; color: var(--accent-2); text-transform: uppercase; }
.modal-box h4 { margin: 22px 0 8px; font-size: 15px; color: var(--gold); }
.modal-box p { margin: 6px 0; font-size: 14px; line-height: 1.5; color: #d5d8e0; }
.modal-msg { color: var(--bad); min-height: 18px; font-size: 13px; margin-top: 6px; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }

.tut-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; margin-top: 8px; }
.tut-item { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; display: flex; gap: 10px; align-items: center; font-size: 13px; }
.tut-icon { width: 32px; height: 32px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.tut-icon canvas { display: block; }
.tut-name { font-weight: 700; color: #fff; margin-bottom: 2px; }
.tut-desc { color: #a9aebd; font-size: 12px; }

.patch-item { background: var(--panel-2); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.patch-version { font-family: var(--font-display); font-size: 17px; letter-spacing: 1px; color: var(--good); }
.patch-date { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.patch-item ul { margin: 0; padding-left: 20px; }
.patch-item li { font-size: 13px; color: #d5d8e0; line-height: 1.6; }

/* ---------- Палитры ---------- */
.color-btn {
  width: 22px; height: 22px; border-radius: 5px;
  border: 2px solid rgba(255,255,255,.2);
  flex-shrink: 0; padding: 0; transition: transform .12s;
}
.color-btn.mine { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,.4); }
.color-btn.mine:hover { transform: scale(1.15); }
.color-btn.static { cursor: default; border-color: rgba(255,255,255,.12); }
.skin-btn {
  width: 28px; height: 24px; border-radius: 5px;
  border: 2px solid rgba(255,255,255,.2);
  flex-shrink: 0; padding: 0; background: transparent;
  display: flex; align-items: center; justify-content: center;
}
.skin-btn canvas { display: block; }
.skin-btn.mine { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,.4); }
.skin-btn.mine:hover { transform: scale(1.15); }
.skin-btn.static { cursor: default; border-color: rgba(255,255,255,.12); }
.color-palette, .skin-palette {
  position: absolute; z-index: 450;
  background: #0d0f18; padding: 8px; border-radius: 10px;
  display: grid; gap: 5px;
  box-shadow: 0 10px 30px rgba(0,0,0,.7);
  border: 1px solid var(--line);
}
.color-palette { grid-template-columns: repeat(8, 22px); }
.skin-palette { grid-template-columns: repeat(5, 44px); }

/* ---------- Тосты и виньетки ---------- */
#dangerVignette, #shieldVignette, #ghostVignette, #frozenOverlay, #psychoOverlay, #teleportFlash {
  position: fixed; inset: 0; pointer-events: none; opacity: 0;
}
#dangerVignette {
  z-index: 150; transition: opacity .25s;
  box-shadow: inset 0 0 120px 40px rgba(255, 0, 40, .85), inset 0 0 40px 10px rgba(255, 0, 40, .6);
}
#dangerVignette.show { opacity: .55; }
#shieldVignette {
  z-index: 151; transition: opacity .25s;
  box-shadow: inset 0 0 140px 50px rgba(255, 215, 0, .85), inset 0 0 50px 15px rgba(255, 240, 120, .6);
}
#shieldVignette.show { opacity: 1; animation: vPulse .9s ease-in-out infinite; }
@keyframes vPulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
#ghostVignette {
  z-index: 150; transition: opacity .25s;
  background: conic-gradient(from 0deg, #ff0000, #ff9900, #ffee00, #33ff00, #00ffee, #0033ff, #9900ff, #ff00cc, #ff0000);
  -webkit-mask: radial-gradient(circle at center, transparent 45%, black 95%);
          mask: radial-gradient(circle at center, transparent 45%, black 95%);
  mix-blend-mode: screen;
}
#ghostVignette.show { opacity: .8; animation: ghostSpin 4s linear infinite; }
@keyframes ghostSpin { from { transform: rotate(0deg) scale(1.2); } to { transform: rotate(360deg) scale(1.2); } }
#frozenOverlay {
  z-index: 149; transition: opacity .2s;
  box-shadow: inset 0 0 140px 50px rgba(0, 180, 255, .9), inset 0 0 50px 15px rgba(0, 220, 255, .7);
  background: radial-gradient(circle at center, rgba(0,200,255,0) 40%, rgba(0,200,255,.25) 100%);
}
#frozenOverlay.show { opacity: .6; }
#psychoOverlay {
  z-index: 148; transition: opacity .2s;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,0,255,.35) 0%, rgba(255,0,255,0) 50%),
    radial-gradient(circle at 80% 70%, rgba(120,0,255,.35) 0%, rgba(120,0,255,0) 50%);
}
#psychoOverlay.show { opacity: .6; }
@keyframes psychoShake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-4px, 3px); }
  50% { transform: translate(3px, -4px); }
  75% { transform: translate(-2px, -2px); }
}
#teleportFlash {
  z-index: 180; transition: opacity .15s;
  background: radial-gradient(circle at center, rgba(180,80,255,0) 0%, rgba(180,80,255,.9) 90%);
}
#teleportFlash.show { opacity: 1; }

/* Компактные тосты снизу по центру: не закрывают поле */
#psychoToast, #chestToast {
  position: fixed; left: 50%; bottom: 46px;
  transform: translate(-50%, 16px);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 8px 10px; border-radius: 12px;
  background: rgba(16, 18, 28, .92);
  color: #fff; font-size: 14px; white-space: nowrap;
  pointer-events: none; opacity: 0; z-index: 302;
  transition: opacity .2s, transform .2s;
}
#psychoToast.show, #chestToast.show { opacity: 1; transform: translate(-50%, 0); }
#chestToast { border: 2px solid #f1c40f; box-shadow: 0 6px 24px rgba(241,196,15,.35); }
#psychoToast { border: 2px solid #c14bff; box-shadow: 0 6px 24px rgba(193,75,255,.35); font-weight: 800; letter-spacing: 1px; }
.toast-icon { font-size: 26px; line-height: 1; }
.toast-title { font-family: var(--font-display); font-size: 17px; letter-spacing: 1px; color: #ffd54a; }
.toast-sub { display: block; font-size: 12px; color: #c8ccd8; margin-top: 1px; }

#soulToast {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.7);
  pointer-events: none; opacity: 0;
  transition: opacity .3s, transform .3s;
  text-align: center; border: 3px solid #fff;
  font-weight: 900;
}
#soulToast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#soulToast {
  background: linear-gradient(135deg, #c9e8ff, #6cb2ff);
  color: #0a2a4a; font-size: 26px; padding: 18px 36px; border-radius: 16px;
  box-shadow: 0 0 60px rgba(140,200,255,.9); z-index: 303;
}

#armageddonAlert, #banner {
  position: fixed; top: 12px; left: 50%;
  transform: translateX(-50%) translateY(-100px);
  color: #fff; font-weight: 900; border-radius: 12px;
  pointer-events: none; opacity: 0;
  transition: opacity .3s, transform .3s;
  text-shadow: 0 0 8px #000;
}
#armageddonAlert.show, #banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#armageddonAlert {
  background: linear-gradient(135deg, rgba(255,0,0,.95), rgba(200,20,0,.95));
  font-size: 22px; letter-spacing: 6px; padding: 12px 40px;
  border: 3px solid #ffcc00; z-index: 301;
  box-shadow: 0 8px 32px rgba(255,60,0,.7);
}
#banner {
  background: linear-gradient(135deg, rgba(232,135,30,.96), rgba(170,80,10,.96));
  font-family: var(--font-display); font-weight: 600;
  font-size: 20px; letter-spacing: 1.5px; padding: 10px 28px;
  border: 2px solid #ffd39a; z-index: 302; white-space: nowrap;
  box-shadow: 0 8px 32px rgba(232,135,30,.5);
}

#keyIndicator, #soulIndicator {
  position: fixed; top: 12px; left: 12px; z-index: 250;
  font-size: 14px; font-weight: 900; padding: 8px 14px; border-radius: 10px;
  border: 3px solid #fff; pointer-events: none;
}
#keyIndicator {
  background: linear-gradient(135deg, #ffd700, #b8860b); color: #2a1a00;
  opacity: 0; transition: opacity .25s;
}
#keyIndicator.show { opacity: 0; }
#soulIndicator { background: linear-gradient(135deg, #c9e8ff, #6cb2ff); color: #0a2a4a; display: none; }
#soulIndicator.show { display: block; }
.patch-section { margin-top: 10px; }
.patch-sec-title { font-weight: 700; font-size: 14px; color: #fff; margin-bottom: 4px; }

/* ---------- «Как играть» — вики ---------- */
.wiki-box { max-width: 1040px; padding: 22px 24px; display: flex; flex-direction: column; max-height: 90vh; overflow: hidden; }
.wiki-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.wiki-head h3 { margin: 0; }
.wiki { display: grid; grid-template-columns: 190px 1fr; gap: 18px; min-height: 0; flex: 1; }
.wiki-nav { display: flex; flex-direction: column; gap: 4px; }
.wiki-tab {
  text-align: left; background: transparent; border: none; color: var(--text);
  padding: 9px 12px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.wiki-tab:hover { background: rgba(255,255,255,.06); }
.wiki-tab.on { background: var(--accent); color: #fff; }
.wiki-body { overflow-y: auto; min-height: 0; padding-right: 6px; }
.wiki-title { margin: 0 0 6px !important; font-family: var(--font-display); font-size: 22px !important; letter-spacing: 1px; color: #fff !important; }
.wiki-intro { color: #c8ccd8 !important; margin: 0 0 14px !important; max-width: 70ch; }
.wiki-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.wcard {
  display: flex; gap: 14px; align-items: flex-start;
  background: linear-gradient(135deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
.wc-art { flex-shrink: 0; border-radius: 10px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,.4); }
.wc-art canvas { display: block; }
.wc-name { font-weight: 800; font-size: 15px; color: #fff; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wc-tag { font-size: 10.5px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; padding: 2px 7px; border-radius: 999px; }
.wc-tag.good { background: rgba(25,211,107,.18); color: #5cf09a; }
.wc-tag.bad { background: rgba(255,59,82,.18); color: #ff7a8a; }
.wc-tag.mix { background: linear-gradient(90deg, rgba(25,211,107,.25), rgba(255,59,82,.25)); color: #fff; }
.wc-tag.gold { background: rgba(241,196,15,.18); color: #ffd54a; }
.wc-desc { font-size: 13.5px; line-height: 1.5; color: #d5d8e0; margin-top: 4px; }
.wc-tip { font-size: 12.5px; line-height: 1.45; color: #ffcf8a; margin-top: 6px; }

/* Телефон горизонтально: окна ниже и плотнее */
@media (max-height: 520px) and (orientation: landscape) {
  .modal-overlay { padding: 8px; }
  .modal-box { padding: 14px 18px; max-height: calc(100dvh - 16px); }
  .modal-box h3 { font-size: 20px; margin-bottom: 8px; }
  .modal-small h3 { margin: 6px 0 10px; }
  .logo-modal svg { height: 38px; }
  .btn-primary.wide { margin-top: 10px; }
  #roomsList { margin: 10px 0; max-height: calc(100dvh - 170px); }
  .wiki-box { padding: 12px 16px; max-height: calc(100dvh - 16px); }
  .wiki { grid-template-columns: 150px 1fr; gap: 12px; }
  .wiki-tab { padding: 7px 10px; font-size: 13px; }
  .wiki-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .wcard { padding: 10px; gap: 10px; }
  .wc-desc { font-size: 12.5px; }
}

@media (max-width: 760px) {
  .wiki-box { padding: 16px; }
  .wiki { grid-template-columns: 1fr; }
  .wiki-nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .wiki-tab { white-space: nowrap; font-size: 13px; padding: 7px 10px; }
  .wiki-grid { grid-template-columns: 1fr; }
}
