/* ==========================================================================
   SUPPORT PURRFECT 8 — WITCHER / DIABLO GRITTY DARK FANTASY UI
   100% FLUID VIEWPORT FIT (No scroll on laptops 1280x720, 1366x768, 1440x900, 1080p)
   ========================================================================== */

:root {
  /* Темна матова база */
  --bg-deep: #0a080c;
  --bg-surface: #120e15;
  --bg-panel: rgba(18, 14, 21, 0.94);
  --bg-subtle: rgba(28, 22, 32, 0.7);

  /* Старовинна кована бронза та темне залізо */
  --iron-dark: #221b14;
  --bronze-dark: #3a2b1b;
  --bronze-mid: #5c442c;
  --bronze-border: #735534;
  --gold-antique: #c59740;
  --gold-bright: #e5b95c;

  /* Теплий тліючий бурштин */
  --ember-dark: #8c320d;
  --ember-mid: #c45718;
  --ember-glow: #e07520;
  --ruby-dark: #5c1410;
  --ruby-mid: #8a1f18;

  /* Тексти */
  --text-main: #dfd7ca;
  --text-muted: #948877;
  --text-gold: #e2ba68;

  /* Шрифти */
  --font-serif: 'Cinzel', 'Trajan Pro', 'Georgia', serif;
  --font-sans: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
  
  --trans: 0.18s cubic-bezier(0.2, 0, 0, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

html, body {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden; /* Жодного вертикального скролу */
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-sans);
  user-select: none;
}

body {
  background-image: 
    radial-gradient(circle at 50% 20%, rgba(35, 22, 30, 0.5) 0%, rgba(10, 8, 12, 0.96) 85%),
    url('images/bg_ambient.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#embers-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

/* --------------------------------------------------------------------------
   КОНТЕЙНЕР: Фіксована висота 100vh з адаптивними відступами
   -------------------------------------------------------------------------- */
.app-container {
  position: relative;
  z-index: 2;
  max-width: 1400px;
  width: 98%;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: clamp(4px, 1vh, 10px) clamp(8px, 1.2vw, 16px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   ШАПКА (Header) — Рівно по центру, без зайвої висоти
   -------------------------------------------------------------------------- */
.app-header {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: clamp(3px, 0.6vh, 6px) clamp(8px, 1vw, 14px);
  border-bottom: 1px solid rgba(115, 85, 52, 0.35);
  margin-bottom: clamp(4px, 0.8vh, 8px);
  background: rgba(12, 9, 14, 0.88);
  border-radius: 6px;
  backdrop-filter: blur(8px);
}

.logo-wrapper {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.main-logo {
  height: clamp(32px, 5vh, 46px);
  max-width: 200px;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.9));
}

.text-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-title {
  font-family: var(--font-serif);
  font-size: clamp(0.95rem, 1.5vh, 1.15rem);
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--gold-antique);
}

/* СТЕППЕР 3 ЕТАПІВ */
.stages-stepper {
  display: flex;
  align-items: center;
  background: rgba(16, 12, 19, 0.85);
  border: 1px solid var(--bronze-dark);
  border-radius: 20px;
  padding: clamp(2px, 0.4vh, 4px) clamp(6px, 0.8vw, 10px);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
}

.step-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: clamp(3px, 0.5vh, 5px) clamp(8px, 0.8vw, 12px);
  border-radius: 14px;
  cursor: pointer;
  transition: all var(--trans);
  font-family: var(--font-serif);
  font-size: clamp(0.68rem, 1.1vh, 0.76rem);
  font-weight: 700;
  letter-spacing: 1px;
}

.step-num {
  width: clamp(15px, 2.2vh, 18px);
  height: clamp(15px, 2.2vh, 18px);
  border-radius: 50%;
  background: rgba(30, 22, 32, 0.9);
  border: 1px solid var(--bronze-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.step-btn:hover {
  color: var(--text-gold);
}

.step-btn.active {
  color: #fff;
  background: linear-gradient(180deg, #5c1810 0%, #360c07 100%);
  border: 1px solid var(--ember-mid);
  box-shadow: 0 0 8px rgba(196, 87, 24, 0.35);
}

.step-btn.active .step-num {
  background: var(--ember-mid);
  color: #fff;
  border-color: var(--gold-bright);
}

.step-btn.completed .step-num {
  background: #2a522c;
  color: #92d695;
  border-color: #3e7341;
}

.step-divider {
  width: 12px;
  height: 1px;
  background: var(--bronze-dark);
}

.header-spacer {
  /* Балансує сітку щоб степпер був по центру */
}

/* --------------------------------------------------------------------------
   ОСНОВНА ОБЛАСТЬ: flex: 1 та min-height: 0
   -------------------------------------------------------------------------- */
.stages-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

.stage-section {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}

.stage-section.active {
  display: flex;
}

/* ==========================================================================
   ЕТАП 2: РОСТЕР АГЕНТІВ — 3 КОЛОНКИ ІДЕАЛЬНО ВПИСАНІ У ВИСОТУ
   ========================================================================== */
.main-stage {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(260px, 330px) 1fr minmax(300px, 390px);
  gap: clamp(8px, 1.1vw, 16px);
  align-items: stretch;
}

/* --------------------------------------------------------------------------
   СЕКЦІЯ 1: Сітка агентів (Left)
   -------------------------------------------------------------------------- */
.roster-section {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-panel);
  border: 1.5px solid var(--bronze-mid);
  border-radius: 6px;
  padding: clamp(6px, 1vh, 12px) clamp(6px, 0.8vw, 10px);
  box-shadow: inset 0 0 25px rgba(0, 0, 0, 0.9), 0 6px 18px rgba(0, 0, 0, 0.8);
}

.roster-header {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: clamp(4px, 0.8vh, 8px);
  border-bottom: 1px solid rgba(115, 85, 52, 0.35);
  margin-bottom: clamp(3px, 0.6vh, 6px);
}

.roster-title {
  font-family: var(--font-serif);
  font-size: clamp(0.72rem, 1.2vh, 0.82rem);
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--gold-antique);
}

.roster-counter {
  font-family: var(--font-serif);
  font-size: clamp(0.68rem, 1.1vh, 0.76rem);
  color: var(--text-muted);
  font-weight: 600;
}

/* 4x3 сітка — повністю пропорційна */
.avatars-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: clamp(4px, 0.8vh, 8px) clamp(3px, 0.5vw, 6px);
  align-content: center;
  margin: auto 0;
}

.avatar-card {
  position: relative;
  aspect-ratio: 1 / 1.44;
  cursor: pointer;
  border-radius: 3px;
  overflow: hidden;
  background: #0f0c13;
  border: 1.5px solid #4a3826;
  transition: transform var(--trans), border-color var(--trans), box-shadow var(--trans);
  
  clip-path: polygon(
    5px 0, calc(100% - 5px) 0,
    100% 5px, 100% calc(100% - 5px),
    calc(100% - 5px) 100%, 5px 100%,
    0 calc(100% - 5px), 0 5px
  );
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: brightness(0.85) contrast(1.05);
  transition: filter var(--trans);
}

.avatar-badge-num {
  position: absolute;
  top: 2px;
  left: 4px;
  font-family: var(--font-serif);
  font-size: 0.6rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 2px #000;
  z-index: 2;
}

.avatar-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold-antique);
}

