/* ===== COMPONENT STYLES ===== */

/* ---- Header / Top Bar ---- */
.top-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  padding-top: calc(var(--sp-3) + env(safe-area-inset-top));
  background: var(--c-surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-bar__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease-out);
}
.top-bar__back:active { background: var(--c-border); }
.top-bar__back svg { width: 20px; height: 20px; }

.top-bar__title {
  flex: 1;
  text-align: center;
  font-size: var(--fs-lg);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar__spacer { width: 44px; flex-shrink: 0; }

/* ---- Turn Indicator ---- */
.turn-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: color var(--dur-mid) var(--ease-out);
}

.turn-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.turn-dot.p0 { background: var(--c-p0); box-shadow: 0 0 6px var(--c-p0-glow); }
.turn-dot.p1 { background: var(--c-p1); box-shadow: 0 0 6px var(--c-p1-glow); }

/* ---- Bottom Bar ---- */
.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: var(--c-surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--c-border);
  flex-wrap: wrap;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  min-height: 44px;
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: var(--fs-sm);
  font-weight: 600;
  border: 1px solid var(--c-border);
  background: var(--c-surface-2);
  color: var(--c-text);
  transition: background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  touch-action: manipulation;
  white-space: nowrap;
  cursor: pointer;
}
.btn:active { transform: scale(0.96); background: var(--c-border); }
.btn--primary {
  background: var(--c-accent);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 12px rgba(91,141,238,0.35);
}
.btn--primary:active { background: #4a78d4; }
.btn--danger {
  background: var(--c-danger);
  color: #fff;
  border-color: transparent;
}
.btn--sm { padding: var(--sp-1) var(--sp-3); min-height: 36px; font-size: var(--fs-xs); }
.btn--lg { padding: var(--sp-3) var(--sp-6); font-size: var(--fs-md); min-height: 52px; }

/* ---- Modal / Dialog ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--sp-4);
  animation: fadeIn var(--dur-mid) var(--ease-out);
}

.modal {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  max-width: 380px;
  width: 100%;
  padding: var(--sp-6);
  animation: slideUp var(--dur-slow) var(--ease-bounce);
  max-height: 85dvh;
  overflow-y: auto;
}

.modal__title {
  font-size: var(--fs-xl);
  font-weight: 700;
  text-align: center;
  margin-bottom: var(--sp-4);
}

.modal__body {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  line-height: 1.7;
  margin-bottom: var(--sp-6);
}

.modal__actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* ---- Lobby ---- */
.lobby {
  flex: 1;
  padding: var(--sp-6) var(--sp-4);
  padding-top: calc(var(--sp-6) + env(safe-area-inset-top));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.lobby__header { text-align: center; }
.lobby__logo {
  font-size: var(--fs-3xl);
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--c-p0), var(--c-p1));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.lobby__subtitle { color: var(--c-text-muted); font-size: var(--fs-sm); margin-top: var(--sp-1); }

.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

.game-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
  box-shadow: var(--shadow-sm);
  touch-action: manipulation;
  text-align: center;
}
.game-card:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-md);
  border-color: var(--c-accent);
}
.game-card__art { width: 80px; height: 80px; }
.game-card__name { font-size: var(--fs-md); font-weight: 700; }
.game-card__desc { font-size: var(--fs-xs); color: var(--c-text-muted); line-height: 1.5; }

/* ---- Mode Picker ---- */
.mode-picker {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.mode-option {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-md);
  border: 2px solid var(--c-border);
  background: var(--c-surface);
  cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast);
  touch-action: manipulation;
}
.mode-option:active { border-color: var(--c-accent); background: var(--c-surface-2); }
.mode-option.selected { border-color: var(--c-accent); background: rgba(91,141,238,0.1); }
.mode-option__icon { font-size: 28px; flex-shrink: 0; }
.mode-option__text strong { display: block; font-size: var(--fs-md); font-weight: 700; }
.mode-option__text span { font-size: var(--fs-xs); color: var(--c-text-muted); }

.difficulty-row {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}
.diff-btn {
  flex: 1;
  padding: var(--sp-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: var(--c-surface-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  transition: background var(--dur-fast), border-color var(--dur-fast);
  min-height: 36px;
  touch-action: manipulation;
}
.diff-btn.selected { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }

/* ---- Game Screen ---- */
.game-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: 100vh;
}

.board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-3) var(--sp-2);
  overflow: hidden;
}

/* ---- Player score chips ---- */
.score-row {
  display: flex;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
}
.score-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  font-size: var(--fs-sm);
  font-weight: 700;
}
.score-chip.p0 { border-color: var(--c-p0); }
.score-chip.p1 { border-color: var(--c-p1); }
.score-chip__dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.score-chip.p0 .score-chip__dot { background: var(--c-p0); }
.score-chip.p1 .score-chip__dot { background: var(--c-p1); }

/* ---- Rules Dialog ---- */
.rules-content {
  text-align: right;
  direction: rtl;
}
.rules-content h3 { font-size: var(--fs-md); font-weight: 700; margin-bottom: var(--sp-2); color: var(--c-accent); }
.rules-content p, .rules-content li {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  line-height: 1.8;
  margin-bottom: var(--sp-2);
}
.rules-content ul { padding-right: var(--sp-4); }

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pieceDrop {
  0%   { transform: translateY(var(--drop-from)); }
  75%  { transform: translateY(4px); }
  100% { transform: translateY(0); }
}
@keyframes scaleIn {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
@keyframes winPulse {
  0%, 100% { filter: brightness(1); }
  50%       { filter: brightness(1.5) drop-shadow(0 0 8px var(--c-win-glow)); }
}
@keyframes flipFront {
  0%   { transform: rotateY(0deg); }
  50%  { transform: rotateY(-90deg); }
  100% { transform: rotateY(-90deg); }
}
@keyframes flipBack {
  0%   { transform: rotateY(90deg); }
  50%  { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}
@keyframes lastMovePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.3); }
  50%       { box-shadow: 0 0 0 4px rgba(255,255,255,0.15); }
}

/* ---- Scripted demo (how to play) ---- */
.demo {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--c-bg);
  overflow: hidden;
  animation: fadeIn var(--dur-mid) var(--ease-out);
}

.demo__caption {
  min-height: 4.6em;
  margin: var(--sp-3) var(--sp-4) 0;
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: var(--fs-md);
  line-height: 1.6;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
}

.demo__caption--win {
  font-weight: 700;
  border-color: var(--c-p0);
}

.demo__stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.demo__shield {
  position: absolute;
  inset: 0;
  z-index: 5;
}

.demo__progress {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: var(--sp-2) 0;
}

.demo__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-border);
  transition: background var(--dur-mid) var(--ease-out);
}

.demo__dot--on { background: var(--c-border-focus); }

.demo__bar {
  display: flex;
  gap: var(--sp-2);
  justify-content: center;
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
}
