/* ============================================================
   Начална страница и лоби — Имоти и Империи
   ============================================================ */

/* --- Начална страница --- */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: clamp(0.7rem, 2.5vh, 1.8rem) 1rem 4.5rem;
  gap: 1.25rem;
}

.landing .logo {
  width: min(860px, 96vw);
  text-align: center;
}

.landing-card {
  width: min(430px, 94vw);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.landing-card label {
  font-size: 0.85rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 0.25rem;
}

.landing-card input { width: 100%; }

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

#join-code { text-transform: uppercase; letter-spacing: 0.28em; font-weight: 700; }

.divider {
  display: flex;
  align-items: center;
  gap: 0.8em;
  color: var(--ink-soft);
  font-size: 0.82rem;
  margin: 0.2rem 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(90, 100, 116, 0.35);
}

.landing-footer {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.site-credit {
  position: fixed;
  right: 1.1rem;
  bottom: 0.8rem;
  z-index: 20;
  color: rgba(236, 241, 248, 0.7);
  font-size: 0.78rem;
  text-align: right;
}

/* --- Правила --- */
.rules-modal {
  max-width: min(980px, 94vw);
  padding: clamp(1.1rem, 3vw, 2rem);
}

.rules-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid rgba(122, 74, 28, 0.2);
}

.rules-heading h3 {
  margin: 0.15rem 0 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
}

.rules-kicker {
  color: #8a622d;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.rules-close {
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(88, 61, 32, 0.1);
  color: #583d20;
  font-size: 1.65rem;
  line-height: 1;
  cursor: pointer;
}

.rules-close:hover { background: rgba(88, 61, 32, 0.18); }

.rules-lead {
  margin: 1rem 0 0;
  padding: 0.85rem 1rem;
  border-left: 4px solid #a66b2c;
  background: rgba(166, 107, 44, 0.08);
  line-height: 1.55;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 1.8rem;
  margin-top: 0.65rem;
}

.rules-section {
  padding: 1rem 0;
  border-bottom: 1px solid rgba(88, 61, 32, 0.16);
}

.rules-section h4 {
  margin: 0 0 0.45rem;
  color: #6f431b;
  font-size: 1rem;
}

.rules-section ul {
  margin: 0;
  padding-left: 1.2rem;
}

.rules-section li {
  margin: 0.28rem 0;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* --- Лоби --- */
.lobby-wrap {
  max-width: 1060px;
  margin: 0 auto;
  padding: 1.6rem 1rem 0.6rem;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.2rem;
}
.lobby-wrap > .panel { align-self: start; }
/* Настройките (само за домакина) заемат дясната колона в две редици,
   а чатът запълва мястото под играчите — без празни дупки. */
@media (min-width: 761px) {
  .lobby-wrap > #settings-panel { grid-column: 2; grid-row: 2 / span 2; }
  .lobby-wrap > .chat-box { grid-column: 1; align-self: stretch; }
  .lobby-wrap .chat-messages { max-height: none; }
}
/* Широк екран: три колони — играчи | настройки | чат. */
@media (min-width: 1240px) {
  .lobby-wrap:not(:has(> #settings-panel.hidden)) {
    max-width: 1520px;
    grid-template-columns: 1.15fr 1.05fr 0.95fr;
  }
  .lobby-wrap:not(:has(> #settings-panel.hidden)) > #settings-panel { grid-row: 2; }
  .lobby-wrap:not(:has(> #settings-panel.hidden)) > .chat-box { grid-column: 3; grid-row: 2; }
}
/* Гост без панел с настройки: една централна колона. */
@media (min-width: 761px) {
  .lobby-wrap:has(> #settings-panel.hidden) { max-width: 720px; grid-template-columns: 1fr; }
  .lobby-wrap:has(> #settings-panel.hidden) > .chat-box { grid-column: 1; }
}
.lobby-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.8rem;
}
.lobby-header .logo { font-size: 1.7rem; }

.room-code-box {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--bg-raised);
  border: 1px dashed rgba(230, 195, 107, 0.5);
  border-radius: var(--radius-md);
  padding: 0.5rem 1rem;
}
.room-code-box .code {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--gold);
}

.player-list { display: flex; flex-direction: column; gap: 0.55rem; }

.player-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(11, 22, 38, 0.5);
  border: 1px solid rgba(230, 195, 107, 0.12);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.9rem;
}
.player-row .p-token {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
}
.player-row .p-token svg { width: 100%; height: 100%; }
.player-row .p-name { font-weight: 700; flex: 1; }
.player-row .p-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2em 0.7em;
  border-radius: 20px;
  letter-spacing: 0.03em;
}
.p-badge.host { background: rgba(230, 195, 107, 0.18); color: var(--gold); }
.p-badge.ready { background: rgba(63, 174, 122, 0.2); color: #6fd3a5; }
.p-badge.waiting { background: rgba(168, 179, 196, 0.15); color: var(--text-dim); }
.p-badge.offline { background: rgba(208, 85, 69, 0.2); color: #e59084; }
.p-badge.spectator { background: rgba(74, 157, 181, 0.2); color: #7cc4d8; }
.p-badge.bot { background: rgba(185, 138, 221, 0.18); color: #d2afe9; }
.p-badge.gender-male { background: rgba(25, 118, 201, 0.2); color: #78bdf3; }
.p-badge.gender-female { background: rgba(192, 38, 120, 0.2); color: #f29bc9; }
.lobby-remove-bot { width: 30px; height: 30px; flex: none; font-size: 1.25rem; }

.avatar-picker-heading {
  margin-top: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}
.avatar-picker-heading h3 { margin: 0; }

.gender-picker {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  padding: 3px;
  border: 1px solid rgba(230, 195, 107, 0.24);
  border-radius: 7px;
  background: rgba(5, 12, 24, 0.58);
}
.gender-picker button {
  min-height: 34px;
  padding: 0.35rem 0.75rem;
  border: 0;
  border-radius: 5px;
  color: var(--text-dim);
  background: transparent;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.38rem;
}
.gender-picker .gender-symbol { font-size: 1.25rem; line-height: 1; }
.gender-picker button.active {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.gender-picker button[data-gender="male"].active { color: #fff; background: #1976c9; }
.gender-picker button[data-gender="female"].active { color: #fff; background: #c02678; }
.gender-picker button:disabled { cursor: default; }

.token-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.token-choice {
  position: relative;
  min-width: 0;
  min-height: 82px;
  background: rgba(11, 22, 38, 0.55);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.35rem 0.25rem 0.45rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  color: var(--text-light);
  cursor: pointer;
}
.token-choice svg { width: 46px; height: 46px; }
.token-choice-name {
  max-width: 100%;
  color: var(--text-dim);
  font-size: 0.69rem;
  font-weight: 700;
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.token-swatch {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.token-choice.selected { border-color: var(--gold); background: rgba(230, 195, 107, 0.12); }
.token-choice.selected .token-choice-name { color: var(--gold-soft); }
.token-choice.taken { opacity: 0.28; cursor: not-allowed; }
.token-choice:nth-child(2n) .avatar-figure { animation-delay: -0.45s; }
.token-choice:nth-child(3n) .avatar-figure { animation-delay: -0.9s; }

/* Кожа, коса, прическа — под избора на цвят. Цветът остава главният избор
   (уникален в стаята), затова тези редове са по-дребни и без рамки. */
.look-picker {
  margin-top: 0.85rem;
  display: grid;
  gap: 0.55rem;
}
.look-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.look-label {
  flex: none;
  min-width: 62px;
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 700;
}
.look-swatches {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.look-swatch {
  width: 26px;
  height: 26px;
  flex: none;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}
.look-swatch.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(230, 195, 107, 0.28), 0 1px 3px rgba(0, 0, 0, 0.45);
}
.look-swatch:disabled { cursor: default; opacity: 0.45; }

.hairstyle-picker {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.hairstyle-choice {
  flex: none;
  width: 52px;
  padding: 0.2rem 0.1rem 0.25rem;
  background: rgba(11, 22, 38, 0.55);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
}
.hairstyle-choice .head-preview { width: 34px; height: 30px; }
.hairstyle-name {
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.hairstyle-choice.selected {
  border-color: var(--gold);
  background: rgba(230, 195, 107, 0.12);
}
.hairstyle-choice.selected .hairstyle-name { color: var(--gold-soft); }
.hairstyle-choice:disabled { cursor: default; opacity: 0.45; }

.settings-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.85rem 0.9rem;
  /* Контролата се подравнява със заглавието (първия ред на етикета),
     не с центъра на целия двуреден блок заглавие + описание. */
  align-items: start;
  font-size: 0.92rem;
}
/* Всяко поле в лявата колона: заглавие отгоре, описание отдолу. */
.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  color: var(--text-dim);
  cursor: pointer;
}
.settings-grid label > span { line-height: 1.25; }
/* Секционни заглавия — списъкът е дълъг и без тях се чете трудно. */
.settings-grid .set-group {
  grid-column: 1 / -1;
  margin-top: 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid rgba(230, 195, 107, 0.22);
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.settings-grid .set-group:first-child { margin-top: 0; }
.settings-grid .set-hint {
  color: rgba(168, 179, 196, 0.62);
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.3;
}
/* Контролите се снишават леко, за да седят срещу реда със заглавието. */
.settings-grid input,
.settings-grid select { margin-top: 0.1rem; }
.settings-grid input[type="number"] { width: 108px; padding: 0.35em 0.6em; }
.settings-grid input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--copper); justify-self: end; }
.settings-grid select { padding: 0.35em 0.6em; }
.settings-grid input:disabled { opacity: 0.45; cursor: not-allowed; }
/* Изключеното описание (напр. размер на субсидията) също потъмнява. */
.settings-grid label:has(+ input:disabled) .set-hint { opacity: 0.5; }
.bot-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  margin-top: 0.65rem;
}
.bot-controls select { min-width: 0; }

/* --- Чат (споделен между лоби и игра) --- */
.chat-box { display: flex; flex-direction: column; min-height: 0; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.4rem 0.2rem;
  min-height: 120px;
  max-height: 260px;
}
.chat-line { font-size: 0.9rem; word-break: break-word; }
.chat-line .who { font-weight: 700; color: var(--gold-soft); }
.chat-form { position: relative; display: flex; align-items: stretch; gap: 0.5rem; margin-top: 0.5rem; }
.chat-form input { flex: 1; min-width: 0; }
.chat-emoji-toggle {
  flex: 0 0 40px;
  width: 40px;
  padding: 0;
  color: #fff;
  background: rgba(22, 41, 74, 0.9);
  border: 1px solid rgba(230, 195, 107, 0.3);
  border-radius: 9px;
  font-size: 1.15rem;
  line-height: 1;
}
.chat-emoji-toggle[aria-expanded="true"] {
  color: #251906;
  background: var(--gold);
}
.chat-emoji-picker {
  position: absolute;
  left: 0;
  bottom: calc(100% + 0.4rem);
  z-index: 125;
  display: grid;
  grid-template-columns: repeat(6, 32px);
  gap: 0.25rem;
  width: max-content;
  max-width: calc(100vw - 1.5rem);
  padding: 0.5rem;
  background: rgba(8, 17, 31, 0.98);
  border: 1px solid rgba(230, 195, 107, 0.42);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.56);
}
.chat-emoji-picker button {
  width: 32px;
  height: 32px;
  padding: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 1.1rem;
  line-height: 1;
}
.chat-emoji-picker button:hover,
.chat-emoji-picker button:focus-visible {
  background: rgba(230, 195, 107, 0.2);
  border-color: rgba(230, 195, 107, 0.5);
  outline: none;
  transform: scale(1.12);
}

/* Лентата със старт-бутона е прилепнала към долния ръб на екрана —
   винаги видима, независимо колко е висока страницата. */
.lobby-actions {
  grid-column: 1 / -1;
  position: sticky;
  bottom: 0;
  z-index: 40;
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0.2rem 0 0;
  padding: 0.75rem 0 0.9rem;
  background: linear-gradient(to top, #050914 72%, rgba(5, 9, 20, 0));
}

@media (max-width: 760px) {
  .lobby-wrap { grid-template-columns: minmax(0, 1fr); }
  .lobby-wrap > * { min-width: 0; }
  .room-code-box { max-width: 100%; flex-wrap: wrap; }
  .player-row { flex-wrap: wrap; }
  .player-row .p-name { min-width: 86px; }
  .token-picker { grid-template-columns: repeat(4, minmax(58px, 1fr)); }
  .rules-grid { grid-template-columns: 1fr; }
  .site-credit {
    right: 0.7rem;
    bottom: 0.55rem;
    font-size: 0.7rem;
  }
}
