/* =========================================
   Family Game Center — Global Styles
   Mobile-first responsive design
   ========================================= */

:root {
  --primary: #4a6fa5;
  --primary-dark: #3a5a8a;
  --primary-light: #6a8fc5;
  --danger: #e05252;
  --danger-dark: #c03030;
  --success: #3a9e6e;
  --warning: #e09a2e;
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-muted: #7f8c8d;
  --border: #dce1e7;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.14);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ---- Navbar ---- */
.navbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  background: var(--primary);
  padding: 0 1rem;
  min-height: 56px;
  gap: 0.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.nav-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  flex: 1;
  white-space: nowrap;
}
.nav-brand:hover { text-decoration: none; opacity: 0.9; }

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid rgba(255,255,255,0.5);
  color: #fff;
  font-size: 1.2rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}

.nav-links {
  display: flex;
  list-style: none;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.nav-link {
  color: rgba(255,255,255,0.9);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
  transition: background 0.15s;
}
.nav-link:hover { background: rgba(255,255,255,0.15); text-decoration: none; }

.nav-user {
  color: rgba(255,255,255,0.85);
  font-size: 0.9rem;
  padding: 0.4rem 0.5rem;
}

.btn-outline-nav {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.6);
  color: #fff;
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-outline-nav:hover { background: rgba(255,255,255,0.2); }

.logout-form { display: inline; }

/* Mobile nav */
@media (max-width: 640px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.5rem 0 0.75rem;
    gap: 0.25rem;
  }
  .nav-links.open { display: flex; }
  .nav-links li { width: 100%; }
  .nav-link { display: block; width: 100%; }
  .nav-user { padding: 0.4rem 0.75rem; }
  .logout-form { width: 100%; }
  .btn-outline-nav { width: 100%; text-align: center; }
}

/* ---- Main Content ---- */
.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ---- Flash Messages ---- */
.flash {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
}
.flash-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}
.flash-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

/* ---- Page Header ---- */
.page-header {
  margin-bottom: 1.75rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}
.page-header h1 { font-size: 1.75rem; color: var(--text); }
.page-subtitle { color: var(--text-muted); margin-top: 0.25rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  text-align: center;
  line-height: 1.4;
}
.btn:hover { transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; }

