/*
 * One stylesheet for every page.
 *
 * The markup lives in .html files and is never generated in JavaScript, so the classes
 * below are the whole contract between the two.
 */

:root {
  color-scheme: light dark;

  --bg: #fbfbfd;
  --surface: #ffffff;
  --surface-2: #f2f3f7;
  --fg: #14161c;
  --muted: #5b6270;
  --line: #e2e5ec;
  --line-strong: #cdd2dc;

  --accent: #4b45d6;
  --accent-fg: #ffffff;
  --accent-soft: #ecebfb;
  --danger: #b3261e;
  --ok: #126b45;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(16 18 27 / 6%), 0 8px 24px -16px rgb(16 18 27 / 24%);
  --measure: 72rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101218;
    --surface: #171a22;
    --surface-2: #1e222c;
    --fg: #e8eaf1;
    --muted: #99a1b3;
    --line: #272c37;
    --line-strong: #3a4150;

    --accent: #9d97ff;
    --accent-fg: #14161c;
    --accent-soft: #23233c;
    --danger: #ef9a93;
    --ok: #6fd3a4;

    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px -16px rgb(0 0 0 / 80%);
  }
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 5rem;
}

h1,
h2,
h3 {
  line-height: 1.25;
}

h1 {
  font-size: 1.9rem;
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.3rem;
  margin: 2.5rem 0 1rem;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.05rem;
  margin: 0 0 0.35rem;
}

p {
  margin: 0 0 1rem;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

.lead {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 46rem;
}

.note,
.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
}

pre code {
  background: none;
  border: none;
  padding: 0;
}

[hidden] {
  display: none !important;
}

/* --- site header ---------------------------------------------------------------------- */

header.site {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.75rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--fg);
  text-decoration: none;
}

nav.main {
  display: flex;
  gap: 0.25rem;
  margin-right: auto;
  flex-wrap: wrap;
}

nav.main a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
}

nav.main a:hover {
  color: var(--fg);
  background: var(--surface-2);
}

nav.main a[aria-current="page"] {
  color: var(--fg);
  background: var(--surface-2);
  font-weight: 550;
}

/* --- buttons -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 550;
  line-height: 1.2;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

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

.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 85%, var(--fg));
}

.btn-quiet {
  border-color: transparent;
  background: none;
  color: var(--muted);
}

.btn-quiet:hover {
  background: var(--surface-2);
  color: var(--fg);
}

/* --- hero and stats -------------------------------------------------------------------- */

