/* ============================================================
   Платформа настольных игр — главный файл стилей
   Стиль: INK (бумага и чернила, книжная эстетика)
   Адаптивность: мобильные, планшеты, десктоп, 2K, 4K
   ============================================================ */

:root {
  --color-bg:            #F5F0E8;
  --color-surface:       #FFFFFF;
  --color-border:        #8B7355;
  --color-text:          #1A1A1A;
  --color-text-dim:      #6B5B4F;
  --color-accent:        #2C2C2C;
  --color-highlight:     #000000;
  --font-body:           'Georgia', 'Times New Roman', serif;
  --font-mono:           'JetBrains Mono', 'Courier New', monospace;
  --font-size-xs:        0.75rem;
  --font-size-sm:        0.875rem;
  --font-size-base:      1.125rem;
  --font-size-lg:        1.375rem;
  --font-size-xl:        1.75rem;
  --font-size-2xl:       2.25rem;
  --radius-sm:           4px;
  --shadow-card:         0 2px 8px rgba(44, 44, 44, 0.08);
  --chat-width:          320px;
}

/* ============================================================
   ТЁМНАЯ ТЕМА
   ============================================================ */
body.dark {
  --color-bg:            #1A1A1A;
  --color-surface:       #2C2C2C;
  --color-border:        #4A4A4A;
  --color-text:          #E8E0D5;
  --color-text-dim:      #9B8B7A;
  --color-accent:        #D4C5B2;
  --color-highlight:     #FFFFFF;
}

body.dark .btn:hover {
  background: #3A3A3A;
  color: #FFFFFF;
  border-color: #FFFFFF;
}

body.dark .btn--outline:hover {
  background: #FFFFFF;
  color: #1A1A1A;
}

/* Плавный переход тем */
body, body *, :root {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Автоопределение системной темы */
@media (prefers-color-scheme: dark) {
  body:not(.light):not(.dark) {
    --color-bg:            #1A1A1A;
    --color-surface:       #2C2C2C;
    --color-border:        #4A4A4A;
    --color-text:          #E8E0D5;
    --color-text-dim:      #9B8B7A;
    --color-accent:        #D4C5B2;
    --color-highlight:     #FFFFFF;
  }
}

/* ============================================================
   РЕЖИМ ДЛЯ СЛАБОВИДЯЩИХ
   ============================================================ */
body.a11y-contrast {
  --color-bg: #000000;
  --color-surface: #000000;
  --color-border: #FFFFFF;
  --color-text: #FFFFFF;
  --color-text-dim: #CCCCCC;
  --color-accent: #FFFF00;
  --color-highlight: #FFFFFF;
}

body.a11y-large {
  --font-size-base: 1.5rem;
  --font-size-lg: 1.75rem;
  --font-size-xl: 2rem;
  --font-size-2xl: 2.5rem;
}

body.a11y-outline .btn {
  border: 3px solid currentColor;
}

body.a11y-outline .sidebar__item {
  border: 1px solid currentColor;
  margin-bottom: 2px;
}

body.a11y-outline .header__nav a {
  border-bottom: 2px solid currentColor;
}

body.a11y-outline a {
  text-decoration: underline;
  text-underline-offset: 4px;
}

body.a11y-no-anim * {
  animation: none !important;
  transition: none !important;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.5;
  overflow-y: auto;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  overflow-y: auto;
}

h1, h2, h3 {
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--color-highlight);
  line-height: 1.3;
}

h1 {
  font-size: var(--font-size-2xl);
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 0.5rem;
}

h2 { font-size: var(--font-size-xl); margin-bottom: 1rem; }
h3 { font-size: var(--font-size-lg); margin-bottom: 0.75rem; }

a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:hover { color: var(--color-highlight); }

p { margin-bottom: 1rem; }

/* ============================================================
   КОНТЕЙНЕР — адаптивный
   ============================================================ */
.container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem clamp(1rem, 3vw, 3rem);
}

