/* =========================================================
   ПРЕДЕЛ · Оборона — второй режим и переключатель режимов
   ========================================================= */

[hidden] { display: none !important; }

.head-actions { flex-wrap: wrap; }

.welcome-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 14px 0;
}
.welcome-list > div {
  display: grid;
  grid-template-columns: 25px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: rgba(6, 13, 24, 0.4);
}
.welcome-list > div > span {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border: 1px solid rgba(103, 232, 249, 0.19);
  border-radius: 7px;
  background: rgba(103, 232, 249, 0.055);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 8px;
}
.welcome-list p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.welcome-page .formula-card { margin: 15px 0; }

.btn.welcome {
  border-color: rgba(251, 191, 36, 0.17);
  background: rgba(251, 191, 36, 0.035);
  color: #e6d4a0;
}
.btn.welcome:hover {
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.075);
  color: #f7e8bd;
}

/* ---------- переключатель режимов ---------- */

.modebar {
  position: relative;
  z-index: 35;
  border-bottom: 1px solid rgba(127, 179, 235, 0.08);
  background: rgba(5, 8, 15, 0.55);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.modebar-inner {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  max-width: 1720px;
  min-width: 0;
  margin: 0 auto;
  padding: 7px clamp(12px, 2vw, 26px);
}

.modebar-label {
  color: var(--muted-2);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.mode-tabs {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: rgba(3, 9, 17, 0.44);
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.is-active {
  border-color: rgba(103, 232, 249, 0.2);
  background: rgba(103, 232, 249, 0.1);
  color: var(--cyan);
}
.mode-tab[data-mode="defense"].is-active {
  border-color: rgba(251, 113, 133, 0.25);
  background: rgba(251, 113, 133, 0.1);
  color: #fda4af;
}
.mode-tab-icon { font-family: var(--font-mono); font-size: 11px; line-height: 1; }

.modebar-record {
  overflow: hidden;
  margin-left: auto;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}
.modebar-record:hover {
  border-color: var(--line-soft);
  background: rgba(251, 191, 36, 0.035);
  color: #e6d4a0;
}
.modebar-record b { color: var(--muted); font-weight: 500; }
.modebar-record:hover b { color: var(--amber); }

body.mode-defense { padding-bottom: 28px; }

/* ---------- каркас обороны ---------- */

.defense-layout {
  --df-accent: #fbbf24;
  --df-danger: #fb7185;
  --df-cyan: #67e8f9;
  --df-violet: #c4b5fd;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(330px, 0.85fr);
  align-items: start;
  gap: 14px;
  width: 100%;
  max-width: 1720px;
  margin: 0 auto;
  padding: 14px clamp(12px, 2vw, 26px) 0;
}

.defense-stage {
  min-width: 0;
  padding: clamp(14px, 1.5vw, 20px);
  border-color: rgba(251, 113, 133, 0.16);
  background:
    radial-gradient(ellipse at 80% 0%, rgba(251, 113, 133, 0.055), transparent 50%),
    linear-gradient(155deg, rgba(21, 35, 56, 0.38), rgba(8, 14, 25, 0.1) 42%),
    var(--panel);
}

.defense-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 18px;
  margin-bottom: 12px;
}
.defense-title { min-width: 0; flex: 1 1 360px; }
.defense-kicker { color: #fda4af !important; }
.defense-title h1 {
  margin: 3px 0 4px;
  font-size: clamp(23px, 2.2vw, 32px);
  font-weight: 740;
  letter-spacing: -0.035em;
  line-height: 1.08;
}
.defense-title p {
  max-width: 670px;
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.defense-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(65px, 1fr));
  gap: 6px;
  min-width: 300px;
}
.df-stat {
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: rgba(8, 15, 27, 0.5);
}
.df-stat span {
  display: block;
  overflow: hidden;
  color: var(--muted-2);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.df-stat b {
  display: block;
  overflow: hidden;
  margin-top: 1px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.df-stat.is-record b { color: var(--df-accent); }
.df-stat.is-low b { color: #fda4af; }

.defense-field-wrap {
  position: relative;
  width: 100%;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid rgba(251, 113, 133, 0.16);
  border-radius: 16px;
  aspect-ratio: 16 / 8.1;
  background:
    radial-gradient(ellipse at 80% 45%, rgba(251, 113, 133, 0.075), transparent 54%),
    radial-gradient(ellipse at 15% 0%, rgba(34, 211, 238, 0.04), transparent 50%),
    #050b14;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025), 0 12px 34px rgba(0, 0, 0, 0.2);
}
.defense-field-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(127, 179, 235, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(127, 179, 235, 0.026) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse at center, black, transparent 88%);
  -webkit-mask-image: radial-gradient(ellipse at center, black, transparent 88%);
}
#defenseScene {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.defense-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  background: rgba(3, 7, 14, 0.62);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
.defense-overlay-card {
  width: min(470px, 100%);
  padding: 21px;
  border: 1px solid rgba(251, 191, 36, 0.2);
  border-radius: 16px;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(251, 191, 36, 0.08), transparent 62%),
    rgba(8, 15, 27, 0.94);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.045);
  text-align: center;
}
.df-overlay-mark {
  display: grid;
  place-items: center;
  width: 51px;
  height: 51px;
  margin: 0 auto 11px;
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: 14px;
  background: rgba(251, 191, 36, 0.07);
  color: var(--df-accent);
  font-family: var(--font-math);
  font-size: 28px;
}
.defense-overlay-card h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(20px, 3.2vw, 27px);
  letter-spacing: -0.03em;
}
.defense-overlay-card p {
  margin: 7px auto 0;
  max-width: 390px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
}
.defense-overlay-card .df-overlay-stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}
.defense-overlay-card .df-overlay-stats span {
  padding: 4px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.018);
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9px;
}
.defense-overlay-card .df-overlay-stats b { color: var(--df-accent); font-weight: 500; }
.df-overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin-top: 14px; }
.df-overlay-actions .btn { flex: 0 1 auto; }
.df-overlay-small {
  margin-top: 9px !important;
  color: var(--muted-2) !important;
  font-size: 9px !important;
}

