/* ===========================
   GameVault — Black/Orange Theme
   =========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:               #080808;
  --surface:          #101010;
  --surface2:         #161616;
  --surface3:         #1e1e1e;
  --border:           #252525;
  --border2:          #2e2e2e;
  --orange:           #f97316;
  --orange-dim:       #c2580f;
  --orange-bg:        rgba(249,115,22,0.08);
  --orange-glow:      rgba(249,115,22,0.14);
  --text:             #e2e2e2;
  --text-muted:       #858585;
  --text-dim:         #4a4a4a;

  --c-finished:       #22c55e;
  --c-finished-bg:    rgba(34,197,94,0.1);
  --c-progress:       #f97316;
  --c-progress-bg:    rgba(249,115,22,0.1);
  --c-backlog:        #60a5fa;
  --c-backlog-bg:     rgba(96,165,250,0.1);
  --c-abandoned:      #f87171;
  --c-abandoned-bg:   rgba(248,113,113,0.1);
  --c-notrel:         #a78bfa;
  --c-notrel-bg:      rgba(167,139,250,0.1);
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ======= HEADER ======= */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 54px;
  gap: 28px;
}

.logo {
  font-size: 17px;
  font-weight: 800;
  color: var(--orange);
  text-decoration: none;
  letter-spacing: -0.4px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-icon { font-size: 20px; }

nav { display: flex; gap: 2px; }

nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
}

nav a:hover { color: var(--text); background: var(--surface2); }
nav a.active { color: var(--orange); background: var(--orange-bg); font-weight: 600; }

.header-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-dim);
}

/* ======= LAYOUT ======= */
.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.4px;
}

.page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ======= BUTTONS ======= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--orange-dim); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: #404040; background: var(--surface2); }

.btn-danger {
  background: rgba(248,113,113,0.08);
  color: #f87171;
  border: 1px solid rgba(248,113,113,0.2);
}
.btn-danger:hover:not(:disabled) { background: rgba(248,113,113,0.18); }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 4px; }

/* ======= STATUS SUMMARY BAR ======= */
.status-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

/* ======= CONTROLS ======= */
.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.controls-right { margin-left: auto; font-size: 12px; color: var(--text-muted); }

.search-wrap { position: relative; }

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px 7px 32px;
  color: var(--text);
  font-size: 13px;
  width: 220px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input::placeholder { color: var(--text-dim); }
.search-input:focus { border-color: var(--orange); box-shadow: 0 0 0 2px var(--orange-glow); }

.filter-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s;
}

