@import url("Color.css");
@import url("General.css");
@import url("Font.css");

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg-page);
  color: var(--color-text-primary);
  min-height: 100vh;
}

.container {
  display: flex;
  min-height: 100vh;
  padding-left: var(--sidebar-width, 220px);
  padding-right: clamp(10px, 2vw, 24px);
  gap: clamp(10px, 2vw, 22px);
}

.main {
  margin-left: 0;
  width: auto;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: clamp(14px, 2vw, 20px);
}

.top-bar,
.bottom-bar {
  width: min(960px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-bg-panel);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-soft);
}

.top-bar p,
.bottom-bar p {
  margin: 0;
  max-width: 74%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer {
  background: var(--color-bg-dark);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-soft);
  white-space: nowrap;
}

.right-panel {
  width: clamp(220px, 18vw, 300px);
  padding: clamp(14px, 2vw, 20px) 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: center;
  position: relative;
}

.custom-select {
  position: relative;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  user-select: none;
  z-index: 10;
}

.custom-select .selected {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}

.custom-select .options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background: var(--color-bg-darker);
  border-radius: 6px;
  overflow: hidden;
  z-index: 1000;
}

.custom-select .option {
  min-height: 42px;
  padding: 10px;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.custom-select .option:hover {
  background: var(--color-accent);
}

.btn-blue {
  background: var(--color-accent);
  border: none;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-grey {
  background: var(--color-bg-surface);
  border: none;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.playground {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1vw, 10px);
  width: 100%;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  margin: 8px auto;
  border: 3px solid var(--color-board-border);
  width: min(72vmin, 720px);
  aspect-ratio: 1 / 1;
  background: var(--color-board-bg);
}

.playground .board {
  margin: 0;
}

.captures {
  padding: 10px;
  background: var(--color-bg-darker);
  margin: 0;
  height: min(64vmin, 620px);
  width: min(72px, 14vw);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
}

.captures img {
  width: 100%;
  aspect-ratio: 1 / 1;
  cursor: pointer;
}

.captures img.selected {
  background-color: var(--color-piece-selected);
  border-radius: 50%;
}

.cell {
  border: 1px solid var(--color-bg-darker);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.5vmin;
  cursor: pointer;
  aspect-ratio: 1 / 1;
}

.cell img.piece-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.rotated {
  transform: rotate(180deg);
}

.cell.selected {
  background-color: var(--color-highlight-selected);
}

.cell.legal {
  position: relative;
}

.cell.legal::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  background-color: var(--color-highlight-legal);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.cell.last-move {
  background-color: var(--color-highlight-last-move);
}

.cell.check {
  background-color: var(--color-highlight-check);
}

.game-modal {
  border: none;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

.game-modal__content {
  background: var(--color-bg-dark);
  color: var(--color-text-primary);
  padding: 30px;
  border-radius: var(--radius-md);
  max-width: 90vw;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 15px;
  box-shadow: 0 10px 30px var(--color-shadow-strong);
  animation: modalFade 0.2s ease-out;
}

.game-modal__content h2 {
  margin: 0;
  color: var(--color-accent);
}

.game-modal__content p {
  margin: 0;
  opacity: 0.9;
}

.game-modal__actions {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 10px;
}

.game-modal__actions button,
.game-modal__actions .btn-secondary {
  padding: 10px 20px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-weight: bold;
  transition: 0.2s;
}

.game-modal__actions button {
  background: var(--color-accent);
  color: var(--color-text-primary);
}

.game-modal__actions button:hover {
  background: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-bg-secondary-dark);
  color: var(--color-text-primary);
}

.btn-secondary:hover {
  background: var(--color-bg-secondary-darker);
}

@keyframes modalFade {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 1100px) {
  .main {
    padding: 16px;
  }

  .right-panel {
    width: 220px;
    padding: 16px 0;
  }

  .board {
    width: min(74vmin, 560px);
  }
}

@media (max-width: 1024px) {
  .container {
    padding-right: 14px;
  }

  .top-bar,
  .bottom-bar {
    width: min(900px, 100%);
  }
}

@media (max-width: 900px) {
  .container {
    flex-direction: column;
    padding-left: 0;
  }

  .main {
    width: min(100%, 980px);
    margin-right: auto;
    margin-left: auto;
    padding: 16px;
  }

  .right-panel {
    width: 100%;
    padding: 0 16px 16px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .right-panel > * {
    flex: 1;
  }

  .playground {
    flex-direction: column;
    gap: 6px;
  }

  .captures {
    width: min(92vw, 560px);
    min-height: 56px;
    height: auto;
    margin: 0;
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .captures img {
    width: 44px;
    min-width: 44px;
  }

  .board {
    width: min(92vw, 560px);
  }

  .bottom-bar .timer {
    margin-right: 72px;
  }
}

@media (max-width: 768px) {
  .top-bar,
  .bottom-bar {
    width: min(94vw, 760px);
  }

  .timer {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 640px) {
  .top-bar,
  .bottom-bar {
    padding: 8px 10px;
    font-size: 1rem;
  }

  .timer {
    padding: 4px 10px;
  }

  .bottom-bar .timer {
    margin-right: 64px;
  }

  .right-panel {
    flex-direction: column;
    align-items: stretch;
    padding: 0 12px 14px;
  }

  .right-panel > * {
    width: 100%;
  }

  .cell.legal::after {
    width: 18px;
    height: 18px;
  }

  .game-modal__content {
    padding: 20px;
  }

  .game-modal__actions {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .main {
    padding: 12px;
    gap: 10px;
  }

  .top-bar,
  .bottom-bar {
    padding: 8px 10px;
  }

  .bottom-bar .timer {
    margin-right: 58px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-modal__content,
  .btn-blue,
  .btn-grey,
  .custom-select .option {
    animation: none;
    transition: none;
  }
}
