/* «Осада» — оформление страницы игры. Токены цвета и шрифтов — из общего
   assets/css/style.css, здесь только раскладка игры.
   Компьютер: слева поле с кнопками, справа панель обороны.
   Телефон (портрет): поле во всю ширину экрана, под ним кнопки и панель —
   всё под палец, ничего не прячется за наведением. */

.os-section { padding-top: clamp(20px, 3vw, 40px); }

.os-game {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start;
  outline: none;
  /* Прокрутка к игре не должна прятать верхнюю строку под липкой шапкой сайта. */
  scroll-margin-top: calc(var(--nav-h) + 8px);
}
.os-main { min-width: 0; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Верхняя строка ---------- */
.os-hud { display: flex; gap: 10px; align-items: stretch; }
.os-stat {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); font-variant-numeric: tabular-nums;
}
.os-stat b { font-size: 1.05rem; color: var(--text); font-weight: 600; }
.os-stat i { font-style: normal; font-size: .8rem; color: var(--violet-2); }
.os-lbl { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.os-wall { flex: 1; min-width: 0; }
.os-bar { flex: 1; height: 8px; border-radius: 4px; background: rgba(255,255,255,.07); overflow: hidden; min-width: 40px; }
.os-bar i { display: block; height: 100%; width: 100%; border-radius: 4px; background: linear-gradient(90deg, #5fd4c4, #9fe3d8); transition: width .2s linear; }
.os-bar i.is-mid { background: linear-gradient(90deg, var(--gold), var(--gold-2)); }
.os-bar i.is-bad { background: linear-gradient(90deg, #c0503a, #e8734c); }
.os-gold b { color: var(--gold-2); }
.os-gold b::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 50%; vertical-align: -1px;
  background: radial-gradient(circle at 40% 35%, #f7cf8e, #e8934c 60%, #8f4d17);
}

/* ---------- Поле ---------- */
.os-stage {
  position: relative; border-radius: var(--radius); overflow: hidden; background: var(--bg);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.os-stage canvas { display: block; width: 100%; aspect-ratio: 640 / 400; height: auto; cursor: pointer; }
.os-loading {
  display: none; position: absolute; inset: 0; align-items: center; justify-content: center;
  color: var(--text-2); font-size: .95rem; background: var(--bg);
}
.os-stage.is-loading .os-loading { display: flex; }

/* ---------- Кнопки под полем ---------- */
.os-ctrl { display: flex; gap: 8px; flex-wrap: wrap; }
.os-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: .92rem; transition: background .15s, border-color .15s, transform .1s;
}
.os-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.os-btn:hover:not(:disabled) { background: var(--surface-2); border-color: rgba(255,255,255,.28); }
.os-btn:active:not(:disabled) { transform: translateY(1px); }
.os-btn[aria-pressed="true"] { border-color: rgba(240,180,111,.55); color: var(--gold-2); }
.os-btn:disabled { opacity: .45; cursor: default; }
.os-early { margin-left: auto; color: #1a1206; border-color: transparent; background: linear-gradient(135deg, var(--gold-2), var(--gold) 60%, #d99a3d); }
.os-early:hover:not(:disabled) { background: linear-gradient(135deg, #f6c78b, var(--gold-2) 60%, var(--gold)); }
.os-early:disabled { background: var(--surface); color: var(--text-3); border-color: var(--border); }
.os-early b { font-weight: 700; }
.os-early b:empty { display: none; }

/* ---------- Панель обороны ---------- */
.os-panel {
  border-radius: var(--radius); border: 1px solid var(--border); background: linear-gradient(180deg, rgba(107,111,174,.08), rgba(255,255,255,.02));
  padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 100%;
}
.os-p-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.os-p-title { font-family: var(--font-display); font-size: 1.2rem; color: var(--gold-2); line-height: 1.25; }
.os-p-note { font-size: .84rem; color: var(--text-2); line-height: 1.45; margin-top: 2px; }
.os-p-desc { font-size: .84rem; color: var(--text-2); line-height: 1.45; min-height: 2.9em; }
.os-x {
  flex: none; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  font-size: 1.3rem; line-height: 1; color: var(--text-2);
}
.os-x:hover { color: var(--text); border-color: var(--border-strong); }

.os-slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.os-slot {
  position: relative; display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 6px 24px 6px 6px; text-align: left;
  border-radius: 12px; border: 1px dashed rgba(240,180,111,.35); background: rgba(240,180,111,.04);
}
.os-slot.is-busy { border-style: solid; border-color: var(--border-strong); background: var(--surface); }
.os-slot:hover:not(:disabled) { border-color: var(--gold-2); }
.os-slot-plus { flex: none; width: 44px; height: 44px; display: grid; place-items: center; font-size: 1.4rem; color: var(--gold-2); }
.os-slot-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.os-slot-txt b { font-size: .8rem; font-weight: 600; }
.os-slot-txt span { font-size: .75rem; color: var(--text-3); }
.os-key { position: absolute; top: 4px; right: 6px; font: 600 10px/1 var(--font-body); color: var(--text-3); }
/* Цифры клавиш на телефоне ни к чему, а в узкой карточке они наезжали на название места. */
@media (hover: none) { .os-key { display: none; } .os-slot { padding-right: 6px; } }
.os-ico { width: 44px; height: 44px; flex: none; }

.os-build { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.os-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 8px; min-height: 92px;
  border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); transition: border-color .15s, background .15s;
}
.os-card b { font-size: .8rem; font-weight: 600; }
.os-card:hover:not(:disabled), .os-card:focus-visible { border-color: var(--gold-2); background: rgba(240,180,111,.08); }
.os-card:disabled { cursor: default; }
.os-card:disabled .os-ico, .os-card:disabled b { opacity: .5; }
.os-card.is-locked { border-style: dashed; }
.os-price { font-size: .8rem; font-weight: 600; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.os-price.is-short { color: var(--text-3); }
.os-card.is-locked .os-price { color: var(--violet-2); font-weight: 500; }

.os-info { display: flex; gap: 12px; align-items: flex-start; }
.os-info .os-ico { width: 56px; height: 56px; }
.os-info b { font-size: .95rem; }
.os-stats { margin-top: 4px; font-size: .84rem; color: var(--text-2); line-height: 1.5; }
.os-stats .is-buff { color: var(--violet-2); }
.os-row { display: flex; gap: 8px; flex-wrap: wrap; }
.os-row .btn { flex: 1; min-height: 44px; }
.os-row .btn:disabled { opacity: .5; transform: none; box-shadow: none; cursor: default; }

.os-repair {
  margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 8px 14px;
  border-radius: 12px; border: 1px solid rgba(95,212,196,.35); background: rgba(95,212,196,.06); color: var(--text); font-size: .88rem;
}
.os-repair b { color: var(--gold-2); font-variant-numeric: tabular-nums; }
.os-repair:hover:not(:disabled) { border-color: var(--teal); }
.os-repair:disabled { opacity: .45; cursor: default; }

/* ---------- Меню поверх поля ---------- */
.os-menu {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(12,10,19,.55), rgba(12,10,19,.88));
}
.os-menu[hidden] { display: none; }
.os-box { width: min(440px, 100%); max-height: 100%; overflow: auto; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.os-eyebrow { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }
.os-h { font-family: var(--font-display); font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.1; color: var(--text); }
.os-h-sm { font-size: clamp(1.4rem, 3vw, 1.9rem); }
.os-t { color: var(--text-2); font-size: .95rem; line-height: 1.5; }
.os-small { font-size: .82rem; }
.os-ok { color: var(--gold-2); }
.os-facts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.os-facts span { font-size: .8rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); }
.os-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.os-btns .btn { min-height: 44px; }
.os-shop { width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.os-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px;
  border-radius: 12px; border: 1px solid var(--border); background: rgba(12,10,19,.6);
}
.os-item b { display: block; font-size: .88rem; }
.os-item span { display: block; font-size: .76rem; color: var(--text-3); line-height: 1.35; }
.os-item .btn { flex: none; min-width: 96px; min-height: 40px; padding: 8px 12px; }
.os-item .btn:disabled { transform: none; box-shadow: none; cursor: default; }
.os-item .btn-primary:disabled { background: var(--surface-2); color: var(--text-3); border-color: var(--border); }
.os-item .btn-ghost:disabled { color: var(--teal); border-color: rgba(95,212,196,.3); }

/* ---------- Кошель под игрой ---------- */
.os-koshel-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 16px; }
.os-sprites-link { font-size: .82rem; color: var(--text-3); }
.os-sprites-link:hover { color: var(--text-2); }

/* ---------- Правила ---------- */
.os-rules { margin-top: 26px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.os-rules[open] { border-color: var(--border-strong); }
.os-rules summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 22px; font-weight: 600; font-size: 1.02rem;
}
.os-rules summary::-webkit-details-marker { display: none; }
.os-rules summary svg { width: 20px; height: 20px; fill: none; stroke: var(--text-3); stroke-width: 2; stroke-linecap: round; transition: transform .25s; }
.os-rules[open] summary svg { transform: rotate(180deg); stroke: var(--gold); }
.os-rules-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); padding: 0 16px 16px; }
.os-rules .card { padding: 20px; }
.os-rules .card:hover { transform: none; }
.os-rules h3 { font-family: var(--font-display); font-size: 1.1rem; margin: 0 0 8px; color: var(--gold-2); }
.os-rules p { margin: 0; color: var(--text-2); line-height: 1.55; font-size: .94rem; }
.os-rules p b { color: var(--text); font-weight: 600; }
kbd { font: 600 12px/1 var(--font-body); padding: 3px 7px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); }

/* ---------- Узкие экраны ---------- */
@media (max-width: 980px) {
  /* minmax(0, …), а не 1fr: у 1fr нижняя граница — ширина содержимого, и строка
     кнопок с «Вызвать раньше +N» раздвигала всю колонку на 9px шире телефона
     в 360px — правый край поля и панели уезжал за экран. */
  .os-game { grid-template-columns: minmax(0, 1fr); }
  .os-panel { min-height: 0; }
}
@media (max-width: 560px) {
  /* Поле во всю ширину телефона: каждая точка поля на счету, рамка не нужна. */
  /* −16px — ровно поле .container на узком экране (style.css: 100% − 32px). При
     −24px холст вылезал на 8px за оба края, и край двора со спавном срезало. */
  .os-stage { margin-inline: -16px; border-radius: 0; border-left: 0; border-right: 0; }
  .os-hud { gap: 6px; }
  .os-stat { padding: 6px 10px; gap: 6px; }
  .os-lbl { display: none; }
  .os-wall .os-lbl { display: none; }
  .os-stat b { font-size: .95rem; }
  #osWallTxt { font-size: .8rem; color: var(--text-2); }
  .os-ctrl { gap: 6px; flex-wrap: nowrap; }
  .os-early { flex: 1; min-width: 0; padding: 0 10px; }
  .os-early span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .os-btn { padding: 0 12px; }
  .os-btn span { display: none; }
  .os-btn#osSpeed span { display: inline; }
  .os-early span { display: inline-block; }
  .os-panel { padding: 12px; gap: 10px; }
  .os-build { gap: 6px; }
  .os-card { min-height: 84px; }
  .os-h { font-size: 1.7rem; }
  .os-t { font-size: .88rem; }
  .os-menu { padding: 10px; }
  .os-box { gap: 6px; }
  .os-item .btn { min-width: 84px; }
  /* Лавке в полосе поля высотой 240 точек тесно — на телефоне она открывается
     поверх всей страницы, а поле с игрой остаётся под ней. */
  .os-menu.is-shop { position: fixed; inset: 0; z-index: 70; align-items: flex-start; overflow-y: auto; padding: 28px 16px; background: rgba(12,10,19,.97); }
  .os-menu.is-shop .os-box { max-height: none; overflow: visible; }
}
@media (prefers-reduced-motion: reduce) {
  .os-bar i, .os-btn, .os-card, .os-rules summary svg { transition: none; }
}
