/* ═══════════════════════════════════════════════════════════════════
   chessmat.ing — styles
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #161512;
  --bg2: #1e1c19;
  --bg3: #272522;
  --fg: #e8e6e3;
  --fg2: #8b8987;
  --accent: #7fa650;
  --accent-hover: #8fb85a;
  --accent-glow: rgba(127, 166, 80, 0.25);
  --danger: #cc5555;
  --board-light: #eeeed2;
  --board-dark: #769656;
  --board-highlight: rgba(255, 255, 50, 0.42);
  --board-legal: rgba(0, 0, 0, 0.12);
  --board-legal-capture: rgba(0, 0, 0, 0.12);
  --radius: 4px;
  --radius-sm: 4px;
  --radius-lg: 8px;
  --transition: 0.15s ease;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screens ──────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 1;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
  z-index: 10;
}

/* ─── Buttons ──────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 48px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--bg3);
  color: var(--fg2);
  border: 1px solid #3a3835;
  padding: 12px 36px;
  font-size: 0.95rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-secondary:hover { border-color: #555; color: var(--fg); background: #302e2b; }

.btn-small {
  padding: 8px 20px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
  border: 1px solid #3a3835;
  background: var(--bg3);
  color: var(--fg2);
  cursor: pointer;
  transition: all var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
}
.btn-small:hover { border-color: #555; color: var(--fg); }
.btn-danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-muted { opacity: 0.5; }

.btn-back {
  position: absolute;
  top: 20px;
  left: 20px;
  background: var(--bg3);
  border: 1px solid #3a3835;
  color: var(--fg2);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.btn-back:hover { border-color: #555; color: var(--fg); }

.hidden { display: none !important; }

/* ─── Welcome ──────────────────────────────────────────────────── */
.welcome-container {
  text-align: center;
  padding: 40px;
}
.logo {
  margin-bottom: 20px;
}
.logo-icon {
  font-size: 4rem;
  display: block;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 40px var(--accent-glow));
}
.logo h1 {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--fg);
}
.dot { color: var(--accent); }
.tagline {
  color: var(--fg2);
  font-size: 1.1rem;
  margin-bottom: 44px;
  font-weight: 400;
}
.subtitle {
  color: var(--fg2);
  font-size: 0.82rem;
  margin-top: 16px;
  opacity: 0.5;
}

/* ─── Onboarding ───────────────────────────────────────────────── */
.onboard-container {
  width: 100%;
  max-width: 400px;
  padding: 40px 28px;
  position: relative;
  background: var(--bg2);
  border: 1px solid #2a2825;
  border-radius: var(--radius-lg);
}
.onboard-container h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 32px;
  text-align: center;
}
.field {
  margin-bottom: 24px;
}
.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--fg2);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.editable-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid #3a3835;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition);
  -webkit-user-select: text;
  user-select: text;
}
.editable-input:focus { border-color: var(--accent); }
.editable-input:empty::before {
  content: attr(data-placeholder);
  color: #555;
  pointer-events: none;
}

.pill-group {
  display: flex;
  gap: 8px;
}
.pill {
  flex: 1;
  padding: 11px 8px;
  background: var(--bg);
  border: 1px solid #3a3835;
  border-radius: var(--radius-sm);
  color: var(--fg2);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.pill:hover { border-color: #555; color: var(--fg); }
.pill.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(127, 166, 80, 0.08);
}

.onboard-container .btn-primary {
  width: 100%;
  margin-top: 8px;
}

.btn-quick-match {
  width: 100%;
  margin-top: 4px;
}

.divider-or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: lowercase;
}
.divider-or::before,
.divider-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #2a2825;
}

/* ─── Waiting ──────────────────────────────────────────────────── */
.waiting-container {
  text-align: center;
  padding: 40px;
}
.pulse-ring {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  position: relative;
}
.pulse-ring::before {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.9); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 0.1; }
}
.waiting-icon { font-size: 2.8rem; }
.waiting-container h2 {
  font-weight: 500;
  margin-bottom: 8px;
}
.waiting-sub {
  color: var(--fg2);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

/* ─── Game ─────────────────────────────────────────────────────── */
.game-container {
  width: 100%;
  max-width: 500px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.player-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all var(--transition);
}

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

.player-name {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.clock {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fg);
  background: var(--bg3);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  min-width: 72px;
  text-align: center;
}

/* ─── Video PIP ────────────────────────────────────────────────── */
.video-pip {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg3);
  border: 2px solid #3a3835;
  position: relative;
  flex-shrink: 0;
}
.video-pip video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  pointer-events: none;
}
/* hide iOS native video controls and play button */
video::-webkit-media-controls {
  display: none !important;
  -webkit-appearance: none;
}
video::-webkit-media-controls-panel {
  display: none !important;
  -webkit-appearance: none;
}
video::-webkit-media-controls-play-button {
  display: none !important;
  -webkit-appearance: none;
}
video::-webkit-media-controls-start-playback-button {
  display: none !important;
  -webkit-appearance: none;
}
video::-webkit-media-controls-overlay-play-button {
  display: none !important;
  -webkit-appearance: none;
}
.video-pip-self {
  border-color: var(--accent);
}