.defense-wave-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: 3;
  padding: 5px 12px;
  border: 1px solid rgba(251, 191, 36, 0.26);
  border-radius: 8px;
  background: rgba(7, 13, 23, 0.82);
  color: var(--df-accent);
  font-family: var(--font-mono);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  backdrop-filter: blur(8px);
}
.defense-wave-banner.is-visible { opacity: 1; transform: translate(-50%, 0); }

.defense-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 9px;
}
.defense-toolbar-left { display: flex; flex-wrap: wrap; gap: 6px; }
.defense-toolbar-hint {
  overflow: hidden;
  color: var(--muted-2);
  font-size: 9.5px;
  line-height: 1.4;
  text-align: right;
  text-overflow: ellipsis;
}

/* ---------- боковая панель ---------- */

.defense-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.puzzle-card {
  padding: 15px;
  border-color: rgba(103, 232, 249, 0.16);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(34, 211, 238, 0.045), transparent 55%),
    linear-gradient(155deg, rgba(21, 35, 56, 0.38), rgba(8, 14, 25, 0.1) 42%),
    var(--panel);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.puzzle-card.is-solved {
  border-color: rgba(134, 239, 172, 0.24);
  box-shadow: 0 0 35px rgba(134, 239, 172, 0.045), var(--shadow-panel);
}
.puzzle-card.is-paused .puzzle-options { opacity: 0.45; pointer-events: none; }
.puzzle-card.is-paused .puzzle-footer { opacity: 0.6; }