/* ============================================================
   КНОПКИ
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.5rem;
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  color: var(--color-bg);
  background: var(--color-accent);
  border: 2px solid var(--color-accent);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.btn:hover {
  background: var(--color-bg);
  color: var(--color-accent);
}

.btn--outline {
  background: transparent;
  color: var(--color-accent);
}

.btn--outline:hover {
  background: var(--color-accent);
  color: var(--color-bg);
}

.btn--small {
  padding: 0.35rem 1rem;
  font-size: var(--font-size-sm);
}

/* ============================================================
   ШАПКА
   ============================================================ */
.header {
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  padding: 0.75rem clamp(1rem, 3vw, 3rem);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-card);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header__logo {
  font-family: var(--font-body);
  font-size: clamp(1rem, 2.5vw, var(--font-size-xl));
  font-weight: 700;
  color: var(--color-highlight);
}

.header__nav {
  display: flex;
  gap: clamp(0.5rem, 2vw, 2rem);
  flex-wrap: wrap;
}

.header__nav a {
  font-family: var(--font-body);
  font-size: clamp(0.8rem, 1.5vw, var(--font-size-base));
  color: var(--color-text);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  padding-bottom: 2px;
  transition: border-color 0.2s;
}

.header__nav a:hover,
.header__nav a.active {
  border-color: var(--color-accent);
  color: var(--color-highlight);
}

.header__user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: clamp(0.8rem, 1.5vw, var(--font-size-base));
}

/* ============================================================
   КАРТОЧКИ
   ============================================================ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: clamp(1rem, 2vw, 1.5rem);
  margin-bottom: 1rem;
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-sm);
}

.card__header {
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card__title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-highlight);
}

/* ============================================================
   ФОРМЫ
   ============================================================ */
.form-group { margin-bottom: 1.25rem; }

.form-label {
  display: block;
  font-size: var(--font-size-base);
  color: var(--color-text-dim);
  margin-bottom: 0.35rem;
}

.form-input {
  width: 100%;
  padding: 0.65rem;
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  outline: none;
  transition: border-color 0.2s;
  border-radius: var(--radius-sm);
}

.form-input:focus { border-color: var(--color-accent); }

/* ============================================================
   МОДАЛЬНОЕ ОКНО
   ============================================================ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(26, 26, 26, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  padding: clamp(1rem, 3vw, 2rem);
  width: clamp(320px, 90vw, 520px);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-sm);
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
}

.modal__title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-highlight);
}

.modal__close {
  background: none;
  border: none;
  font-size: var(--font-size-xl);
  cursor: pointer;
  color: var(--color-text-dim);
}

/* ============================================================
   ТАБЛИЦА
   ============================================================ */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(0.75rem, 1.5vw, var(--font-size-base));
}

.table th {
  text-align: left;
  color: var(--color-text-dim);
  font-weight: 700;
  padding: 0.75rem;
  border-bottom: 2px solid var(--color-border);
}

.table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

/* ============================================================
   ИГРОВОЙ МАКЕТ — с боковой панелью чата
   ============================================================ */
.game-layout {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
}

.game-layout__main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(0.5rem, 2vw, 2rem);
  min-width: 0;
}

.game-layout__chat {
  width: var(--chat-width);
  background: var(--color-surface);
  border-left: 2px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.game-layout__chat-header {
  background: var(--color-accent);
  color: var(--color-bg);
  padding: 0.5rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: var(--font-size-sm);
  cursor: pointer;
}

.game-layout__chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  font-size: var(--font-size-sm);
  background: var(--color-bg);
}

.game-layout__chat-input {
  display: flex;
  border-top: 1px solid var(--color-border);
}

.game-layout__chat-input input {
  flex: 1;
  padding: 0.65rem;
  border: none;
  background: var(--color-surface);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  outline: none;
}

.game-layout__chat-input button {
  padding: 0.65rem 1rem;
  background: var(--color-accent);
  color: var(--color-bg);
  border: none;
  cursor: pointer;
}

/* ============================================================
   ЧАТ НА МОБИЛЬНОМ — полноэкранный
   ============================================================ */
.chat-mobile-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: var(--color-surface);
  z-index: 1500;
  flex-direction: column;
}

.chat-mobile-overlay.open {
  display: flex;
}

