:root {
  --ink: #0a0b12;
  --ink-soft: #2b2f3a;
  --canvas: #f7f3ee;
  --accent: #f35b4f;
  --accent-dark: #d64337;
  --mint: #3ccfcf;
  --card: rgba(255, 255, 255, 0.92);
  --modal-bg: #fff;
  --shadow: 0 20px 40px rgba(10, 11, 18, 0.15);
  --radius: 22px;
  --radius-sm: 12px;
  /* theming helpers */
  --body-bg: radial-gradient(circle at 20% 20%, #fff2db 0%, transparent 55%),
    radial-gradient(circle at 80% 10%, #dff7ff 0%, transparent 40%),
    linear-gradient(140deg, #fef8f2 0%, #eaf6ff 55%, #fdf5f0 100%);
  --divider: rgba(10, 11, 18, 0.08);
  --input-bg: #fff;
  --input-border: rgba(10, 11, 18, 0.15);
  --btn-border: rgba(10, 11, 18, 0.15);
  --th-bg: rgba(10, 11, 18, 0.04);
  --hover-bg: rgba(60, 207, 207, 0.08);
  --eyebrow-color: var(--accent-dark);
}

[data-theme="dark"] {
  --ink: #e8e8ed;
  --ink-soft: #888;
  --canvas: #1a1a1f;
  --card: rgba(255, 255, 255, 0.06);
  --modal-bg: #1e1e26;
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  --body-bg: #0d0d0f;
  --divider: rgba(255, 255, 255, 0.1);
  --input-bg: rgba(255, 255, 255, 0.07);
  --input-border: rgba(255, 255, 255, 0.15);
  --btn-border: rgba(255, 255, 255, 0.12);
  --th-bg: rgba(255, 255, 255, 0.04);
  --hover-bg: rgba(60, 207, 207, 0.05);
  --eyebrow-color: #888;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

body {
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background: var(--body-bg);
  color: var(--ink);
  min-height: 100vh;
}

.background-orbit {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 15% 65%, rgba(243, 91, 79, 0.12), transparent 55%),
    radial-gradient(circle at 80% 55%, rgba(60, 207, 207, 0.18), transparent 50%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 16px;
}

.hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
}

/* Auth modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 18, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: float-in 0.15s ease both;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--modal-bg);
  color: var(--ink);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 28px 32px;
  min-width: 300px;
  display: grid;
  gap: 20px;
}

.modal h3 {
  font-size: 1.3rem;
}

.modal-body {
  display: grid;
  gap: 8px;
}

.modal-body label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.modal-body input {
  padding: 10px 14px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--ink);
}

.modal-body input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.auth-error {
  margin: 6px 0 0;
  font-size: 0.875rem;
  color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.eyebrow {
  font-size: 0.85rem;
  letter-spacing: 0.2rem;
  text-transform: uppercase;
  color: var(--eyebrow-color);
  font-weight: 600;
  text-decoration: none;
}

h1 {
  font-size: clamp(2.4rem, 3.5vw, 3.5rem);
  margin: 12px 0 10px;
}

.subtitle {
  max-width: 520px;
  color: var(--ink-soft);
  font-size: 1.05rem;
}

.hero-title-link {
  text-decoration: none;
}

#authStatus {
  font: 600 0.8rem "Space Grotesk", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

#heroTitleLink {
  cursor: pointer;
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 26px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: float-in 0.6s ease both;
}

.controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}

.controls-header-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12rem;
  color: var(--ink-soft);
}

.controls-toggle-icon {
  font-size: 0.75rem;
  color: var(--ink-soft);
  transition: transform 0.2s ease;
  line-height: 1;
}

.controls-header[aria-expanded="true"] .controls-toggle-icon {
  transform: rotate(180deg);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  align-items: end;
  margin-top: 16px;
}

.control-group {
  display: grid;
  gap: 8px;
}

label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12rem;
  color: var(--ink-soft);
}

input,
select {
  border-radius: var(--radius-sm);
  border: 1px solid var(--input-border);
  padding: 10px 12px;
  font-size: 0.95rem;
  background: var(--input-bg);
  color: var(--ink);
  font-family: inherit;
}

select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%232b2f3a' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(60, 207, 207, 0.4);
  border-color: rgba(60, 207, 207, 0.8);
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 24px rgba(243, 91, 79, 0.3);
}

button.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(243, 91, 79, 0.35);
}

button.primary:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

button.ghost {
  background: transparent;
  border: 1px solid var(--btn-border);
  color: var(--ink-soft);
}

button.small {
  font-size: 0.8rem;
  padding: 4px 14px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  color: var(--ink-soft);
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: 1.4rem;
  color: var(--ink);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 18px;
}

.form-grid label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.form-grid span {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.form-actions {
  margin-top: 18px;
  display: flex;
  gap: 12px;
}

.checkbox-label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.checkbox-label span {
  margin-bottom: 0 !important;
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--divider);
}

.table-panel table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 12px;
  text-align: left;
  font-size: 0.95rem;
}

/* Rating+YouTube combined cell */
.rating-yt-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

th {
  background: var(--th-bg);
  text-transform: uppercase;
  letter-spacing: 0.1rem;
  font-size: 0.75rem;
}

.sort-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  padding: 0;
  cursor: pointer;
}

.sort-btn:focus-visible {
  outline: 2px solid rgba(60, 207, 207, 0.6);
  border-radius: 999px;
}

.sort-indicator {
  font-size: 0.7rem;
  opacity: 0.7;
}

.sort-indicator::before {
  content: "";
}

.sort-btn.is-active[data-order="asc"] .sort-indicator::before {
  content: "▲";
}

.sort-btn.is-active[data-order="desc"] .sort-indicator::before {
  content: "▼";
}

tr {
  border-bottom: 1px solid var(--divider);
  transition: background 0.2s ease;
  cursor: pointer;
}

tr:hover {
  background: var(--hover-bg);
}

th tr {
  cursor: default;
}

.cover {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 8px 16px rgba(10, 11, 18, 0.12);
}

/* Right-justify the Bin column */
.table-panel thead th:last-child,
.table-panel tbody td:nth-child(6) {
  text-align: right;
}

.actions {
  display: flex;
  gap: 8px;
}

.muted {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.error-msg {
  font-weight: 700;
  color: #c0392b;
  font-size: 0.95rem;
}

.actions button {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.empty {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: rgba(243, 91, 79, 0.08);
  color: var(--accent-dark);
  text-align: center;
}

.pagination {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 700px) {
  .app {
    padding: 24px 10px 48px;
  }

  .panel {
    padding: 16px 12px;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  /* New Mobile Form Layout */
  .form-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .form-grid label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .form-grid label span {
    margin-bottom: 0;
    width: auto;
    min-width: 80px; /* Consistently sized label width */
    max-width: 120px;
    flex-shrink: 0;
  }

  .form-grid input,
  .form-grid select {
    flex: 1;
    width: 100%; /* Ensure it takes available space */
    min-width: 0;
  }

  .file-input-group {
    flex: 1;
    width: 100%;
  }

  .form-grid .checkbox-label {
    justify-content: flex-end;
    gap: 0.25em;
  }

  .form-grid .checkbox-label input[type="checkbox"] {
    flex: none;
  }

  /* Library Mobile Layout */
  .table-panel table,
  .table-panel tbody,
  .table-panel tr,
  .table-panel td {
    display: block;
    width: 100%;
  }

  .table-panel thead {
    display: none;
  }

  /* Make row a grid container */
  .table-panel tr {
    display: grid;
    /*
      Col 1: Cover (fixed 50px)
      Col 2: Name (takes remaining space)
      Col 3: YouTube icon (auto, collapses when empty)
      Col 4: Year / Bin (auto)
      Col 5: Players / Actions (auto)
    */
    grid-template-columns: 50px 1fr auto auto;

    /* Rows defined implicitly, but we can be explicit */
    /* Row 1: Main Info */
    /* Row 2: Secondary Info */
    grid-template-rows: auto auto;

    gap: 6px 8px;
    padding: 10px 0;
    align-items: center;
    border-bottom: 1px solid var(--divider);
  }

  /* Target specific cells by order */
  /*
    DOM Order:
    1: Cover
    2: Name
    3: Year
    4: Players
    5: Rating+YouTube
    6: Bin
  */

  /* --- Row 1 --- */
  .table-panel td:nth-child(1) { /* Cover */
    grid-column: 1;
    grid-row: 1;
    padding: 0;
  }

  .table-panel td:nth-child(2) { /* Name */
    grid-column: 2;
    grid-row: 1;
    padding: 0;
    align-self: center;
    min-width: 0;
  }

  .table-panel td:nth-child(3) { /* Year */
    grid-column: 3;
    grid-row: 1;
    padding: 0;
    align-self: center;
    font-size: 0.95rem;
    color: var(--ink-soft);
    white-space: nowrap;
    text-align: right;
  }

  .table-panel td:nth-child(3):empty {
    display: none;
  }

  .table-panel td:nth-child(4) { /* Players */
    grid-column: 4;
    grid-row: 1;
    padding: 0;
    align-self: center;
    font-size: 0.95rem;
    white-space: nowrap;
    justify-self: end;
    text-align: right;
  }

  /* Append " Players" text if not empty */
  .table-panel td:nth-child(4):empty {
    display: none;
  }

  .table-panel td:nth-child(4):not(:empty)::after {
    content: "p";
    color: var(--ink-soft);
  }

  /* --- Row 2 --- */
  .table-panel td:nth-child(5) { /* Rating+YouTube */
    grid-column: 2;
    grid-row: 2;
    padding: 0;
    align-self: center;
  }

  .table-panel td:nth-child(6) { /* Bin */
    grid-column: 4;
    grid-row: 2;
    padding: 0;
    align-self: center;
    font-size: 0.95rem;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-self: end;
    justify-content: flex-end;
    text-align: right;
  }

  .table-panel td:nth-child(6):empty {
    display: none;
  }

  .table-panel td:nth-child(6):not(:empty)::before {
    content: "Bin ";
    color: var(--ink-soft);
    margin-right: 4px;
    font-size: 0.95rem;
  }

  .table-panel td:nth-child(7) { /* Heart */
    grid-column: 3;
    grid-row: 2;
    padding: 0;
    align-self: center;
    justify-self: center;
  }

  .table-panel td:nth-child(8) { /* Plays */
    grid-column: 1;
    grid-row: 2;
    padding: 0;
    align-self: center;
    justify-self: center;
    font-size: 0.85rem;
    text-align: center;
  }

  .cover {
    width: 44px;
    height: 44px;
    border-radius: 10px;
  }
}

.form-grid label:has(.file-input-group),
.form-grid label.full-width {
  grid-column: 1 / -1;
  display: block;
}

/* Ensure consistent spacing for the span inside since we reset display */
.form-grid label:has(.file-input-group) > span {
  display: block;
  margin-bottom: 6px;
}

.form-grid textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  font-family: inherit;
  font-size: inherit;
  padding: 8px 10px;
  border: 1px solid rgba(10, 11, 18, 0.18);
  border-radius: var(--radius-sm, 6px);
  background: var(--surface, #fff);
  color: var(--ink, #0a0b12);
  line-height: 1.5;
}

.file-input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Ensure the file input takes available space */
.file-input-group input[type="file"] {
  width: 100%;
}

.preview-container {
  margin-top: 0;
  position: relative;
  width: fit-content;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

#coverPreview {
  max-width: 100px;
  max-height: 100px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: block;
}

#coverPreview[hidden] {
  display: none !important;
}

#uploadStatus[hidden] {
  display: none !important;
}

#clearCoverBtn {
  font-size: 0.75rem;
  padding: 4px 8px;
}

/* ── Game Card ─────────────────────────────────────────── */

.game-card-section {
  animation: float-in 0.35s ease both;
  position: relative;
}

.back-btn {
  margin-bottom: 24px;
}

.gc-card-actions {
  position: absolute;
  top: 22px;
  right: 26px;
  display: flex;
  gap: 8px;
}

.gc-card-actions[hidden] {
  display: none;
}

.gc-card-actions button {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.gc-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 36px;
  align-items: flex-start;
}

.gc-cover-wrap {
  flex-shrink: 0;
}

.gc-cover {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: block;
}

.gc-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.gc-description {
  flex: 0 0 33%;
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.65;
  max-height: 300px;
  overflow-y: auto;
  border-left: 2px solid var(--divider);
  padding-left: 20px;
  align-self: flex-start;
}

.gc-name {
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  line-height: 1.2;
}

.gc-alt-name {
  margin-top: 4px;
  font-size: 0.95rem;
}

.gc-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 20px;
  align-items: baseline;
}

.gc-meta dt {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.gc-meta dd {
  font-size: 0.95rem;
  color: var(--ink);
}

.gc-notes {
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-style: italic;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--th-bg);
  border-left: 3px solid var(--input-border);
  border-radius: 0 4px 4px 0;
  white-space: pre-wrap;
}

.gc-notes[hidden] {
  display: none;
}

.gc-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 100%;
  padding-top: 14px;
  border-top: 1px solid var(--divider);
  margin-top: 4px;
}

.gc-footer-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.gc-footer-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.rating-badge {
  display: inline-block;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  white-space: nowrap;
  text-decoration: none;
}

.rating-badge.medium {
  background: linear-gradient(135deg, #f39c12, #e67e22);
}

.rating-badge.high {
  background: linear-gradient(135deg, #27ae60, #229954);
}

.gc-rating {
  font-weight: 700;
  font-size: 1rem;
  padding: 6px 16px;
  border-radius: 999px;
  color: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  background: linear-gradient(135deg, #e74c3c, #c0392b); /* default/low */
}

.gc-rating.medium {
  background: linear-gradient(135deg, #f39c12, #e67e22);
  box-shadow: 0 8px 20px rgba(243, 156, 18, 0.35);
}

.gc-rating.high {
  background: linear-gradient(135deg, #27ae60, #229954);
  box-shadow: 0 8px 20px rgba(39, 174, 96, 0.35);
}

.gc-rating:not([href]) {
  cursor: default;
}

a.gc-rating:hover {
  transform: translateY(-2px);
}

.gc-bins {
  display: flex;
  gap: 8px;
}

.gc-bin-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  background: rgba(60, 207, 207, 0.12);
  border: 1px solid rgba(60, 207, 207, 0.3);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.gc-bin-badge:hover {
  background: rgba(60, 207, 207, 0.22);
  border-color: rgba(60, 207, 207, 0.55);
}

.gc-bin-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.15rem;
  color: var(--ink-soft);
}

.gc-bin-number {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--mint);
  line-height: 1.2;
}

/* ── Bin View ─────────────────────────────────────────── */

.bin-view-section {
  animation: float-in 0.35s ease both;
}

.bin-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.bin-view-heading {
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  margin-bottom: 0;
}

.bin-upload-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 420px;
}

.bin-upload-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.bin-upload-label input[type="file"] {
  font-size: 0.9rem;
}

.bin-upload-actions {
  display: flex;
  gap: 10px;
}

.bin-upload-status {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.bin-upload-status.error {
  color: var(--error, #c0392b);
}

.bin-upload-status.success {
  color: var(--success, #27ae60);
}

.bin-view-photo-wrap {
  display: flex;
  justify-content: center;
}

.bin-view-photo {
  max-width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.gc-external-links {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gc-yt-btn[hidden] {
  display: none;
}

.th-heart,
.td-heart {
  width: 56px;
  padding: 0 4px;
  white-space: nowrap;
}

/* ══════════════════════════════════════════════════════
   DARK MODE ADJUSTMENTS
══════════════════════════════════════════════════════ */

[data-theme="dark"] .background-orbit {
  background: radial-gradient(circle at 15% 65%, rgba(243, 91, 79, 0.06), transparent 55%),
    radial-gradient(circle at 80% 55%, rgba(60, 207, 207, 0.08), transparent 50%);
}

[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ══════════════════════════════════════════════════════
   UTILITIES
══════════════════════════════════════════════════════ */

.page-flex {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Auth button (shared) ────────────────────────────── */

#authBtn {
  padding: 0.5rem 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--btn-border);
  background: transparent;
  color: var(--ink);
  font: 600 0.875rem "Space Grotesk", sans-serif;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#authBtn:hover {
  background: var(--hover-bg);
}

/* ── Theme toggle ────────────────────────────────────── */

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--btn-border);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover {
  background: var(--hover-bg);
  color: var(--ink);
}

.theme-toggle svg { width: 16px; height: 16px; display: block; }

/* Light mode shows moon; dark mode shows sun */
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ══════════════════════════════════════════════════════
   HOME PAGE
══════════════════════════════════════════════════════ */

.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 24px;
  gap: 1rem;
}

.home-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.home-main h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 2rem;
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.nav a {
  display: inline-block;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  border: 1px solid var(--btn-border);
  color: var(--ink);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.nav a:hover {
  background: var(--hover-bg);
  border-color: var(--accent);
}

/* ══════════════════════════════════════════════════════
   PHOTOS PAGE
══════════════════════════════════════════════════════ */

.photos-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
}

.photos-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px 24px;
}

.upload-card {
  background: var(--card);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  gap: 1.25rem;
}

.upload-card h2 { font-size: 1.25rem; font-weight: 700; }

.field { display: grid; gap: 0.4rem; }

.field label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.field input[type="text"],
.field input[type="file"],
.field select,
.field textarea {
  padding: 0.6rem 0.875rem;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  font: 0.9rem "Space Grotesk", sans-serif;
  width: 100%;
}

.field input[type="file"] { padding: 0.5rem; cursor: pointer; }
.field input:focus,
.field select:focus,
.field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.upload-actions { display: flex; justify-content: space-between; align-items: center; }
.upload-actions-right { display: flex; align-items: center; gap: 0.75rem; }

.btn-primary {
  padding: 10px 18px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font: 600 0.95rem "Space Grotesk", sans-serif;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 12px 24px rgba(243, 91, 79, 0.3);
}

.btn-primary:hover { opacity: 0.88; transform: translateY(-1px); box-shadow: 0 16px 30px rgba(243, 91, 79, 0.35); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }

.status-msg { font-size: 0.875rem; min-height: 1.25rem; }
.status-msg.success { color: #4caf82; }
.status-msg.error { color: var(--accent); }
.locked-msg { color: var(--ink-soft); font-size: 1rem; }

.gallery-section {
  width: 100%;
}

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.gallery-head h3 {
  margin-bottom: 0;
}

.gallery-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  margin-bottom: 1rem;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.gallery-count {
  font-size: 0.75rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.7;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}

.gallery-grid img {
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  transition: opacity 0.15s;
}

.gallery-grid img.filter-hidden { display: none; }

.thumb-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.thumb-wrap.filter-hidden { display: none; }

.thumb-img-wrap {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
}

.thumb-wrap:hover .rotate-btn { opacity: 1; }

.rotate-btn {
  position: absolute;
  bottom: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.rotate-btn:hover { background: rgba(243, 91, 79, 0.8); }
.rotate-btn svg { width: 14px; height: 14px; display: block; }

.delete-btn {
  position: absolute;
  bottom: 5px;
  left: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.thumb-wrap:hover .delete-btn { opacity: 1; }
.delete-btn:hover { background: rgba(200, 30, 20, 0.85); }
.delete-btn svg { width: 13px; height: 13px; display: block; }

.thumb-wrap:hover .tag-btn { opacity: 1; }
.tag-btn {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.tag-btn:hover { background: rgba(60, 130, 210, 0.85); }
.tag-btn svg { width: 13px; height: 13px; display: block; }

.thumb-wrap:hover .info-btn { opacity: 1; }
.info-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.info-btn:hover { background: rgba(60, 180, 140, 0.85); }
.info-btn svg { width: 14px; height: 14px; display: block; }

.thumb-tags {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  opacity: 0.7;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.gallery-empty { color: var(--ink-soft); font-size: 0.875rem; }

.photo-section {
  width: 100%;
  margin-top: 2rem;
}

.photo-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: none;
  color: var(--ink-soft);
  font: 600 0.8rem "Space Grotesk", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  padding: 0;
  margin-bottom: 1rem;
  transition: color 0.15s;
}

.photo-back:hover { color: var(--ink); }
.photo-back svg { width: 14px; height: 14px; }

.photo-viewer {
  position: relative;
}

.photo-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  opacity: 0.7;
  transition: opacity 0.15s;
  z-index: 1;
}
.photo-nav:hover { opacity: 1; }
.photo-nav[hidden] { display: none; }
.photo-nav svg { width: 18px; height: 18px; }
.photo-nav-prev { left: 10px; }
.photo-nav-next { right: 10px; }

.photo-full {
  width: 100%;
  max-width: 100%;
  border-radius: 10px;
  display: block;
}

.photo-full-layout {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}
.photo-full-layout .photo-viewer {
  flex: 1 1 auto;
  min-width: 0;
}
.photo-note-panel {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: var(--input-bg);
  border: 1px solid var(--divider);
  border-radius: 10px;
}
.photo-note-text {
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  min-height: 1.5rem;
}
.photo-note-text:empty::before {
  content: "No note yet.";
  color: var(--ink-soft);
  font-style: italic;
}
.photo-note-edit-btn {
  align-self: flex-start;
  font-size: 0.8rem;
  padding: 0.3rem 0.75rem;
}
@media (max-width: 680px) {
  .photo-full-layout { flex-direction: column; }
  .photo-note-panel { flex: 1 1 auto; width: 100%; box-sizing: border-box; }
}

/* Thumbnail note tooltip */
.thumb-img-wrap {
  position: relative;
}

.exif-note {
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--divider);
}

.photo-caption {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  opacity: 0.7;
}

/* ══════════════════════════════════════════════════════
   ALBUMS PAGE
══════════════════════════════════════════════════════ */

#albumsSection {
  width: 100%;
  max-width: 520px;
}

.albums-list {
  list-style: none;
  display: grid;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.album-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: var(--input-bg);
}

.album-info {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  overflow: hidden;
}

.album-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.album-count {
  font-size: 0.75rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.album-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.album-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--btn-border);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

.album-btn:hover { background: var(--hover-bg); color: var(--ink); }
.album-btn:disabled { opacity: 0.3; cursor: default; pointer-events: none; }
.album-btn.album-btn-danger:hover { background: rgba(200, 30, 20, 0.1); color: var(--accent); }
.album-btn svg { width: 13px; height: 13px; display: block; }

.btn-secondary {
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--btn-border);
  background: transparent;
  color: var(--ink);
  font: 600 0.95rem "Space Grotesk", sans-serif;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-secondary:hover { background: var(--hover-bg); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 18, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--modal-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: min(420px, calc(100vw - 2rem));
  display: grid;
  gap: 1.25rem;
}

.modal-title { font-size: 1.1rem; font-weight: 700; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.qr-modal-box {
  width: min(320px, calc(100vw - 2rem));
  text-align: center;
}

.qr-modal-url {
  font-size: 0.75rem;
  color: var(--ink-soft);
  word-break: break-all;
  margin: 0;
}

.qr-canvas-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
}

.qr-canvas-wrap canvas {
  border-radius: 8px;
}

.exif-modal-box {
  width: min(480px, calc(100vw - 2rem));
  max-height: calc(100dvh - 4rem);
  overflow-y: auto;
}

.exif-body {
  min-height: 40px;
}

.exif-loading, .exif-empty {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin: 0;
}

.exif-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
  font-size: 0.875rem;
}

.exif-list dt {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  white-space: nowrap;
  align-self: baseline;
  padding-top: 1px;
}

.exif-list dd {
  margin: 0;
  color: var(--ink);
  word-break: break-word;
  align-self: baseline;
}

.exif-list dd a {
  color: var(--accent);
  text-decoration: none;
}

.exif-list dd a:hover {
  text-decoration: underline;
}

/* ══════════════════════════════════════════════════════
   BOOKS PAGES
══════════════════════════════════════════════════════ */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 24px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.book {
  background: var(--card);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 12px;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.book:hover {
  transform: translateY(-2px);
}

.book img {
  width: 120px;
  height: 180px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--canvas);
  margin-bottom: 8px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.book-title {
  font-size: 0.95em;
  margin-bottom: 8px;
  color: var(--ink);
  min-height: 2.5em;
  font-weight: 600;
}

.book-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.book-actions a {
  background: var(--accent);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.15s;
}

.book-actions a:hover { opacity: 0.85; }

.td-heart {
  text-align: right;
  vertical-align: middle;
}

.notes-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #888;
  margin-right: 2px;
}

.notes-icon svg {
  width: 15px;
  height: 15px;
  display: block;
}

.heart-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #aaa;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, transform 0.1s ease;
}

.heart-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}

.heart-btn:hover {
  color: #e0334c;
  transform: scale(1.2);
}

.heart-btn.is-favorite {
  color: #e0334c;
}

.th-plays,
.td-plays {
  width: 64px;
  padding: 0 4px;
  white-space: nowrap;
}

.td-plays {
  text-align: right;
  vertical-align: middle;
}

.play-count {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-right: 1px;
}

.play-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
  vertical-align: middle;
}

.play-btn:hover {
  transform: scale(1.2);
}

.yt-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ff0000;
  text-decoration: none;
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

.yt-icon:hover {
  opacity: 1;
}

.yt-icon svg {
  width: 40px;
  height: 40px;
  display: block;
}

.gc-yt-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ff0000;
  color: #fff;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 8px 20px rgba(255, 0, 0, 0.28);
  flex-shrink: 0;
}

.gc-yt-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(255, 0, 0, 0.38);
}