/* ─── Chess Board ──────────────────────────────────────────────── */
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(85vw, 460px);
  height: min(85vw, 460px);
  border-radius: 2px;
  overflow: hidden;
  box-shadow:
    0 2px 4px rgba(0,0,0,0.3),
    0 12px 40px rgba(0,0,0,0.25);
  user-select: none;
  -webkit-user-select: none;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: none;
}
.square.light { background: var(--board-light); }
.square.dark { background: var(--board-dark); }

.square.selected.light { background: #f6f669; }
.square.selected.dark { background: #baca2b; }

.square.legal::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--board-legal);
}
.square.legal.has-piece::after {
  width: 85%;
  height: 85%;
  border-radius: 50%;
  background: transparent;
  border: 6px solid var(--board-legal-capture);
}

.square.last-move.light { background: #f6f669; }
.square.last-move.dark { background: #baca2b; }

.square.check {
  box-shadow: inset 0 0 0 3px #cc3333;
  border-radius: 1px;
}

.piece {
  width: 85%;
  height: 85%;
  pointer-events: none;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
  will-change: opacity;
  contain: layout style;
}

/* ─── Game controls ────────────────────────────────────────────── */
.game-controls {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* ─── Post-game ────────────────────────────────────────────────── */
.postgame-container {
  text-align: center;
  padding: 40px;
  z-index: 2;
}
.postgame-result { margin-bottom: 40px; }
.result-icon { font-size: 3rem; display: block; margin-bottom: 12px; }
.postgame-result h2 { font-weight: 600; margin-bottom: 8px; font-size: 1.6rem; }
.postgame-result p { color: var(--fg2); }

.postgame-prompt {
  font-size: 1.15rem;
  margin-bottom: 20px;
  font-weight: 400;
}
.postgame-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.postgame-waiting p {
  color: var(--fg2);
  margin-top: 16px;
}
.mini-pulse {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  margin: 0 auto;
  animation: pulse 1.5s ease-in-out infinite;
}

.postgame-matched {
  animation: fadeIn 0.5s ease;
}
.match-icon { font-size: 2.5rem; display: block; margin-bottom: 12px; }
.postgame-matched h2 { color: var(--accent); margin-bottom: 8px; }

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

/* ─── Messenger chat (post-game) ───────────────────────────────── */
.chat-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100dvh;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid #2a2825;
  flex-shrink: 0;
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-video-pip {
  width: 66px;
  height: 66px;
}
.chat-partner-name {
  font-size: 1rem;
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-msg {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.4;
  word-wrap: break-word;
  animation: fadeIn 0.15s ease;
}
.chat-msg.self {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.other {
  align-self: flex-start;
  background: var(--bg3);
  color: var(--fg);
  border-bottom-left-radius: 4px;
}

.chat-msg-system {
  align-self: center;
  color: var(--fg2);
  font-size: 0.78rem;
  padding: 8px 16px;
  opacity: 0.7;
}

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg2);
  border-top: 1px solid #2a2825;
  flex-shrink: 0;
}
.chat-self-pip {
  width: 54px;
  height: 54px;
  flex-shrink: 0;
}

.chat-input-editable {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid #3a3835;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
  min-height: 40px;
  max-height: 80px;
  overflow-y: auto;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
}
.chat-input-editable:focus {
  border-color: var(--accent);
}
.chat-input-editable:empty::before {
  content: attr(data-placeholder);
  color: #555;
  pointer-events: none;
}

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}
.btn-send:hover {
  background: var(--accent-hover);
}

/* ─── Modal ────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.modal-content {
  background: var(--bg2);
  border: 1px solid #2a2825;
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
}
.modal-icon { font-size: 2.5rem; display: block; margin-bottom: 12px; }
.modal-content h3 { font-weight: 600; margin-bottom: 8px; }
.modal-content p { color: var(--fg2); font-size: 0.9rem; margin-bottom: 20px; }
.report-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.btn-report-option {
  padding: 12px;
  background: var(--bg3);
  border: 1px solid #3a3835;
  border-radius: var(--radius-sm);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition);
}
.btn-report-option:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Responsive ───────────────────────────────────────────────── */
@media (max-width: 480px) {
  .logo h1 { font-size: 2rem; }
  .tagline { font-size: 1rem; }
  .board {
    width: 96vw;
    height: 96vw;
  }
  .piece { width: 88%; height: 88%; }
  .player-bar { padding: 6px 10px; }
  .clock { font-size: 1.05rem; padding: 3px 8px; }
  .video-pip { width: 56px; height: 56px; }
  .game-container { padding: 6px; gap: 4px; }
  .onboard-container {
    border: none;
    background: transparent;
  }
}

@media (min-width: 768px) {
  .board {
    width: 460px;
    height: 460px;
  }
}

/* ─── Turn indicator ───────────────────────────────────────────── */
.player-bar.active-turn {
  background: #272522;
  border: 1px solid #3a3835;
}
.player-bar.active-turn .clock {
  background: var(--accent);
  color: #fff;
}

/* ─── Promotion modal ──────────────────────────────────────────── */
.promo-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.promo-options {
  display: flex;
  gap: 4px;
  background: var(--bg2);
  padding: 8px;
  border-radius: var(--radius-lg);
  border: 1px solid #2a2825;
}
.promo-option {
  width: 68px;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  background: var(--bg3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.promo-option:hover {
  border-color: var(--accent);
  background: rgba(127, 166, 80, 0.1);
}

/* ─── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3835; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }
