/* ----------------------------------------------------------------------- */
/*  KSTUDIO — Reference Library                                            */
/*  Brand palette from kstudio.lv: deep navy + turquoise accent.           */
/* ----------------------------------------------------------------------- */

:root {
  --bg:        #10121d;        /* deep navy */
  --bg-soft:   #181a26;
  --panel:     #161824;
  --panel-2:   #1c1f2c;
  --line:      #232636;
  --line-strong: #2c3043;

  --ink:       #ffffff;        /* primary text */
  --ink-soft:  #e0f2f1;        /* warm cream-cyan */
  --ink-mute:  #9ca3af;        /* muted gray */
  --ink-faint: #6b7280;

  --accent:    #5ee3d3;        /* kstudio turquoise */
  --accent-deep: #3fbfb1;
  --accent-soft: #b3f0e9;
  --warn:      #cc344e;
  --orange:    #e8553a;

  --display: "Montserrat", "Helvetica Neue", system-ui, sans-serif;
  --sans:    "Inter", "Helvetica Neue", system-ui, sans-serif;
  --mono:    "IBM Plex Mono", "Menlo", ui-monospace, monospace;

  --side-w:  280px;
  --r-card:  10px;
  --r-pill:  999px;
  --shadow-card: 0 1px 0 #ffffff05 inset, 0 12px 40px -20px #000;
}

* { box-sizing: border-box; }
*::selection { background: var(--accent); color: #000; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 12% -5%, rgba(94, 227, 211, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 88% 100%, rgba(94, 227, 211, 0.05) 0%, transparent 50%);
}

#grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  opacity: 0.025; mix-blend-mode: overlay;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ------- Top bar ------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  background: rgba(16, 18, 29, 0.85);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: 14px;
}
.brand-logo-img {
  height: 28px;
  width: auto;
  display: block;
}
.brand-divider {
  color: var(--ink-faint);
  font-family: var(--display);
  font-weight: 300;
  font-size: 16px;
}
.brand-sub {
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.brand-sub em {
  font-style: normal;
  color: var(--accent);
  font-weight: 800;
}

.topnav {
  display: flex; align-items: center; gap: 8px;
}
.topnav input[type="search"] {
  width: 360px; max-width: 38vw;
  padding: 9px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  outline: 0;
  color: var(--ink);
  transition: border-color .18s, box-shadow .18s;
}
.topnav input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94, 227, 211, 0.18);
}
.topnav input[type="search"]::placeholder { color: var(--ink-mute); }

.topnav select, .topnav button.text {
  padding: 9px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
#reroll {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--bg-soft);
  color: var(--ink-soft);
  transition: transform .25s, color .15s, border-color .15s;
}
#reroll:hover { color: var(--accent); border-color: var(--accent); }
#reroll:active { transform: rotate(180deg); }

/* ------- Layout -------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  align-items: start;
  position: relative; z-index: 2;
}

.sidebar {
  position: sticky; top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 24px 22px 32px;
  border-right: 1px solid var(--line);
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.filter-block { padding: 18px 0; border-bottom: 1px solid var(--line); }
.filter-block:last-child { border-bottom: 0; }
.filter-block:first-child { padding-top: 0; }
.block-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-mute);
  margin-bottom: 14px;
}

.counter {
  display: flex; align-items: baseline; gap: 8px;
  font-family: var(--display);
}
.counter-num {
  font-size: 56px;
  line-height: 1;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
  font-feature-settings: "tnum" 1;
}
.counter-of {
  font-size: 13px;
  color: var(--ink-mute);
  font-weight: 400;
}
.counter-total {
  font-family: var(--display);
  font-size: 16px;
  color: var(--ink-soft);
  font-weight: 600;
  font-feature-settings: "tnum" 1;
}
.counter-word {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-mute);
  margin-left: auto;
  align-self: flex-end;
}

.cats { list-style: none; padding: 0; margin: 0; }
.cats li {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px;
  padding: 7px 8px;
  margin: 0 -8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.cats li:hover { background: var(--bg-soft); }
.cats li.active {
  background: rgba(94, 227, 211, 0.10);
}
.cats li.active .cat-name { color: var(--accent); }
.cats li .cat-name {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}
.cats.compact li .cat-name {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 400;
  text-transform: lowercase;
  letter-spacing: 0;
}
.cats li .cat-count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-mute);
  font-feature-settings: "tnum" 1;
  flex-shrink: 0;
}

.tag-cloud {
  display: flex; flex-wrap: wrap; gap: 5px;
  max-height: 220px;
  overflow: hidden auto;
  scrollbar-width: thin;
}
.tag-pill {
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 9px;
  border-radius: var(--r-pill);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
}
.tag-pill:hover { color: var(--accent); border-color: var(--accent); }
.tag-pill.active {
  background: var(--accent);
  color: #0b0d17;
  border-color: var(--accent);
  font-weight: 500;
}
.tag-pill .tag-count {
  margin-left: 5px; opacity: .55;
}

.active-filters { display: flex; flex-wrap: wrap; gap: 5px; min-height: 22px; }
.active-filters .tag-pill { background: var(--bg-soft); border-color: var(--line-strong); }
.active-filters .tag-pill::after { content: " ×"; opacity: .55; margin-left: 4px; }
.active-filters .muted { color: var(--ink-mute); font-family: var(--mono); font-size: 11px; }

.ghost {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  margin-top: 12px;
  padding: 6px 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  transition: color .12s, border-color .12s;
}
.ghost:hover { color: var(--accent); border-color: var(--accent); }

.tinyprint {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  line-height: 1.7;
}

/* ------- Content ------------------------------------------------------ */