.puzzle-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}
.puzzle-kicker {
  color: var(--muted-2);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.puzzle-kicker b { color: var(--cyan); font-family: var(--font-mono); font-weight: 500; letter-spacing: 0; }
.puzzle-type {
  padding: 2px 6px;
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  color: var(--muted-2);
  font-size: 8.5px;
  line-height: 1.4;
}
.puzzle-accuracy {
  margin-left: auto;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 8.5px;
  white-space: nowrap;
}
.puzzle-accuracy.is-good { color: var(--green); }
.puzzle-accuracy.is-bad { color: var(--amber); }

.puzzle-equation {
  overflow-x: auto;
  padding: 12px 8px 9px;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  color: #dffaff;
  font-family: var(--font-math);
  font-size: clamp(21px, 2.4vw, 28px);
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  scrollbar-width: none;
}
.puzzle-equation::-webkit-scrollbar { display: none; }
.puzzle-equation sup { font-size: 0.65em; }
.puzzle-condition {
  padding: 6px 8px 2px;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9.5px;
  line-height: 1.4;
  text-align: center;
}
.puzzle-step { padding-top: 10px; }
.puzzle-step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted-2);
  font-size: 8.5px;
  letter-spacing: 0.05em;
}
.puzzle-step-head span:first-child { color: var(--cyan); font-family: var(--font-mono); }
.puzzle-prompt {
  margin: 7px 0 9px;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 550;
  line-height: 1.45;
}
.puzzle-options { display: flex; flex-direction: column; gap: 6px; }
.puzzle-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: rgba(7, 14, 25, 0.5);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.puzzle-option:hover:not(:disabled) {
  border-color: rgba(103, 232, 249, 0.26);
  background: rgba(17, 36, 55, 0.75);
  color: var(--text);
}
.puzzle-option:active:not(:disabled) { transform: translateY(1px); }
.puzzle-option:disabled { cursor: default; }
.puzzle-option.is-correct {
  border-color: rgba(134, 239, 172, 0.42);
  background: rgba(38, 87, 58, 0.3);
  color: #d4f8df;
  opacity: 1;
}
.puzzle-option.is-wrong {
  border-color: rgba(251, 113, 133, 0.4);
  background: rgba(97, 31, 43, 0.3);
  color: #ffd8de;
  opacity: 1;
}
.puzzle-option.is-dim { opacity: 0.82; }
.puzzle-option code {
  padding: 1px 4px;
  border: 1px solid rgba(127, 179, 235, 0.1);
  border-radius: 4px;
  background: rgba(3, 9, 17, 0.38);
  color: #d7edff;
  font-family: var(--font-mono);
  font-size: 0.92em;
  overflow-wrap: anywhere;
}
.option-letter {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin-top: 1px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 8px;
  line-height: 1;
}
.puzzle-option.is-correct .option-letter { border-color: rgba(134, 239, 172, 0.4); color: var(--green); }
.puzzle-option.is-wrong .option-letter { border-color: rgba(251, 113, 133, 0.4); color: #fda4af; }
.option-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}
.option-text { min-width: 0; overflow-wrap: anywhere; }
.option-text sup { font-size: 0.65em; }
.option-why {
  display: block;
  padding-top: 4px;
  border-top: 1px solid rgba(127, 179, 235, 0.1);
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 400;
  line-height: 1.45;
}
.option-why[hidden] { display: none; }
.option-why b { color: var(--muted); font-weight: 600; }
.puzzle-option.is-correct .option-why { border-top-color: rgba(134, 239, 172, 0.18); color: #b7e8c5; }
.puzzle-option.is-correct .option-why b { color: #dcfce7; }
.puzzle-option.is-wrong .option-why { border-top-color: rgba(251, 113, 133, 0.18); color: #ffc9c9; }
.puzzle-option.is-wrong .option-why b { color: #ffe4e6; }

.puzzle-explanation {
  display: none;
  margin-top: 8px;
  padding: 8px 9px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(4, 11, 20, 0.42);
  color: var(--muted-2);
  font-size: 10px;
  line-height: 1.5;
}
.puzzle-explanation.is-visible { display: block; animation: feedback-in 0.18s ease-out; }
.puzzle-explanation.is-good { border-color: rgba(134, 239, 172, 0.22); color: #c8f5d2; }
.puzzle-explanation.is-bad { border-color: rgba(251, 191, 36, 0.22); color: #f0dca3; }
.puzzle-explanation b { color: var(--text); font-weight: 600; }
.puzzle-deep {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(127, 179, 235, 0.14);
}
.puzzle-deep-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.puzzle-deep p {
  margin: 0;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 400;
  line-height: 1.58;
}
.puzzle-next-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(127, 179, 235, 0.1);
}
.puzzle-next-hint {
  color: var(--muted-2);
  font-size: 9px;
  font-weight: 400;
  line-height: 1.4;
}
.puzzle-next-btn { margin-left: auto; }
.puzzle-prompt:focus { outline: none; }

.puzzle-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line-soft);
}
.puzzle-dots { display: flex; gap: 4px; }
.puzzle-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid rgba(127, 179, 235, 0.22);
  background: rgba(127, 179, 235, 0.06);
}
.puzzle-dot.is-correct { border-color: var(--green); background: var(--green); box-shadow: 0 0 7px rgba(134, 239, 172, 0.3); }
.puzzle-dot.is-wrong { border-color: var(--amber); background: var(--amber); }
.puzzle-dot.is-current { border-color: var(--cyan); background: rgba(103, 232, 249, 0.25); }

.defense-log-card {
  padding: 14px;
  min-height: 150px;
}
.defense-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.defense-log {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 258px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(251, 113, 133, 0.22) transparent;
}
.defense-log::-webkit-scrollbar { width: 6px; }
.defense-log::-webkit-scrollbar-thumb { border-radius: 99px; background: rgba(251, 113, 133, 0.22); }
.df-log-entry {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 7px;
  align-items: start;
  padding: 7px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(7, 13, 24, 0.45);
  animation: feedback-in 0.22s ease-out;
}
.df-log-entry .df-log-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  color: var(--df-accent);
  font-family: var(--font-mono);
  font-size: 9px;
}
.df-log-copy { min-width: 0; }
.df-log-copy b { display: block; color: var(--text); font-size: 10px; font-weight: 600; line-height: 1.3; }
.df-log-copy span { display: block; margin-top: 1px; color: var(--muted-2); font-size: 9px; line-height: 1.4; }
.df-log-entry.is-tower .df-log-icon { color: var(--cyan); }
.df-log-entry.is-good .df-log-icon { color: var(--green); }
.df-log-empty {
  padding: 18px 10px;
  color: var(--muted-2);
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
}
.defense-tip {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted-2);
  font-size: 9px;
  line-height: 1.45;
}
.defense-tip span { margin-right: 3px; color: var(--df-accent); }

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