.avatar-card.active {
  border: 2px solid var(--ember-mid);
  transform: translateY(-2px) scale(1.03);
  box-shadow: 
    0 0 12px rgba(196, 87, 24, 0.65),
    inset 0 0 8px rgba(196, 87, 24, 0.5);
}

.avatar-card.active .avatar-img {
  filter: brightness(1.15) contrast(1.1);
}

.avatar-card.empty-slot {
  background: radial-gradient(circle, #1a1424 0%, #0c0910 100%);
  border: 1px dashed rgba(140, 105, 65, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-card.empty-slot .empty-slot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  opacity: 0.45;
  transition: opacity var(--trans), transform var(--trans);
}

.avatar-card.empty-slot .empty-lock-icon {
  font-size: clamp(0.95rem, 1.8vh, 1.25rem);
  filter: drop-shadow(0 2px 4px #000);
}

.avatar-card.empty-slot .empty-label {
  font-size: 0.52rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-family: var(--font-serif);
}

.avatar-card.empty-slot:hover .empty-slot-inner {
  opacity: 0.85;
  transform: scale(1.1);
}

.avatar-card.empty-slot.active {
  border: 1.5px solid var(--ember-mid);
  box-shadow: 0 0 10px rgba(196, 87, 24, 0.4), inset 0 0 6px rgba(0, 0, 0, 0.8);
}

.avatar-card.empty-slot.active .empty-slot-inner {
  opacity: 1;
}

.roster-hint {
  flex-shrink: 0;
  padding-top: clamp(3px, 0.6vh, 6px);
  text-align: center;
  font-size: clamp(0.62rem, 1vh, 0.7rem);
  color: var(--text-muted);
  border-top: 1px solid rgba(115, 85, 52, 0.2);
}

/* --------------------------------------------------------------------------
   СЕКЦІЯ 2: Центральний Герой (Arch) + Характеристики знизу
   -------------------------------------------------------------------------- */
.hero-section {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: clamp(6px, 1vh, 12px);
}

.arch-frame {
  position: relative;
  flex: 1 1 auto;
  height: clamp(340px, 58vh, 600px);
  max-height: 62vh;
  width: auto;
  aspect-ratio: 1 / 1.30;
  border-radius: clamp(80px, 15vh, 175px) clamp(80px, 15vh, 175px) 6px 6px;
  padding: 4px;
  background: linear-gradient(180deg, #38291c 0%, #17121b 100%);
  border: 2px solid var(--bronze-mid);
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.95),
    inset 0 0 18px rgba(0, 0, 0, 0.85);
  display: flex;
}

.hero-image-container {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: clamp(76px, 14.5vh, 170px) clamp(76px, 14.5vh, 170px) 4px 4px;
  overflow: hidden;
  background: #09070c;
}

.hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 15%;
  display: block;
}

.hero-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: 
    radial-gradient(circle at 50% 25%, transparent 55%, rgba(8, 6, 10, 0.7) 100%),
    linear-gradient(180deg, transparent 65%, rgba(10, 8, 12, 0.95) 100%);
}

/* Компактна та багата панель характеристик опущена вниз під портретом */
.hero-stats-panel {
  width: 100%;
  max-width: 540px;
  background: var(--bg-panel);
  border: 1.5px solid var(--bronze-mid);
  border-radius: 6px;
  padding: clamp(5px, 0.8vh, 8px) clamp(8px, 1vw, 12px);
  box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.8), 0 4px 12px rgba(0, 0, 0, 0.6);
  flex-shrink: 0;
  margin-top: auto;
}

.stats-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 3px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(115, 85, 52, 0.3);
}

.stats-panel-title {
  font-family: var(--font-serif);
  font-size: clamp(0.68rem, 1vh, 0.75rem);
  font-weight: 700;
  color: #ffd479;
  letter-spacing: 1px;
}