.content {
  padding: 36px 40px 80px;
  min-height: calc(100vh - 60px);
}

.hero {
  margin-bottom: 56px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
}
.hero-eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-mute);
  margin-bottom: 14px;
}
.hero-title {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(40px, 5.5vw, 84px);
  line-height: 0.96;
  letter-spacing: -0.025em;
  margin: 0 0 36px 0;
  color: var(--ink);
  text-transform: uppercase;
}
.hero-title em {
  font-style: normal;
  color: var(--accent);
  font-weight: 900;
}
.hero-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 14px;
  height: 50vh;
  min-height: 420px;
  max-height: 560px;
}
.hero-grid .card { margin: 0; height: 100%; }
.hero-grid .card:nth-child(1) { grid-row: span 2; }
.hero-grid .card .card-media { height: 100%; aspect-ratio: auto; }

.results-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 22px;
  border-top: 1px solid var(--line);
  padding-top: 24px;
}
.results-title {
  font-family: var(--display);
  font-size: 32px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.results-title em { color: var(--accent); font-style: normal; font-weight: 800; }
.results-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ------- Card grid ---------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
  cursor: pointer;
  transition: transform .25s cubic-bezier(.2,.7,.2,1), border-color .15s;
  outline: 0;
  box-shadow: var(--shadow-card);
}
.card:hover, .card:focus { transform: translateY(-3px); border-color: var(--accent); }
.card:focus { box-shadow: 0 0 0 2px var(--accent), var(--shadow-card); }

.card-media {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}
.card-media video,
.card-media .card-thumb,
.card-media .card-iframe {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.card-media .card-iframe {
  position: absolute; inset: 0;
  border: 0;
  pointer-events: none;
}
.card-media .card-thumb {
  position: absolute; inset: 0;
  z-index: 1;
}
.card-media::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,.35) 100%);
  pointer-events: none;
}

.card-cat {
  position: absolute; top: 10px; left: 10px;
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  background: rgba(11, 13, 23, 0.78);
  backdrop-filter: blur(6px);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid rgba(94, 227, 211, 0.2);
}

.card-meta {
  padding: 12px 14px 14px;
}
.card-title {
  font-family: var(--display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.005em;
  margin: 0 0 6px 0;
  line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--ink);
}
.card-prompt {
  font-size: 12px;
  color: var(--ink-mute);
  margin: 0 0 10px 0;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
}
.card-tags {
  display: flex; flex-wrap: wrap; gap: 4px;
}
.card-tags .tag {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg-soft);
  color: var(--ink-mute);
  border: 1px solid var(--line);
}

.grid-end {
  text-align: center;
  padding: 60px 0 20px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
}
.loading {
  text-align: center;
  padding: 40px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

/* ------- Lightbox ----------------------------------------------------- */

.lightbox {
  width: min(1200px, 92vw);
  max-height: 90vh;
  border: 0;
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink-soft);
  padding: 0;
  overflow: hidden;
  box-shadow: 0 60px 120px -40px #000, 0 0 0 1px var(--line-strong);
}
.lightbox::backdrop {
  background: rgba(11, 13, 23, 0.82);
  backdrop-filter: blur(8px);
}
.lb-close {
  position: absolute; top: 14px; right: 14px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  font-size: 22px;
  line-height: 1;
  z-index: 10;
  transition: background .15s, color .15s;
}
.lb-close:hover { background: var(--accent); color: #0b0d17; }

.lb-body { display: grid; grid-template-columns: 1.4fr 1fr; gap: 0; }
.lb-video {
  background: #000;
  aspect-ratio: 16/9;
  width: 100%;
  display: block;
  border: 0;
}
iframe.lb-video { height: auto; }
.lb-info {
  padding: 32px 36px 36px;
  overflow-y: auto;
  max-height: 90vh;
}
.lb-eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 8px;
}
.lb-eyebrow .acid { color: var(--accent); }
.lb-title {
  font-family: var(--display);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.15;
  margin: 0 0 18px 0;
  color: var(--ink);
}
.lb-section { margin: 22px 0; }
.lb-section h5 {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink-mute);
  margin: 0 0 8px 0;
  font-weight: 500;
}
.lb-section p, .lb-section .body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: 0;
}
.lb-section .body.prompt {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}
.lb-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.lb-params {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  font-family: var(--mono);
  font-size: 11px;
}
.lb-params dt { color: var(--ink-mute); }
.lb-params dd { color: var(--ink); margin: 0; }
.lb-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 22px;
}
.lb-actions a, .lb-actions button {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  transition: color .12s, border-color .12s, background .12s;
}
.lb-actions a:hover, .lb-actions button:hover {
  color: var(--accent); border-color: var(--accent);
}
.lb-actions .primary {
  background: var(--accent); color: #0b0d17; border-color: var(--accent);
  font-weight: 600;
}
.lb-actions .primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: #0b0d17; }

