/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d1a;
  --surface:   #16162a;
  --surface2:  #1e1e38;
  --border:    rgba(255,255,255,0.08);
  --text:      #f0f0f8;
  --muted:     #7878a0;
  --accent:    #7c3aed;
  --correct:   #22c55e;
  --wrong:     #ef4444;
  --gold:      #f59e0b;
  --radius:    14px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  user-select: none;
  -webkit-app-region: no-drag;
}

/* ── App shell ───────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* dvh accounts for mobile browser chrome (URL bar, nav bar) */
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  -webkit-app-region: drag;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-app-region: drag;
}

.logo-icon { font-size: 20px; }
.logo-text  { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }

.header-stats {
  display: flex;
  gap: 16px;
  align-items: center;
  -webkit-app-region: no-drag;
}

.hstat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 44px;
}

.hstat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.hstat-value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.hstat-streak {
  flex-direction: row;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
}

.hstat-streak .hstat-label {
  font-size: 10px;
  color: var(--muted);
  margin-left: 2px;
}

.streak-flame { font-size: 14px; min-width: 16px; text-align: center; }

.hstat-best {
  cursor: default;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  position: relative;
}

/* Show the native title tooltip with a styled pseudo-element alternative */
.hstat-best:hover { border-color: rgba(255,255,255,0.18); }

/* ── Loading / Error screens ─────────────────────────────────────────────── */
.loading-screen,
.error-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.08);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.loading-text { font-size: 15px; }

.error-icon { font-size: 40px; }
.error-msg  { font-size: 15px; text-align: center; max-width: 360px; color: var(--text); }

.btn-retry {
  margin-top: 8px;
  padding: 10px 28px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-retry:hover { opacity: 0.85; }

/* ── Game layout ─────────────────────────────────────────────────────────── */
.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Prompt / Commander section ──────────────────────────────────────────── */
.prompt {
  padding: 12px 24px 10px;
  flex-shrink: 0;
}

.prompt-label {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.commander-display {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px 8px 8px;
}

.commander-img {
  width: 52px;
  height: 73px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--surface2);
}

.commander-info {
  flex: 1;
  min-width: 0;
}

.commander-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.commander-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.btn-new-commander {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-new-commander:hover { color: var(--text); background: var(--surface); }

/* ── Comparison grid ─────────────────────────────────────────────────────── */
.comparison {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr clamp(36px, 5vw, 52px) 1fr;
  padding: clamp(4px, 1vh, 12px) clamp(10px, 2vw, 24px) clamp(4px, 1vh, 10px);
  min-height: 0;
  align-items: center;
  overflow: hidden;
}

.card-option {
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 5px 5px 14px;
  transition: background 0.15s, transform 0.12s;
}

.card-option:hover:not(.revealed) {
  background: rgba(124, 58, 237, 0.1);
  transform: scale(1.012);
}

.card-option:active:not(.revealed) {
  transform: scale(0.985);
}

.card-img-wrap {
  position: relative;
  width: 100%;
  /* Lock to MTG card aspect ratio so the full card is always visible */
  aspect-ratio: 488 / 680;
  /* 380px accounts for all fixed UI + bottom breathing room */
  max-height: calc(100vh - 380px);
  max-height: calc(100dvh - 380px);
  border-radius: clamp(6px, 1vw, 12px);
  overflow: hidden;
  background: transparent;
}

/* Tighten spacing on short viewports so cards never get clipped */
@media (max-height: 700px) {
  .prompt        { padding: 6px 24px 6px; }
  .commander-img { width: 40px; height: 56px; }
  .difficulty-bar { padding: 3px 24px; }
  .feedback-bar  { min-height: 38px; padding: 5px 24px; }
  .key-hints     { padding: 3px; }
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity 0.2s;
  background: transparent;
}

/* ── Result overlays ─────────────────────────────────────────────────────── */
.result-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
  border-radius: 10px;
}

.result-overlay.winner {
  background: rgba(34, 197, 94, 0.82);
}

.result-overlay.loser {
  background: rgba(0, 0, 0, 0.72);
}

.result-overlay.picked-wrong {
  background: rgba(239, 68, 68, 0.82);
}

.result-icon {
  font-size: 32px;
  font-weight: 900;
  color: white;
  line-height: 1;
}

.result-pct {
  font-size: 26px;
  font-weight: 800;
  color: white;
  line-height: 1;
}

.result-count {
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  font-weight: 500;
}

/* ── VS column ───────────────────────────────────────────────────────────── */
.vs-column {
  display: flex;
  align-items: center;
  justify-content: center;
}

.vs-badge {
  width: 34px;
  height: 34px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.5px;
}

/* ── Difficulty bar ──────────────────────────────────────────────────────── */
.difficulty-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 24px;
  flex-shrink: 0;
}

.difficulty-bar::before,
.difficulty-bar::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

#difficulty-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--muted);
  transition: color 0.4s;
}

/* ── Card label ──────────────────────────────────────────────────────────── */
.card-label {
  text-align: center;
  flex-shrink: 0;
}

.card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Feedback bar ────────────────────────────────────────────────────────── */
.feedback-bar {
  flex-shrink: 0;
  padding: 8px 24px;
  text-align: center;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: background 0.2s;
  border-top: 1px solid var(--border);
}

.feedback-bar.correct {
  background: rgba(34, 197, 94, 0.12);
  border-top-color: rgba(34, 197, 94, 0.3);
}

.feedback-bar.wrong {
  background: rgba(239, 68, 68, 0.12);
  border-top-color: rgba(239, 68, 68, 0.3);
}

.feedback-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.feedback-bar.correct .feedback-text { color: var(--correct); }
.feedback-bar.wrong   .feedback-text { color: var(--wrong); }

.feedback-sub {
  font-size: 12px;
  color: var(--muted);
}

/* ── Key hints ───────────────────────────────────────────────────────────── */
.key-hints {
  flex-shrink: 0;
  text-align: center;
  padding: 6px;
  font-size: 11px;
  color: var(--muted);
}

kbd {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
}

/* ── Lightbox ────────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.lightbox.open {
  opacity: 1;
  pointer-events: all;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 32px 96px rgba(0,0,0,0.8);
  animation: zoomIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes zoomIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  color: white;
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.3); }

.commander-img {
  cursor: zoom-in;
}

/* ── Touch devices: hide keyboard hints, enlarge commander UI ────────────── */
@media (hover: none) and (pointer: coarse) {
  .key-hints { display: none; }
  .commander-name { font-size: 18px; }
  .btn-new-commander { width: 40px; height: 40px; font-size: 20px; }

  /* Pin feedback bar to bottom of viewport — avoids it being cut off by browser chrome */
  .feedback-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    min-height: calc(56px + env(safe-area-inset-bottom));
    z-index: 10;
  }
  .feedback-bar.correct { background: rgba(34, 197, 94, 0.12); }
  .feedback-bar.wrong   { background: rgba(239, 68, 68, 0.12); }

  /* Reserve space so the fixed bar doesn't overlap the comparison cards */
  .game { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* ── Share button ────────────────────────────────────────────────────────── */
.share-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.share-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}
.share-btn.copied {
  color: #22c55e;
  border-color: #22c55e;
}
