:root {
  --accent: #2f5dff;
  --ink: #0a0a0a;
  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #e5e5e5;
  --gray-400: #a3a3a3;
  --gray-500: #737373;
  --gray-600: #525252;
  --red: #ef4444;
  --green: #16a34a;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--gray-200);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: none;
  background: none;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-area { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 14px; font-weight: 600; }
.save-indicator { font-size: 12px; color: var(--gray-400); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: var(--gray-100); color: var(--ink); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-outline { background: #fff; border: 1px solid var(--gray-200); color: var(--ink); }
.btn-outline:hover { background: var(--gray-50); }
.btn-ghost { background: none; color: var(--gray-500); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger { background: #fef2f2; color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn {
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--gray-400);
  cursor: pointer;
  padding: 4px;
}
.icon-btn:hover { color: var(--ink); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--gray-200);
  background: var(--gray-100);
  color: var(--gray-600);
}
.badge-owner { background: var(--ink); color: #fff; border-color: var(--ink); }
.badge-admin { background: var(--accent); color: #fff; border-color: var(--accent); }
.badge-toggle { cursor: pointer; border: none; }
.badge-toggle.on { background: #f0fdf4; color: var(--green); }
.badge-toggle.off { background: var(--gray-100); color: var(--gray-500); }

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 28px 20px 60px; }

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.search-wrap { position: relative; flex: 1; min-width: 220px; max-width: 320px; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--gray-400); }
.search-wrap input { padding-left: 32px; }
.toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; }

input[type="text"], input[type="password"], input[type="file"], textarea, select {
  font: inherit;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  color: var(--ink);
  width: 100%;
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47,93,255,0.12);
}
select { width: auto; }

/* ---------- Grid / Cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.06); }

.card-thumb {
  position: relative;
  height: 128px;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-thumb .placeholder { color: var(--gray-400); font-size: 26px; }
.cat-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(255,255,255,0.92);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 10px;
  font-weight: 600;
  color: var(--gray-600);
}
.unactive-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.unactive-overlay span {
  background: rgba(10,10,10,0.8);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 6px;
}

.card-body { padding: 14px; display: flex; flex-direction: column; flex: 1; }
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.card-desc {
  font-size: 12px;
  color: var(--gray-500);
  margin: 0 0 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.code-wrap { position: relative; margin-bottom: 10px; }
.code-box {
  max-height: 96px;
  overflow: hidden;
  border-radius: 8px;
  background: #0a0a0a;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--gray-400);
  margin-bottom: 10px;
}
.card-actions { display: flex; gap: 6px; margin-top: auto; }
.card-actions .btn { flex: 1; justify-content: center; }
.card-actions .btn.icon-only { flex: none; padding: 9px 10px; }

.empty-state {
  border: 1px dashed var(--gray-200);
  border-radius: var(--radius);
  padding: 60px 20px;
  text-align: center;
  color: var(--gray-400);
  font-size: 14px;
}

/* ---------- Admins / Categories views ---------- */
.two-col { display: grid; grid-template-columns: 1fr 300px; gap: 24px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
.section-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 12px 14px;
}
.list-item .name { font-size: 14px; font-weight: 600; }
.list-item .meta { font-size: 12px; color: var(--gray-400); }
.side-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  height: fit-content;
}
.side-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 999px;
  padding: 6px 6px 6px 12px;
  font-size: 13px;
}
.chip .count { font-size: 11px; color: var(--gray-400); }
.chip button { border: none; background: none; color: var(--gray-400); cursor: pointer; border-radius: 999px; width: 20px; height: 20px; }
.chip button:hover { background: #fee2e2; color: var(--red); }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { font-size: 12px; font-weight: 600; color: var(--gray-600); display: flex; flex-direction: column; gap: 6px; }
.error { color: var(--red); font-size: 12px; font-weight: 500; margin: 0; }
.hint { font-size: 11px; color: var(--gray-400); text-align: center; margin: 0; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,10,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-sm { max-width: 380px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
}
.modal-head h2 { font-size: 15px; margin: 0; }
.modal-head-actions { display: flex; align-items: center; gap: 8px; }
.modal-body { padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

.thumb-row { display: flex; align-items: center; gap: 10px; }
.thumb-preview {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  border: 1px dashed var(--gray-200);
  background: var(--gray-50);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.thumb-preview img { width: 100%; height: 100%; object-fit: cover; }
.color-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--gray-500); margin-bottom: 6px; }
.color-row input[type="color"] { width: 36px; height: 24px; padding: 0; border: 1px solid var(--gray-200); border-radius: 6px; cursor: pointer; }
.code-textarea {
  background: #0a0a0a;
  color: #7dd3fc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  border-color: #0a0a0a;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

/* ---------- Simplified cards (Phase 2 UI update) ---------- */
.card { cursor: pointer; }
.card-thumb { height: 150px; position: relative; }
.verified-tag {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.card-hover-actions {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .card-hover-actions { opacity: 1; }
.icon-only-sm {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.95);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  cursor: pointer;
  font-size: 13px;
}
.icon-only-sm:hover { background: #fff; }
.card-body-simple {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.card-title { font-size: 14px; font-weight: 600; margin: 0; }
.card-views { font-size: 11px; color: var(--gray-400); white-space: nowrap; }

/* ---------- Script detail modal ---------- */
.modal-detail { max-width: 640px; }
.detail-thumb {
  width: 100%;
  height: 180px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.detail-thumb img { width: 100%; height: 100%; object-fit: cover; }
.detail-thumb-placeholder { font-size: 30px; color: var(--gray-300, #d4d4d4); }
.detail-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.detail-desc { font-size: 13px; color: var(--gray-600); margin: 0 0 16px; line-height: 1.6; white-space: pre-wrap; }
.code-block-wrap { position: relative; margin-bottom: 14px; }
.code-block-wrap pre {
  margin: 0;
  background: #0d1117;
  border-radius: 10px;
  padding: 16px;
  max-height: 360px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.6;
}
.code-block-wrap code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.copy-icon-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #d4d4d4;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.copy-icon-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.detail-meta {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--gray-400);
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  font-size: 12px;
  color: var(--gray-400);
  padding: 24px 20px 32px;
}

/* ---------- Phase 2: type tags, discord, file block ---------- */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.type-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
}
.type-free { background: #16a34a; }
.type-paid { background: #f59e0b; }
.cat-tag ~ .type-tag { left: auto; }
.badge.type-free { background: #f0fdf4; color: #16a34a; border-color: #bbf7d0; }
.badge.type-paid { background: #fffbeb; color: #b45309; border-color: #fde68a; }

.discord-btn { margin-bottom: 14px; }
.file-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--gray-100);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--gray-600);
}

.show-more-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0 12px;
}

/* ---------- Like / Report actions ---------- */
.detail-actions { display: flex; gap: 8px; margin: 14px 0 22px; }
#detailLikeBtn.liked { color: #e11d48; border-color: #fecdd3; background: #fff1f2; }

/* ---------- Comments ---------- */
.comments-section { border-top: 1px solid var(--gray-100); padding-top: 18px; margin-top: 4px; }
.comment-form { display: flex; gap: 8px; margin-bottom: 14px; align-items: flex-start; }
.comment-form textarea { flex: 1; resize: vertical; }
.comments-list { display: flex; flex-direction: column; gap: 12px; }
.comment-item { background: var(--gray-50); border-radius: 10px; padding: 10px 12px; }
.comment-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.comment-author { font-size: 12.5px; font-weight: 700; }
.comment-date { font-size: 11px; color: var(--gray-400); margin-left: auto; }
.comment-delete { border: none; background: none; color: var(--gray-400); cursor: pointer; font-size: 15px; line-height: 1; }
.comment-delete:hover { color: var(--red); }
.comment-text { font-size: 13px; color: var(--gray-600); margin: 0; white-space: pre-wrap; }

/* ---------- Other scripts ---------- */
.other-scripts-section { border-top: 1px solid var(--gray-100); padding-top: 18px; margin-top: 18px; }
.other-scripts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.other-script-card { cursor: pointer; text-align: center; }
.other-script-thumb {
  height: 72px;
  border-radius: 8px;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 6px;
  color: var(--gray-300, #d4d4d4);
  font-size: 18px;
}
.other-script-thumb img { width: 100%; height: 100%; object-fit: cover; }
.other-script-name { font-size: 11.5px; font-weight: 500; color: var(--gray-600); display: block; }

/* ---------- Phase 3: notifications, auth tabs, dashboard, settings ---------- */
.notif-wrap { position: relative; }
.icon-btn-round {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--gray-200);
  background: #fff;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn-round:hover { background: var(--gray-50); }
.notif-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--red);
  border: 1.5px solid #fff;
}
.notif-panel {
  position: absolute;
  top: 42px;
  right: 0;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.12);
  z-index: 40;
}
.notif-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
  font-weight: 700;
}
.link-btn { border: none; background: none; color: var(--accent); font-size: 12px; font-weight: 600; cursor: pointer; }
.notif-list { display: flex; flex-direction: column; }
.notif-item { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--gray-100); }
.notif-item.unread { background: #f5f8ff; }
.notif-icon { font-size: 14px; flex-shrink: 0; margin-top: 2px; }
.notif-text { font-size: 12.5px; margin: 0; color: var(--ink); }
.notif-time { font-size: 11px; color: var(--gray-400); }

/* Auth modal tabs */
.auth-tabs { display: flex; gap: 4px; padding: 0 20px; margin-top: 4px; }
.auth-tab {
  flex: 1;
  border: none;
  background: var(--gray-100);
  color: var(--gray-500);
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}
.auth-tab.active { background: var(--ink); color: #fff; }

/* Dashboard */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; max-width: 560px; }
.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-value { font-size: 26px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--gray-500); }

/* Settings row (Sign In toggle) */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  max-width: 640px;
}

/* ================= Mobile support ================= */
@media (max-width: 720px) {
  .topbar-inner { padding: 12px 14px; gap: 10px; }
  .brand-name { font-size: 16px; }
  .brand-mark { width: 26px; height: 26px; font-size: 11px; }

  .topbar-right { gap: 6px; }
  .save-indicator { display: none; }
  .user-name { display: none; } /* role badge still shows who's logged in */
  #loginBtn span, #loginBtn { font-size: 13px; }
  .btn { padding: 8px 10px; font-size: 13px; }
  .btn-ghost { padding: 8px; }

  .tabs { padding: 0 14px 2px; }
  .tabs button { padding: 8px 10px; font-size: 13px; }

  .container { padding: 18px 14px 44px; }

  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .search-wrap { max-width: none; }
  .toolbar-right { justify-content: stretch; }
  .toolbar-right select { flex: 1; min-width: 0; }
  #addScriptBtn { width: 100%; justify-content: center; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card-thumb { height: 110px; }
  .card-body-simple { padding: 10px; }
  .card-title { font-size: 13px; }

  /* Touch devices have no hover — keep quick actions reachable */
  .card-hover-actions { opacity: 1; bottom: 6px; right: 6px; }
  .icon-only-sm { width: 26px; height: 26px; }

  .two-col { grid-template-columns: 1fr; }
  .side-card { max-width: none !important; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: none;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }
  .modal-sm { max-width: none; }
  .modal-detail { max-width: none; }
  .modal-body { padding: 16px; }
  .modal-head { padding: 14px 16px; }

  .field-row { grid-template-columns: 1fr; }
  .thumb-row { flex-wrap: wrap; }

  .stats-grid { grid-template-columns: 1fr 1fr; max-width: none; }
  .stat-value { font-size: 22px; }

  .setting-row { max-width: none; flex-wrap: wrap; gap: 10px; }

  .comment-form { flex-direction: column; align-items: stretch; }
  .comment-form .btn { align-self: flex-end; }

  .other-scripts-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }

  .notif-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
  }
  .notif-wrap { position: static; }

  .code-block-wrap pre { max-height: 260px; font-size: 12px; }
  .detail-actions { flex-wrap: wrap; }

  .list-item { flex-direction: column; align-items: flex-start; gap: 10px; }
  .list-item > div:last-child { width: 100%; display: flex; }
  .list-item > div:last-child .btn { flex: 1; justify-content: center; }
}