.filter-select:focus { border-color: var(--orange); }
.filter-select option { background: #1a1a1a; }

/* ======= TABLE ======= */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 7px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

thead th[data-col] { cursor: pointer; }
thead th[data-col]:hover { color: var(--text); }
thead th.sort-asc::after { content: ' ▲'; color: var(--orange); font-size: 9px; }
thead th.sort-desc::after { content: ' ▼'; color: var(--orange); font-size: 9px; }

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

tbody td {
  padding: 11px 7px;
  font-size: 13px;
  color: var(--text);
  vertical-align: middle;
}

.td-muted { color: var(--text-muted); }
.td-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.td-name { font-weight: 600; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-actions { white-space: nowrap; }
.td-actions .btn-sm { padding: 4px 8px; }
.sort-select { display: none; }

/* ======= BADGES ======= */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.badge-finished    { background: var(--c-finished-bg);  color: var(--c-finished); }
.badge-in-progress { background: var(--c-progress-bg);  color: var(--c-progress); }
.badge-online      { background: rgba(34,211,238,0.1);  color: #22d3ee; }
.badge-backlog     { background: var(--c-backlog-bg);   color: var(--c-backlog); }
.badge-abandoned   { background: var(--c-abandoned-bg); color: var(--c-abandoned); }
.badge-not-released{ background: var(--c-notrel-bg);    color: var(--c-notrel); }

.badge-clickable { cursor: pointer; transition: filter 0.15s; }
.badge-clickable:hover { filter: brightness(1.2); }

/* ======= RATING ======= */
.rating-val { font-weight: 700; color: var(--orange); }

/* ======= RATINGS COLUMN ======= */
.td-ratings { min-width: 360px; }
.td-rating-col { text-align: center; white-space: nowrap; }

.ratings-row { display: flex; align-items: stretch; gap: 6px; width: 100%; }
.rating-col { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; min-width: 0; }
.rating-col-overall { flex: 0 0 auto; min-width: 72px; padding-left: 10px; border-left: 1px solid var(--border); }
.rating-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.ratings-divider { width: 1px; background: var(--border); margin: 0 2px; align-self: stretch; }

.sub-rating {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; padding: 3px 6px; border-radius: 5px; min-width: 36px;
}
.sub-rating-high    { background: rgba(74,222,128,0.15);  color: #4ade80; border: 1px solid rgba(74,222,128,0.25); }
.sub-rating-mid     { background: rgba(251,191,36,0.12);  color: #fbbf24; border: 1px solid rgba(251,191,36,0.2); }
.sub-rating-low     { background: rgba(248,113,113,0.12); color: #f87171; border: 1px solid rgba(248,113,113,0.2); }
.sub-rating-empty   { color: var(--text-dim); font-size: 12px; }
.sub-rating-overall { background: rgba(249,115,22,0.18); color: var(--orange); border: 1px solid rgba(249,115,22,0.35); font-size: 13px; font-weight: 700; min-width: 48px; }
.sub-rating-platinum { background: linear-gradient(135deg, rgba(192,168,255,0.22), rgba(220,200,255,0.12)); color: #d4b8ff; border: 1px solid rgba(192,168,255,0.45); font-weight: 800; }

.td-extra { margin-top: 3px; display: flex; gap: 5px; flex-wrap: wrap; }
.td-extra-pill { font-size: 11px; color: var(--text-dim); background: rgba(255,255,255,0.04); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; }

/* ======= EMPTY STATE ======= */
.empty-state {
  text-align: center;
  padding: 64px 24px !important;
  color: var(--text-muted) !important;
  font-size: 14px !important;
  font-weight: normal !important;
}

.empty-icon { font-size: 36px; display: block; margin-bottom: 10px; opacity: 0.4; }

/* ======= MODAL ======= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 12px;
  width: 100%;
  max-width: 680px;
  margin: auto;
  transform: translateY(-10px);
  transition: transform 0.18s;
  flex-shrink: 0;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 15px; font-weight: 700; color: var(--text); }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.1s, background 0.1s;
  line-height: 1;
}
.modal-close:hover { color: var(--text); background: var(--surface3); }

.modal-body {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ======= FORM ======= */
.form-section-title {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--orange);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 11px; }
.form-full   { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-label-orange { color: var(--orange); }

.form-input, .form-select, .form-textarea {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px var(--orange-glow);
}

.form-input::placeholder { color: var(--text-dim); }
.form-select option { background: #1c1c1c; }
.form-textarea { resize: vertical; min-height: 64px; }

.form-hint { font-size: 11px; color: var(--text-dim); }

.form-input-orange { border-color: rgba(249,115,22,0.3); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: auto;
  padding: 7px 0;
}
.checkbox-row input[type=checkbox] { accent-color: var(--orange); width: 15px; height: 15px; cursor: pointer; }

/* ======= CONFIRM DIALOG ======= */
.confirm-dialog {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 28px 24px;
  max-width: 360px;
  width: 100%;
  margin: auto;
  text-align: center;
}

.confirm-icon { font-size: 32px; margin-bottom: 10px; }
.confirm-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.confirm-text { color: var(--text-muted); font-size: 13px; margin-bottom: 22px; line-height: 1.6; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }

/* ======= STATS PAGE ======= */
.stats-stack { display: flex; flex-direction: column; gap: 16px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: visible;
}

.stat-card-header {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 11px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--orange);
}

.stat-card-body { padding: 18px; min-width: 0; }

.stat-hero {
  font-size: 40px;
  font-weight: 900;
  color: var(--text);
  line-height: 1;
  margin-bottom: 18px;
  letter-spacing: -1px;
}

.stat-hero-suffix {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 4px;
  letter-spacing: 0;
}

.stat-row { margin-bottom: 10px; }

.stat-table-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

/* Stat tiles: label on top, value below; wrap onto more rows instead of scrolling */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
}

.stat-cell {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.stat-cell-label {
  background: var(--surface3);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-cell-value {
  padding: 7px 8px;
  font-size: 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

.stat-highlight { color: var(--orange); font-weight: 700; }
.stat-divider { height: 1px; background: var(--border); margin: 14px 0; }

.stat-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ======= SCROLLBAR ======= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #404040; }

/* ======= TOAST ======= */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text);
  z-index: 999;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  transform: translateY(8px);
  opacity: 0;
  transition: all 0.2s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.toast-ok { border-color: rgba(34,197,94,0.4); }
.toast.toast-err { border-color: rgba(248,113,113,0.4); }

/* ======= RESPONSIVE ======= */
@media (max-width: 700px) {
  /* Layout */
  .main { padding: 12px; }
  .page-header { flex-direction: column; gap: 10px; }
  .page-title { font-size: 18px; }

  /* Header */
  .header-inner { padding: 0 12px; gap: 12px; height: 48px; }
  .logo { font-size: 15px; }
  .logo-icon { font-size: 18px; }
  .header-count { display: none; }

  /* Controls */
  .controls { flex-direction: column; align-items: stretch; gap: 6px; }
  .search-wrap { width: 100%; }
  .search-input { width: 100%; }
  .filter-select { width: 100%; }
  .controls-right { margin-left: 0; text-align: right; }

  /* Status pills */
  .status-summary { gap: 5px; }

  /* Forms */
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .form-full { grid-column: auto; }
  .modal-body { padding: 14px 14px; max-height: calc(100vh - 140px); }
  .modal-header { padding: 14px 16px 12px; }
  .modal-footer { padding: 12px 16px; }

  /* Confirm dialog */
  .confirm-dialog { padding: 20px 16px; }

  /* Stats */
  .stat-grid-2 { grid-template-columns: 1fr 1fr; }
  .stat-hero { font-size: 26px; margin-bottom: 10px; }
  .stat-hero-suffix { font-size: 13px; }
  .stat-card-header { flex-direction: column; align-items: flex-start; gap: 2px; }
  .stat-card-body { padding: 10px; }
  .stat-card-header { padding: 8px 10px; }
  .stat-tiles { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 5px; }
  .stat-cell-label { font-size: 9px; padding: 5px 4px; letter-spacing: 0.02em; }
  .stat-cell-value { font-size: 13px; padding: 6px 4px; }
  .stat-table-title { font-size: 9px; margin-bottom: 4px; }
  .stat-divider { margin: 8px 0; }
  .stats-stack { gap: 10px; }

  /* Toast */
  .toast { left: 12px; right: 12px; bottom: 12px; }
}

@media (max-width: 400px) {
  .stat-grid-2 { grid-template-columns: 1fr; }
  .confirm-actions { flex-direction: column; }
}

/* ======= CATALOGUE AS CARDS (below 1440px the full table would not fit) ======= */
@media (max-width: 1439px) {
  .sort-select { display: block; }
  .table-wrap { background: none; border: none; border-radius: 0; }
  .table-wrap table, .table-wrap tbody { display: block; }
  .table-wrap thead { display: none; }

  .table-wrap tbody {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr));
    gap: 10px;
  }

  /* One card per game, on a 12-column grid */
  .table-wrap tbody tr {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 10px 8px;
    align-content: start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
  }
  .table-wrap tbody tr:hover { background: var(--surface2); }
  .table-wrap tbody tr:last-child { border-bottom: 1px solid var(--border); }

  .table-wrap tbody td { display: block; padding: 0; font-size: 13px; min-width: 0; }
  .table-wrap tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin-bottom: 2px;
  }

  .table-wrap .td-name {
    grid-column: 1 / span 8;
    grid-row: 1;
    max-width: none;
    white-space: normal;
    font-size: 15px;
    overflow-wrap: anywhere;
  }
  .table-wrap .td-status { grid-column: 9 / span 4; grid-row: 1; text-align: right; }
  .table-wrap .td-genre  { grid-column: span 6; overflow-wrap: anywhere; }
  .table-wrap .td-type,
  .table-wrap .td-trophy { grid-column: span 3; }
  .table-wrap .td-third  { grid-column: span 4; }
  .table-wrap .td-half   { grid-column: span 6; }

  .table-wrap .td-rating-col { grid-column: span 2; text-align: center; }
  .table-wrap .td-rating-col::before { text-align: center; }
  .table-wrap .sub-rating { min-width: 0; width: 100%; padding: 3px 2px; }

  .table-wrap .td-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
  }

  /* "No games" / loading message spans the whole grid */
  .table-wrap tbody tr:has(.empty-state) { grid-column: 1 / -1; display: block; }
  .table-wrap .empty-state { display: block; }
}

/* ======= TOUCH: stop iPhone auto-zoom ======= */
/* iOS Safari zooms in on any text box / dropdown under 16px when tapped. */
@media (pointer: coarse), (max-width: 700px) {
  .search-input, .filter-select,
  .form-input, .form-select, .form-textarea { font-size: 16px; }
}

/* ======= VERY NARROW SCREENS (under 360px) ======= */
@media (max-width: 359px) {
  /* Header: logo shrinks to just the icon so both links fit */
  .header-inner { gap: 6px; padding: 0 10px; }
  .logo { font-size: 0; gap: 0; }
  .logo-icon { font-size: 20px; }
  nav a { padding: 6px 8px; }

  /* Cards: name gets the full width, status badge goes on its own row */
  .table-wrap .td-name   { grid-column: 1 / -1; }
  .table-wrap .td-status { grid-column: 1 / -1; grid-row: 2; text-align: left; }
  .table-wrap tbody tr   { padding: 10px; }
  .table-wrap .sub-rating { font-size: 11px; }
  .badge { white-space: normal; }
}
@media (max-width: 359px) {
  .modal-body { padding: 12px 10px; }
  .form-group { min-width: 0; }
  .form-input, .form-select, .form-textarea { width: 100%; min-width: 0; box-sizing: border-box; }
}

/* ======= LOGIN: edit controls only show when logged in ======= */
.admin-only { display: none !important; }
body.is-admin .admin-only { display: inline-flex !important; }
.header-login { margin-left: auto; }
.header-count + .header-login { margin-left: 10px; }
@media (max-width: 700px) {
  .header-count + .header-login { margin-left: auto; }
}
