:root {
  --blue: #087bff;
  --cyan: #25c7d9;
  --purple: #7441d9;
  --line: #dfe5ee;
  --ink: #202832;
  --muted: #6c7684;
  --bg: #f1f4f8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

.body-wrap {
  width: min(100%, 1500px);
  min-height: 100vh;
  margin: 0 auto;
  background: #fff;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(16, 24, 40, .08);
}

.header {
  position: relative;
  min-height: 150px;
  padding: 34px 40px;
  border-left: 4px solid var(--blue);
  border-bottom: 1px solid var(--line);
}

.logo {
  margin: 0;
  font-size: 38px;
  line-height: 1;
  font-weight: 800;
}

.online-count {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 400;
}

.tagline {
  margin-top: 8px;
  color: var(--muted);
}

.portalcore-header-logo-link {
  position: absolute;
  top: 30px;
  right: 235px;
  display: block;
  width: 280px;
  padding: 12px 24px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(16, 24, 40, .14);
}

.portalcore-header-logo {
  display: block;
  width: 100%;
  height: auto;
}

.leave-link {
  position: absolute;
  top: 58px;
  right: 40px;
  color: #b00020;
  font-size: 18px;
  font-weight: 800;
}

.signup-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 22px 40px 0;
  padding: 15px 18px;
  color: #172033;
  text-decoration: none;
  background: linear-gradient(90deg, #f4fbfd, #fff);
  border: 1px solid #c9e7f0;
  border-left: 4px solid var(--cyan);
  border-radius: 6px;
  box-shadow: 0 10px 26px rgba(16, 24, 40, .08);
}

.signup-banner:hover,
.signup-banner:focus {
  color: #172033;
  text-decoration: none;
  border-color: #86d6e5;
}

.signup-banner-action {
  flex: 0 0 auto;
  color: var(--blue);
  font-weight: 800;
}

.account-banner {
  cursor: default;
}

.history-banner-button {
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  padding: 10px 14px;
}

.history-banner-button:hover,
.history-banner-button:focus {
  background: #0668d8;
  color: #fff;
}

.notifications {
  padding: 18px 40px 0;
}

.notification {
  width: min(100%, 650px);
  margin: 0 auto;
  padding: 14px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid #ffbf00;
  border-radius: 5px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .08);
}

.notification.is-win { border-left-color: #28a745; }
.notification.is-danger { border-left-color: #dc3545; }

.chess-layout {
  display: grid;
  grid-template-columns: minmax(420px, 720px) minmax(280px, 420px);
  gap: 56px;
  align-items: start;
  justify-content: center;
  padding: 70px 40px 36px;
}

.board-panel,
.opponent-panel,
.moves-card,
.chat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-top: 4px solid var(--blue);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .08);
}

.board-panel {
  padding: 28px;
}

.board-wrap {
  width: min(100%, 560px);
  margin: 0 auto;
}

.chess-board {
  display: grid;
  grid-template-columns: 28px repeat(8, minmax(36px, 1fr));
  grid-template-rows: 28px repeat(8, minmax(36px, 1fr));
  aspect-ratio: 1 / 1;
  padding: 18px;
  background: linear-gradient(180deg, #fff, #fbfcff);
  touch-action: none;
}

.coord {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 800;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #aab6ff;
  background: #fff;
  color: #111827;
  font-size: clamp(24px, 4vw, 44px);
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.cell.dark {
  background: #eef5ff;
}

.cell.selected {
  outline: 3px solid var(--blue);
  outline-offset: -3px;
}

.cell.legal::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(8, 123, 255, .34);
  position: absolute;
}

.cell.capture::after {
  width: calc(100% - 12px);
  height: calc(100% - 12px);
  border: 3px solid rgba(220, 53, 69, .35);
  background: transparent;
}

.cell.drag-origin .piece {
  opacity: .22;
}

.piece {
  position: relative;
  z-index: 1;
  display: inline-flex;
  width: 82%;
  height: 82%;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-family: Georgia, "Times New Roman", serif;
  text-shadow: 0 1px 0 rgba(255,255,255,.55);
}

.piece.white {
  color: #111827;
}

.piece.black {
  color: #4c1d95;
}

.piece-icon {
  transform: translateY(-1px);
  pointer-events: none;
}

.chess-drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 14px 34px rgba(16, 24, 40, .22);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 42px;
  line-height: 1;
}

.chess-drag-ghost.white {
  color: #111827;
}

.chess-drag-ghost.black {
  color: #4c1d95;
}

.battlefield-label {
  margin-top: 14px;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
}

.battlefield-label-comment {
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
  font-weight: 400;
}

.opponent-panel {
  border-top-color: var(--purple);
  padding: 22px;
}

.opponent-panel h2,
.moves-card h3,
.chat-card h3 {
  margin: 0 0 12px;
  font-size: 28px;
}

.choice-row {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.choice,
.link-button,
.play-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--blue);
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
  padding: 8px 12px;
}

.choice.active,
.play-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.play-button,
.link-button {
  display: block;
  width: 100%;
  margin-top: 10px;
}

.invite-panel {
  margin: 16px 0;
}

.invite-panel label {
  display: block;
  margin-bottom: 8px;
}

.copy-field {
  display: flex;
  gap: 8px;
}

.copy-field input {
  min-width: 0;
  flex: 1;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 15px;
}