/* ------- Reveal / load animation -------------------------------------- */

.card {
  animation: fadeup .6s ease both;
  animation-delay: var(--d, 0ms);
}
@keyframes fadeup {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ------- Responsive --------------------------------------------------- */

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .hero-grid { grid-template-columns: 1fr 1fr; height: auto; max-height: none; }
  .hero-grid .card:nth-child(1) { grid-row: auto; }
  .lb-body { grid-template-columns: 1fr; }
  .lb-info { max-height: 50vh; }
}

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .topnav { flex-wrap: wrap; }
  .topnav input[type="search"] { width: 100%; max-width: none; }
  .content { padding: 24px 16px 60px; }
  .hero-grid { grid-template-columns: 1fr; }
  .results-title { font-size: 24px; }
  .brand-sub { display: none; }
}

/* ------- Auth screen ----------------------------------------------------- */

body.auth-locked { overflow: hidden; }
body.auth-locked .layout, body.auth-locked .topbar { filter: blur(8px); pointer-events: none; user-select: none; }

.auth-screen {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(11, 13, 23, 0.88);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
}
.auth-screen[hidden] { display: none !important; }
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 44px 44px 36px;
  width: min(420px, 92vw);
  text-align: center;
  box-shadow: 0 60px 120px -40px #000;
}
.auth-logo { height: 38px; margin: 0 auto 22px; display: block; }
.auth-title {
  font-family: var(--display);
  font-weight: 800;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0 0 6px 0;
  color: var(--ink);
  text-transform: uppercase;
}
.auth-title em { font-style: normal; color: var(--accent); font-weight: 800; }
.auth-sub { color: var(--ink-mute); font-size: 13px; margin: 0 0 28px 0; }
.auth-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px 18px;
  background: #fff; color: #111;
  border: 0; border-radius: 8px;
  font-family: var(--display);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s;
}
.auth-google:hover { transform: translateY(-1px); box-shadow: 0 8px 24px -10px rgba(94,227,211,.4); }
.auth-google:active { transform: translateY(0); }
.auth-error {
  margin: 18px 0 0 0;
  padding: 10px 14px;
  background: rgba(204, 52, 78, 0.12);
  border: 1px solid rgba(204, 52, 78, 0.5);
  color: #ff8c9b;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
  font-family: var(--sans);
}

.auth-hint {
  color: var(--ink-mute);
  font-size: 11px;
  margin: 18px 0 0 0;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.auth-hint strong { color: var(--accent); font-weight: 500; }
.auth-preview-link {
  margin: 28px 0 0 0;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--ink-faint);
  letter-spacing: 0.05em;
}
.auth-preview-link a {
  color: var(--ink-soft);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
  transition: color .12s;
}
.auth-preview-link a:hover { color: var(--accent); }

/* ------- User button (top bar) ------------------------------------------ */

.user-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.user-btn:hover { border-color: var(--accent); color: var(--accent); }
.user-btn img {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--panel);
  display: inline-block;
  object-fit: cover;
}
.user-btn img[hidden] { display: none; }

.mode-line {
  margin-top: 4px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.75;
}

/* ------- Settings dialog ------------------------------------------------- */

.settings-dialog { width: min(560px, 92vw); }
.settings-body { padding: 36px 36px 28px; }
.settings-title {
  font-family: var(--display);
  font-weight: 800;
  font-size: 22px;
  margin: 0 0 22px 0;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.settings-row-label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-mute);
}
.settings-row-value {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}
.settings-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.settings-actions button {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  background: var(--bg-soft);
  transition: color .12s, border-color .12s, background .12s;
}
.settings-actions button:hover { color: var(--accent); border-color: var(--accent); }
.settings-help {
  margin-top: 22px;
  font-size: 12px;
  color: var(--ink-mute);
  line-height: 1.6;
}
.settings-help code {
  font-family: var(--mono);
  background: var(--bg-soft);
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--line);
  color: var(--accent);
}