.stats-panel-hint {
  font-size: clamp(0.58rem, 0.9vh, 0.65rem);
  color: var(--text-muted);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   СЕКЦІЯ 3: Досьє персонажа (Right)
   -------------------------------------------------------------------------- */
.dossier-section {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-panel);
  border: 1.5px solid var(--bronze-mid);
  border-radius: 6px;
  padding: clamp(8px, 1.2vh, 12px) clamp(10px, 1.2vw, 16px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.9), inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.dossier-header {
  flex-shrink: 0;
  text-align: center;
  padding-bottom: clamp(4px, 0.7vh, 6px);
  border-bottom: 1px solid rgba(115, 85, 52, 0.3);
}

.agent-tag {
  font-family: var(--font-serif);
  font-size: clamp(0.65rem, 1vh, 0.72rem);
  letter-spacing: 2px;
  color: var(--text-muted);
}

.agent-tag::before,
.agent-tag::after {
  content: '♦';
  font-size: 0.5rem;
  color: var(--bronze-border);
  margin: 0 4px;
}

.character-name {
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 2.3vh, 1.6rem);
  font-weight: 800;
  letter-spacing: 1.5px;
  margin: 1px 0 clamp(2px, 0.5vh, 4px);
  background: linear-gradient(180deg, #ffffff 0%, #f1d394 50%, #b88632 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
}

.class-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(180deg, #5c1810 0%, #300c08 100%);
  border: 1px solid #8f3424;
  border-radius: 3px;
  padding: clamp(2px, 0.4vh, 3px) clamp(8px, 1vw, 12px);
}

.class-icon {
  font-size: clamp(0.8rem, 1.3vh, 0.92rem);
}

.class-text {
  font-family: var(--font-serif);
  font-size: clamp(0.68rem, 1.1vh, 0.75rem);
  font-weight: 700;
  letter-spacing: 1.2px;
  color: #faebd2;
}

/* Перемикач вкладок вгорі досьє (ХАРАКТЕРИСТИКИ / ІСТОРІЯ ТА МЕТА) */
.dossier-tabs-nav {
  display: flex;
  gap: 6px;
  margin-top: clamp(4px, 0.7vh, 7px);
}

.dossier-tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: #140f1a;
  border: 1px solid rgba(115, 85, 52, 0.4);
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-size: clamp(0.68rem, 1.1vh, 0.75rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: clamp(4px, 0.7vh, 6px) 6px;
  border-radius: 3px;
  cursor: pointer;
  transition: all var(--trans);
}

.dossier-tab-btn:hover {
  background: #23192c;
  color: #fff;
  border-color: var(--gold-antique);
}

.dossier-tab-btn.active {
  background: linear-gradient(180deg, #5c2014 0%, #2a0c06 100%);
  color: #fed876;
  border-color: var(--ember-mid);
  box-shadow: 0 0 10px rgba(196, 87, 24, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.dossier-tab-btn .tab-badge {
  background: linear-gradient(135deg, #d47e1c 0%, #8c2a05 100%);
  color: #fff;
  font-size: 0.55rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 2px #000;
  box-shadow: 0 0 6px rgba(212, 126, 28, 0.6);
  animation: badgePulse 2s infinite ease-in-out;
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.08); filter: brightness(1.25); }
}

/* Інтерактивний банер підказка */
.story-quick-callout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(196, 87, 24, 0.12);
  border: 1px dashed rgba(212, 126, 28, 0.45);
  border-radius: 3px;
  padding: clamp(3px, 0.5vh, 4px) 8px;
  margin-bottom: clamp(3px, 0.5vh, 5px);
  cursor: pointer;
  transition: all var(--trans);
  flex-shrink: 0;
}

.story-quick-callout:hover {
  background: rgba(196, 87, 24, 0.24);
  border-color: #ffd479;
  transform: translateY(-1px);
}

.story-quick-callout .callout-text {
  font-family: var(--font-serif);
  font-size: clamp(0.66rem, 1vh, 0.72rem);
  font-weight: 600;
  color: #ffca7a;
  text-align: center;
}

/* Посилена анімація кнопки "Історія персонажа" */
.btn-to-story {
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(196, 87, 24, 0.45);
  animation: storyBtnGlow 2.5s infinite ease-in-out;
}

@keyframes storyBtnGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(196, 87, 24, 0.35); border-color: #a34832; }
  50% { box-shadow: 0 0 16px rgba(212, 126, 28, 0.75); border-color: #fed876; }
}

.btn-stage-3-nav-big {
  width: 100%;
  background: linear-gradient(180deg, #6e1c14 0%, #3d0c07 100%);
  border: 1.5px solid #a34832;
  border-radius: 4px;
  padding: clamp(7px, 1.1vh, 10px) 14px;
  color: #faebd2;
  font-family: var(--font-serif);
  font-size: clamp(0.78rem, 1.2vh, 0.88rem);
  font-weight: 700;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(196, 87, 24, 0.5);
  transition: all var(--trans);
}

.btn-stage-3-nav-big:hover {
  background: linear-gradient(180deg, #8a241a 0%, #4f100a 100%);
  border-color: var(--gold-antique);
  box-shadow: 0 0 18px rgba(212, 126, 28, 0.8);
  transform: translateY(-1px);
}

.dossier-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: clamp(4px, 0.8vh, 8px);
  overflow: hidden;
}

.view-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  justify-content: space-between;
}

.view-panel.active {
  display: flex;
}

/* 6 ШКАЛ ХАРАКТЕРИСТИК З ЦИТАТАМИ */
.stats-list {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(4px, 0.6vh, 6px) clamp(8px, 1vw, 12px);
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 1.5px;
  background: rgba(18, 14, 23, 0.65);
  border: 1px solid rgba(115, 85, 52, 0.3);
  border-radius: 3px;
  padding: 3px 6px;
  transition: all 0.2s ease;
}

.stat-card:hover {
  background: rgba(28, 20, 36, 0.85);
  border-color: rgba(212, 126, 28, 0.5);
  transform: translateY(-1px);
}

.stat-main-line {
  display: grid;
  grid-template-columns: 16px 1fr 44px 22px;
  align-items: center;
  gap: 3px;
  font-size: clamp(0.65rem, 1vh, 0.72rem);
}

.stat-icon {
  font-size: clamp(0.78rem, 1.2vh, 0.86rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-name {
  color: var(--text-main);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-segments {
  display: flex;
  gap: 2px;
  align-items: center;
  height: clamp(8px, 1.3vh, 10px);
}

.stat-segment {
  flex: 1;
  height: 100%;
  transform: skewX(-15deg);
  border-radius: 1px;
  background: #141017;
  border: 1px solid rgba(90, 70, 50, 0.4);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
}

.stat-segment.filled {
  background: linear-gradient(180deg, #fed876 0%, #d47e1c 60%, #8c4205 100%);
  border-color: #ffd479;
  box-shadow: 0 0 5px rgba(212, 126, 28, 0.5), inset 0 1px 1px #fff;
}

.stat-value {
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--text-gold);
  text-align: right;
  font-size: clamp(0.66rem, 1vh, 0.72rem);
}

.stat-desc {
  font-size: clamp(0.57rem, 0.88vh, 0.63rem);
  line-height: 1.25;
  color: #c4bcb0;
  font-style: italic;
  padding-left: 2px;
  white-space: normal;
}

/* РОЛЬ У КОМАНДІ */
.role-divider {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: clamp(2px, 0.5vh, 5px) 0;
}

.divider-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(115, 85, 52, 0.4), transparent);
}

.divider-title {
  font-family: var(--font-serif);
  font-size: clamp(0.66rem, 1.1vh, 0.72rem);
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--gold-antique);
}

.role-content {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-subtle);
  border: 1px solid rgba(115, 85, 52, 0.35);
  border-radius: 4px;
  padding: clamp(4px, 0.7vh, 7px) clamp(6px, 0.8vw, 10px);
  margin-bottom: clamp(4px, 0.8vh, 8px);
}

.role-emblem-wrap {
  width: clamp(34px, 4.5vh, 42px);
  height: clamp(34px, 4.5vh, 42px);
  flex-shrink: 0;
  position: relative;
}

.role-emblem {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  filter: drop-shadow(0 0 5px rgba(212, 126, 28, 0.5));
}

.emblem-pulse {
  display: none;
}

.role-text {
  font-size: clamp(0.72rem, 1.15vh, 0.78rem);
  line-height: 1.35;
  color: #d1c8bb;
}

/* КНОПКИ ВНИЗУ ДОСЬЄ */
.dossier-buttons-row {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  margin-top: auto;
}

.action-btn {
  background: linear-gradient(180deg, #6e1c14 0%, #3d0c07 100%);
  border: 1.5px solid #a34832;
  border-radius: 3px;
  padding: clamp(6px, 1vh, 9px) clamp(8px, 1vw, 12px);
  color: #faebd2;
  font-family: var(--font-serif);
  font-size: clamp(0.74rem, 1.2vh, 0.82rem);
  font-weight: 700;
  letter-spacing: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.6);
  transition: all var(--trans);
  flex: 0 0 auto;
}

.dossier-buttons-row .action-btn {
  flex: 1;
}

.action-btn:hover {
  background: linear-gradient(180deg, #8a241a 0%, #4f100a 100%);
  border-color: var(--gold-antique);
  box-shadow: 0 0 10px rgba(196, 87, 24, 0.5);
  transform: translateY(-1px);
}

.btn-stage-3-nav {
  background: linear-gradient(180deg, #241c29 0%, #141018 100%);
  border-color: var(--bronze-mid);
  flex: 0 0 auto;
  font-size: clamp(0.7rem, 1.1vh, 0.76rem);
}

.btn-stage-3-nav:hover {
  background: linear-gradient(180deg, #35283c 0%, #1e1724 100%);
  border-color: var(--gold-antique);
}

/* --------------------------------------------------------------------------
   ВКЛАДКА 2: ІСТОРІЯ ПЕРСОНАЖА (Story)
   -------------------------------------------------------------------------- */
.story-scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 6px;
}

.story-lead {
  font-size: clamp(0.74rem, 1.2vh, 0.82rem);
  font-weight: 600;
  color: #f1d394;
  line-height: 1.35;
  margin-bottom: 5px;
  border-left: 2.5px solid var(--ember-mid);
  padding-left: 6px;
}

.story-paragraphs p {
  font-size: clamp(0.7rem, 1.1vh, 0.76rem);
  line-height: 1.35;
  color: #c9c1b3;
  margin-bottom: 4px;
}

.mini-stats-section {
  background: var(--bg-subtle);
  border: 1px solid rgba(115, 85, 52, 0.3);
  border-radius: 3px;
  padding: 4px 6px;
  margin: 5px 0;
}

.mini-stats-title {
  font-family: var(--font-serif);
  font-size: 0.62rem;
  letter-spacing: 1.2px;
  color: var(--gold-antique);
  margin-bottom: 2px;
  font-weight: 700;
}

.mini-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 6px;
}

.mini-stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.68rem;
}

.mini-stat-label {
  color: var(--text-muted);
}

.mini-stat-bars {
  display: flex;
  gap: 1.5px;
}

.mini-bar {
  width: 7px;
  height: 5px;
  transform: skewX(-18deg);
  background: #19141d;
}

.mini-bar.filled {
  background: var(--ember-mid);
}

.story-badges {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  margin-top: 4px;
}

.story-badge-card {
  background: var(--bg-subtle);
  border: 1px solid rgba(115, 85, 52, 0.3);
  border-radius: 3px;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-icon-box {
  font-size: 0.9rem;
}

.badge-label {
  font-family: var(--font-serif);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--gold-antique);
}

.badge-text {
  font-size: 0.7rem;
  color: #dfd7ca;
}

/* --------------------------------------------------------------------------
   ЕТАП 1: ВСТУПНЕ ВІДЕО
   -------------------------------------------------------------------------- */
.stage-1 {
  justify-content: center;
  align-items: center;
}

.stage-header {
  flex-shrink: 0;
  text-align: center;
  margin-bottom: clamp(6px, 1.2vh, 12px);
}

.stage-badge {
  font-family: var(--font-serif);
  font-size: clamp(0.65rem, 1vh, 0.7rem);
  letter-spacing: 2px;
  color: var(--ember-mid);
  font-weight: 700;
}

.stage-title {
  font-family: var(--font-serif);
  font-size: clamp(1.2rem, 2.5vh, 1.5rem);
  letter-spacing: 1.5px;
  margin: 1px 0 3px;
  background: linear-gradient(180deg, #ffffff 0%, #f1d394 50%, #b88632 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stage-desc {
  font-size: clamp(0.74rem, 1.2vh, 0.82rem);
  color: var(--text-muted);
}

.video-theatre-frame {
  max-width: 800px;
  width: 90%;
  max-height: calc(100vh - 120px);
  background: var(--bg-panel);
  border: 2px solid var(--bronze-mid);
  border-radius: 6px;
  padding: clamp(8px, 1.2vh, 12px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1vh, 10px);
}

.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 4px;
  overflow: hidden;
}

.intro-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(circle at center, rgba(30, 20, 35, 0.85) 0%, rgba(8, 6, 10, 0.96) 100%),
    url('images/bg_ambient.jpg');
  background-size: cover;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 14px;
}

