* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #161512;
  color: #c9c8c5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* Только мобилы: блокирующий экран при открытии не с телефона */
.mobile-only-block {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #161512;
  color: #bababa;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.mobile-only-block.active {
  display: flex;
}

.mobile-only-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin: 0 0 16px;
}

.mobile-only-text {
  font-size: 1.1rem;
  margin: 0 0 8px;
}

.mobile-only-hint {
  font-size: 0.9rem;
  color: #888;
  margin: 0;
}

body.mobile-blocked #app {
  display: none !important;
}

.build-info {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(6px + env(safe-area-inset-bottom));
  z-index: 15;
  text-align: center;
  font-size: 0.67rem;
  color: #6f6e6b;
  background: rgba(12, 12, 11, 0.72);
  border: 1px solid #2b2a27;
  border-radius: 6px;
  padding: 3px 6px;
  pointer-events: none;
  backdrop-filter: blur(2px);
}

#app {
  min-height: 100vh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.screen {
  display: none;
  flex-direction: column;
  align-items: stretch;
  padding: 10px 10px 14px;
  min-height: 100vh;
}

.screen.active {
  display: flex;
}

/* Лобби */
#lobby-screen .title {
  margin: 16px 0 6px;
  font-size: 1.45rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
}

.subtitle {
  margin: 0 0 14px;
  color: #8f8e8a;
  font-size: 0.9rem;
  text-align: center;
}

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.mode-btn {
  background: #2a2926;
  color: #fff;
  border: 1px solid #3a3935;
  padding: 14px 10px;
  font-size: 1.2rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.mode-btn:active {
  background: #373632;
}

.mode-btn .queue-count {
  font-size: 0.75rem;
  color: #8c8b87;
  font-weight: normal;
}

.mode-btn.in-queue {
  background: #2d4a2d;
  border-color: #5a9a5a;
}

.mode-btn.in-queue .queue-count {
  color: #8fcc8f;
}

.ws-status {
  margin-top: 14px;
  font-size: 0.8rem;
  color: #767572;
  text-align: center;
}

.btn-private-game {
  width: 100%;
  max-width: 420px;
  margin: 10px auto 0;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid #4c5f86;
  background: #2b3a57;
  color: #e2ecff;
  font-size: 0.92rem;
}

.lobby-tools {
  width: 100%;
  max-width: 420px;
  margin: 8px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lobby-tools .btn-private-game {
  margin: 0;
}

#login-input {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid #3a3935;
  background: #161512;
  color: #d0cfcc;
  padding: 0 10px;
}

#login-form-wrap {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.private-waiting-panel {
  display: none;
  width: 100%;
  max-width: 420px;
  margin: 10px auto 0;
  border: 1px solid #4c5f86;
  background: #222e45;
  border-radius: 10px;
  padding: 10px 12px;
}

.private-waiting-panel.active {
  display: block;
}

.private-waiting-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #e2ecff;
}

.private-waiting-text {
  margin-top: 4px;
  font-size: 0.82rem;
  color: #c4d3f0;
  line-height: 1.35;
}

.private-time-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(12, 12, 11, 0.72);
  padding: 16px;
}

.private-time-modal.active {
  display: flex;
}

.private-time-card {
  width: min(420px, 100%);
  border-radius: 12px;
  border: 1px solid #3a3935;
  background: #1f1e1b;
  padding: 12px;
}

.private-time-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 10px;
}

.private-time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.private-time-grid .mode-btn {
  padding: 10px 8px;
  font-size: 1rem;
}

.bot-difficulty-hint {
  font-size: 0.82rem;
  color: #9a9893;
  margin: 0 0 12px;
  line-height: 1.35;
}

.mode-btn.bot-level-locked {
  opacity: 0.42;
  pointer-events: none;
  cursor: not-allowed;
}

.mode-btn.bot-level-ok .bot-level-sub {
  display: block;
  font-size: 0.75rem;
  color: #7a9a6a;
  margin-top: 4px;
}

.mode-btn.bot-level-ok .bot-level-sub.muted {
  color: #7d7c78;
}