.btn-secondary {
  background: #e8eef6;
  color: var(--primary);
  border: 1px solid var(--primary-light);
}
.btn-secondary:hover { background: #d0dcf0; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-dark); color: #fff; }

.btn-sm {
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
}
.btn-full { width: 100%; display: block; }

/* ---- Forms ---- */
.form-container {
  max-width: 420px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.form-card {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-title {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
  color: var(--text);
}
.form-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.form-group {
  margin-bottom: 1.1rem;
}
.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}
.form-input {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: #fafafa;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 111, 165, 0.15);
  background: #fff;
}

.form-footer {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ---- Games Grid ---- */
.games-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.game-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.75rem 1.25rem;
  text-align: center;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.game-card--available {
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
}
.game-card--available:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--primary-light);
  text-decoration: none;
  color: var(--text);
}

.game-card--soon {
  opacity: 0.75;
  cursor: default;
}

.game-icon { font-size: 2.75rem; line-height: 1; }
.game-name { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.game-desc { font-size: 0.85rem; color: var(--text-muted); line-height: 1.4; }

.game-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 0.25rem;
}
.game-badge--play { background: var(--primary); color: #fff; }
.game-badge--soon { background: #e8eef6; color: var(--text-muted); }

/* ---- Admin Table ---- */
.admin-container {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.admin-table th {
  background: #f5f7fa;
  padding: 0.85rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border);
}
.admin-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr.row-self { background: #f9fbff; }
.admin-table tr:hover { background: #fafbfc; }

.actions-cell { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline; }

.role-badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.role-admin { background: #dbeafe; color: #1d4ed8; }
.role-user { background: #f3f4f6; color: #6b7280; }

.tag-you {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.45rem;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}

.text-muted { color: var(--text-muted); }

/* Mobile admin table — card layout */
@media (max-width: 580px) {
  .admin-table thead { display: none; }
  .admin-table tbody, .admin-table tr, .admin-table td {
    display: block;
    width: 100%;
  }
  .admin-table tr {
    padding: 0.75rem 1rem;
    border-bottom: 2px solid var(--border);
  }
  .admin-table tr:last-child { border-bottom: none; }
  .admin-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0;
    border-bottom: none;
  }
  .admin-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex: 0 0 80px;
  }
  .actions-cell { justify-content: flex-end; }
  /* Hide the edit-row's pseudo-label on mobile */
  .edit-row td::before { display: none; }
  .edit-row td { display: block; }
}

/* =========================================
   Admin — tabs, inline edit, add-user form
   ========================================= */

/* ── Submenu tabs ── */
.admin-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.admin-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: 6px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.admin-tab:hover:not(.active) {
  border-color: var(--primary);
  color: var(--primary);
}
.admin-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Badge showing user count */
.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5em;
  padding: 0 0.4rem;
  border-radius: 10px;
  font-size: 0.76rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.25);
  line-height: 1.6;
}
.admin-tab:not(.active) .tab-count {
  background: var(--border);
  color: var(--text-muted);
}

/* ── Panels ── */
.admin-panel         { display: none; }
.admin-panel.active  { display: block; }

/* ── Inline edit row ── */
.edit-row > td {
  padding: 0.85rem 1rem;
  background: #f0f5ff;
  border-top: 2px dashed var(--primary-light);
}

.edit-form {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 160px;
}
.edit-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.edit-field .form-input {
  padding: 0.45rem 0.75rem;
  font-size: 0.95rem;
}

.edit-actions {
  display: flex;
  gap: 0.5rem;
  padding-bottom: 1px; /* align baseline with inputs */
}

/* Highlight the view row while its edit row is open */
.row-editing td { background: #f0f5ff; }

/* ── Add User form ── */
.add-user-wrap {
  padding: 2rem;
  max-width: 560px;
}
.add-user-wrap h2 {
  font-size: 1.2rem;
  margin-bottom: 0.35rem;
}
.add-user-wrap .form-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 1.5rem;
}

/* Two-column password row */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}
@media (max-width: 500px) {
  .form-row { grid-template-columns: 1fr; }
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.faint { opacity: 0.45; }

/* =========================================
   Admin — Games tab styles
   ========================================= */

/* Icon cell — larger emoji, centred */
.game-icon-cell {
  font-size: 1.5rem;
  text-align: center;
  width: 52px;
}

/* Monospace URL pill */
.url-code {
  display: inline-block;
  font-family: monospace;
  font-size: 0.82rem;
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  color: var(--text);
  word-break: break-all;
}

/* Sort order column — narrow, centred */
.sort-cell {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Games edit form — two-row grid instead of single horizontal strip */
.edit-form-games {
  display: block; /* override the flex from .edit-form */
}
.edit-fields-grid {
  display: grid;
  grid-template-columns: 70px 1fr 90px; /* icon | name | sort */
  grid-template-rows: auto auto;
  gap: 0.65rem 1rem;
  margin-bottom: 0.75rem;
}
.edit-field-icon  { grid-column: 1; grid-row: 1; }
.edit-field-name  { grid-column: 2; grid-row: 1; }
.edit-field-sort  { grid-column: 3; grid-row: 1; }
.edit-field-desc  { grid-column: 1 / 3; grid-row: 2; }
.edit-field-url   { grid-column: 3 / 4; grid-row: 2; } /* overridden below */
.edit-field-avail { grid-column: 3; grid-row: 2; }      /* overridden below */

/* Re-lay the last two fields so desc+url share row 2, avail goes row 3 */
.edit-field-desc  { grid-column: 1 / 3; grid-row: 2; }
.edit-field-url   { grid-column: 3 / 4; grid-row: 2; }
.edit-field-avail { grid-column: 1 / -1; grid-row: 3; }

@media (max-width: 640px) {
  .edit-fields-grid {
    grid-template-columns: 70px 1fr;
  }
  .edit-field-sort  { grid-column: 2; grid-row: 1; }
  .edit-field-desc  { grid-column: 1 / -1; grid-row: 2; }
  .edit-field-url   { grid-column: 1 / -1; grid-row: 3; }
  .edit-field-avail { grid-column: 1 / -1; grid-row: 4; }
}

/* Add Game section below the table */
.add-game-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}
.add-game-section h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text);
}

/* Required star */
.required-star {
  color: var(--danger);
  font-weight: 700;
}

/* ── Card Set Admin — image upload & management ─────────────────────────────── */

/* Drag & drop zone */
.cs-drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--bg);
  user-select: none;
}
.cs-drop-zone:hover,
.cs-drop-zone.drag-over {
  border-color: var(--primary);
  background: #eef3fb;
}
.cs-drop-icon {
  font-size: 2rem;
  margin-bottom: 0.4rem;
}
.cs-drop-zone p {
  margin: 0.2rem 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.cs-upload-link {
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
  text-decoration: underline;
}
.cs-file-input {
  display: none;
}

/* Image grid (previews + existing images) */
.cs-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.6rem;
  margin-top: 0.5rem;
}
.cs-preview-grid {
  margin-top: 0.75rem;
}

/* Individual card image tile */
.cs-image-item {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: var(--bg);
}
.cs-image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* × remove button on each image */
.cs-img-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s;
}
.cs-img-remove:hover {
  background: var(--danger);
}

/* Expand panel for managing an existing image set */
.cs-manage-panel {
  padding: 1.25rem 1rem 1rem;
}
.cs-manage-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}
.cs-add-more {
  margin-top: 1.5rem;
}
.cs-add-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Status message under create button */
.cs-status-msg {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-left: 0.75rem;
}
