:root {
  --bg-primary: #0d0d0f;
  --bg-secondary: #141418;
  --bg-card: #1a1a20;
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(219,112,147,0.35);
  --text-primary: #f0edf5;
  --text-secondary: #9b94a8;
  --text-muted: #5c576b;
  --pink-light: #f4a8c7;
  --pink: #db7093;
  --pink-dark: #b85478;
  --pink-glow: rgba(219,112,147,0.15);
  --radius-card: 14px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --danger: #e05c5c;
  --success: #5cba8a;
  --sidebar-w: 260px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

/* ── Layout ── */
.admin-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 1.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand { padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.sidebar-title {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--pink-light), var(--pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.sidebar-sub { font-size: 0.72rem; color: var(--text-muted); letter-spacing: 0.1em; text-transform: uppercase; margin-top: 0.2rem; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.86rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all var(--transition);
  cursor: pointer;
  background: none;
  width: 100%;
  text-align: left;
}
.sidebar-link:hover { color: var(--pink-light); background: var(--pink-glow); border-color: var(--border-hover); }
.sidebar-link .icon { font-size: 0.9rem; width: 1.1rem; text-align: center; }

/* Hamburger */
.hamburger {
  display: none;
  position: fixed;
  top: 1rem; left: 1rem;
  z-index: 300;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.hamburger span { display: block; width: 18px; height: 2px; background: var(--text-primary); border-radius: 2px; transition: all 0.2s; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 199;
}

/* ── Main ── */
.admin-main {
  padding: 2rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 860px;
}

/* ── Section header ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  font-family: inherit;
  white-space: nowrap;
}
.btn-primary { background: var(--pink-glow); border-color: var(--pink); color: var(--pink-light); }
.btn-primary:hover { background: rgba(219,112,147,0.25); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn-ghost:hover { border-color: var(--border-hover); color: var(--text-primary); }
.btn-danger { background: transparent; border-color: rgba(224,92,92,0.3); color: var(--danger); font-size: 0.78rem; padding: 0.3rem 0.65rem; }
.btn-danger:hover { background: rgba(224,92,92,0.1); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-icon { width: 30px; height: 30px; padding: 0; justify-content: center; font-size: 0.9rem; }

/* ── Game list ── */
.game-list { display: flex; flex-direction: column; gap: 0.5rem; }

.game-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 0.65rem 0.9rem;
  transition: border-color var(--transition);
}
.game-item:hover { border-color: rgba(219,112,147,0.2); }
.game-item.dragging { opacity: 0.4; border-style: dashed; }
.game-item.drag-over { border-color: var(--pink); background: var(--pink-glow); }

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 0 0.2rem;
  flex-shrink: 0;
  user-select: none;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; }

.game-item-img {
  width: 38px; height: 50px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.game-item-img-placeholder {
  width: 38px; height: 50px;
  background: var(--bg-secondary);
  border-radius: 6px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 1rem;
}

.game-item-info { flex: 1; min-width: 0; }
.game-item-name { font-size: 0.88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-item-meta { font-size: 0.76rem; color: var(--text-secondary); margin-top: 0.2rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; }

.game-item-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* Tags */
.tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.17rem 0.55rem;
  border-radius: 100px;
  white-space: nowrap;
}

/* ── Form panel ── */
.form-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1.5rem;
}
.form-panel.hidden { display: none; }
.form-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 1.25rem; color: var(--pink-light); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group.full { grid-column: 1/-1; }

label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; }

input[type="text"], input[type="url"], input[type="password"], input[type="color"],
select, textarea {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.86rem;
  padding: 0.5rem 0.8rem;
  font-family: inherit;
  transition: border-color var(--transition);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pink); }
textarea { resize: vertical; min-height: 65px; }
select option { background: #1a1a20; }
input[type="color"] { padding: 0.2rem 0.4rem; height: 36px; cursor: pointer; }

.form-hint { font-size: 0.7rem; color: var(--text-muted); }
.form-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; flex-wrap: wrap; }

/* Image preview */
.img-preview-wrap {
  margin-top: 0.5rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  height: 120px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  position: relative;
}
.img-preview-wrap > div {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.img-preview-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; }
.img-preview-empty { color: var(--text-muted); font-size: 0.78rem; }