@media (max-width: 380px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .stats-grid { grid-template-columns: 1fr; }
}

/* ================= Page loader ================= */
#pageLoader {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transition: opacity 0.45s ease, visibility 0.45s ease;
}
#pageLoader.fade-out { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-mark {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  animation: pulse 1.4s ease-in-out infinite;
}
.loader-spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}
.loader-text { font-size: 13px; color: var(--gray-400); font-weight: 500; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes sheetUp { from { opacity: 0; transform: translateY(100%); } to { opacity: 1; transform: translateY(0); } }

/* ================= General "not stiff" motion ================= */
body, .card, .btn, input, select, textarea, .icon-btn-round, .chip, .list-item, .stat-card, .hero-badge {
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.card { animation: cardIn 0.35s ease backwards; }
.card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0,0,0,0.08); }
.stat-card:hover, .other-script-card:hover .other-script-thumb { transform: translateY(-2px); }
.chip:hover { border-color: var(--accent); }

.modal-overlay:not(.hidden) { animation: fadeIn 0.18s ease; }
.modal-overlay:not(.hidden) .modal { animation: fadeSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
.toast:not(.hidden) { animation: fadeSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1); }
.notif-panel:not(.hidden) { animation: fadeSlideUp 0.2s ease; }

/* ================= Public hero (works without login) ================= */
.hero {
  background: linear-gradient(180deg, #fff, var(--gray-50));
  border: 1px solid var(--gray-200);
  border-radius: 18px;
  padding: 28px 24px;
  margin-bottom: 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.hero-text h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -0.02em; }
.hero-text p { font-size: 13.5px; color: var(--gray-500); margin: 0 0 14px; max-width: 420px; }
.hero-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.hero-badge {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
}
.hero-stats { display: flex; gap: 10px; }
.hero-stat {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 14px;
  padding: 14px 18px;
  min-width: 90px;
  text-align: center;
}
.hero-stat-value { display: block; font-size: 22px; font-weight: 800; }
.hero-stat-label { display: block; font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* ================= Outlines & dividers ("pembatas") ================= */
.card-thumb { border-bottom: 1px solid var(--gray-100); }
.detail-thumb { border: 1px solid var(--gray-200); }
.code-block-wrap pre { border: 1px solid #1f2530; }
.file-block { border: 1px solid var(--gray-200); }
.comment-item { border: 1px solid var(--gray-100); }
.detail-badges { padding-bottom: 12px; border-bottom: 1px solid var(--gray-100); margin-bottom: 14px; }
.comments-section, .other-scripts-section { border-top: 1px solid var(--gray-100); }
.detail-actions { padding-bottom: 18px; border-bottom: 1px solid var(--gray-100); }
.modal-head { border-bottom: 1px solid var(--gray-100); }
.stat-card, .hero-stat, .side-card, .other-script-thumb { border: 1px solid var(--gray-200); }

/* ================= Mobile: hero + motion tweaks ================= */
@media (max-width: 720px) {
  .hero { flex-direction: column; align-items: stretch; padding: 20px 18px; border-radius: 16px; }
  .hero-text h1 { font-size: 21px; }
  .hero-stats { justify-content: space-between; }
  .hero-stat { flex: 1; padding: 12px 8px; min-width: 0; }
  .hero-stat-value { font-size: 18px; }

  .modal-overlay:not(.hidden) .modal { animation: sheetUp 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
  .card:hover { transform: none; } /* avoid odd lift on touch tap */
}

/* ================= AI Lab ================= */
.ai-fab {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  border: none;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 28px rgba(0,0,0,0.22);
  cursor: pointer;
  z-index: 45;
  animation: pulse 2.4s ease-in-out infinite;
}
.ai-fab:hover { background: var(--accent); transform: translateY(-2px); }

.modal-ai {
  max-width: 440px;
  display: flex;
  flex-direction: column;
  height: 560px;
  max-height: 82vh;
  overflow: visible;
  border: 1px solid var(--gray-200);
  box-shadow: 0 20px 55px rgba(10,10,10,0.18);
}
.modal-ai .modal-head { align-items: flex-start; flex-shrink: 0; position: relative; border-bottom: 1px solid var(--gray-200); }
.modal-ai .modal-head h2 { margin-bottom: 8px; }
.ai-head-info { flex: 1; min-width: 0; }

/* ---- Model picker (custom dropdown) ---- */
.ai-model-picker { position: relative; display: inline-block; }
.ai-model-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  padding: 6px 8px 6px 10px;
  background: #f5f8ff;
  cursor: pointer;
  font: inherit;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.ai-model-trigger:hover { border-color: var(--accent); }
.ai-model-trigger[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,93,255,0.14); }
.ai-model-trigger-text { display: flex; align-items: baseline; gap: 5px; }
.ai-model-trigger-name { font-size: 13px; font-weight: 700; color: var(--ink); }
.ai-model-trigger-tag { font-size: 11px; font-weight: 700; color: var(--accent); }
.ai-model-caret { color: var(--gray-500); transition: transform .15s ease; flex-shrink: 0; }
.ai-model-trigger[aria-expanded="true"] .ai-model-caret { transform: rotate(180deg); }

.ai-model-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 300px;
  max-width: 84vw;
  background: #fff;
  border: 1.5px solid var(--gray-200);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.16);
  padding: 6px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: aiMenuIn .14s ease;
}
@keyframes aiMenuIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.ai-model-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: 1.5px solid transparent;
  border-radius: 10px;
  padding: 8px 9px;
  cursor: pointer;
  font: inherit;
  transition: background .12s ease, border-color .12s ease;
}
.ai-model-option:hover { background: var(--gray-100); }
.ai-model-option.is-active { background: #f0f4ff; border-color: rgba(47,93,255,0.35); }
.ai-model-option.is-locked { cursor: not-allowed; opacity: 0.62; }
.ai-model-option.is-locked:hover { background: none; }
.ai-model-option-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-model-option-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.ai-model-option-name b { font-weight: 800; }
.ai-model-option-desc { font-size: 11px; color: var(--gray-500); line-height: 1.35; }
.ai-model-divider { height: 1px; background: var(--gray-200); margin: 4px 6px; }

.ai-model-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 3px 7px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.ai-model-badge.free { background: #e8f9ee; color: var(--green); border-color: #c8ecd5; }
.ai-model-badge.pro { background: #fff2e0; color: #c2760a; border-color: #ffe1b3; }
.ai-model-badge.proplus { background: #f2e9ff; color: #7c3aed; border-color: #e1cfff; }
.ai-model-badge.owner { background: #fff7d6; color: #a16207; border-color: #ffe89e; }

.ai-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ai-msg-row { display: flex; flex-direction: column; gap: 4px; max-width: 82%; }
.ai-msg-row-user { align-self: flex-end; align-items: flex-end; }
.ai-msg-row-bot { align-self: flex-start; align-items: flex-start; }
.ai-msg {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1.5px solid transparent;
}
.ai-msg-bot { background: var(--gray-100); color: var(--ink); border-bottom-left-radius: 4px; border-color: var(--gray-200); }
.ai-msg-user { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; border-color: #1d43d6; }
.ai-msg-typing { display: flex; gap: 4px; align-items: center; padding: 12px 14px; }
.ai-dot {
  width: 6px; height: 6px; border-radius: 999px; background: var(--gray-400);
  animation: aiTyping 1s infinite ease-in-out;
}
.ai-dot:nth-child(2) { animation-delay: 0.15s; }
.ai-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes aiTyping { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* message send/receive animation */
.ai-msg-in { animation: aiMsgIn .22s cubic-bezier(.2,.8,.3,1); }
@keyframes aiMsgIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* copy button under each bubble */
.ai-msg-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  color: var(--gray-500);
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease, color .12s ease;
}
.ai-msg-row:hover .ai-msg-copy { opacity: 1; }
.ai-msg-copy:hover { color: var(--accent); }
.ai-msg-copy.is-copied { opacity: 1; color: var(--green); }
@media (hover: none) {
  .ai-msg-copy { opacity: 0.75; }
}

.ai-chat-form {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 16px;
  border-top: 1.5px solid var(--gray-200);
}
.ai-chat-form textarea {
  flex: 1;
  resize: none;
  max-height: 90px;
  font-size: 13.5px;
  border: 1.5px solid var(--gray-200);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.ai-chat-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,93,255,0.14); outline: none; }
#aiChatSendBtn { position: relative; transition: transform .12s ease; }
#aiChatSendBtn:active { transform: scale(0.94); }
#aiChatSendBtn.is-sending { color: transparent; pointer-events: none; }
#aiChatSendBtn.is-sending::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid rgba(255,255,255,0.5);
  border-top-color: #fff;
  border-radius: 999px;
  animation: aiSpin .6s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .ai-fab { bottom: 16px; right: 16px; width: 50px; height: 50px; }
  .modal-ai { height: 100%; max-height: 100vh; border-radius: 0; }
  #aiLabModal.modal-overlay { padding: 0; align-items: stretch; }
}
