/* ============================================================
   Board Game Tracker — style.css
   Tailwind utility classes handle most layout/spacing.
   This file adds: game tile cards, texture overlays,
   progress bars, animations, and iOS PWA fixes.
   ============================================================ */

/* ── BASE ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  font-family: 'Inter', system-ui, sans-serif;
  background-color: #0f172a;
  color: #e2e8f0;
  min-height: 100dvh;
}

/* Prevent iOS zoom on input focus */
input, textarea, select {
  font-size: 16px !important;
}

/* ── VIEWS — toggled via .hidden class only ───────────────────── */
/* Views start hidden via class="view hidden" in HTML.
   showView() removes .hidden from the target and adds it to others.
   .hidden { display: none !important } is defined in the utility section. */

/* ── LOGIN ────────────────────────────────────────────────────── */
#login-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.login-card {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 1.25rem;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}

/* ── iOS INSTALL BANNER ───────────────────────────────────────── */
#ios-banner {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1e293b;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  padding: 1rem 1.25rem;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
}
#ios-banner.visible { display: flex; align-items: center; gap: 0.75rem; }

/* ── SHELF ────────────────────────────────────────────────────── */
#shelf-view { min-height: 100dvh; }

.shelf-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  padding: 0.875rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  padding: 1rem;
}

@media (min-width: 640px) {
  .game-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .game-grid { grid-template-columns: repeat(4, 1fr); gap: 1rem; padding: 1.25rem; }
}

/* ── GAME TILE ────────────────────────────────────────────────── */
.game-tile {
  position: relative;
  border-radius: 0.875rem;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 3/4;
  background: #1e293b;
  border: 1px solid rgba(148, 163, 184, 0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.game-tile:active {
  transform: scale(0.97);
}

.game-tile:hover {
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  transform: translateY(-2px);
}

.tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
  transition: transform 0.3s ease;
}

.game-tile:hover .tile-img {
  transform: scale(1.04);
}

.tile-placeholder {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #1e293b, #334155);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  opacity: 0.4;
}

.tile-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.6) 60%, transparent 100%);
  padding: 0.875rem 0.75rem 0.75rem;
}

.tile-name {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  color: #f1f5f9;
  margin-bottom: 0.4rem;
  /* Two-line clamp */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── PROGRESS BAR ─────────────────────────────────────────────── */
.progress-wrap {
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  margin-bottom: 0.3rem;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: #22d3ee;
  border-radius: 2px;
  transition: width 0.4s ease;
}

.progress-label {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.7);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wanted-badge {
  background: rgba(251, 146, 60, 0.9);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 9999px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* ── FAB (Floating Action Button) ─────────────────────────────── */
.fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 9999px;
  background: #0ea5e9;
  color: white;
  border: none;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(14, 165, 233, 0.5);
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 50;
  -webkit-tap-highlight-color: transparent;
}

.fab:active { transform: scale(0.93); }
.fab:hover { box-shadow: 0 6px 28px rgba(14, 165, 233, 0.65); }

/* ── SYNC INDICATOR ───────────────────────────────────────────── */
.sync-indicator {
  display: none;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: #94a3b8;
}

.sync-indicator.visible { display: flex; }

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22d3ee;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* ── MODALS ───────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 60;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 1rem; }
}

.modal-backdrop.open { display: flex; }

.modal {
  background: #1e293b;
  border-radius: 1.25rem 1.25rem 0 0;
  padding: 1.5rem;
  width: 100%;
  max-width: 540px;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(148,163,184,0.1);
  animation: slideUp 0.22s ease;
}

@media (min-width: 640px) {
  .modal { border-radius: 1.25rem; }
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-handle {
  width: 2.5rem;
  height: 4px;
  background: rgba(148,163,184,0.3);
  border-radius: 2px;
  margin: 0 auto 1.25rem;
}

/* ── DETAIL VIEW ──────────────────────────────────────────────── */
#detail-view { min-height: 100dvh; }

.detail-hero {
  position: relative;
  height: 220px;
  background: #1e293b;
  overflow: hidden;
}

.detail-hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.5;
}

.detail-hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.2) 0%, rgba(15,23,42,1) 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.25rem;
}

.detail-header-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
}

.btn-back {
  background: rgba(0,0,0,0.4);
  border: none;
  color: white;
  border-radius: 9999px;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
}