.chat-mobile-overlay__header {
  background: var(--color-accent);
  color: var(--color-bg);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}

.chat-mobile-overlay__close {
  background: none;
  border: none;
  color: var(--color-bg);
  font-size: 1.5rem;
  cursor: pointer;
}

.chat-mobile-overlay__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  font-size: var(--font-size-base);
  background: var(--color-bg);
}

.chat-mobile-overlay__input {
  display: flex;
  border-top: 2px solid var(--color-border);
  padding: 0.5rem;
}

.chat-mobile-overlay__input input {
  flex: 1;
  padding: 0.75rem;
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  outline: none;
  border-radius: var(--radius-sm);
}

.chat-mobile-overlay__input button {
  padding: 0.75rem 1.25rem;
  background: var(--color-accent);
  color: var(--color-bg);
  border: none;
  margin-left: 0.5rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

/* Кнопка открытия чата (мобильный) */
.chat-fab {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-bg);
  font-size: 1.5rem;
  border: none;
  cursor: pointer;
  z-index: 400;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* ============================================================
   СЕТКА
   ============================================================ */
.grid {
  display: grid;
  gap: clamp(1rem, 2vw, 1.5rem);
}

.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
  .grid--4 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: repeat(2, 1fr); }
  
  :root { --chat-width: 0px; }
  
  .game-layout__chat {
    display: none;
  }
  
  .chat-fab {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
  html { font-size: 14px; }
  .header { flex-direction: column; text-align: center; }
}

/* ============================================================
   2K и 4K экраны
   ============================================================ */
@media (min-width: 2560px) {
  html { font-size: 20px; }
  .container { max-width: 2000px; }
  :root { --chat-width: 400px; }
}

/* ============================================================
   ДОСТУПНОСТЬ
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.friends-subtab { 
  text-decoration: none; 
  color: var(--color-text-dim); 
  font-size: 0.9rem; 
  padding: 0.5rem 1rem;
  border-bottom: 2px solid transparent;
  transition: color 0.2s;
}
.friends-subtab:hover { color: var(--color-text); }
.friends-subtab.active { 
  color: var(--color-accent); 
  border-bottom-color: var(--color-accent); 
  font-weight: 700; 
}

.friend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  transition: background 0.15s;
}
.friend-row:hover { background: var(--color-bg); }

.friend-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--color-bg);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-online { background: #4CAF50; }
.status-ingame { background: #FF9800; }
.status-offline { background: #9E9E9E; }

.btn--icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--color-text-dim);
  font-size: 1rem;
  transition: all 0.15s;
}
.btn--icon:hover {
  background: var(--color-bg);
  color: var(--color-accent);
}

.pinned-section {
  background: var(--color-bg);
  border-radius: 10px;
  padding: 0.5rem;
  margin-bottom: 1rem;
}
.privacy-option {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem 0;
  border-bottom: 1px solid var(--color-border);
  gap: 1rem;
}
.privacy-option:last-child { border-bottom: none; }
.privacy-option select,
.privacy-option .form-input {
  flex-shrink: 0;
}

#incoming-requests .friend-row {
  display: flex !important;
  min-height: 40px;
}

/* ============================================================
   ПУБЛИЧНЫЙ ПРОФИЛЬ
   ============================================================ */
.profile-header {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}
.profile-avatar {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid var(--color-border);
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-info h1 { margin-bottom: 0.25rem; }
.profile-info .status { font-size: 0.9rem; color: var(--color-text-dim); }
.profile-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 1.25rem 1rem;
  border-radius: 8px;
  text-align: center;
}
.stat-card .value { font-size: 2rem; font-weight: 700; color: var(--color-accent); }
.stat-card .label { font-size: 0.85rem; color: var(--color-text-dim); }
.hidden-message { text-align: center; padding: 3rem; color: var(--color-text-dim); }
.status-away { background: #FFC107; }
.status-dnd { background: #F44336; }

.gcm-emoji-panel {
  position: absolute;
  bottom: 40px;
  left: 0;
  z-index: 9999;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  max-height: 250px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  width: 300px;
}

body { overflow-y: auto; }