.btn-private-time-close {
  margin-top: 10px;
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid #3a3935;
  background: #2a2926;
  color: #d0cfcc;
}

.ws-status.connected {
  color: #5a9a5a;
}

.ws-status.error {
  color: #c55;
}

/* Игра */
#game-screen {
  padding: 6px 6px 10px;
}

.game-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 8px;
}

.btn-back {
  background: #2a2926;
  border: 1px solid #3a3935;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
}

.btn-back:active {
  background: #373632;
}

#game-info {
  font-size: 0.82rem;
  color: #999894;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.game-alert {
  display: none;
  margin: 0 auto 8px;
  max-width: 480px;
  font-size: 0.78rem;
  border-radius: 8px;
  padding: 6px 8px;
  border: 1px solid #3a3935;
  background: #262522;
  color: #cfcfcb;
}

.game-alert.active {
  display: block;
}

.game-alert.warning {
  border-color: #a1733e;
  background: #3a2c1f;
  color: #ffd9a9;
}

.game-alert.info {
  border-color: #4b6aa0;
  background: #273247;
  color: #d8e6ff;
}

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
}

.player-meta {
  min-width: 0;
  flex: 1;
}

.player-row-top {
  margin-bottom: -1px;
}

.player-row-bottom {
  margin-top: -2px;
}

.material-captured {
  width: 100%;
  max-width: min(100vw - 12px, 480px);
  margin: 0 auto;
  min-height: 1.35rem;
  padding: 2px 6px;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0.12em;
  color: #c4c3bf;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.material-captured .material-pile {
  opacity: 0.92;
}

.material-balance {
  width: 100%;
  max-width: min(100vw - 12px, 480px);
  margin: 0 auto;
  text-align: center;
  font-size: 0.78rem;
  color: #9a988f;
  padding: 0 4px 2px;
  min-height: 1rem;
}

.material-balance-val {
  font-family: "Roboto Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.game-your-side {
  font-size: 0.73rem;
  color: #6fa650;
  margin-top: 2px;
  line-height: 1.2;
}

.clock-label {
  font-size: 0.8rem;
  color: #a8a7a3;
  line-height: 1.2;
}

.clock {
  font-family: "Roboto Mono", "Lucida Console", Monaco, monospace;
  font-size: 2rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 4px;
  background: #2b2a27;
  color: #d8d8d5;
  text-align: center;
  min-width: 4.6ch;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.clock.low-time {
  color: #c55;
}

.clock.our-turn {
  box-shadow: inset 0 -2px 0 0 #77a23f;
  background: #353a2f;
  color: #eef3e7;
}

.clock.opp-turn {
  box-shadow: inset 0 -2px 0 0 #6b819c;
  background: #2f3338;
  color: #dfe7ef;
}

/* Доска (Lichess: светлые/тёмные клетки) */
.board-wrap {
  width: 100%;
  max-width: min(100vw - 12px, 480px);
  margin: 0 auto;
  aspect-ratio: 1;
  position: relative;
}

.ping-indicator {
  margin: 2px auto 0;
  width: 100%;
  max-width: min(100vw - 12px, 480px);
  text-align: right;
  font-size: 0.7rem;
  color: #7f7e7b;
  line-height: 1.2;
  min-height: 0.9rem;
}

.chess-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid #3f3e3a;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

.coord-file,
.coord-rank {
  position: absolute;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  opacity: 0.72;
  z-index: 4;
  pointer-events: none;
  user-select: none;
}

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

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

.square.light .coord-file,
.square.light .coord-rank {
  color: #7b5e3f;
}

.square.dark .coord-file,
.square.dark .coord-rank {
  color: #f1e0c5;
}

.piece-sprite {
  position: absolute;
  width: 88%;
  height: 88%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 2;
}

.square.light {
  background: #f0d9b5;
  color: #000;
}

.square.dark {
  background: #b58863;
  color: #000;
}

.square.last-move::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(247, 246, 105, 0.52);
  z-index: 1;
  pointer-events: none;
}