/* ── EXPANSION ROW ────────────────────────────────────────────── */
.expansion-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid rgba(148,163,184,0.08);
}

.expansion-row:last-child { border-bottom: none; }

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

.expansion-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: #f1f5f9;
  line-height: 1.3;
}

.expansion-year {
  font-size: 0.7rem;
  color: #64748b;
  margin-top: 0.125rem;
}

.expansion-notes {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 0.25rem;
  cursor: pointer;
  border-radius: 0.25rem;
  padding: 0.1rem 0.25rem;
  margin-left: -0.25rem;
  transition: background 0.1s;
}

.expansion-notes:hover { background: rgba(148,163,184,0.1); }
.expansion-notes.empty { color: #475569; font-style: italic; }

.expansion-toggles {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  align-items: flex-end;
}

/* ── TOGGLE CHECKBOX ──────────────────────────────────────────── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  color: #94a3b8;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.toggle-check {
  appearance: none;
  -webkit-appearance: none;
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid rgba(148,163,184,0.4);
  border-radius: 0.25rem;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.toggle-check.owned:checked {
  background: #22d3ee;
  border-color: #22d3ee;
}

.toggle-check.wanted:checked {
  background: #fb923c;
  border-color: #fb923c;
}

.toggle-check:checked::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 0px;
  width: 5px;
  height: 9px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* ── BUTTONS ──────────────────────────────────────────────────── */
.btn {
  padding: 0.625rem 1.25rem;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: #0ea5e9; color: white; }
.btn-primary:hover:not(:disabled) { background: #0284c7; }

.btn-secondary {
  background: rgba(148,163,184,0.12);
  color: #cbd5e1;
  border: 1px solid rgba(148,163,184,0.15);
}

.btn-secondary:hover:not(:disabled) { background: rgba(148,163,184,0.2); }

.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-ghost { background: transparent; color: #94a3b8; }

/* ── SEARCH RESULT ITEM ───────────────────────────────────────── */
.search-result {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.625rem;
  cursor: pointer;
  border: 1px solid rgba(148,163,184,0.08);
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.search-result:hover, .search-result:active {
  background: rgba(148,163,184,0.1);
}

.search-thumb {
  width: 3.5rem;
  height: 3.5rem;
  object-fit: cover;
  border-radius: 0.375rem;
  flex-shrink: 0;
  background: #334155;
}

.search-thumb-placeholder {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 0.375rem;
  flex-shrink: 0;
  background: #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #475569;
  font-size: 1.25rem;
}

/* ── NOTES INLINE EDIT ────────────────────────────────────────── */
.notes-input {
  width: 100%;
  background: rgba(15,23,42,0.5);
  border: 1px solid rgba(148,163,184,0.2);
  border-radius: 0.375rem;
  color: #e2e8f0;
  padding: 0.375rem 0.5rem;
  font-size: 0.75rem;
  resize: none;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}

.notes-input:focus {
  border-color: #0ea5e9;
}

/* ── OWNERSHIP PROMPT ─────────────────────────────────────────── */
.ownership-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: 0.75rem;
  border: 2px solid rgba(148,163,184,0.12);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.ownership-option:hover {
  border-color: #0ea5e9;
  background: rgba(14,165,233,0.08);
}

.ownership-option.selected {
  border-color: #0ea5e9;
  background: rgba(14,165,233,0.12);
}

/* ── SPINNER / LOADING ────────────────────────────────────────── */
.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(148,163,184,0.2);
  border-top-color: #0ea5e9;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

.loading-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  color: #64748b;
  font-size: 0.875rem;
}

/* ── ERROR / EMPTY STATES ─────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  color: #475569;
}

.empty-state-icon { font-size: 3.5rem; margin-bottom: 1rem; opacity: 0.6; }

.error-banner {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  border-radius: 0.625rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  margin: 0.75rem 0;
}

.info-banner {
  background: rgba(14,165,233,0.1);
  border: 1px solid rgba(14,165,233,0.3);
  color: #7dd3fc;
  border-radius: 0.625rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  margin: 0.75rem 0;
}

/* ── UTILITY ──────────────────────────────────────────────────── */
.hidden { display: none !important; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.text-muted { color: #64748b; }
.divider { border: none; border-top: 1px solid rgba(148,163,184,0.08); margin: 1rem 0; }
