/* =====================================================================
   Resource Library — visual system
   Palette: deep marine ink on cool paper; every file type owns a hue,
   carried on the "spine" strip down the left edge of each file card.
   ===================================================================== */

:root {
  --ink:        #0F1D24;
  --ink-soft:   #4A5F6B;
  --ink-faint:  #8497A2;
  --paper:      #FFFFFF;
  --wash:       #E6EDF0;
  --wash-deep:  #D5E0E5;
  --marine:     #16505F;
  --marine-lit: #1E6E82;
  --line:       #C9D6DC;

  /* Functional file-type hues */
  --k-video:   #C1436E;
  --k-audio:   #6D5BD0;
  --k-pdf:     #C0392B;
  --k-slides:  #D98014;
  --k-doc:     #2D74B8;
  --k-sheet:   #1F8A62;
  --k-image:   #0E97A0;
  --k-text:    #5C7080;
  --k-archive: #6B7A85;

  --radius: 4px;
  --shadow: 0 1px 0 rgba(15,29,36,.06), 0 8px 24px -18px rgba(15,29,36,.55);

  --display: 'Bricolage Grotesque', 'Trebuchet MS', sans-serif;
  --body: 'Source Sans 3', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--wash);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.55;
}

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

.wrap { width: min(1180px, 100% - 3rem); margin-inline: auto; }
@media (max-width: 640px) { .wrap { width: min(1180px, 100% - 1.75rem); } }

.mono { font-family: var(--mono); font-size: .78rem; letter-spacing: .04em; }

:focus-visible { outline: 3px solid var(--marine-lit); outline-offset: 2px; }

/* ---------- Masthead ---------- */
.masthead {
  background: var(--ink);
  color: #EAF2F5;
  border-bottom: 4px solid var(--marine-lit);
}
.masthead-admin { background: var(--marine); border-bottom-color: var(--k-slides); }
.masthead-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1.5rem; padding: .95rem 0; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .7rem; text-decoration: none; color: inherit; }
.brand-mark {
  width: 26px; height: 26px; flex: none; border-radius: 2px;
  background:
    linear-gradient(var(--k-video) 0 33.3%, transparent 0 100%),
    linear-gradient(transparent 0 33.3%, var(--k-slides) 0 66.6%, transparent 0),
    linear-gradient(transparent 0 66.6%, var(--k-image) 0 100%);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-family: var(--display); font-weight: 700; font-size: 1.12rem; letter-spacing: -.01em; }