.square.premove-from::before,
.square.premove-to::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.square.premove-from::before {
  box-shadow: inset 0 0 0 2px var(--premove-color, rgba(95, 140, 245, 0.9));
  background: color-mix(in srgb, var(--premove-color, #4f8cff) 16%, transparent);
}

.square.premove-to::before {
  background: color-mix(in srgb, var(--premove-color, #4f8cff) 34%, transparent);
}

.square.premove-to::after {
  content: attr(data-premove-step);
  position: absolute;
  right: 4px;
  top: 4px;
  min-width: 14px;
  height: 14px;
  border-radius: 999px;
  padding: 0 3px;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  color: #0f0f0f;
  background: var(--premove-color, #4f8cff);
  z-index: 3;
  pointer-events: none;
}

.square.legal::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(82, 126, 210, 0.45);
  z-index: 1;
  pointer-events: none;
}

.square.legal.legal-drag::after {
  background: rgba(82, 126, 210, 0.28);
}

.square.legal.legal-tap::after {
  background: rgba(82, 126, 210, 0.64);
}

.square.drag-hover::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  border: 2px solid rgba(92, 143, 235, 0.75);
  background: rgba(92, 143, 235, 0.14);
  z-index: 1;
  pointer-events: none;
}

.square.selected {
  box-shadow: inset 0 0 0 3px #7ea742;
}

.square.check {
  box-shadow: inset 0 0 0 3px #c55;
}

.promotion-picker {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(17, 17, 16, 0.55);
  z-index: 8;
}

.promotion-picker.active {
  display: flex;
}

.promotion-choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  width: min(88px, 28%);
}

.promotion-choice {
  aspect-ratio: 1;
  border: 1px solid rgba(208, 207, 204, 0.38);
  border-radius: 6px;
  background: rgba(47, 46, 43, 0.58);
  position: relative;
  padding: 0;
}

.promotion-choice .piece-sprite {
  position: absolute;
  width: 76%;
  height: 76%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.88;
}

.moves-panel {
  background: #1f1e1b;
  border: 1px solid #31302d;
  border-radius: 10px;
  padding: 8px;
  margin-top: 4px;
}

.moves-header {
  font-size: 0.76rem;
  color: #8f8e8a;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.move-list {
  min-height: 42px;
  max-height: 86px;
  overflow-y: auto;
  font-size: 0.88rem;
  color: #c9c8c5;
  line-height: 1.5;
  background: #171613;
  border: 1px solid #2b2a27;
  border-radius: 6px;
  padding: 6px 8px;
}

.move-list .move-num {
  color: #767572;
  margin-right: 4px;
}

.game-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-flip,
.btn-draw,
.btn-draw-claim,
.btn-resign,
.btn-replay {
  flex: 1;
  min-height: 40px;
  padding: 0 10px;
  font-size: 0.86rem;
  border-radius: 8px;
  border: 1px solid #3a3935;
  background: #2a2926;
  color: #d0cfcc;
  cursor: pointer;
}

.btn-flip:active,
.btn-draw:active,
.btn-draw-claim:active,
.btn-resign:active {
  background: #373632;
}

.btn-draw.draw-pending {
  background: #2f3d55;
  border-color: #5878ad;
  color: #d6e5ff;
}

.btn-resign.resign-confirm {
  background: #583332;
  border-color: #c55;
  color: #ff9999;
}

.btn-replay {
  flex: 0.6;
  min-width: 38px;
}

.analysis-panel {
  margin-top: 8px;
  border: 1px solid #2f3a4d;
  border-radius: 8px;
  padding: 8px;
  background: #1a202c;
  display: none;
}

.analysis-panel.active {
  display: block;
}

.btn-analysis-toggle {
  margin-top: 0;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid #40587e;
  background: #2a3f61;
  color: #e3eeff;
  width: 100%;
}

.analysis-lines {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.74rem;
  color: #b9c8df;
  line-height: 1.38;
  max-height: 200px;
  overflow-y: auto;
}

.analysis-lines .analysis-row {
  padding: 5px 6px;
  border-radius: 6px;
  background: #141923;
  border: 1px solid #273146;
}

.analysis-lines .analysis-row-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin-bottom: 3px;
  font-family: "Roboto Mono", "Lucida Console", Monaco, monospace;
  font-size: 0.72rem;
}

.analysis-lines .analysis-row-line {
  opacity: 0.85;
  word-break: break-word;
}

.analysis-lines .analysis-row-empty {
  color: #7d8999;
}

.analysis-lines .anal-plies-note {
  opacity: 0.82;
  font-size: 0.68rem;
  color: #8fa3bc;
}

.move-list button.move-entry {
  display: inline;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  border-radius: 3px;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.move-list .move-span.move-ply-active,
.move-list button.move-entry.move-ply-active {
  outline: 1px solid #5b8fd4;
  outline-offset: 1px;
  border-radius: 4px;
  padding: 0 2px;
}

.move-list button.move-entry.move-ply-active {
  text-decoration: none;
}
.result-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(12, 12, 11, 0.64);
  padding: 16px;
}

.result-modal.active {
  display: flex;
}

.result-modal-card {
  width: min(360px, 100%);
  border-radius: 12px;
  border: 1px solid #3a3935;
  background: #1f1e1b;
  padding: 14px 12px;
}

.result-modal-card.result-white {
  border-color: #7ca866;
  box-shadow: inset 0 36px 0 rgba(124, 168, 102, 0.22);
}

.result-modal-card.result-black {
  border-color: #6f88a8;
  box-shadow: inset 0 36px 0 rgba(111, 136, 168, 0.2);
}

.result-modal-card.result-draw {
  border-color: #7b7b7b;
  box-shadow: inset 0 36px 0 rgba(123, 123, 123, 0.18);
}

.result-modal-title {
  font-size: 1.18rem;
  color: #fff;
  font-weight: 700;
  margin-bottom: 10px;
  text-align: center;
}

.result-modal-text {
  font-size: 0.9rem;
  color: #c9c8c5;
  margin-bottom: 12px;
  line-height: 1.35;
  text-align: center;
}

.result-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-result-analysis {
  border-color: #4b6a8f;
  background: #2a3540;
  color: #dfe9f5;
}

.clock.flagged {
  background: #5a2e2e;
  color: #ffe4e4;
  box-shadow: inset 0 -2px 0 0 #de6f6f;
}

.btn-result-lobby {
  width: 100%;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid #507f4a;
  background: #2e4a2b;
  color: #e7f6e2;
  font-size: 0.9rem;
}

/* Временно скрыт UI турниров; убери класс .tournament-ui-hidden с разметки, чтобы вернуть */
.tournament-ui-hidden {
  display: none !important;
}

.tournament-panel {
  margin: 12px 0 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #33322e;
  background: #1a1916;
}

.tournament-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #eae9e6;
  margin-bottom: 8px;
}

.tournament-tc-label {
  display: block;
  font-size: 0.75rem;
  color: #888;
  margin-bottom: 4px;
}

.tournament-tc-select {
  width: 100%;
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #3a3935;
  background: #262522;
  color: #e0dfdc;
  font-size: 0.95rem;
}

.tournament-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-bottom: 8px;
}

.tournament-label {
  flex: 1 1 88px;
  font-size: 0.85rem;
  color: #b0afa8;
}

.btn-tournament,
.btn-tournament-secondary {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  border: 1px solid #4a7a44;
  background: #2e4a2b;
  color: #e7f6e2;
}

.btn-tournament-secondary {
  border-color: #555;
  background: #2a2826;
  color: #ccc;
}

.tournament-count {
  flex: 1 1 100%;
  font-size: 0.78rem;
  color: #8a897f;
}

.tournament-hint {
  font-size: 0.72rem;
  color: #6f6e68;
  margin: 4px 0 0;
  line-height: 1.3;
}

.profile-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #aaa;
  margin: 10px 0 6px;
}

.profile-tournaments {
  margin-bottom: 8px;
}

@media (min-width: 520px) {
  .screen {
    padding-left: 12px;
    padding-right: 12px;
  }

  .moves-panel {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
  }
}