.video-ph-icon {
  font-size: clamp(2rem, 4vh, 2.6rem);
  margin-bottom: 4px;
}

.video-ph-title {
  font-family: var(--font-serif);
  font-size: clamp(1.1rem, 2vh, 1.3rem);
  color: var(--gold-antique);
  margin-bottom: 4px;
}

.video-ph-text {
  font-size: clamp(0.74rem, 1.2vh, 0.82rem);
  line-height: 1.35;
  color: #c9c1b3;
  margin-bottom: 10px;
}

.video-demo-play-btn {
  background: linear-gradient(180deg, #6e1c14 0%, #3d0c07 100%);
  border: 1px solid #a34832;
  color: #fff;
  padding: 6px 16px;
  border-radius: 3px;
  font-family: var(--font-serif);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.video-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid rgba(115, 85, 52, 0.25);
}

.video-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ember-mid);
}

.btn-stage-next {
  min-width: 200px;
}

/* --------------------------------------------------------------------------
   ЕТАП 3: МІНІ-ГРА
   -------------------------------------------------------------------------- */
.stage3-top-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 6px;
}

.back-link-btn {
  background: none;
  border: 1px solid var(--bronze-mid);
  color: var(--text-gold);
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--font-serif);
  font-size: 0.72rem;
}

.stage-badge-small {
  font-family: var(--font-serif);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.minigame-container {
  flex: 1;
  min-height: 0;
  max-width: 780px;
  width: 90%;
  margin: 0 auto;
  background: var(--bg-panel);
  border: 2px solid var(--bronze-mid);
  border-radius: 6px;
  padding: clamp(10px, 1.5vh, 16px);
  display: flex;
}

.mg-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.mg-badge {
  font-family: var(--font-serif);
  font-size: 0.68rem;
  color: var(--ember-mid);
  font-weight: 700;
  margin-bottom: 3px;
}

.mg-title {
  font-family: var(--font-serif);
  font-size: clamp(1.3rem, 2.5vh, 1.6rem);
  color: #fff;
  margin-bottom: 6px;
}

.mg-desc {
  font-size: clamp(0.76rem, 1.2vh, 0.84rem);
  color: #c9c1b3;
  margin-bottom: 12px;
}

.mg-rules {
  display: flex;
  gap: 8px;
  background: var(--bg-subtle);
  border: 1px solid rgba(115, 85, 52, 0.3);
  border-radius: 3px;
  padding: 6px 10px;
  margin-bottom: 14px;
}

.rule-item {
  font-size: 0.74rem;
  color: var(--text-gold);
}

.rule-item.bad {
  color: #d9534f;
}

.mg-start-btn {
  font-size: 0.88rem;
  padding: 10px 24px;
}

.mg-note {
  margin-top: 12px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Ігровий HUD */
.mg-hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  background: var(--bg-subtle);
  border: 1px solid rgba(115, 85, 52, 0.3);
  border-radius: 3px;
  padding: 6px 12px;
  margin-bottom: 8px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.hud-label {
  font-family: var(--font-serif);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hud-val {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold-antique);
}

.mg-arena {
  width: 100%;
  flex: 1;
  min-height: 0;
  background: #0d0a11;
  border: 1px solid rgba(115, 85, 52, 0.3);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  cursor: crosshair;
}

.mg-target {
  position: absolute;
  width: 58px;
  height: 58px;
  background: linear-gradient(180deg, #241c28 0%, #120e16 100%);
  border: 1.5px solid var(--gold-antique);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(196, 87, 24, 0.4);
}

.mg-target-bad {
  border-color: #d9534f;
}

.mg-target-icon {
  font-size: 1.35rem;
}

.mg-target-pts {
  font-family: var(--font-serif);
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-gold);
}

.mg-target-bad .mg-target-pts {
  color: #ff6b6b;
}

.mg-float-txt {
  position: absolute;
  font-family: var(--font-serif);
  font-weight: 800;
  font-size: 1rem;
  pointer-events: none;
  animation: float-up 0.6s ease-out forwards;
}

.mg-float-txt.pos { color: #5cb85c; }
.mg-float-txt.neg { color: #d9534f; }

@keyframes float-up {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-25px); opacity: 0; }
}

.mg-win-icon {
  font-size: 2.8rem;
  margin-bottom: 6px;
}

.mg-end-title {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  color: #fff;
  margin-bottom: 8px;
}

.mg-final-score-box {
  background: var(--bg-subtle);
  border: 1px solid rgba(115, 85, 52, 0.3);
  border-radius: 4px;
  padding: 8px 18px;
  margin-bottom: 8px;
}

.final-score-num {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  font-weight: 900;
  color: var(--gold-antique);
  display: block;
}

.mg-rank {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--ember-mid);
  font-weight: 700;
  margin-bottom: 14px;
}

.mg-end-actions {
  display: flex;
  gap: 8px;
}

.btn-secondary {
  background: linear-gradient(180deg, #241c29 0%, #151119 100%);
  border-color: var(--bronze-border);
}

/* --------------------------------------------------------------------------
   МОДАЛЬНЕ ВІКНО
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 4, 7, 0.88);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-window {
  background: #141017;
  border: 2px solid var(--bronze-mid);
  border-radius: 6px;
  max-width: 540px;
  width: 100%;
  padding: 16px 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(115, 85, 52, 0.3);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  color: var(--gold-antique);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.modal-body {
  font-size: 0.8rem;
  line-height: 1.45;
  color: #c9c1b3;
}

.modal-body h3 {
  font-family: var(--font-serif);
  color: var(--gold-antique);
  margin: 10px 0 3px;
  font-size: 0.85rem;
}

.modal-footer {
  margin-top: 10px;
  text-align: right;
  border-top: 1px solid rgba(115, 85, 52, 0.2);
  padding-top: 8px;
}

.modal-btn {
  background: linear-gradient(180deg, #6e1c14 0%, #3d0c07 100%);
  border: 1px solid #a34832;
  color: #fff;
  padding: 5px 16px;
  border-radius: 3px;
  font-family: var(--font-serif);
  font-weight: 700;
  cursor: pointer;
}

/* ==========================================================================
   ЕТАП 3: ЧАТ САПОРТУ + МАТЧ-3 "ТРИ В РЯД" (WITCHER/DIABLO STYLE)
   ========================================================================== */
.m3-game-container {
  flex: 1;
  min-height: 0;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  background: var(--bg-panel);
  border: 1.5px solid var(--bronze-mid);
  border-radius: 6px;
  padding: clamp(8px, 1.2vh, 14px);
  display: flex;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.9), inset 0 0 20px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.m3-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  width: 100%;
}

/* --------------------------------------------------------------------------
   Екран 1: Старт та Легенда
   -------------------------------------------------------------------------- */
.m3-start-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(10px, 2vh, 20px);
}