.img-source-tabs { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.img-source-tab {
  font-size: 0.75rem; padding: 0.3rem 0.75rem;
  border: 1px solid var(--border); border-radius: 100px;
  color: var(--text-muted); cursor: pointer; background: none; transition: all var(--transition);
}
.img-source-tab.active { border-color: var(--pink); color: var(--pink-light); background: var(--pink-glow); }

/* ── Modals (shared) ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 1.5rem;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid rgba(219,112,147,0.2);
  border-radius: 16px;
  width: 100%;
  transform: translateY(12px) scale(0.97);
  transition: transform var(--transition);
  overflow: hidden;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
}
.modal-head-title { font-size: 0.95rem; font-weight: 600; color: var(--pink-light); }
.modal-x {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.1rem; cursor: pointer; padding: 0.2rem 0.4rem;
  transition: color var(--transition);
}
.modal-x:hover { color: var(--pink); }

.modal-body { padding: 1.25rem 1.4rem; }
.modal-foot {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  display: flex; gap: 0.6rem; justify-content: flex-end;
}

/* Options modal */
.modal-opts { max-width: 440px; }

/* Game form modal */
.modal-game-form { max-width: 600px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-game-form .modal-body { overflow-y: auto; flex: 1; }

/* Tags modal */
.modal-tags-mgr { max-width: 560px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-tags-mgr .modal-body { overflow-y: auto; flex: 1; }

.tag-cat-section { margin-bottom: 1.5rem; }
.tag-cat-title { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.6rem; }

.tag-list { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.75rem; }
.tag-row {
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.5rem 0.75rem;
}
.tag-row input[type="text"] { flex: 1; font-size: 0.84rem; padding: 0.3rem 0.6rem; }
.tag-row input[type="color"] { width: 32px; height: 28px; padding: 0.1rem 0.2rem; flex-shrink: 0; }
.tag-preview-pill {
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  padding: 0.17rem 0.55rem; border-radius: 100px; white-space: nowrap; flex-shrink: 0;
  min-width: 48px; text-align: center;
}
.add-tag-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.add-tag-row input[type="text"] { flex: 1; min-width: 100px; }

/* Images modal */
#modal-images { z-index: 210; }
.modal-images { max-width: 640px; max-height: 85vh; display: flex; flex-direction: column; }
.modal-images .modal-body { overflow-y: auto; flex: 1; }

.img-upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.83rem;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 1.25rem;
}
.img-upload-zone:hover, .img-upload-zone.drag-active {
  border-color: var(--pink);
  background: var(--pink-glow);
  color: var(--pink-light);
}
.img-upload-zone input { display: none; }

.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.6rem;
}
.img-thumb {
  position: relative;
  aspect-ratio: 3/4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color var(--transition);
  background: var(--bg-card);
}
.img-thumb:hover { border-color: var(--pink); }
.img-thumb.selected { border-color: var(--pink); }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-thumb-del {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.7); border: none; color: #fff;
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 0.7rem; cursor: pointer; display: none;
  align-items: center; justify-content: center;
  transition: background var(--transition);
}
.img-thumb:hover .img-thumb-del { display: flex; }
.img-thumb-del:hover { background: var(--danger); }
.img-thumb-name {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.7); color: #ccc;
  font-size: 0.6rem; padding: 0.2rem 0.3rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.img-empty { color: var(--text-muted); font-size: 0.82rem; text-align: center; padding: 1rem 0; }

/* ── Notification ── */
.notif {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--bg-card);
  border: 1px solid rgba(92,186,138,0.4);
  color: #7ddaaa;
  font-size: 0.83rem;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-sm);
  z-index: 400;
  opacity: 0; transform: translateY(8px);
  transition: all 0.2s ease;
  pointer-events: none;
}
.notif.show { opacity: 1; transform: translateY(0); }
.notif.error { border-color: rgba(224,92,92,0.4); color: var(--danger); }

/* ── Login ── */
.login-wrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary);
}
.login-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 2.25rem;
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 1rem;
}
.login-title {
  font-size: 1.4rem; font-weight: 700; text-align: center;
  background: linear-gradient(135deg, var(--pink-light), var(--pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.login-box label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; }
.login-box input { margin-top: 0.3rem; }
.login-error { font-size: 0.8rem; color: var(--danger); text-align: center; }

/* ── Filter dropdown ── */
.filter-dropdown { position: relative; }

.filter-drop-trigger { gap: 0.35rem; }
.filter-drop-trigger.active { border-color: var(--pink); color: var(--pink-light); background: var(--pink-glow); }

.filter-drop-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  min-width: 180px;
  padding: 0.6rem;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.filter-drop-panel.open { display: block; }

.filter-drop-group { margin-bottom: 0.5rem; }
.filter-drop-group:last-of-type { margin-bottom: 0; }

.filter-drop-cat {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0.15rem 0.5rem 0.3rem;
}

.filter-drop-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-transform: none;
  letter-spacing: 0;
  width: 100%;
}
.filter-drop-item:hover { background: var(--pink-glow); color: var(--text-primary); }

.filter-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-check {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--pink-light);
}

.filter-drop-clear {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.35rem 0.5rem;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
  cursor: pointer;
  font-family: inherit;
  transition: color var(--transition);
  padding-top: 0.6rem;
}
.filter-drop-clear:hover { color: var(--danger); }

/* ── Scroll to top ── */
.scroll-top {
  position: fixed;
  bottom: 1.75rem;
  right: 1.75rem;
  width: 40px;
  height: 40px;
  background: var(--pink-glow);
  border: 1px solid var(--pink);
  color: var(--pink-light);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease, background 0.2s ease;
  z-index: 90;
}
.scroll-top.visible { opacity: 1; pointer-events: all; transform: translateY(0); }
.scroll-top:hover { background: rgba(219,112,147,0.3); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .admin-layout { grid-template-columns: 1fr; }

  .hamburger { display: flex; }

  .sidebar {
    position: fixed; top: 0; left: -100%; width: var(--sidebar-w);
    height: 100vh; z-index: 200;
    transition: left 0.25s ease;
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }

  .admin-main { padding: 1.25rem 1rem 2rem; padding-top: 4rem; }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: 1; }
  .game-item-actions { flex-wrap: wrap; }
  .section-header { flex-wrap: wrap; gap: 0.5rem; }
}

@media (max-width: 480px) {
  .modal-backdrop { padding: 0.75rem; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; }
  .img-grid { grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); }
}
