/* === CSS Variables === */
:root {
  --bg: #000000;
  --surface: #1a1a1a;
  --text: #e0e0e0;
  --text-dim: #888888;
  --accent: #4fc3f7;
  --accent-dim: rgba(79, 195, 247, 0.3);
  --danger: #ef5350;
  --success: #66bb6a;
  --light-square: #b0a090;
  --dark-square: #6b5b4f;
  --selected: rgba(79, 195, 247, 0.5);
  --legal-move: rgba(79, 195, 247, 0.35);
  --last-move: rgba(255, 235, 59, 0.25);
  --check: rgba(239, 83, 80, 0.5);
  --focus-ring: 2px solid var(--accent);
  --radius: 6px;
  --piece-size: 48px;
}

/* === Reset === */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  -webkit-user-select: none;
  user-select: none;
}

/* === Screens === */
.screen {
  width: 600px;
  height: 600px;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.hidden { display: none; }

/* === Header === */
.header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid #333;
}

.header h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

/* === Focus States === */
.focusable {
  outline: none;
  border: 2px solid transparent;
  transition: border-color 0.15s, background-color 0.15s;
}

.focusable.focused {
  border-color: var(--accent);
  background-color: rgba(79, 195, 247, 0.1);
}

/* === Menu === */
.menu-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
}

.menu-btn {
  width: 320px;
  padding: 18px 24px;
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
}

/* === Game Screen === */
.game-header {
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid #333;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-dim);
}

.player-info.active-turn {
  color: var(--accent);
  font-weight: 600;
}

.captures {
  font-size: 14px;
  letter-spacing: 1px;
}

/* === Board === */
.board-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 4px 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 56px);
  grid-template-rows: repeat(8, 56px);
  border: 2px solid #555;
}

.square {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--piece-size);
  line-height: 1;
  position: relative;
  cursor: pointer;
}

.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }

/* Cursor - the D-pad highlighted square */
.square.cursor {
  box-shadow: inset 0 0 0 3px var(--accent);
  z-index: 2;
}

/* Selected piece */
.square.selected {
  background: var(--selected) !important;
}

/* Legal move indicator */
.square.legal-move::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--legal-move);
}

.square.legal-move.has-piece::after {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: transparent;
  border: 3px solid var(--legal-move);
}

/* Last move highlight */
.square.last-move-from,
.square.last-move-to {
  background-color: var(--last-move) !important;
}

/* Check highlight */
.square.in-check {
  background: var(--check) !important;
}

/* Piece colors */
.piece-white {
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.piece-black {
  color: #1a1a1a;
  text-shadow: 0 1px 2px rgba(255,255,255,0.2);
}

/* === Game Footer === */
.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  height: 32px;
}

.status-bar {
  font-size: 13px;
  color: var(--text-dim);
  text-align: right;
}

.status-bar.thinking {
  color: var(--accent);
}

/* === Game Nav === */
.game-nav {
  display: flex;
  gap: 8px;
  padding: 4px 12px 8px;
  justify-content: center;
}

.nav-btn {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
}

/* === Promotion === */
.promo-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
}

.promo-btn {
  width: 280px;
  padding: 16px 24px;
  font-size: 24px;
  color: var(--text);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
}

/* === Game Over === */
.gameover-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.gameover-msg {
  font-size: 20px;
  color: var(--text);
  text-align: center;
  line-height: 1.5;
}

.nav-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
}

/* === Code Entry Screen === */
.code-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
}

.code-instruction {
  font-size: 16px;
  color: var(--text-dim);
}

.code-url {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  word-break: break-all;
  text-align: center;
  margin-bottom: 8px;
}

.code-digits {
  display: flex;
  gap: 12px;
  margin: 12px 0;
  align-items: center;
}

.code-digit-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.digit-arrow {
  font-size: 12px;
  line-height: 1;
  color: transparent;
}

.digit-arrow.visible {
  color: var(--accent);
}

.code-nav-arrow {
  font-size: 28px;
  color: var(--text-dim);
  padding: 0 2px;
  line-height: 1;
}

.code-nav-arrow.active {
  color: var(--accent);
}

.code-digit {
  width: 64px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: bold;
  font-family: monospace;
  background: var(--surface);
  border: 2px solid #555;
  border-radius: var(--radius);
  color: var(--text);
}

.code-digit.active {
  border-color: var(--accent);
  background: rgba(79, 195, 247, 0.1);
}

.code-error {
  font-size: 14px;
  color: var(--danger);
  min-height: 20px;
}

/* === Time Control Screen === */
.tc-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 20px;
}

.online-user {
  font-size: 15px;
  color: var(--accent);
  margin: 0;
}

.tc-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 480px;
}

.tc-label {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-align: center;
  margin: 6px 0 2px;
  padding: 0;
}

.tc-btn {
  padding: 14px 4px;
  font-size: 17px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.tc-btn.focused {
  border-color: var(--accent);
}

.tc-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 4px;
}

.tc-action-btn {
  padding: 12px 28px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.tc-action-btn.focused {
  border-color: var(--accent);
}

/* === Seeking Screen === */
.seeking-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 20px;
}

.seeking-text {
  font-size: 20px;
  color: var(--text);
}

/* === Online Game Additions === */
.clock-display {
  font-family: monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: auto;
}

.player-info.active-turn .clock-display {
  color: var(--accent);
}

.clock-display:empty {
  display: none;
}
