/* Chess Coach — Pure OLED Black Minimalist Theme (JetBrains Mono) */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700;800&display=swap');

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

/* Полное удаление любых полос прокрутки (скроллбаров) */
html, body {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden !important;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
  background: #000000 !important;
  color: #f1f5f9;
  font-family: 'JetBrains Mono', -apple-system, BlinkMacSystemFont, monospace;
  display: flex;
  justify-content: center;
  align-items: center;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
*::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

/* Векторные SVG иконки */
.svg-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* Основной контейнер */
.app-layout {
  width: 100%;
  max-width: 500px;
  height: 100vh;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: space-between;
  overflow: hidden;
  background: #000000;
}

/* ========================================================================== */
/*  Шапка: 2 аккуратных ряда, кнопки никогда не ломаются                      */
/* ========================================================================== */
.app-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  flex-shrink: 0;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
}

.header-subrow {
  gap: 6px;
}

/* Переключатель стороны */
.side-switcher {
  display: flex;
  background: #0d0d0d;
  border: 1px solid #222222;
  border-radius: 8px;
  overflow: hidden;
  padding: 2px;
  flex: 1;
  max-width: 270px;
}

.side-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: transparent;
  border: none;
  color: #888888;
  padding: 5px 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border-radius: 6px;
  white-space: nowrap;
}

.side-btn:hover {
  background: #1a1a1a;
  color: #f1f5f9;
}

#btnSideW.active {
  background: #ffffff;
  color: #000000;
  font-weight: 800;
  box-shadow: 0 1px 4px rgba(255, 255, 255, 0.2);
}

#btnSideB.active {
  background: #161616;
  color: #38bdf8;
  border: 1px solid #38bdf8;
  font-weight: 800;
  box-shadow: 0 1px 4px rgba(56, 189, 248, 0.25);
}

#btnSideAuto.active {
  background: #2563eb;
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.4);
}

/* Переключатель режима Auto / Best */
.mode-switcher {
  display: flex;
  background: #0d0d0d;
  border: 1px solid #222222;
  border-radius: 8px;
  overflow: hidden;
  padding: 2px;
}

.mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: transparent;
  border: none;
  color: #888888;
  padding: 5px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  border-radius: 6px;
  white-space: nowrap;
}

.mode-btn:hover {
  background: #1a1a1a;
  color: #f1f5f9;
}

#btnModeAuto.active {
  background: rgba(34, 197, 94, 0.18);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.45);
}

#btnModeBest.active {
  background: linear-gradient(135deg, #ef4444, #f97316);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.45);
  font-weight: 800;
}

/* Кнопка рейтинга ELO */
.btn-rating {
  background: #0d0d0d;
  border: 1px solid #262626;
  color: #38bdf8;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-rating:hover {
  background: #161616;
  border-color: #38bdf8;
  color: #7dd3fc;
}

/* Кнопки действий (Ряд 2) */
.header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn-sm {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #0d0d0d;
  border: 1px solid #222222;
  color: #cbd5e1;
  padding: 5px 9px;
  border-radius: 7px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-sm:hover {
  background: #1a1a1a;
  color: #fff;
  border-color: #333333;
}

.btn-icon-only {
  padding: 5px 8px;
}

.btn-reset {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
  font-weight: 700;
}

.btn-reset:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
  color: #fca5a5;
}

.btn-reset.success {
  background: rgba(34, 197, 94, 0.25) !important;
  border-color: #22c55e !important;
  color: #4ade80 !important;
}

/* ========================================================================== */
/*  Доска                                                                     */
/* ========================================================================== */
.board-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #080808;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid #1a1a1a;
  flex: 1;
  min-height: 0;
  width: 100%;
}

/* Зафиксированный идеальный квадрат доски */
.board-container {
  position: relative;
  width: min(calc(100vw - 28px), 460px, calc(100dvh - 190px));
  height: min(calc(100vw - 28px), 460px, calc(100dvh - 190px));
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.85);
  flex-shrink: 0;
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.square.light {
  background: #ebecd0;
}

.square.dark {
  background: #779556;
}

/* Фигуры как на Chess.com (векторный SVG) */
.piece-svg-wrap {
  width: 90%;
  height: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.piece-svg {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
  transition: transform 0.15s ease-out;
}

.coord {
  position: absolute;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  pointer-events: none;
}

.coord-file {
  bottom: 2px;
  right: 3px;
}

.coord-rank {
  top: 2px;
  left: 3px;
}

.square.light .coord {
  color: #779556;
}

.square.dark .coord {
  color: #ebecd0;
}

.arrows-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* ========================================================================== */
/*  Карточка рекомендованного хода                                           */
/* ========================================================================== */
.recommendation-card {
  background: #080808;
  border: 1px solid #1a1a1a;
  border-radius: 10px;
  padding: 8px 12px;
  flex-shrink: 0;
}

.rec-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.rec-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: #555555;
  text-transform: uppercase;
  font-family: 'JetBrains Mono', monospace;
}

