/* ============================================================
   madChess Web — стилизация по DESIGN_SPEC.md (Qt/QML копия)
   ============================================================ */

:root {
  --bg: #4a3728;
  --toolbar: #33231a;
  --btn-normal: #60442f;
  --btn-hover: #6d4d36;
  --btn-pressed: #7a573c;
  --btn-disabled: #4a403a;
  --btn-text: #fff2dc;
  --btn-text-disabled: #9f938b;
  --btn-border: #c7a777;
  --btn-border-disabled: #6f625a;
  --btn-accent: #8a6820;
  --btn-accent-hover: #987426;
  --btn-accent-pressed: #a77d25;
  --cell-light: #f0d9b5;
  --cell-dark: #b58863;
  --status: #eadfd5;
  --status-check: #ffe7a6;
  --slot-white-a: #7b5b3d;
  --slot-white-b: #3c2a1e;
  --slot-black-a: #5a3c2a;
  --slot-black-b: #261a13;
  --slot-active: #ffe09a;
  --slot-inactive: #a98c72;
  --slot-inner: #22160f;
  --highlight: rgba(255, 224, 154, 0.65);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background-color: var(--bg);
  background-image: url(../assets/main_backgrownd_1.png);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--btn-text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------------- Кнопка WoodButton ---------------- */

.wood-btn {
  height: 52px;
  padding: 0 16px;
  border-radius: max(8px, calc(52px * 0.17));
  font-weight: bold;
  font-size: max(15px, calc(52px * 0.31));
  color: var(--btn-text);
  background: var(--btn-normal);
  border: 1px solid var(--btn-border);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background .12s ease;
}
.wood-btn:hover:not(:disabled) { background: var(--btn-hover); }
.wood-btn:active:not(:disabled) { background: var(--btn-pressed); }
.wood-btn:focus-visible { outline: none; border-color: #ffe09a; border-width: 2px; }
.wood-btn:disabled {
  background: var(--btn-disabled);
  color: var(--btn-text-disabled);
  border-color: var(--btn-border-disabled);
  cursor: default;
}
.wood-btn.accent { background: var(--btn-accent); }
.wood-btn.accent:hover:not(:disabled) { background: var(--btn-accent-hover); }
.wood-btn.accent:active:not(:disabled) { background: var(--btn-accent-pressed); }

/* ---------------- Тулбар ---------------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--toolbar);
  border-bottom: 1px solid rgba(199, 167, 119, 0.35);
  flex: 0 0 auto;
}
.toolbar-center {
  flex: 1;
  text-align: center;
  min-width: 0;
}
.app-title {
  font-size: 22px;
  font-weight: bold;
  color: #fff;
  letter-spacing: 0.5px;
}
.status {
  font-size: 14px;
  color: var(--status);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.check {
  color: var(--status-check);
  font-weight: bold;
}

/* ---------------- Игровая область ---------------- */

.game-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 12px;
  padding: 12px;
  align-items: center;
  justify-content: center;
}
.game-area.wide { flex-direction: row; }
.game-area.narrow { flex-direction: column; }

/* ---------------- Рамка доски ---------------- */

.board-frame {
  position: relative;
  padding: 6px;
  flex: 0 0 auto;
  background: #2a1c12;
  border-radius: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
}
.frame-top, .frame-bottom {
  position: absolute;
  left: 0; right: 0;
  height: 6px;
  background-image: url(../assets/dark_wood_profile_horizontal_1.png);
  background-repeat: repeat-x;
  background-size: auto 100%;
  z-index: 2;
}
.frame-top { top: 0; }
.frame-bottom { bottom: 0; }
.frame-left, .frame-right {
  position: absolute;
  top: 0; bottom: 0;
  width: 6px;
  background-image: url(../assets/dark_wood_profile_vertical_1.png);
  background-repeat: repeat-y;
  background-size: 100% auto;
  z-index: 2;
}
.frame-left { left: 0; }
.frame-right { right: 0; }

.board {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  background: var(--cell-light);
}

/* ---------------- Клетки ---------------- */

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell.light {
  background-color: var(--cell-light);
  background-image: url(../assets/derevo_dark.png);
  background-size: cover;
}
.cell.dark {
  background-color: var(--cell-dark);
  background-image: url(../assets/derevo_light.png);
  background-size: cover;
}

.coord {
  position: absolute;
  font-size: min(13px, 2.2vmin);
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 3px #000;
  pointer-events: none;
  line-height: 1;
  z-index: 3;
}
.coord.file-top { top: 3px; left: 50%; transform: translateX(-50%); }
.coord.file-bottom { bottom: 3px; left: 50%; transform: translateX(-50%); }
.coord.rank-left { left: 3px; top: 50%; transform: translateY(-50%); }
.coord.rank-right { right: 3px; top: 50%; transform: translateY(-50%); }

/* ---------------- Фигуры ---------------- */

.piece {
  width: 88%;
  height: 88%;
  object-fit: contain;
  cursor: grab;
  -webkit-user-drag: element;
  user-select: none;
  pointer-events: auto;
  position: relative;
  z-index: 4;
  animation: pieceIn 0.2s ease;
}
.piece:active { cursor: grabbing; }

@keyframes pieceIn {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------------- Подсветка ---------------- */

.cell.selected { box-shadow: inset 0 0 0 3px var(--slot-active); }
.cell.target-empty::after {
  content: '';
  position: absolute;
  width: 32%;
  height: 32%;
  border-radius: 50%;
  background: var(--highlight);
  opacity: 0.85;
  z-index: 5;
  pointer-events: none;
}
.cell.target-capture { box-shadow: inset 0 0 0 3px var(--highlight); }
.cell.ai-from { box-shadow: inset 0 0 0 3px #ff6b6b; }
.cell.ai-to { box-shadow: inset 0 0 0 3px #4ecdc4; }

/* ---------------- Резервы ---------------- */

.reserve {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 4px;
  padding: 6px;
  border-radius: 12px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(0, 0, 0, 0.35);
}
.reserve-white { background: linear-gradient(180deg, var(--slot-white-a), var(--slot-white-b)); }
.reserve-black { background: linear-gradient(180deg, var(--slot-black-a), var(--slot-black-b)); }

.slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12%;
  background: rgba(34, 22, 15, 0.22);
  border: 1px solid var(--slot-inactive);
}
.slot.active { border-color: var(--slot-active); box-shadow: 0 0 6px rgba(255, 224, 154, 0.35); }
.slot .piece { width: 82%; height: 82%; }

/* ---------------- Панель действий ---------------- */

.actions {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
  padding: 10px 16px 12px;
  justify-content: center;
  flex-wrap: wrap;
  background: var(--toolbar);
  border-top: 1px solid rgba(199, 167, 119, 0.35);
}

/* ---------------- Оверлеи и диалоги ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.overlay.show { display: flex; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dialog {
  background: linear-gradient(180deg, #6d4d36, #4a3728);
  border: 1px solid var(--btn-border);
  border-radius: 12px;
  padding: 24px;
  width: 420px;
  max-width: 94vw;
  max-height: 90vh;
  overflow-y: auto;
  color: var(--btn-text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  animation: dialogIn 0.2s ease;
}
@keyframes dialogIn { from { opacity: 0; transform: scale(0.92) translateY(10px); } to { opacity: 1; transform: none; } }
.dialog h2 { text-align: center; margin-bottom: 18px; font-size: 20px; color: #fff; }

.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 13px;
  color: #eadfd5;
  margin-bottom: 6px;
  letter-spacing: 0.4px;
}

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  font-weight: bold;
  font-size: 14px;
  color: var(--btn-text);
  background: var(--btn-normal);
  border: 1px solid var(--btn-border);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.seg-btn:hover { background: var(--btn-hover); }
.seg-btn.active {
  background: var(--btn-accent);
  border-color: var(--slot-active);
}

.dialog-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}
.dialog-actions .wood-btn { flex: 1 1 auto; }

/* Превращение пешки */
.promote-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.promote-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  background: var(--btn-normal);
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  color: var(--btn-text);
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.promote-btn:hover { background: var(--btn-hover); border-color: var(--slot-active); }
.promote-btn img { width: 72px; height: 72px; object-fit: contain; pointer-events: none; }

/* Результат */
.result-sub {
  text-align: center;
  font-size: 16px;
  color: var(--status);
  margin-top: -6px;
}

/* ---------------- Drawer «Ходы» ---------------- */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 90vw);
  background: var(--toolbar);
  border-left: 1px solid var(--btn-border);
  transform: translateX(102%);
  transition: transform 0.25s ease;
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(199, 167, 119, 0.35);
  flex: 0 0 auto;
}
.drawer-title { font-size: 18px; font-weight: bold; color: #fff; }
.drawer-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 12px;
}
.move-item {
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--btn-text);
}
.move-item:nth-child(odd) { background: rgba(255, 255, 255, 0.05); }
.move-item.ai { color: #cbb9a0; font-style: italic; }
.drawer-empty { color: var(--btn-text-disabled); text-align: center; padding: 24px 0; }

/* ---------------- Тост ---------------- */

.toast-container {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: #7a2f2f;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  animation: toastIn 0.2s ease;
}
.toast.info { background: #3d6b35; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
.toast.out { transition: opacity 0.3s ease, transform 0.3s ease; opacity: 0; transform: translateY(-8px); }

/* ---------------- Страницы (переключение) ---------------- */

.page { display: none; flex: 1 1 auto; min-height: 0; }
.page.active { display: flex; flex-direction: column; }
.page-center { align-items: center; justify-content: center; overflow-y: auto; padding: 20px; }

/* ---------------- Строка пользователя ---------------- */

.user-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  background: rgba(51, 35, 26, 0.6);
  border-bottom: 1px solid rgba(199, 167, 119, 0.25);
}
.user-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-nick {
  font-size: 15px;
  font-weight: bold;
  color: var(--btn-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

/* ---------------- Аватар ---------------- */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--slot-white-a), var(--slot-white-b));
  border: 1px solid var(--btn-border);
  color: var(--btn-text);
  font-weight: bold;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 96px; height: 96px; font-size: 40px; cursor: pointer; }
