:root {
  --bg-main: #161512;
  --bg-card: #262421;
  --bg-card-hover: #322f2b;
  --bg-board-light: #ebecd0;
  --bg-board-dark: #779556;
  --text-main: #bababa;
  --text-bright: #ffffff;
  --accent-gold: #c39a5c;
  --accent-green: #629924;
  --accent-green-hover: #74b22c;
  --accent-blue: #3692e7;
  --accent-red: #c0392b;
  --border-subtle: #3d3a34;
  --sq-highlight: rgba(245, 246, 130, 0.55);
  --sq-last-move: rgba(255, 255, 0, 0.38);
  --sq-check: radial-gradient(ellipse at center, rgba(255,0,0,0.85) 0%, rgba(231,76,60,0.3) 70%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: #1f1d1a;
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-bright);
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
}

.brand-icon {
  width: 28px;
  height: 28px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-bright);
}

/* Home / Lobby */
.lobby-container {
  max-width: 680px;
  margin: 40px auto;
  padding: 0 20px;
  width: 100%;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.4);
}

.card h1 {
  color: var(--text-bright);
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.card p.subtitle {
  color: #8c8883;
  margin-bottom: 24px;
  font-size: 0.95rem;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: #cfccc8;
}

.btn-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.choice-btn {
  background: #1c1b18;
  border: 2px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-main);
  padding: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.choice-btn:hover {
  border-color: #666;
  color: var(--text-bright);
}

.choice-btn.active {
  border-color: var(--accent-green);
  background: rgba(98, 153, 36, 0.15);
  color: var(--text-bright);
}

.choice-btn .choice-icon {
  font-size: 1.4rem;
}

.time-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.time-btn {
  background: #1c1b18;
  border: 2px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-main);
  padding: 10px 6px;
  cursor: pointer;
  text-align: center;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.time-btn strong {
  display: block;
  color: var(--text-bright);
  font-size: 1rem;
}

.time-btn.active {
  border-color: var(--accent-green);
  background: rgba(98, 153, 36, 0.15);
}

.btn-primary {
  background: var(--accent-green);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: 700;
  width: 100%;
  cursor: pointer;
  margin-top: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--accent-green-hover);
}

/* Game Page Layout */
.game-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  max-width: 1280px;
  margin: 20px auto;
  padding: 0 16px;
  width: 100%;
  flex: 1;
}

.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

/* Player Bar */
.player-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 560px;
  padding: 8px 12px;
  background: #1c1b18;
  border: 1px solid var(--border-subtle);
}

.player-bar.top {
  border-radius: 8px 8px 0 0;
  border-bottom: none;
}

.player-bar.bottom {
  border-radius: 0 0 8px 8px;
  border-top: none;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #333;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.9rem;
}

.player-avatar.white {
  background: #f0f0f0;
  color: #222;
}

.player-avatar.black {
  background: #2b2b2b;
  color: #fff;
  border: 1px solid #444;
}

.player-meta {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 600;
  color: var(--text-bright);
  font-size: 0.95rem;
}

.player-status-badge {
  font-size: 0.75rem;
  color: #8c8883;
}

.captured-pieces {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 18px;
  font-size: 0.75rem;
}

.captured-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
}

.material-diff {
  color: #aaa;
  font-size: 0.75rem;
  font-weight: bold;
  margin-left: 4px;
}

.clock {
  font-family: monospace;
  font-size: 1.3rem;
  font-weight: 700;
  background: #12110f;
  padding: 4px 12px;
  border-radius: 6px;
  color: #ffffff;
  border: 1px solid #333;
  letter-spacing: 1px;
}

.clock.active {
  background: #e67e22;
  color: #fff;
  border-color: #f39c12;
  box-shadow: 0 0 10px rgba(230, 126, 34, 0.4);
}