.hero {
  padding: 1rem 0 0.5rem;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.stat {
  display: flex;
  flex-direction: column;
  min-width: 7rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat strong {
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.stat span {
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- forms ---------------------------------------------------------------------------- */

.searchbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}

.searchbar input[type="search"] {
  flex: 1 1 18rem;
}

input,
select,
textarea {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1rem;
}

.form-row label {
  font-size: 0.9rem;
  font-weight: 550;
}

/*
  A label that wraps its own control - <label>Title <input></label> - instead of pointing at it
  by id. Repeated cards cannot carry ids, so this form is the correct one there, but the label
  is inline by default: the caption then sits *beside* the field and eats part of the row. That
  is what made every input in an icon card a different width, since "Use cases" is wider than
  "Tags". Stacking it makes the control fill the column, so the columns line up.
*/
.form-row label:has(> input, > textarea, > select) {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.form-inline .form-row {
  margin-bottom: 0;
}

.panel {
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

/* --- cards and grids ------------------------------------------------------------------ */

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

.pack-card {
  display: block;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}

.pack-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.pack-preview {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  min-height: 36px;
}

.pack-preview img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--surface-2);
  padding: 4px;
}

.pack-card p {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.pack-card .meta {
  margin: 0;
  font-size: 0.82rem;
}

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

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.9rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  text-align: center;
}

.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.card img {
  width: 64px;
  height: 64px;
}

.card-name {
  font-size: 0.9rem;
  font-weight: 550;
}

.card-slug {
  font-size: 0.75rem;
  color: var(--muted);
}

.chip {
  display: inline-block;
  font-size: 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  margin: 0 0.25rem 0.25rem 0;
}

/* --- detail pages --------------------------------------------------------------------- */

.fields {
  margin: 1rem 0;
  display: grid;
  gap: 0.5rem;
}

.field {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.field dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.field dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 40rem) {
  .field {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
}

.asset-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  align-items: flex-start;
}

.asset-preview {
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.asset-preview img {
  width: 128px;
  height: 128px;
}

.asset-info {
  flex: 1 1 22rem;
}

/*
 * --- rows -------------------------------------------------------------------------------
 *
 * A row is a list entry carrying an optional icon, a link and one line of context. The
 * recommendation results and the pack ranking share this shape.
 */

.rows {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
}

.row img {
  width: 40px;
  height: 40px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  flex: none;
}

.row-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1 1 16rem;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

a.row-main:hover strong {
  text-decoration: underline;
}

.row-main code,
.row-meta {
  font-size: 0.85rem;
  color: var(--muted);
  /* Long slugs and reasons must wrap rather than widen the row past the viewport. */
  overflow-wrap: anywhere;
}

.badge {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  font-size: 0.8rem;
  white-space: nowrap;
}

.badge[data-kind="primary"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  background: var(--accent-soft);
}

.badge[data-kind="completion"] {
  color: var(--muted);
}

/* --- notices and empty states ---------------------------------------------------------- */

.notice {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

.notice-ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 35%, var(--line));
  background: color-mix(in srgb, var(--ok) 8%, transparent);
}

.notice-error {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.empty strong {
  display: block;
  color: var(--fg);
  margin-bottom: 0.35rem;
}

ul.tools,
ul.endpoints {
  padding-left: 1.1rem;
}

ul.tools li,
ul.endpoints li {
  margin-bottom: 0.35rem;
}

footer.site {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

footer.site .inner {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.25rem;
}

/* --- account area --------------------------------------------------------------------- */

.btn-danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  color: var(--danger);
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

/*
 * The header menu is a <details>, not a scripted dropdown: it opens, closes and answers the
 * keyboard without a line of JavaScript, and it still works if the module fails to load.
 */
.account-menu {
  position: relative;
}

.account-menu > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  list-style: none;
  color: var(--muted);
}

.account-menu > summary::-webkit-details-marker {
  display: none;
}

.account-menu > summary:hover {
  background: var(--surface-2);
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 650;
  font-size: 0.9rem;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  min-width: 15rem;
  padding: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.1rem;
}

.menu-panel a,
.menu-panel button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.menu-panel a:hover,
.menu-panel button:hover {
  background: var(--surface-2);
}

.menu-panel .who {
  display: grid;
  gap: 0.1rem;
  padding: 0.5rem 0.6rem 0.6rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.2rem;
}

.menu-panel .who span {
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.menu-panel hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0.2rem 0;
}

.account-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.account-head .avatar {
  width: 3.5rem;
  height: 3.5rem;
  font-size: 1.5rem;
}

.account-head h1 {
  margin: 0;
}

.sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

/*
 * Tabs are links to fragments, so each section is bookmarkable and the back button works.
 */
.tabs {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
}

.tabs a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
}

.tabs a:hover {
  color: var(--fg);
  background: var(--surface-2);
}

.tabs a[aria-current="page"] {
  color: var(--fg);
  background: var(--surface-2);
  font-weight: 550;
}

.tabs .spacer {
  margin-left: auto;
}

.form-card {
  max-width: 26rem;
  margin: 3rem auto;
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-card h1 {
  margin-top: 0;
}

.form-card button[type="submit"] {
  width: 100%;
  margin-top: 0.5rem;
}

.empty {
  display: grid;
  gap: 0.4rem;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.empty strong {
  color: var(--fg);
  font-size: 1.05rem;
}

/* .panel, .upload-list and .icon-list carry their own bottom margin; .grid and .empty do
   not, so wherever one of them sits above another block in the same stack the two touch.
   Give them the same rhythm - but only when a sibling below is actually rendered: on the
   home and pack pages the grid ends its section, and a trailing margin there would push
   the next section apart. :has(~ :not([hidden])) is the test, because these stacks toggle
   siblings with the hidden attribute rather than removing them. */
.grid:has(~ :not([hidden])),
.empty:has(~ :not([hidden])) {
  margin-bottom: 1.25rem;
}

/* ---------------------------------------------------------------------------------------------
   Uploads
   --------------------------------------------------------------------------------------------- */

.upload-list {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

.upload-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-areas: "title status meta" "id status meta";
  gap: 0.15rem 0.75rem;
  align-items: center;
  padding: 0.9rem 1.1rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.upload-row:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.upload-title {
  grid-area: title;
  font-weight: 550;
}

.upload-id {
  grid-area: id;
  font-size: 0.85rem;
  color: var(--muted);
}

.upload-meta {
  grid-area: meta;
  font-size: 0.85rem;
  color: var(--muted);
}

.badge {
  grid-area: status;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 550;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}

/* One colour per state. Kept here rather than in the page script so the vocabulary of the
   status field and the way it looks stay separable. */
.badge-draft {
  color: var(--muted);
}

.badge-pending,
.badge-ai_review,
.badge-ai_running {
  color: #8a5a00;
  background: #fff5e0;
  border-color: #f0d9a8;
}

.badge-published {
  color: #10603a;
  background: #e6f6ee;
  border-color: #b6e0cb;
}

/* Its own colour rather than the rejected red: nothing was refused, and a creator scanning a
   list of their packs reads the colour before the word. */
.badge-amended {
  color: #2a4b8d;
  background: #eaf0fd;
  border-color: #c3d2f2;
}

.badge-rejected,
.badge-ai_failed {
  color: #94261f;
  background: #fdecea;
  border-color: #f3c4c0;
}

.upload-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.upload-head h1 {
  margin: 0 0 0.25rem;
}

.upload-head .sub {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
}

.crumbs {
  margin: 0 0 1rem;
  font-size: 0.9rem;
}

.dropzone {
  display: grid;
  gap: 0.6rem;
  justify-items: center;
  padding: 1.5rem;
  text-align: center;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.dropzone.dragging {
  border-color: var(--accent, var(--fg));
  background: var(--surface);
}

.dropzone .hint {
  margin: 0;
}

.intake-results {
  display: grid;
  gap: 0.35rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.intake-result {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.intake-ok {
  color: #10603a;
}

.intake-bad {
  color: #94261f;
}

.icon-list {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.icon-card {
  display: grid;
  gap: 1rem;
  margin-bottom: 0;
  padding: 1rem;
}

/* Every direct child sits in the card grid, so one gap governs the whole card. */
.icon-card > * {
  margin: 0;
}

.icon-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Pushes "Remove" to the far edge without an empty spacer element in the markup. */
.icon-head .js-delete {
  margin-left: auto;
  flex: none;
}

.icon-head img {
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
}

/* A slug or a file name can be one unbroken string; it must wrap rather than widen the card. */
.icon-ident {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.icon-facts {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
}

.icon-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/*
  The reviewer's copy of the card. The fields stay real controls - the text is selectable and
  copyable, which is what a reviewer does with a keyword list - but they are flat rather than
  raised, so the card does not look like something to fill in.
*/
.icon-card[data-readonly] input,
.icon-card[data-readonly] textarea {
  background: var(--surface-2);
  cursor: default;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.75rem 1rem;
}

.form-grid .form-row {
  margin: 0;
}

/* Description: one field across the full width, so it does not leave two columns blank. */
.form-row-wide {
  grid-column: 1 / -1;
}

.icon-fields textarea {
  min-height: 3.5rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/*
  What a section says about itself once it has written - the whole of what is left of the Save
  buttons. Quiet by default and only loud when it failed: this line updates a few seconds after
  every sentence somebody types, and a green "Saved" flashing in the corner of the eye all
  afternoon is noise. A refusal is the one case worth the interruption.

  Aligned to the row's centre rather than baseline so the buttons keep their own rhythm, and it
  reserves no space while empty - a blank gap next to two buttons reads as a missing third one.
*/
.save-status {
  align-self: center;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Not a colour change, only a lean: "saving" is a state that ends by itself. */
.save-status.is-working {
  font-style: italic;
}

.save-status.is-error {
  color: var(--danger);
  font-weight: 600;
}

.history {
  display: grid;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history li {
  display: grid;
  gap: 0.15rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
}

.history li:first-child {
  border-top: none;
}