.game-name-label {
  display: block;
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.game-name-input {
  width: 100%;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 15px;
}

.copy-icon {
  display: inline-block;
  width: 14px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 2px;
  box-shadow: 5px -5px 0 -2px #fff, 5px -5px 0 0 currentColor;
}

.hidden { display: none !important; }

.modal.chess-history-modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: none;
  overflow: auto;
  padding: 24px;
  background: rgba(15, 23, 42, .58);
}

.modal.chess-history-modal.show {
  display: block;
}

.chess-history-modal .modal-dialog {
  width: min(1120px, calc(100vw - 48px));
  margin: 24px auto;
}

.chess-history-modal .modal-content {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, .32);
}

.chess-history-modal .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.chess-history-modal .modal-title {
  margin: 0;
  font-size: 28px;
}

.chess-history-modal .close {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 34px;
  line-height: 1;
}

.chess-history-modal .modal-body {
  padding: 20px;
}

.history-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.history-search-row .form-control {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.history-search-row .btn {
  border: 0;
  border-radius: 6px;
  background: var(--cyan);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  padding: 11px 16px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.meta-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.meta-grid strong,
.meta-grid span {
  display: block;
}

.meta-grid span {
  color: var(--muted);
  font-size: 13px;
}

.moves-panel {
  display: grid;
  grid-template-columns: minmax(280px, 520px) minmax(280px, 1fr);
  gap: 24px;
  padding: 0 40px 36px;
}

.moves-card,
.chat-card {
  padding: 18px;
}

.moves-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  padding-left: 26px;
}

.moves-list li {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.35;
  padding: 2px 0;
}

.move-half {
  display: block;
}

.move-san {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  opacity: .72;
}

.log {
  min-height: 68px;
  max-height: 140px;
  overflow: auto;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

.chat-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.settings {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 0 40px 34px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.settings dt {
  font-weight: 800;
}

.settings dd {
  margin: 0;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.footer-links {
  display: flex;
  gap: 18px;
}

.pc-chess-home {
  padding: 18px;
}

.pc-chess-home .body-wrap {
  width: 100%;
  min-height: 0;
  border: 0;
  box-shadow: none;
}

.pc-chess-home .header {
  min-height: auto;
  padding: 22px 26px;
  border-radius: 6px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--cyan);
}

.pc-chess-home .portalcore-header-logo-link,
.pc-chess-home .footer {
  display: none;
}

.pc-chess-home .chess-layout {
  grid-template-columns: minmax(360px, 610px) minmax(260px, 360px);
  gap: 28px;
  padding: 28px 0;
}

.pc-chess-home .moves-panel,
.pc-chess-home .settings {
  width: 100%;
  padding-left: 0;
  padding-right: 0;
  margin-left: 0;
  margin-right: 0;
}

.history-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 18px 0 0;
}

.player-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.player-stats div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.player-stats strong,
.player-stats span {
  display: block;
}

.player-stats strong {
  font-size: 18px;
}

.player-stats span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.history-list {
  max-height: 420px;
  overflow: auto;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  text-align: left;
}

.history-row + .history-row {
  margin-top: 8px;
}

.history-row strong,
.history-row span {
  display: block;
}

.history-row span {
  color: var(--muted);
  font-size: 13px;
}

.replay-layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(220px, 1fr);
  gap: 20px;
  align-items: start;
}

.replay-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(28px, 1fr));
  grid-template-rows: repeat(8, minmax(28px, 1fr));
  aspect-ratio: 1 / 1;
  border: 1px solid #aab6ff;
  width: min(100%, 420px);
}

.replay-board .cell {
  border: 0;
  inline-size: 100%;
  block-size: 100%;
  min-inline-size: 0;
  min-block-size: 0;
  aspect-ratio: 1 / 1;
  font-size: clamp(22px, 4vw, 38px);
}

.replay-moves {
  max-height: 420px;
  overflow: auto;
}

.replay-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 10px;
}

.replay-controls .choice {
  min-width: 42px;
}

.replay-position {
  font-size: 13px;
  font-weight: 700;
}

.replay-move {
  display: inline-flex;
  margin: 0 6px 8px 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
}

.replay-move.active {
  border-color: var(--blue);
  color: var(--blue);
  font-weight: 800;
}

@media (max-width: 1000px) {
  .portalcore-header-logo-link {
    position: static;
    margin-top: 18px;
  }
  .leave-link {
    top: 42px;
  }
  .chess-layout,
  .moves-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .body-wrap {
    border: 0;
  }
  .header,
  .notifications,
  .signup-banner,
  .chess-layout,
  .moves-panel,
  .settings,
  .footer {
    padding-left: 18px;
    padding-right: 18px;
  }
  .header {
    min-height: 0;
  }
  .leave-link {
    position: static;
    display: inline-block;
    margin-top: 12px;
  }
  .board-panel {
    padding: 10px;
  }
  .chess-board {
    padding: 8px;
    grid-template-columns: 20px repeat(8, minmax(28px, 1fr));
    grid-template-rows: 20px repeat(8, minmax(28px, 1fr));
  }
  .signup-banner,
  .history-search-row,
  .replay-layout {
    display: block;
  }
  .history-banner-button,
  .history-search-row .btn {
    width: 100%;
    margin-top: 12px;
  }
  .chess-history-modal .modal-dialog {
    width: auto;
    margin: 0;
  }
}