.state-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  letter-spacing: 0.3px;
  font-family: 'JetBrains Mono', monospace;
}

.state-normal,
.state-position,
.state-development {
  background: rgba(34, 197, 94, 0.18);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.state-attack {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.state-defense {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.state-counter {
  background: rgba(168, 85, 247, 0.18);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.4);
}

.state-capture {
  background: rgba(234, 179, 8, 0.2);
  color: #facc15;
  border: 1px solid rgba(234, 179, 8, 0.45);
}

.state-check {
  background: rgba(249, 115, 22, 0.2);
  color: #fb923c;
  border: 1px solid rgba(249, 115, 22, 0.45);
}

.state-mate {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.35), rgba(234, 179, 8, 0.35));
  color: #fef08a;
  border: 1px solid rgba(234, 179, 8, 0.55);
  font-weight: 800;
  box-shadow: 0 0 10px rgba(234, 179, 8, 0.3);
}

.state-castling {
  background: rgba(20, 184, 166, 0.18);
  color: #2dd4bf;
  border: 1px solid rgba(20, 184, 166, 0.4);
}

.state-waiting {
  background: rgba(38, 38, 38, 0.5);
  color: #888888;
  border: 1px solid #333333;
}

.state-tension {
  background: rgba(234, 179, 8, 0.18);
  color: #facc15;
  border: 1px solid rgba(234, 179, 8, 0.4);
}

.state-rescue {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.state-brilliant {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.45);
}

.rec-body {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rec-move-san {
  font-family: 'JetBrains Mono', monospace;
  font-size: 26px;
  font-weight: 800;
  color: #38bdf8;
  min-width: 55px;
  font-variant-numeric: tabular-nums;
}

.rec-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.rec-reason {
  font-size: 12px;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rec-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 1px;
}

.rec-timing-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: #141414;
  border: 1px solid #2a2a2a;
  color: #93c5fd;
  white-space: nowrap;
}

.rec-timing-badge.timing-slow {
  background: rgba(234, 179, 8, 0.15);
  border-color: rgba(234, 179, 8, 0.4);
  color: #facc15;
}

.rec-timing-badge.timing-predict {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
  color: #4ade80;
}

.rec-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #666666;
  font-variant-numeric: tabular-nums;
}

/* ========================================================================== */
/*  Модальные окна                                                            */
/* ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  padding: 16px;
}

.modal-card {
  background: #0a0a0a;
  border: 1px solid #262626;
  border-radius: 12px;
  padding: 16px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.9);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: #38bdf8;
  margin-bottom: 8px;
}

.modal-close {
  background: transparent;
  border: none;
  color: #888888;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: #fff;
}

.modal-desc {
  font-size: 11px;
  color: #aaaaaa;
  line-height: 1.4;
  margin-bottom: 12px;
}

.modal-link-box {
  display: flex;
  gap: 6px;
}

#mobileLinkInput,
#ratingInput {
  flex: 1;
  background: #141414;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  color: #38bdf8;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
  outline: none;
}

#mobileLinkInput {
  color: #4ade80;
  font-size: 11px;
}

.btn-copy {
  background: #2563eb;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-copy:hover {
  background: #1d4ed8;
}

.rating-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.preset-btn {
  background: #141414;
  border: 1px solid #262626;
  color: #888888;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  padding: 4px 7px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
}

.preset-btn:hover {
  background: #1e1e1e;
  color: #38bdf8;
  border-color: #38bdf8;
}

/* ========================================================================== */
/*  Экран авторизации (для веб-панели)                                        */
/* ========================================================================== */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999999;
  padding: 16px;
}

.auth-card {
  background: #0a0a0a;
  border: 1px solid #222222;
  border-radius: 14px;
  padding: 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.95);
}

.auth-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.auth-title {
  font-size: 15px;
  font-weight: 700;
  color: #f1f5f9;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 11px;
  color: #777777;
  margin-bottom: 16px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-field label {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.auth-field input {
  background: #141414;
  border: 1px solid #262626;
  border-radius: 6px;
  color: #f1f5f9;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s;
}

.auth-field input:focus {
  border-color: #38bdf8;
}

.auth-error {
  color: #f87171;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.btn-auth {
  background: #2563eb;
  border: none;
  border-radius: 6px;
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.15s;
}

.btn-auth:hover {
  background: #1d4ed8;
}

/* ========================================================================== */
/*  Адаптивность под смартфоны                                                */
/* ========================================================================== */
@media (max-width: 540px) {
  .app-layout {
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding: 6px 8px;
    gap: 6px;
  }
  .side-btn,
  .mode-btn,
  .btn-sm {
    padding: 5px 6px;
    font-size: 10px;
  }
  .board-wrapper {
    padding: 4px;
  }
}