.df-board {
  overflow: hidden;
  margin: 11px 0 0;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}
.df-board-row {
  display: grid;
  grid-template-columns: 28px minmax(64px, 1.2fr) 58px 66px 72px;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 10px;
}
.df-board-row:last-child { border-bottom: 0; }
.df-board-row:nth-child(odd) { background: rgba(127, 179, 235, 0.025); }
.df-board-row.is-head {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.df-board-row .df-rank { color: var(--muted-2); font-family: var(--font-mono); }
.df-board-row .df-points { color: var(--df-accent); font-family: var(--font-mono); font-weight: 600; font-variant-numeric: tabular-nums; }
.df-board-row .df-date { color: var(--muted-2); font-family: var(--font-mono); font-size: 8.5px; text-align: right; }
.df-board-empty { padding: 20px; color: var(--muted-2); font-size: 11px; text-align: center; }
.df-current-stat {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 13px 0;
}
.df-current-stat > div {
  flex: 1 1 100px;
  padding: 8px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: rgba(6, 13, 24, 0.4);
}
.df-current-stat span { display: block; color: var(--muted-2); font-size: 8.5px; }
.df-current-stat b { display: block; margin-top: 2px; color: var(--text); font-family: var(--font-mono); font-size: 13px; font-weight: 500; }

/* ---------- готово / пауза / конец ---------- */

.defense-overlay.is-over .defense-overlay-card { border-color: rgba(196, 119, 85, 0.35); }
.defense-overlay.is-over .df-overlay-mark { color: #d89170; border-color: rgba(196, 119, 85, 0.4); background: rgba(196, 119, 85, 0.1); }
.defense-overlay.is-paused .defense-overlay-card { border-color: rgba(127, 212, 192, 0.25); }
.defense-overlay.is-paused .df-overlay-mark { color: #9adccb; border-color: rgba(127, 212, 192, 0.32); background: rgba(127, 212, 192, 0.08); }

@keyframes df-banner {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- адаптив обороны ---------- */

@media (max-width: 1280px) {
  .defense-layout { grid-template-columns: minmax(0, 1.45fr) minmax(310px, 0.8fr); }
  .defense-stats { grid-template-columns: repeat(2, minmax(70px, 1fr)); min-width: 230px; }
}

@media (max-width: 1050px) {
  .defense-layout { grid-template-columns: minmax(0, 1fr); }
  .defense-side {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    align-items: start;
  }
}

@media (max-width: 860px) {
  .defense-side { grid-template-columns: minmax(0, 1fr); }
  .defense-log { max-height: 190px; }
}

@media (max-width: 700px) {
  body.mode-defense { padding-bottom: 16px; }
  .modebar-label { display: none; }
  .modebar-record { display: none; }
  .modebar-inner { padding: 6px 10px; gap: 6px; }
  .mode-tab { padding: 5px 8px; font-size: 9.5px; }
  .defense-layout { gap: 9px; padding: 10px 9px 0; }
  .defense-stage { padding: 12px 10px; border-radius: 17px; }
  .defense-title { flex-basis: 100%; }
  .defense-title h1 { font-size: 25px; margin-bottom: 1px; }
  .defense-title p { display: none; }
  .defense-head { margin-bottom: 9px; gap: 8px; }
  .defense-stats {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }
  .df-stat { padding: 5px 6px; }
  .df-stat span { font-size: 7.5px; letter-spacing: 0.03em; }
  .df-stat b { font-size: 11px; }
  .defense-field-wrap {
    min-height: 0;
    height: clamp(260px, 66vw, 310px);
    aspect-ratio: auto;
  }
  .defense-overlay { padding: 10px; align-items: flex-start; }
  .defense-overlay-card {
    margin: auto;
    padding: 14px 12px;
    border-radius: 13px;
  }
  .defense-overlay-card p { font-size: 10.5px; }
  .defense-overlay-card .df-overlay-mark {
    width: 40px;
    height: 40px;
    margin-bottom: 8px;
    font-size: 22px;
    border-radius: 11px;
  }
  .defense-overlay-card .df-overlay-stats { display: none; }
  .defense-overlay-card .df-overlay-small { display: none; }
  .defense-toolbar { align-items: flex-start; }
  .defense-toolbar-hint { width: 100%; text-align: left; }
  .defense-side { gap: 9px; }
  .puzzle-card { padding: 12px 11px; border-radius: 17px; }
  .puzzle-equation { font-size: 22px; padding: 10px 6px 7px; }
  .puzzle-prompt { font-size: 12px; }
  .puzzle-option { font-size: 11px; padding: 8px; }
  .defense-log-card { padding: 12px 11px; border-radius: 17px; }
  .df-board-row { grid-template-columns: 22px minmax(55px, 1fr) 45px 54px; }
  .df-board-row .df-date { display: none; }
}

@media (max-width: 420px) {
  .mode-tab { gap: 4px; padding: 5px 6px; font-size: 9px; }
  .mode-tab-icon { font-size: 10px; }
  .puzzle-top { gap: 4px; }
  .puzzle-accuracy { margin-left: 0; width: 100%; }
  .defense-overlay-card .df-overlay-actions .btn { flex: 1 1 42%; }
  .df-board-row { grid-template-columns: 20px minmax(52px, 1fr) 44px 50px; padding: 6px 8px; font-size: 9px; }
}

@media (max-width: 360px) {
  .defense-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* =========================================================
   Салон исчислений: тёплая гравюрная тема
   ========================================================= */

.defense-layout {
  --df-accent: #d8b15e;
  --df-danger: #c47755;
  --df-cyan: #7fd4c0;
  --df-violet: #a58ac9;
}

body.mode-defense .ambient {
  background:
    radial-gradient(ellipse at 72% 8%, rgba(216, 177, 94, 0.09), transparent 55%),
    radial-gradient(ellipse at 18% 68%, rgba(119, 63, 38, 0.12), transparent 48%),
    #070604;
}
body.mode-defense .ambient-grid {
  background-image:
    linear-gradient(rgba(216, 177, 94, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(216, 177, 94, 0.045) 1px, transparent 1px);
}
body.mode-defense .orb-a { background: rgba(216, 177, 94, 0.13); }
body.mode-defense .orb-b { background: rgba(116, 58, 35, 0.14); }
body.mode-defense .topbar {
  border-bottom-color: rgba(216, 177, 94, 0.1);
  background: linear-gradient(180deg, rgba(10, 8, 5, 0.95), rgba(10, 8, 5, 0.76));
}
body.mode-defense .modebar {
  border-bottom-color: rgba(216, 177, 94, 0.1);
  background: rgba(10, 8, 5, 0.58);
}

.mode-tab[data-mode="defense"].is-active {
  border-color: rgba(216, 177, 94, 0.3);
  background: rgba(216, 177, 94, 0.11);
  color: #e4c77d;
}

.defense-stage {
  border-color: rgba(216, 177, 94, 0.19);
  background:
    radial-gradient(ellipse at 80% 0%, rgba(216, 177, 94, 0.075), transparent 52%),
    linear-gradient(155deg, rgba(56, 43, 24, 0.24), rgba(10, 11, 14, 0.16) 42%),
    var(--panel);
}
.defense-kicker { color: #d8b15e !important; }
.defense-title h1 {
  font-family: var(--font-math);
  font-size: clamp(27px, 2.5vw, 38px);
  font-weight: 600;
  letter-spacing: 0;
}
.defense-title p { color: #b8aa8e; }
.defense-title p b { color: #e6ca87; font-weight: 600; }
.defense-era { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.defense-era span {
  padding: 2px 6px;
  border: 1px solid rgba(216, 177, 94, 0.13);
  border-radius: 4px;
  background: rgba(216, 177, 94, 0.035);
  color: rgba(214, 194, 153, 0.6);
  font-family: var(--font-mono);
  font-size: 7.5px;
  line-height: 1.4;
}

.defense-field-wrap {
  border-color: rgba(216, 177, 94, 0.2);
  background:
    radial-gradient(ellipse at 82% 48%, rgba(216, 177, 94, 0.09), transparent 45%),
    radial-gradient(ellipse at 18% 0%, rgba(121, 212, 180, 0.035), transparent 55%),
    #090a0c;
}
.defense-overlay { background: rgba(7, 6, 4, 0.68); }
.defense-overlay-card {
  border-color: rgba(216, 177, 94, 0.3);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(216, 177, 94, 0.12), transparent 62%),
    rgba(16, 14, 10, 0.96);
}
.df-overlay-mark {
  border-color: rgba(216, 177, 94, 0.4);
  background: rgba(216, 177, 94, 0.08);
  color: #e4c77d;
  font-family: var(--font-math);
}
.defense-overlay-card h2 {
  font-family: var(--font-math);
  font-weight: 600;
  letter-spacing: 0;
}
.defense-overlay-card p { color: #b9aa8b; }
.defense-overlay-card .df-overlay-stats span { border-color: rgba(216, 177, 94, 0.14); color: #b3a17d; }
.defense-overlay-card .df-overlay-stats b { color: #e3c679; }

.df-stat.is-mega { border-color: rgba(216, 177, 94, 0.3); background: rgba(216, 177, 94, 0.07); }
.df-stat.is-mega b { color: #e7c97d; }

.puzzle-card {
  border-color: rgba(216, 177, 94, 0.21);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(216, 177, 94, 0.06), transparent 55%),
    linear-gradient(155deg, rgba(56, 43, 24, 0.2), rgba(10, 11, 14, 0.16) 42%),
    var(--panel);
}
.puzzle-kicker b { color: #d8b15e; }
.puzzle-equation { color: #f0e2c4; border-color: rgba(216, 177, 94, 0.17); }
.puzzle-condition { color: #b8a57e; }
.puzzle-step-head span:first-child { color: #d8b15e; }
.puzzle-option {
  border-color: rgba(216, 177, 94, 0.12);
  background: rgba(17, 14, 9, 0.52);
  color: #bcae92;
}
.puzzle-option:hover:not(:disabled) {
  border-color: rgba(216, 177, 94, 0.35);
  background: rgba(50, 39, 20, 0.55);
  color: #f0e3c9;
}
.puzzle-option.is-correct { border-color: rgba(139, 193, 133, 0.45); background: rgba(43, 73, 38, 0.35); }
.puzzle-option.is-wrong { border-color: rgba(196, 119, 85, 0.48); background: rgba(85, 40, 27, 0.35); }
.puzzle-explanation { border-color: rgba(216, 177, 94, 0.1); background: rgba(16, 13, 8, 0.5); }
.puzzle-explanation.is-good { border-color: rgba(139, 193, 133, 0.25); }
.puzzle-explanation.is-bad { border-color: rgba(216, 177, 94, 0.26); }
.puzzle-option .option-why { border-top-color: rgba(216, 177, 94, 0.13); color: #a69575; }
.puzzle-option .option-why b { color: #cfc0a0; }
.puzzle-option.is-correct .option-why { border-top-color: rgba(139, 193, 133, 0.22); color: #b6d8b8; }
.puzzle-option.is-correct .option-why b { color: #d9efdb; }
.puzzle-option.is-wrong .option-why { border-top-color: rgba(196, 119, 85, 0.22); color: #ddb094; }
.puzzle-option.is-wrong .option-why b { color: #f0cdb7; }
.puzzle-deep { border-top-color: rgba(216, 177, 94, 0.16); }
.puzzle-deep-kicker { color: #d8b15e; }
.puzzle-deep p { color: #b9aa8b; }
.puzzle-next-row { border-top-color: rgba(216, 177, 94, 0.12); }
.puzzle-next-hint { color: #a99776; }
body.mode-defense .puzzle-next-btn.btn.primary {
  border-color: rgba(216, 177, 94, 0.55);
  background: linear-gradient(135deg, #e3c477, #c69b50);
  color: #181207;
  box-shadow: 0 5px 16px rgba(216, 177, 94, 0.15);
}
body.mode-defense .puzzle-next-btn.btn.primary:hover {
  border-color: rgba(232, 201, 123, 0.8);
  background: linear-gradient(135deg, #efd28a, #d1a75c);
}
.puzzle-dot.is-current { border-color: #d8b15e; background: rgba(216, 177, 94, 0.25); }
.puzzle-footer { border-color: rgba(216, 177, 94, 0.12); }

.defense-shop-card {
  min-width: 0;
  padding: 14px;
  border-color: rgba(216, 177, 94, 0.2);
  background:
    radial-gradient(ellipse at 90% 0%, rgba(216, 177, 94, 0.055), transparent 55%),
    linear-gradient(155deg, rgba(56, 43, 24, 0.18), rgba(10, 11, 14, 0.16) 45%),
    var(--panel);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.defense-shop-card.is-flashing { animation: salon-flash 1.2s ease-out; }
@keyframes salon-flash {
  0%, 100% { border-color: rgba(216, 177, 94, 0.2); box-shadow: var(--shadow-panel); }
  24% { border-color: rgba(216, 177, 94, 0.7); box-shadow: 0 0 45px rgba(216, 177, 94, 0.16), var(--shadow-panel); }
}
.defense-shop-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 9px;
  padding-bottom: 9px;
  border-bottom: 1px solid rgba(216, 177, 94, 0.13);
}
.mega-balance {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 2px;
  min-width: 74px;
  color: #d8b15e;
}
.mega-balance > span { margin-right: 3px; font-size: 16px; line-height: 1; text-shadow: 0 0 12px rgba(216, 177, 94, 0.35); }
.mega-balance b { font-family: var(--font-mono); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.mega-balance small { width: 100%; color: #a89773; font-size: 7.5px; letter-spacing: 0.05em; text-align: right; text-transform: uppercase; }

.defense-shop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}
.df-shop-section-label {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding: 1px 1px 0;
  color: #a99776;
  font-family: var(--font-mono);
  font-size: 7.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.df-shop-section-label:first-child { margin-top: 0; }
.df-shop-item {
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr) auto;
  align-items: start;
  gap: 6px;
  min-width: 0;
  padding: 7px;
  border: 1px solid rgba(216, 177, 94, 0.12);
  border-radius: 9px;
  background: rgba(17, 14, 9, 0.45);
  color: #b9aa8d;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.12s ease;
}
.df-shop-item:hover:not(:disabled) { border-color: rgba(216, 177, 94, 0.36); background: rgba(47, 37, 19, 0.52); }
.df-shop-item:active:not(:disabled) { transform: translateY(1px); }
.df-shop-item:disabled { opacity: 0.46; cursor: default; }
.df-shop-glyph {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border: 1px solid color-mix(in srgb, var(--shop-color, #d8b15e) 45%, transparent);
  border-radius: 50%;
  background: rgba(216, 177, 94, 0.045);
  color: var(--shop-color, #d8b15e);
  font-family: var(--font-math);
  font-size: 16px;
  line-height: 1;
}
.df-shop-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.df-shop-title { display: flex; flex-direction: column; color: #ebdfc5; font-size: 10.5px; font-weight: 600; line-height: 1.3; }
.df-shop-title i { color: #a99673; font-family: var(--font-mono); font-size: 7.5px; font-style: normal; font-weight: 400; }
.df-shop-copy small { color: #a69575; font-size: 9px; line-height: 1.38; }
.df-shop-copy em { margin-top: 3px; color: #c9ae75; font-family: var(--font-mono); font-size: 8px; font-style: normal; }
.df-shop-cost { display: flex; align-items: center; gap: 2px; color: #e0bd70; font-family: var(--font-mono); font-size: 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.df-shop-cost i { font-style: normal; font-size: 8px; opacity: 0.8; }
.defense-shop-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(216, 177, 94, 0.12);
}
.defense-quote {
  flex: 1 1 220px;
  min-width: 0;
  color: #a99776;
  font-family: var(--font-math);
  font-size: 10px;
  font-style: italic;
  line-height: 1.45;
}
.defense-chronicle { margin-top: 8px; border-top: 1px solid rgba(216, 177, 94, 0.1); }
.defense-chronicle summary {
  padding-top: 8px;
  color: #a99776;
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
}
.defense-chronicle summary::-webkit-details-marker { display: none; }
.defense-chronicle summary span { color: #d8b15e; font-family: var(--font-mono); letter-spacing: 0; }
.defense-chronicle[open] summary { margin-bottom: 7px; }
.defense-log { max-height: 160px; }
.df-log-entry { border-color: rgba(216, 177, 94, 0.1); background: rgba(17, 14, 9, 0.4); }
.df-log-entry .df-log-icon { border-color: rgba(216, 177, 94, 0.14); color: #d8b15e; }
.df-log-copy b { color: #e8dcc3; }
.df-log-copy span { color: #9f8f71; }
.df-log-entry.is-tower .df-log-icon { color: var(--df-cyan); }
.df-log-entry.is-good .df-log-icon { color: #9bc48e; }

.df-overlay-actions .btn.primary,
.defense-shop-card .btn.primary,
body.mode-defense .modal .btn.primary {
  border-color: rgba(216, 177, 94, 0.55);
  background: linear-gradient(135deg, #e3c477, #c69b50);
  color: #181207;
  box-shadow: 0 7px 22px rgba(216, 177, 94, 0.16);
}

body.mode-defense .modal {
  border-color: rgba(216, 177, 94, 0.28);
  background:
    radial-gradient(ellipse at 12% 0%, rgba(216, 177, 94, 0.12), transparent 42%),
    linear-gradient(180deg, #17130d, #0d0c09 82%);
}
body.mode-defense .modal-kicker { color: #d8b15e; }
body.mode-defense .modal-head h2 {
  font-family: var(--font-math);
  font-weight: 600;
  letter-spacing: 0;
}
body.mode-defense .modal-body { color: #b9aa8b; }
body.mode-defense .modal-body b { color: #ebdfc5; }
body.mode-defense .modal-close {
  border-color: rgba(216, 177, 94, 0.15);
  background: rgba(22, 17, 10, 0.8);
  color: #b8a581;
}
body.mode-defense :focus-visible { outline-color: #e3c477; }
body.mode-defense .modal-actions { border-color: rgba(216, 177, 94, 0.15); }
body.mode-defense .modal-actions .btn.ghost {
  border-color: rgba(216, 177, 94, 0.16);
  background: rgba(28, 22, 13, 0.5);
  color: #bba989;
}
body.mode-defense .df-current-stat > div {
  border-color: rgba(216, 177, 94, 0.15);
  background: rgba(27, 21, 12, 0.55);
}
body.mode-defense .df-current-stat span { color: #a89773; }
body.mode-defense .df-current-stat b { color: #ebdfc5; }
body.mode-defense .df-board { border-color: rgba(216, 177, 94, 0.15); }
body.mode-defense .df-board-row { border-color: rgba(216, 177, 94, 0.1); color: #b6a688; }
body.mode-defense .df-board-row:nth-child(odd) { background: rgba(216, 177, 94, 0.035); }
body.mode-defense .df-board-row .df-points { color: #e0bd70; }
body.mode-defense .df-board-row .df-date,
body.mode-defense .df-board-row .df-rank { color: #9f8f71; }
body.mode-defense .help-section h3 { color: #ebdfc5; }
body.mode-defense .modal .callout {
  border-color: rgba(216, 177, 94, 0.17);
  background: rgba(216, 177, 94, 0.04);
  color: #cfc0a0;
}
body.mode-defense .modal .callout b { color: #f0d896; }

@media (max-width: 1280px) {
  .defense-shop-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .defense-era { display: none; }
  .defense-shop-card { padding: 12px 11px; border-radius: 17px; }
  .defense-shop-grid { grid-template-columns: minmax(0, 1fr); }
}
