/* ---------------------------------------------------
   Game Shelf — tokens
--------------------------------------------------- */
:root {
  --bg:            #1c1917;
  --bg-panel:      #241f1c;
  --bg-elevated:   #2e2723;
  --border:        #3c332d;
  --border-soft:   #342c27;
  --text:          #f0e9e4;
  --text-muted:    #a89a8f;
  --text-faint:    #6e6259;

  --accent:        #d97757;
  --accent-hover:  #c8674a;
  --accent-soft:   rgba(217, 119, 87, 0.15);

  --owned:         #8bab6f;
  --sold:          #8f8478;
  --wished:        #d9a857;

  --danger:        #c0604f;

  --radius:        6px;
  --radius-lg:     10px;

  --font-display:  'Fraunces', Georgia, serif;
  --font-body:     'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* iOS Safari auto-zooms the viewport when focusing a form field with a
   font-size under 16px, and doesn't reliably zoom back out on blur —
   especially inside a modal. Keeping these at 16px prevents that. */
input, select, textarea {
  font-size: 16px;
}

a { color: var(--accent); }

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

/* ---------------------------------------------------
   Topbar
--------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1800px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  margin: 0;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.status-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}

/* On desktop this wrapper is invisible to layout — status-tabs still behaves
   as a direct flex item of .topbar-inner, same as before. The platform
   dropdown only appears on mobile (see media query below), since desktop
   already has a platform filter in the table's column-filter row. */
.status-row {
  display: contents;
}

.platform-filter {
  display: none;
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}

.tab:hover { color: var(--text); }

.tab.active {
  background: var(--bg-elevated);
  color: var(--text);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
  flex: 1 1 260px;
  max-width: 420px;
}

#filterInput {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text);
}

#filterInput:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------------------------------------------------
   Buttons
--------------------------------------------------- */
.btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}

.btn:hover { border-color: var(--text-faint); }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #221a15;
}

.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(192, 96, 79, 0.12); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.icon-btn:hover { color: var(--text); }

/* ---------------------------------------------------
   Main / list view
--------------------------------------------------- */
main {
  max-width: 1800px;
  margin: 0 auto;
  padding: 24px;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.empty-state h2 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--text);
}

.game-count {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
  white-space: nowrap;
}

table.game-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-panel);
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.game-table thead th {
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.game-table thead th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.game-table thead th.sortable:hover { color: var(--text); }

.sort-arrow {
  color: var(--accent);
  font-size: 10px;
  margin-left: 2px;
}

.filter-row th {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.col-filter {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
}
.col-filter:focus { border-color: var(--accent); }
.col-filter::placeholder { color: var(--text-faint); }

.game-table tbody tr {
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}
.game-table tbody tr:last-child { border-bottom: none; }
.game-table tbody tr:hover { background: var(--bg-elevated); }

.game-table td {
  padding: 12px 16px;
  vertical-align: middle;
}

.game-title-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
}

.game-title-cell img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.status-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: var(--radius);
}
.status-pill.owned  { background: rgba(139,171,111,0.15); color: var(--owned); }
.status-pill.sold   { background: rgba(143,132,120,0.18); color: var(--sold); }
.status-pill.wished { background: rgba(217,168,87,0.15);  color: var(--wished); }

.score-cell { font-variant-numeric: tabular-nums; color: var(--text-muted); }

/* Mobile card list (replaces table on small screens) */
.game-cards { display: none; flex-direction: column; gap: 10px; }

.game-card {
  display: flex;
  gap: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  cursor: pointer;
}
.game-card img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-elevated);
  flex-shrink: 0;
}
.game-card .card-title {
  font-weight: 600;
  margin: 0 0 2px;
}
.game-card .card-meta {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

/* ---------------------------------------------------
   Detail view
--------------------------------------------------- */
.back-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 0 16px;
}
.back-link:hover { color: var(--text); }

.detail-view {
  max-width: 900px;
  margin: 0 auto;
}

.detail-header {
  display: flex;
  gap: 28px;
  margin-bottom: 28px;
}