.m3-start-title {
  font-family: var(--font-serif);
  font-size: clamp(1.4rem, 2.8vh, 1.9rem);
  letter-spacing: 1.5px;
  margin-bottom: 4px;
  background: linear-gradient(180deg, #ffffff 0%, #f1d394 50%, #b88632 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.m3-start-sub {
  font-size: clamp(0.76rem, 1.2vh, 0.84rem);
  color: var(--text-gold);
  margin-bottom: 12px;
}

/* Вибір клієнта (3 варіанти) */
.m3-client-selector {
  display: flex;
  gap: 10px;
  max-width: 580px;
  width: 100%;
  margin-bottom: 14px;
  justify-content: center;
}

.m3-client-card {
  flex: 1;
  background: #140f1a;
  border: 1.5px solid var(--bronze-mid);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: left;
}

.m3-client-card:hover {
  border-color: var(--gold-antique);
  transform: translateY(-2px);
  background: #1c1524;
}

.m3-client-card.active {
  border-color: var(--gold-bright);
  background: linear-gradient(180deg, #2a1a12 0%, #170d10 100%);
  box-shadow: 0 0 12px rgba(255, 140, 20, 0.4), inset 0 0 10px rgba(196, 87, 24, 0.3);
}

.client-avatar {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.client-name {
  font-family: var(--font-serif);
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
}

.client-issue {
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.2;
}

.m3-compact-hint {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(20, 14, 22, 0.7);
  border: 1px solid rgba(115, 85, 52, 0.4);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 0.68rem;
  color: #c9c1b3;
  margin-bottom: 14px;
}

.m3-compact-hint span {
  font-weight: 600;
}

/* Індикатор цілі раунду у шапці пазла */
.m3-quest-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #140f1a;
  border: 1px solid var(--bronze-mid);
  border-radius: 4px;
  padding: 2px 8px;
}

.quest-label {
  font-family: var(--font-serif);
  font-size: 0.62rem;
  color: var(--text-muted);
  font-weight: 700;
}

.quest-text {
  font-family: var(--font-serif);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold-bright);
}

.quest-dots {
  display: flex;
  gap: 4px;
}

.q-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #332736;
  border: 1px solid var(--bronze-mid);
  transition: all 0.2s ease;
}