.brand-text em { font-style: normal; font-size: .78rem; color: #9FBAC4; }
.masthead-admin .brand-text em { color: #B9D6DE; }

.masthead-nav { display: flex; align-items: center; gap: 1.4rem; flex-wrap: wrap; }
.masthead-nav a { color: #DCE9ED; text-decoration: none; font-size: .93rem; }
.masthead-nav a:hover { color: #fff; text-decoration: underline; text-underline-offset: 4px; }
.masthead-nav .nav-quiet { color: #8FA9B3; }
.masthead-nav .nav-cta {
  background: var(--k-slides); color: #1B1204; padding: .32rem .8rem;
  border-radius: var(--radius); font-weight: 600;
}
.masthead-nav .nav-cta:hover { text-decoration: none; filter: brightness(1.08); }

/* ---------- Page furniture ---------- */
main.wrap { padding: 2.6rem 0 4rem; }

.page-head { margin: 0 0 2rem; }
.eyebrow {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-faint); margin: 0 0 .45rem;
}
h1 {
  font-family: var(--display); font-weight: 800; letter-spacing: -.025em;
  font-size: clamp(1.9rem, 1.2rem + 2.4vw, 3rem); line-height: 1.05; margin: 0;
}
h2 { font-family: var(--display); font-weight: 700; letter-spacing: -.015em; font-size: 1.35rem; margin: 0 0 .8rem; }
.lede { color: var(--ink-soft); max-width: 62ch; margin: .7rem 0 0; }

.crumb { font-family: var(--mono); font-size: .76rem; text-decoration: none; color: var(--ink-soft); }
.crumb:hover { color: var(--marine); }

.flash {
  background: #DFF3E7; border-left: 4px solid var(--k-sheet); color: #14432F;
  padding: .7rem 1rem; border-radius: var(--radius); margin: 0 0 1.5rem;
}
.error-box {
  background: #FBE4E1; border-left: 4px solid var(--k-pdf); color: #6B1D14;
  padding: .7rem 1rem; border-radius: var(--radius); margin: 0 0 1.25rem;
}
.empty {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 3rem 1.5rem; text-align: center; color: var(--ink-soft); background: #EDF3F5;
}
.empty strong { display: block; font-family: var(--display); font-size: 1.2rem; color: var(--ink); margin-bottom: .3rem; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; cursor: pointer;
  font: 600 .92rem/1 var(--body); padding: .62rem 1.05rem;
  border-radius: var(--radius); border: 1px solid var(--marine);
  background: var(--marine); color: #fff; text-decoration: none;
}
.btn:hover { background: var(--marine-lit); border-color: var(--marine-lit); }
.btn-ghost { background: transparent; color: var(--marine); }
.btn-ghost:hover { background: rgba(22,80,95,.08); color: var(--marine); }
.btn-danger { background: transparent; border-color: var(--k-pdf); color: var(--k-pdf); }
.btn-danger:hover { background: var(--k-pdf); color: #fff; }
.btn-sm { padding: .38rem .7rem; font-size: .82rem; }

.field { margin-bottom: 1.1rem; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field .hint { font-size: .82rem; color: var(--ink-soft); margin: .3rem 0 0; }
input[type=text], input[type=password], input[type=number], input[type=file], textarea, select {
  width: 100%; font: 400 1rem var(--body); color: var(--ink);
  padding: .6rem .75rem; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius);
}
textarea { min-height: 7rem; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--marine-lit); outline: none; box-shadow: 0 0 0 3px rgba(30,110,130,.18); }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 1.5rem; }

.auth-shell { max-width: 380px; margin: 4rem auto; }

/* ---------- Topic cards (public + admin) ---------- */
.topic-grid {
  display: grid; gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(285px, 1fr));
}
.topic-card {
  display: flex; flex-direction: column; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: inherit; overflow: hidden;
  box-shadow: var(--shadow); transition: transform .16s ease, box-shadow .16s ease;
}
.topic-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px -20px rgba(15,29,36,.7); }
.topic-cover { aspect-ratio: 16/9; background: var(--ink); position: relative; overflow: hidden; }
.topic-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.topic-cover.is-blank {
  background:
    repeating-linear-gradient(115deg, #16505F 0 14px, #123F4B 14px 28px);
}
.topic-cover .cover-initial {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--display); font-weight: 800; font-size: 3rem; color: rgba(255,255,255,.9);
}
.topic-body { padding: 1.05rem 1.15rem 1.25rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.topic-body h3 { font-family: var(--display); font-weight: 700; font-size: 1.16rem; letter-spacing: -.015em; margin: 0; line-height: 1.2; }
.topic-body p { margin: 0; color: var(--ink-soft); font-size: .93rem; }
.topic-meta { margin-top: auto; padding-top: .6rem; display: flex; flex-wrap: wrap; gap: .35rem; }

.pill {
  font-family: var(--mono); font-size: .68rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; padding: .2rem .5rem; border-radius: 2px;
  color: #fff; background: var(--k-archive);
}
.pill-count { background: transparent; color: var(--ink-faint); border: 1px solid var(--line); }
.pill[data-kind=video]  { background: var(--k-video); }
.pill[data-kind=audio]  { background: var(--k-audio); }
.pill[data-kind=pdf]    { background: var(--k-pdf); }
.pill[data-kind=slides] { background: var(--k-slides); }
.pill[data-kind=doc]    { background: var(--k-doc); }
.pill[data-kind=sheet]  { background: var(--k-sheet); }
.pill[data-kind=image]  { background: var(--k-image); }
.pill[data-kind=text]   { background: var(--k-text); }
.pill-draft { background: var(--ink-faint); }

/* ---------- File cards: the spine ---------- */
.filter-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 1.5rem; }
.filter-bar button {
  font: 600 .85rem var(--body); cursor: pointer; padding: .35rem .8rem;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-soft);
  border-radius: 100px;
}
.filter-bar button[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }

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