.gc-yt-btn svg {
  width: 22px;
  height: 22px;
}

@media (max-width: 800px) {
  .gc-description {
    flex: 0 0 100%;
    max-height: 160px;
    border-left: none;
    border-top: 2px solid rgba(10, 11, 18, 0.08);
    padding-left: 0;
    padding-top: 16px;
  }
}

/* ── Panel view toggle ─────────────────────────────────── */

.panel-head-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-view-btn {
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 999px;
}

/* ── Gallery Grid ──────────────────────────────────────── */

.games-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 10px;
  padding: 4px 0;
}

.gallery-item {
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  background: var(--th-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gallery-item:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(10, 11, 18, 0.2);
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.gallery-bin {
  font-size: 0.75rem;
  text-align: center;
  padding: 2px 4px 3px;
  color: var(--ink);
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  box-sizing: border-box;
}

.gallery-notes-icon,
.gallery-heart-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.gallery-notes-icon svg {
  width: 11px;
  height: 11px;
  color: #888;
}

.gallery-heart-icon svg {
  width: 11px;
  height: 11px;
  color: #e0334c;
}

@media (max-width: 1100px) {
  .games-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

@media (max-width: 800px) {
  .games-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 500px) {
  .games-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
}

@media (max-width: 360px) {
  .games-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }
}