.avatar-lg:hover { border-color: var(--slot-active); }

/* ---------------- Карточка авторизации ---------------- */

.auth-card {
  width: 400px;
  max-width: 94vw;
  background: linear-gradient(180deg, #6d4d36, #4a3728);
  border: 1px solid var(--btn-border);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-title { text-align: center; font-size: 22px; color: #fff; margin: 0 0 4px; }

.auth-tabs {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 4px;
}
.auth-tab {
  flex: 1;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--btn-text);
  font-weight: bold;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
}
.auth-tab:hover { background: rgba(255, 255, 255, 0.08); }
.auth-tab.active { background: var(--btn-accent); }

.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form.hidden { display: none; }

.auth-social {
  text-align: center;
  color: var(--btn-text-disabled);
  font-size: 14px;
  padding: 6px 0;
  cursor: default;
}

/* ---------------- Поля ввода (деревянная тема) ---------------- */

.wood-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--btn-border);
  background: rgba(34, 22, 15, 0.55);
  color: var(--btn-text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.wood-input::placeholder { color: var(--btn-text-disabled); }
.wood-input:focus { border-color: var(--slot-active); }
textarea.wood-input { height: auto; padding: 10px 12px; resize: vertical; }
select.wood-input { cursor: pointer; }
select.wood-input option { background: #4a3728; color: var(--btn-text); }

/* ---------------- Карточка профиля ---------------- */

.profile-card {
  width: 420px;
  max-width: 94vw;
  background: linear-gradient(180deg, #6d4d36, #4a3728);
  border: 1px solid var(--btn-border);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.profile-rating { color: var(--status); font-size: 15px; }
.profile-rating span { font-weight: bold; color: var(--status-check); }

/* ---------------- Адаптивность ---------------- */

@media (max-width: 640px) {
  .toolbar { padding: 6px 8px; gap: 8px; }
  .toolbar .wood-btn { height: 44px; font-size: 15px; padding: 0 12px; }
  .app-title { font-size: 18px; }
  .status { font-size: 12px; }
  .game-area { gap: 8px; padding: 8px; }
  .actions { gap: 8px; padding: 8px; }
  .actions .wood-btn { flex: 1 1 45%; height: 46px; }
  .user-row { padding: 6px 8px; }
  .user-nick { max-width: 50vw; }
}