.clock.low-time {
  background: #c0392b;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* Chessboard */
.board-wrapper {
  position: relative;
  width: 560px;
  height: 560px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  border: 2px solid #333;
}

@media (max-width: 600px) {
  .board-wrapper {
    width: 92vw;
    height: 92vw;
  }
  .player-bar {
    max-width: 92vw;
  }
}

.chessboard {
  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;
  user-select: none;
}

.square.light {
  background-color: var(--bg-board-light);
}

.square.dark {
  background-color: var(--bg-board-dark);
}

.square.selected {
  background-color: var(--sq-highlight) !important;
}

.square.last-move {
  background-color: var(--sq-last-move) !important;
}

.square.in-check {
  background: var(--sq-check) !important;
}

/* Square Coordinates */
.coord-rank {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.coord-file {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.square.light .coord-rank,
.square.light .coord-file {
  color: var(--bg-board-dark);
}

.square.dark .coord-rank,
.square.dark .coord-file {
  color: var(--bg-board-light);
}

/* Piece SVG */
.chess-piece {
  width: 90%;
  height: 90%;
  cursor: grab;
  z-index: 2;
  transition: transform 0.05s ease-out;
}

.chess-piece:active {
  cursor: grabbing;
}

.chess-piece svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Legal Move Hints */
.move-hint {
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background-color: rgba(20, 85, 30, 0.5);
  pointer-events: none;
  z-index: 3;
}

.capture-hint {
  position: absolute;
  width: 86%;
  height: 86%;
  border-radius: 50%;
  border: 5px solid rgba(20, 85, 30, 0.55);
  pointer-events: none;
  z-index: 3;
}

/* Pawn Promotion Modal */
.promotion-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #2b2926;
  border: 2px solid var(--accent-gold);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  gap: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
  z-index: 20;
}

.promotion-piece-btn {
  background: #383531;
  border: 1px solid #555;
  border-radius: 8px;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.promotion-piece-btn:hover {
  background: var(--accent-gold);
  transform: scale(1.05);
}

/* Side Panel (Moves, Controls, Chat) */
.side-panel {
  width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (max-width: 980px) {
  .game-container {
    flex-direction: column;
    align-items: center;
  }
  .side-panel {
    width: 100%;
    max-width: 560px;
  }
}

.game-status-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 16px;
}

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

.status-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-bright);
}

.turn-pill {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.turn-pill.white {
  background: #ffffff;
  color: #111;
}

.turn-pill.black {
  background: #333333;
  color: #fff;
  border: 1px solid #555;
}

.status-desc {
  font-size: 0.9rem;
  color: #9c9790;
}

/* Share Link Box */
.share-box {
  background: #1a1816;
  border: 1px dashed #555;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.share-link-input {
  background: transparent;
  border: none;
  color: #e0deda;
  font-size: 0.82rem;
  width: 100%;
  outline: none;
  user-select: all;
  text-overflow: ellipsis;
  overflow: hidden;
}

.btn-copy {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-copy:hover {
  background: #2a79c5;
}

/* Tabs & Move History */
.moves-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  height: 220px;
  display: flex;
  flex-direction: column;
}

.moves-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-bright);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.moves-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  row-gap: 2px;
  font-family: monospace;
  font-size: 0.95rem;
  align-content: start;
}

.move-num {
  color: #777;
  padding: 4px 6px;
  text-align: right;
}

.move-san {
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text-bright);
  cursor: default;
}

.move-san.active {
  background: rgba(255, 255, 255, 0.15);
  font-weight: bold;
}

/* Action Buttons Bar */
.action-buttons {
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1;
  background: #211f1c;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--bg-card-hover);
  color: #fff;
}

.action-btn.danger:hover {
  background: var(--accent-red);
  color: #fff;
  border-color: var(--accent-red);
}

/* Chat */
.chat-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  height: 220px;
}

.chat-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-bright);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
}

.chat-msg {
  word-break: break-word;
}

.chat-msg .author {
  font-weight: 700;
  color: var(--accent-gold);
}

.chat-msg.system {
  color: #8c8883;
  font-style: italic;
  font-size: 0.8rem;
}

.chat-input-bar {
  display: flex;
  border-top: 1px solid var(--border-subtle);
  padding: 6px;
  gap: 6px;
}

.chat-input {
  flex: 1;
  background: #171614;
  border: 1px solid #3d3a34;
  border-radius: 6px;
  color: #fff;
  padding: 6px 10px;
  font-size: 0.85rem;
  outline: none;
}

.chat-send-btn {
  background: #333;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}

.chat-send-btn:hover {
  background: #444;
}

/* Modals & Dialogs */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: #262421;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
}

.modal-card h2 {
  color: var(--text-bright);
  margin-bottom: 12px;
}

.modal-card p {
  color: #aaa;
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

.hidden {
  display: none !important;
}
