*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #312e2b;
  color: #fff;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

input,
select,
textarea,
option {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

img,
.piece {
  -webkit-user-drag: none;
  user-drag: none;
}

.hidden {
  display: none !important;
}

.screen-loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #312e2b;
  z-index: 200;
  overflow: hidden;
}

#screen-menu {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

.menu-panel {
  width: min(100%, 380px);
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: #262421;
  border-radius: 14px;
  padding: 22px 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.menu-panel h1 {
  margin: 0 0 20px;
  font-size: 2rem;
  text-align: center;
}

.field {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.field select {
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  border-radius: 8px;
  border: none;
  background: #1a1816;
  color: #fff;
}

.check {
  display: block;
  margin: 8px 0;
  font-size: 0.9rem;
}

.btn {
  width: 100%;
  margin-top: 10px;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: #3d3a37;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn.primary {
  background: #81b64c;
  color: #fff;
}

.btn.sm {
  width: auto;
  padding: 8px 12px;
  margin: 0;
  font-size: 0.85rem;
}

.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #262421;
}

#screen-game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #312e2b;
}

.game-shell {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 36vw);
  width: 100%;
  height: 100%;
  min-height: 0;
}

.board-column {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 10px 12px 10px 10px;
  background: #312e2b;
}

.board-frame {
  width: min(100%, calc(100vh - 20px), calc(100vw - 36vw - 24px));
  height: min(100%, calc(100vh - 20px), calc(100vw - 36vw - 24px));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}

.status {
  flex-shrink: 0;
  text-align: left;
  font-weight: 600;
  font-size: clamp(0.9rem, 1.2vw, 1.05rem);
  line-height: 1.35;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 8px;
}

.sidebar {
  background: #262421;
  padding: 14px 16px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.sidebar-toolbar .btn.sm {
  flex: 1;
  min-width: 7rem;
  text-align: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  height: 100%;
}

.sq {
  position: relative;
  border: none;
  padding: 0;
  margin: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.board-brown .sq.light {
  background: #f0d9b5;
}
.board-brown .sq.dark {
  background: #b58863;
}
.board-green .sq.light {
  background: #ffffdd;
}
.board-green .sq.dark {
  background: #86a666;
}
.board-blue .sq.light {
  background: #dee3e6;
}
.board-blue .sq.dark {
  background: #8ca2ad;
}

.sq.sel {
  box-shadow: inset 0 0 0 4px rgba(20, 85, 30, 0.75);
}

.sq.hint::after {
  content: "";
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.15);
}

.sq.hint:has(.piece)::after {
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: rgba(20, 120, 40, 0.35);
  box-shadow: inset 0 0 0 3px rgba(20, 100, 30, 0.6);
}

.sq.last {
  background-color: rgba(155, 199, 0, 0.41) !important;
}

.piece {
  width: 92%;
  height: 92%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}

.coord {
  position: absolute;
  font-size: 0.55rem;
  font-weight: 700;
  opacity: 0.55;
  pointer-events: none;
}

.coord.rk {
  top: 2px;
  left: 3px;
}

.coord.fl {
  right: 3px;
  bottom: 2px;
}

.sidebar h2 {
  margin: 0 0 10px;
  font-size: clamp(0.85rem, 1.1vw, 0.95rem);
  font-weight: 600;
  opacity: 0.85;
  flex-shrink: 0;
}

.move-log {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  font-family: Consolas, "Segoe UI", monospace;
  font-size: clamp(0.8rem, 1.05vw, 0.9rem);
  flex: 1;
  min-height: 0;
}

.move-log li {
  display: grid;
  grid-template-columns: 2em 1fr 1fr;
  gap: 4px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.move-log .n {
  opacity: 0.45;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
}

.modal-box {
  background: #262421;
  border-radius: 12px;
  padding: 20px;
  width: min(100%, 340px);
  text-align: center;
}

.promo-picks {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.promo-picks button {
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  background: #3d3a37;
  cursor: pointer;
  padding: 4px;
}

.pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: grid;
  place-items: center;
  z-index: 150;
  font-size: 1.5rem;
  font-weight: 700;
}

@media (max-width: 720px) {
  .game-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .board-column {
    padding: 6px 8px;
  }
  .board-frame {
    width: min(100%, calc(100vh - 42vh - 24px));
    height: min(100%, calc(100vh - 42vh - 24px));
  }
  .sidebar {
    max-height: 38vh;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
}

@media (max-height: 520px) {
  .menu-panel {
    padding: 14px 16px;
  }
  .menu-panel h1 {
    font-size: 1.5rem;
    margin-bottom: 12px;
  }
  .field,
  .check {
    margin-bottom: 6px;
  }
  .btn {
    padding: 10px;
    margin-top: 6px;
  }
}

/* Режим промо-скриншотов (?promo=1) */
body.promo-shot #screen-loading,
body.promo-shot #screen-menu {
  display: none !important;
}

body.promo-shot .game-shell {
  grid-template-columns: 1fr minmax(240px, 34vw);
}

body.promo-shot .board-frame {
  width: min(100%, calc(100vh - 16px), calc(100vw - 34vw - 20px));
  height: min(100%, calc(100vh - 16px), calc(100vw - 34vw - 20px));
}
