/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #1a0f07;
  --bg-surface:   #2b1a0e;
  --bg-card:      #3a2415;
  --accent:       #c8860a;
  --accent-light: #e8a830;
  --text:         #f5e8d0;
  --text-muted:   #a89070;
  --danger:       #c0392b;
  --success:      #27ae60;
  --board-dark:   #8b4513;
  --board-light:  #d2691e;
  --board-bg:     #2c1a0a;
  --tri-even:     #c0392b;
  --tri-odd:      #f5f5dc;
  --checker-0:    #f5e8d0;
  --checker-1:    #1a1a1a;
  --checker-border: #8b6914;
  --font-en:      'Georgia', 'Times New Roman', serif;
  --font-ar:      'Amiri', 'Traditional Arabic', serif;
  --radius:       12px;
  --transition:   0.2s ease;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-en);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== SCREENS ===== */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  overflow-y: auto;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ===== LANDING SCREEN ===== */
.landing-content {
  text-align: center;
  padding: 2rem;
  max-width: 480px;
  width: 100%;
}

.game-title {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
}

.title-en {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  color: var(--accent-light);
  letter-spacing: 0.02em;
}

.title-ar {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-family: var(--font-ar);
  color: var(--accent);
  direction: rtl;
}

.intro-text {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.7;
  max-width: 380px;
  text-align: center;
  margin-bottom: 1.5rem;
}

.intro-coda {
  color: var(--accent);
  font-size: 0.95rem;
  font-style: italic;
  text-align: center;
  margin-bottom: 2rem;
}

/* ===== BUTTONS ===== */
.btn-primary {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0.75rem auto;
  padding: 1rem 2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-family: var(--font-en);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-light); }
.btn-primary:active:not(:disabled) { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0.5rem auto;
  padding: 0.75rem 1.5rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--text-muted);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font-en);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.btn-secondary:hover { color: var(--text); border-color: var(--text); }

.btn-text {
  display: block;
  width: 100%;
  margin: 0.5rem auto;
  padding: 0.5rem;
  background: none;
  color: var(--text-muted);
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: center;
}

.btn-text:hover { color: var(--text); }

/* ===== SETUP SCREEN ===== */
.setup-content {
  padding: 2rem;
  max-width: 400px;
  width: 100%;
}

.setup-content h2 {
  text-align: center;
  color: var(--accent-light);
  margin-bottom: 2rem;
  font-size: 1.4rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--bg-surface);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font-en);
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus { border-color: var(--accent); }

/* Country picker */
#country-picker {
  position: relative;
}

.country-select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--bg-surface);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.country-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.country-dropdown.open { display: block; }

.country-search {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg-surface);
  border: none;
  border-bottom: 1px solid var(--bg-card);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

.country-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background var(--transition);
}

.country-option:hover, .country-option.selected {
  background: var(--bg-surface);
}

/* ===== MATCHMAKING SCREEN ===== */
.matchmaking-content {
  text-align: center;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
}

.spinner {
  width: 60px;
  height: 60px;
  border: 4px solid var(--bg-card);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 2rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.timer-text {
  color: var(--text-muted);
  font-size: 1.2rem;
  margin: 1rem 0;
}

/* ===== GAME SCREEN ===== */
.game-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 0;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--bg-surface);
  flex-shrink: 0;
  min-height: 52px;
}

.player-bar.active-turn {
  border-left: 3px solid var(--accent);
}

.flag-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.player-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-style: italic;
}

.borne-off-count {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  text-align: right;
}

.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

/* ===== DISCONNECT BANNER ===== */
.disconnect-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(26, 15, 7, 0.95);
  border: 2px solid var(--danger);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  text-align: center;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.disconnect-banner.hidden { display: none; }

.disconnect-en, .disconnect-ar {
  font-size: 1rem;
  color: var(--text);
}

.disconnect-ar { font-family: var(--font-ar); direction: rtl; }

#disconnect-countdown {
  font-size: 2rem;
  font-weight: bold;
  color: var(--danger);
}

/* ===== REACTION BAR ===== */
.reaction-bar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--bg-surface);
  flex-shrink: 0;
}

.reaction-btn {
  font-size: 1.6rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 8px;
  transition: transform var(--transition), background var(--transition);
  line-height: 1;
}

.reaction-btn:hover { background: var(--bg-card); transform: scale(1.2); }
.reaction-btn:active { transform: scale(0.9); }
.reaction-btn.committed { background: var(--bg-card); outline: 2px solid var(--accent); }

/* ===== PEACE ICONS (persistent, shown while one player has committed) ===== */
.peace-icon {
  position: fixed;
  top: calc(50vh - 150px);
  width: 300px;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 200px;
  line-height: 1;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.peace-icon.visible { opacity: 1; }
.peace-icon-mine { left: 0; }
.peace-icon-opp  { right: 0; }

/* ===== PEACE ENDING OVERLAY ===== */
.peace-ending {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: var(--bg);
  z-index: 800;
  animation: peaceFadeIn 1.2s ease forwards;
}
.peace-ending.hidden { display: none; }

@keyframes peaceFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.peace-ending-emoji {
  font-size: 5rem;
}

.peace-ending-word {
  font-size: 2.4rem;
  font-style: italic;
  color: var(--accent);
  font-family: var(--font-en);
  letter-spacing: 0.05em;
}

/* ===== RESULT SCREEN ===== */
.result-content {
  text-align: center;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
}

.result-emoji {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.result-title {
  font-size: 1.8rem;
  color: var(--accent-light);
  margin-bottom: 0.5rem;
}

.result-title-ar {
  font-family: var(--font-ar);
  direction: rtl;
  font-size: 1.5rem;
  color: var(--accent);
  margin-bottom: 1rem;
}

.result-detail {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 1rem;
}

/* ===== STATUS MESSAGE ===== */
.status-en, .status-ar {
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.status-ar {
  font-family: var(--font-ar);
  direction: rtl;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-card); border-radius: 2px; }

/* ===== MOBILE ADJUSTMENTS ===== */
@media (max-width: 480px) {
  .title-en { font-size: 1.6rem; }
  .title-ar { font-size: 1.2rem; }
  .reaction-btn { font-size: 1.4rem; }
  .player-bar { padding: 0.4rem 0.75rem; min-height: 44px; }
}

@media (min-height: 900px) {
  .player-bar { min-height: 64px; padding: 1rem; }
  .reaction-bar { padding: 0.75rem 1rem; }
}

/* No moves message */
.no-moves-toast {
  position: absolute;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 15, 7, 0.9);
  border: 1px solid var(--accent);
  border-radius: 24px;
  padding: 0.6rem 1.5rem;
  font-size: 0.9rem;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  white-space: nowrap;
  z-index: 20;
}

.no-moves-toast.visible { opacity: 1; }