.q-dot.done {
  background: #22c55e;
  border-color: #4ade80;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.8);
}

.m3-big-btn {
  padding: clamp(10px, 1.5vh, 13px) clamp(24px, 3vw, 36px);
  font-size: clamp(0.85rem, 1.3vh, 0.95rem);
}

/* --------------------------------------------------------------------------
   Екран 2: Геймплей (Спліт Чат + Матч-3)
   -------------------------------------------------------------------------- */
.m3-gameplay-screen {
  display: grid;
  grid-template-columns: minmax(320px, 44%) 1fr;
  gap: clamp(8px, 1.2vw, 16px);
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* ЛІВА ЧАСТИНА: ЧАТ */
.m3-chat-panel {
  display: flex;
  flex-direction: column;
  background: rgba(14, 11, 17, 0.92);
  border: 1px solid rgba(115, 85, 52, 0.4);
  border-radius: 5px;
  overflow: hidden;
  height: 100%;
  min-height: 0;
}

.m3-chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, #241a24 0%, #16121a 100%);
  border-bottom: 1px solid rgba(115, 85, 52, 0.35);
  padding: clamp(6px, 1vh, 10px) 12px;
}

.chat-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-av {
  font-size: 1.3rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(40, 30, 45, 0.8);
  border: 1px solid var(--bronze-mid);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-names {
  display: flex;
  flex-direction: column;
}

.chat-user-name {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-gold);
}

.chat-user-status {
  font-size: 0.68rem;
  color: #ff6b6b;
}

.chat-csat-stars {
  font-size: 0.8rem;
  filter: drop-shadow(0 0 5px rgba(255, 183, 3, 0.5));
}

.m3-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.m3-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  max-width: 90%;
  animation: msg-in 0.25s ease-out forwards;
}

.m3-msg-customer {
  align-self: flex-start;
}

.m3-msg-agent {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-av {
  font-size: 1.15rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(30, 22, 34, 0.9);
  border: 1px solid var(--bronze-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-bubble {
  padding: 9px 13px;
  border-radius: 8px;
  font-size: clamp(0.76rem, 1.6vh, 0.86rem);
  line-height: 1.45;
  position: relative;
}

.m3-msg-customer .msg-bubble {
  background: #231b28;
  border: 1px solid #5a4230;
  color: #f5f0e8;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.m3-msg-agent .msg-bubble {
  background: linear-gradient(180deg, #42291a 0%, #24160f 100%);
  border: 1.5px solid var(--gold-antique);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), inset 0 0 12px rgba(196, 87, 24, 0.2);
}

.m3-msg.fail .msg-bubble {
  background: #3d1414;
  border-color: #e53e3e;
  color: #fed7d7;
  font-weight: 600;
}

.m3-msg.angry .msg-bubble {
  border-color: #e53e3e;
  color: #fed7d7;
}

.m3-msg.happy .msg-bubble {
  background: #152c1e;
  border: 1.5px solid #38a169;
  color: #e6fffa;
  box-shadow: 0 2px 10px rgba(56, 161, 105, 0.25);
}

.m3-msg.happy .msg-text {
  color: #ffffff;
  font-weight: 500;
}

.msg-text {
  color: #f7fafc;
  line-height: 1.45;
}

.msg-badge {
  font-family: var(--font-serif);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--gold-bright);
  margin-bottom: 3px;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.m3-chat-footer {
  flex-shrink: 0;
  background: #110d14;
  border-top: 1px solid rgba(115, 85, 52, 0.3);
  padding: 6px 10px;
  text-align: center;
}

.chat-turn-status {
  font-size: 0.72rem;
  color: var(--text-gold);
  font-weight: 600;
}

/* ПРАВА ЧАСТИНА: МАТЧ-3 СІТКА */
.m3-puzzle-panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: rgba(14, 11, 17, 0.92);
  border: 1px solid rgba(115, 85, 52, 0.4);
  border-radius: 5px;
  padding: clamp(6px, 1vh, 10px);
  height: 100%;
  min-height: 0;
}

.m3-puzzle-header {
  flex-shrink: 0;
  margin-bottom: clamp(4px, 0.8vh, 8px);
}

.m3-timer-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-serif);
  font-size: 0.76rem;
  color: var(--text-gold);
  font-weight: 700;
  margin-bottom: 4px;
}

.m3-timer-num {
  font-size: 0.95rem;
  color: #fff;
  font-weight: 800;
}

.m3-timer-bar-wrap {
  width: 100%;
  height: 7px;
  background: #120e15;
  border: 1px solid var(--bronze-mid);
  border-radius: 3px;
  overflow: hidden;
}

.m3-timer-progress {
  width: 100%;
  height: 100%;
  background: var(--ember-mid);
  transition: width 0.9s linear, background-color 0.3s ease;
}

/* СІТКА 6x6 */
.m3-board-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.m3-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: clamp(3px, 0.5vh, 6px);
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1 / 1;
  background: #09070c;
  padding: clamp(4px, 0.8vh, 8px);
  border: 2px solid var(--bronze-mid);
  border-radius: 6px;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.9);
}

.m3-tile {
  background: linear-gradient(180deg, #241c28 0%, #141018 100%);
  border: 1.5px solid #4a3826;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.m3-tile:hover {
  transform: scale(1.05);
  border-color: var(--gold-antique);
}

.m3-tile.selected {
  border: 2px solid var(--ember-mid);
  transform: scale(1.08);
  box-shadow: 0 0 10px rgba(196, 87, 24, 0.8), inset 0 0 6px rgba(196, 87, 24, 0.5);
  animation: tile-pulse 1s infinite alternate;
}

@keyframes tile-pulse {
  from { box-shadow: 0 0 6px rgba(196, 87, 24, 0.5); }
  to { box-shadow: 0 0 14px rgba(255, 130, 20, 0.9); }
}

.m3-tile.match-pop {
  transform: scale(1.2);
  opacity: 0;
  transition: all 0.25s ease-out;
}

.m3-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
  font-size: clamp(1.4rem, 3.8vh, 2rem);
  line-height: 1;
}

.m3-svg {
  width: clamp(28px, 5.5vh, 40px);
  height: clamp(28px, 5.5vh, 40px);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
  transition: transform 0.15s ease;
  pointer-events: none;
}

.m3-tile:hover .m3-svg {
  transform: scale(1.12);
}

.m3-label {
  display: none;
}

.m3-puzzle-hint {
  flex-shrink: 0;
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-muted);
  padding-top: 4px;
}

/* --------------------------------------------------------------------------
   Екран 3: Результати (Перемога / Поразка)
   -------------------------------------------------------------------------- */
.m3-result-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.m3-result-box {
  flex-direction: column;
  align-items: center;
  background: var(--bg-subtle);
  border: 1.5px solid var(--bronze-mid);
  border-radius: 6px;
  padding: clamp(6px, 1.2vh, 12px) clamp(14px, 2vw, 24px);
  max-width: 620px;
  width: 95%;
  margin-bottom: 8px;
}

.win-box {
  border-color: var(--gold-antique);
}

.lose-box {
  border-color: #8f3424;
}

.result-icon {
  font-size: clamp(1.6rem, 3vh, 2.4rem);
  margin-bottom: 4px;
}

.result-title {
  font-family: var(--font-serif);
  font-size: clamp(1.1rem, 1.8vh, 1.35rem);
  color: #fff;
  margin-bottom: 2px;
}

.result-csat {
  font-family: var(--font-serif);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--gold-bright);
  margin-bottom: 4px;
}

.result-csat.fail {
  color: #ff6b6b;
}

.result-desc {
  font-size: 0.74rem;
  line-height: 1.35;
  color: #c9c1b3;
}

/* Поле введення імені гравця перед стартом */
.m3-name-input-box {
  width: 100%;
  max-width: 440px;
  margin-bottom: 10px;
  text-align: left;
}

.m3-name-label {
  display: block;
  font-family: var(--font-serif);
  font-size: 0.72rem;
  letter-spacing: 0.8px;
  color: var(--text-gold);
  margin-bottom: 4px;
  font-weight: 700;
}

.m3-name-field-wrap {
  display: flex;
  align-items: center;
  background: #110c14;
  border: 1.5px solid var(--bronze-mid);
  border-radius: 4px;
  padding: 3px 6px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.7);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.m3-name-field-wrap:focus-within {
  border-color: var(--gold-antique);
  box-shadow: 0 0 10px rgba(212, 163, 89, 0.35), inset 0 1px 4px rgba(0, 0, 0, 0.8);
}

.m3-name-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: #fff;
  padding: 5px 8px;
}

.m3-name-input::placeholder {
  color: #7a6e62;
  font-style: italic;
}

.m3-name-tag {
  font-family: var(--font-serif);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--gold-bright);
  background: rgba(196, 87, 24, 0.25);
  border: 1px solid var(--ember-dark);
  border-radius: 3px;
  padding: 2px 6px;
  letter-spacing: 1px;
}

/* Бейдж оператора в шапці чату */
.chat-agent-info-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(20, 14, 22, 0.85);
  border: 1px solid var(--bronze-mid);
  border-radius: 4px;
  padding: 3px 8px;
}

.agent-role-title {
  font-family: var(--font-serif);
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.agent-display-name {
  font-family: var(--font-serif);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--gold-bright);
}

/* Гіфка котика в чаті */
.m3-chat-gif-card {
  margin-top: 6px;
  background: #110c15;
  border: 1px solid var(--bronze-mid);
  border-radius: 6px;
  padding: 6px;
  text-align: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.6);
}

.m3-chat-cat-img {
  width: 100%;
  max-width: 180px;
  height: auto;
  border-radius: 4px;
  display: block;
  margin: 0 auto;
}

.gif-sub {
  font-size: 0.64rem;
  color: var(--text-gold);
  margin-top: 4px;
  font-family: var(--font-serif);
  font-style: italic;
}

/* Анімація друку ("Олена друкує...") */
.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
}

.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-action-box {
  margin-top: 6px;
  display: flex;
  justify-content: center;
}

.chat-finish-btn {
  padding: 8px 22px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #b84308 0%, #692205 100%);
  border: 1.5px solid var(--gold-bright);
  color: #ffffff;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(255, 140, 20, 0.6);
  transition: all 0.15s ease;
}

.chat-finish-btn:hover {
  background: linear-gradient(180deg, #d9530f 0%, #872e07 100%);
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 0 18px rgba(255, 170, 40, 0.85);
}

/* Таблиця лідерів (хто на скільки закрив чат) */
.m3-leaderboard-card {
  width: 100%;
  max-width: 620px;
  background: var(--bg-subtle);
  border: 1.5px solid var(--bronze-mid);
  border-radius: 6px;
  padding: clamp(6px, 1vh, 10px) clamp(10px, 1.5vw, 16px);
  margin-bottom: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.7);
}

.m3-lb-head-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(115, 85, 52, 0.35);
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.m3-lb-title {
  font-family: var(--font-serif);
  font-size: clamp(0.7rem, 1.1vh, 0.78rem);
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: 0.8px;
}

.m3-lb-hint {
  font-size: 0.62rem;
  color: var(--text-muted);
}

.m3-lb-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.m3-lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(0.68rem, 1vh, 0.74rem);
}

.m3-lb-table th {
  text-align: left;
  padding: 3px 6px;
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.m3-lb-table td {
  padding: 3px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: #dfd8cb;
}

.m3-lb-table tr.current-player-row {
  background: rgba(196, 87, 24, 0.3);
  font-weight: 700;
}

.m3-lb-table tr.current-player-row td {
  color: #fff;
  border-top: 1px solid var(--gold-antique);
  border-bottom: 1px solid var(--gold-antique);
}

.lb-you-badge {
  font-size: 0.55rem;
  background: var(--ember-mid);
  color: #fff;
  padding: 1px 4px;
  border-radius: 2px;
  margin-left: 4px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.m3-result-actions {
  display: flex;
  gap: 10px;
}