.file-card {
  position: relative; display: flex; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.file-spine {
  flex: none; width: 34px; background: var(--k-archive);
  display: flex; align-items: center; justify-content: center;
}
.file-spine span {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-family: var(--mono); font-weight: 700; font-size: .7rem;
  letter-spacing: .18em; text-transform: uppercase; color: rgba(255,255,255,.95);
}
.file-card[data-kind=video]  .file-spine { background: var(--k-video); }
.file-card[data-kind=audio]  .file-spine { background: var(--k-audio); }
.file-card[data-kind=pdf]    .file-spine { background: var(--k-pdf); }
.file-card[data-kind=slides] .file-spine { background: var(--k-slides); }
.file-card[data-kind=doc]    .file-spine { background: var(--k-doc); }
.file-card[data-kind=sheet]  .file-spine { background: var(--k-sheet); }
.file-card[data-kind=image]  .file-spine { background: var(--k-image); }
.file-card[data-kind=text]   .file-spine { background: var(--k-text); }

.file-body { padding: .95rem 1.05rem 1rem; display: flex; flex-direction: column; gap: .35rem; flex: 1; min-width: 0; }
.file-title {
  font-family: var(--display); font-weight: 700; font-size: 1.02rem; line-height: 1.25;
  margin: 0; overflow-wrap: anywhere;
}
.file-sub { font-family: var(--mono); font-size: .72rem; color: var(--ink-faint); }
.file-actions { margin-top: auto; padding-top: .7rem; display: flex; gap: .45rem; flex-wrap: wrap; }

/* ---------- Viewer overlay ---------- */
.viewer[hidden] { display: none; }
.viewer {
  position: fixed; inset: 0; z-index: 90; background: rgba(9,18,23,.9);
  display: flex; flex-direction: column; padding: clamp(.5rem, 2vw, 2rem);
}
.viewer-bar {
  display: flex; align-items: center; gap: 1rem; color: #EAF2F5;
  padding: .35rem .25rem .75rem; flex-wrap: wrap;
}
.viewer-bar h2 {
  margin: 0; font-size: 1.05rem; color: #fff; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viewer-bar .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.3); color: #fff; }
.viewer-bar .btn:hover { background: rgba(255,255,255,.24); }
.viewer-stage {
  flex: 1; min-height: 0; background: #0B161B; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; overflow: auto; position: relative;
}
.viewer-stage video, .viewer-stage img { max-width: 100%; max-height: 100%; display: block; }
.viewer-stage audio { width: min(560px, 90%); }
.viewer-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-stage pre {
  margin: 0; padding: 1.5rem; width: 100%; height: 100%; overflow: auto;
  background: #fff; color: var(--ink); font-family: var(--mono); font-size: .85rem;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.viewer-doc { background: #fff; width: 100%; height: 100%; overflow: auto; padding: 1.5rem; color: var(--ink); }
.viewer-doc table { border-collapse: collapse; font-size: .88rem; }
.viewer-doc td, .viewer-doc th { border: 1px solid var(--line); padding: .3rem .55rem; }
.viewer-note { color: #C5D6DD; text-align: center; padding: 2rem; font-size: .95rem; }
.viewer-note .btn { margin-top: 1rem; }
.spinner {
  width: 30px; height: 30px; border: 3px solid rgba(255,255,255,.25);
  border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Admin tables & dropzone ---------- */
.admin-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.8rem; }

.rows { display: flex; flex-direction: column; gap: .6rem; }
.row {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .75rem .95rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.row-main { flex: 1; min-width: 200px; }
.row-main strong { font-family: var(--display); font-size: 1.02rem; display: block; overflow-wrap: anywhere; }
.row-main .mono { color: var(--ink-faint); }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.row-order { display: flex; flex-direction: column; gap: 2px; }
.row-order a {
  font: 700 .7rem var(--mono); text-decoration: none; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 2px; padding: 0 .35rem; line-height: 1.4;
}
.row-order a:hover { background: var(--ink); color: #fff; border-color: var(--ink); }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); background: #EDF3F5;
  padding: 2.4rem 1.5rem; text-align: center; color: var(--ink-soft); cursor: pointer;
}
.dropzone.is-hot { border-color: var(--marine-lit); background: #E0EEF2; }
.dropzone strong { display: block; font-family: var(--display); font-size: 1.15rem; color: var(--ink); margin-bottom: .25rem; }

.queue { list-style: none; margin: 1.2rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.queue li { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem; }
.queue .q-top { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; }
.queue .q-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .q-state { font-family: var(--mono); font-size: .74rem; color: var(--ink-soft); flex: none; }
.queue .bar { height: 4px; background: var(--wash-deep); border-radius: 2px; margin-top: .45rem; overflow: hidden; }
.queue .bar i { display: block; height: 100%; width: 0; background: var(--marine-lit); transition: width .2s ease; }
.queue li.is-done .bar i { background: var(--k-sheet); }
.queue li.is-failed .bar i { background: var(--k-pdf); width: 100% !important; }
.queue li.is-failed .q-state { color: var(--k-pdf); }

.footer { border-top: 1px solid var(--line); padding: 1.4rem 0; color: var(--ink-faint); font-size: .85rem; }
.footer .wrap { display: flex; justify-content: space-between; gap: 1rem; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