.detail-cover {
  height: 200px;
  width: auto;
  max-width: 380px;
  object-fit: contain;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.detail-header-info h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 30px;
  margin: 0 0 8px;
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.badge {
  display: inline-block;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 13px;
  border-radius: var(--radius);
}

.fact-table {
  margin: 0;
}
.fact-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 4px 10px;
  padding: 3px 0;
  font-size: 14px;
}
.fact-row dt {
  margin: 0;
  color: var(--text-muted);
}
.fact-row dd {
  margin: 0;
  color: var(--text);
  font-weight: 500;
}

.screenshots-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}
.screenshots-row img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-panel);
}

.detail-section {
  margin-bottom: 28px;
}
.detail-section h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  margin: 0 0 10px;
  color: var(--text);
}
.detail-section p { color: var(--text-muted); line-height: 1.65; }

.edit-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.edit-panel .form-grid { margin-bottom: 16px; }

.edit-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.edit-panel-header h3 { margin: 0; }

.status-select-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.status-select {
  display: inline-block;
  width: auto;
  margin-top: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}

.save-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.save-row-primary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#saveStatusMsg {
  font-size: 13px;
  color: var(--owned);
  opacity: 0;
  transition: opacity 0.2s;
}
#saveStatusMsg.show { opacity: 1; }

/* ---------------------------------------------------
   Forms (shared: add modal + detail edit panel)
--------------------------------------------------- */
label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 14px;
}

label > input,
label > select,
label > textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
}

textarea { resize: vertical; font-family: var(--font-body); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-error {
  background: rgba(192, 96, 79, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.form-error[hidden] { display: none; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

/* ---------------------------------------------------
   Modal (add game)
--------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 7, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 19px;
  margin: 0;
}

.modal-body { padding: 22px; }

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.search-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
}
.search-result:hover { background: var(--bg-elevated); }
.search-result img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg-elevated);
  flex-shrink: 0;
}
.search-result .r-title { font-weight: 500; margin: 0; }
.search-result .r-meta { font-size: 12.5px; color: var(--text-muted); margin: 0; }

.add-form-header {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-soft);
}
.add-cover {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-elevated);
}
#addTitle {
  font-family: var(--font-display);
  font-weight: 500;
  margin: 0 0 2px;
  font-size: 18px;
}
#addMeta { margin: 0; font-size: 13px; }

/* ---------------------------------------------------
   Responsive: mobile
--------------------------------------------------- */
@media (max-width: 760px) {
  .topbar {
    position: static; /* only the title/counter row would be worth pinning, and
                          that's not worth the header's added structural
                          complexity — the whole header just scrolls with the
                          page on mobile instead. */
  }

  .topbar-inner {
    padding: 12px 16px;
  }
  .status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    order: 3;
  }
  .status-tabs {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    padding: 2px;
  }
  .status-tabs .tab { width: 100%; text-align: center; }
  .tab { padding: 5px 8px; font-size: 12px; }
  .platform-filter {
    display: block;
    flex-shrink: 0;
    max-width: 34%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 8px;
    color: var(--text);
    font-size: 12px;
  }
  .game-count { order: 1; margin-left: auto; }
  .topbar-actions { order: 2; max-width: none; }

  /* On the detail page, the status tabs / platform filter / search / add-game
     controls and the list counter don't apply to anything — only the title
     is relevant there. */
  body.is-detail-view .status-row,
  body.is-detail-view .topbar-actions,
  body.is-detail-view .game-count {
    display: none;
  }

  main { padding: 16px; }

  table.game-table { display: none; }
  .table-wrap { display: none; }
  .game-cards { display: flex; }

  .detail-header { flex-direction: column; gap: 16px; }
  .detail-cover { width: 100%; height: auto; max-width: 320px; object-fit: contain; }
  .screenshots-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }

  .save-row { flex-direction: column; align-items: stretch; }
  .save-row-primary { flex-direction: column; align-items: stretch; }
  .save-row-primary .btn,
  .save-row > .btn-danger { width: 100%; }
  #saveStatusMsg { text-align: center; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
