/* ============================================================
   Card Engine — Main CSS
   Mobile-first, base at 375px, max content 480px
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600&display=swap');

/* ── CSS Variables ── */
:root {
  --bg-primary:   #0d0d1a;
  --bg-card:      #1a1a2e;
  --bg-surface:   #16213e;
  --bg-surface-2: #1e2a45;
  --accent:       #6C63FF;
  --accent-hover: #5a52e0;
  --accent-2:     #FF6584;
  --accent-3:     #43E97B;
  --text-primary: #f0f0ff;
  --text-muted:   #8888aa;
  --text-dim:     #555577;
  --border:       rgba(108, 99, 255, 0.2);
  --border-light: rgba(255, 255, 255, 0.08);
  --shadow-card:  0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg:    0 16px 48px rgba(0, 0, 0, 0.6);
  --radius-card:  16px;
  --radius-btn:   12px;
  --radius-sm:    8px;
  --transition:   0.2s ease;
  --font-heading: 'Space Grotesk', sans-serif;
  --font-body:    'Inter', sans-serif;
}

/* Light theme */
body.theme-light {
  --bg-primary:   #f0f0f8;
  --bg-card:      #ffffff;
  --bg-surface:   #e8e8f5;
  --bg-surface-2: #ddddf0;
  --text-primary: #1a1a2e;
  --text-muted:   #555577;
  --border:       rgba(108, 99, 255, 0.25);
  --border-light: rgba(0, 0, 0, 0.1);
  --shadow-card:  0 8px 32px rgba(0, 0, 0, 0.15);
  --shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg:    0 16px 48px rgba(0, 0, 0, 0.2);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

img { max-width: 100%; height: auto; display: block; }
a   { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

h1, h2, h3, h4, h5 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.2;
}

/* ── Layout ── */
.app-wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  width: 100%;
}

/* ── Fade-in on load ── */
.page-fade {
  animation: fadeIn 0.2s ease-out both;
}

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

/* ── Navigation ── */
.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-nav .nav-brand {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 18px;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.app-nav .nav-brand span {
  color: var(--accent);
}

.nav-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: background var(--transition), transform var(--transition);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-icon-btn:hover {
  background: var(--accent);
  color: white;
}

.nav-icon-btn:active {
  transform: scale(0.94);
}

/* ── Avatar ── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.15);
}

.avatar-lg {
  width: 72px;
  height: 72px;
  font-size: 36px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius-btn);
  border: none;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  min-height: 44px;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.35);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.5);
  color: white;
}

.btn-secondary {
  background: var(--bg-surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(255, 101, 132, 0.15);
  color: var(--accent-2);
  border: 1px solid rgba(255, 101, 132, 0.3);
}
.btn-danger:hover {
  background: var(--accent-2);
  color: white;
  border-color: var(--accent-2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}
.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-surface-2);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  min-height: 36px;
  border-radius: 8px;
}

.btn-lg {
  padding: 16px 28px;
  font-size: 17px;
  border-radius: 14px;
}

.btn-full { width: 100%; }

/* ── Cards / Surfaces ── */
.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  padding: 20px;
}

.surface-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

/* ── Forms ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
textarea,
select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 44px;
  appearance: none;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.2);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%238888aa' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
}

.form-error {
  color: var(--accent-2);
  font-size: 13px;
  margin-top: 4px;
}

.form-hint {
  color: var(--text-muted);
  font-size: 12px;
}

/* Toggle */
.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}

.toggle {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-light);
  border-radius: 99px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: left 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-slider::after {
  left: 25px;
  background: white;
}

/* ── Deck Cards (horizontal scroll rows) ── */
.deck-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.deck-row::-webkit-scrollbar { display: none; }

.deck-thumb {
  flex-shrink: 0;
  width: 160px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  padding: 16px;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  position: relative;
}

.deck-thumb:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(108,99,255,0.2);
}

.deck-thumb:active { transform: scale(0.97); }

.deck-thumb-name {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.deck-thumb-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.deck-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  margin-top: 8px;
}

.badge-tabletop  { background: rgba(108,99,255,0.15); color: var(--accent); }
.badge-flashcard { background: rgba(67,233,123,0.15); color: var(--accent-3); }
.badge-party     { background: rgba(255,101,132,0.15); color: var(--accent-2); }
.badge-custom    { background: rgba(255,255,255,0.08); color: var(--text-muted); }

.deck-quick-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 6px 10px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
}

.deck-quick-btn:hover  { background: var(--accent-hover); }
.deck-quick-btn:active { transform: scale(0.96); }

/* ── Section Headers ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  margin-top: 24px;
}

.section-title {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 600;
}

/* ── Toasts ── */
#toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 420px;
}

.toast {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease-out both;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.toast-success { border-left: 3px solid var(--accent-3); }
.toast.toast-error   { border-left: 3px solid var(--accent-2); }
.toast.toast-info    { border-left: 3px solid var(--accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(16px) scale(0.95); }
}

/* ── Bottom Sheets ── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  animation: backdropIn 0.25s ease-out forwards;
}

@keyframes backdropIn {
  to { opacity: 1; }
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: 480px;
  background: var(--bg-surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border-light);
  z-index: 201;
  animation: sheetUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  max-height: 80vh;
  overflow-y: auto;
}

@keyframes sheetUp {
  to { transform: translateX(-50%) translateY(0); }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border-light);
  border-radius: 99px;
  margin: 12px auto 0;
}

.sheet-header {
  padding: 16px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
}

.sheet-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 17px;
}

.sheet-body {
  padding: 16px 20px 32px;
}

.sheet-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface-2);
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition);
}
.sheet-close:hover { background: var(--accent-2); color: white; }

/* ── Misc ── */
.divider {
  height: 1px;
  background: var(--border-light);
  margin: 20px 0;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
  margin-top: 4px;
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--accent);
  color: white;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}

/* Data table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-light);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-surface-2); }

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo .logo-emoji {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.auth-logo h1 {
  font-size: 26px;
  font-weight: 700;
}

.auth-logo p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

/* Color picker */
.color-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}

.color-swatch.active,
.color-swatch:hover {
  border-color: white;
  transform: scale(1.15);
}

/* Emoji grid */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.emoji-btn {
  width: 36px;
  height: 36px;
  font-size: 20px;
  border: none;
  background: var(--bg-surface-2);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}

.emoji-btn:hover  { background: var(--accent); transform: scale(1.1); }
.emoji-btn.active { background: var(--accent); }

/* Progress / Loading */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Desktop tweaks ── */
@media (min-width: 600px) {
  .app-wrap { padding: 0 24px; }
  .auth-card { padding: 40px 36px; }
}
