/* ===========================================================================
   Shared chrome + design system, loaded on every page. The "Quiet Craft" tokens
   below (warm paper light / warm near-black dark, one calm blue accent) are the
   single source of truth for the whole app; /upload layers its component rules
   on top via upload.css. Dark mode follows Apple's HIG guidance adapted to the
   web: no pure black, surfaces grow lighter with elevation, and the accent is
   desaturated so it does not vibrate against the dark field.
   =========================================================================== */
:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.5rem;

  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-sunken: #f4f2ee;
  --text: #1c1a17;
  --muted: #5c574f;
  --border: #e2ddd4;
  --border-strong: #cfc8bc;
  --accent: #1f6feb;
  --on-accent: #ffffff;
  --link: #1a5fcc;
  --success-bg: #e7f4ec;
  --success-text: #18603a;
  --warning-bg: #fbf1da;
  --warning-text: #7a5200;
  --danger-bg: #fceded;
  --danger-text: #a11616;
  --danger-border: #e8b4b4;
  --focus: #1545b8;

  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-2: 0 6px 20px -8px rgba(28, 26, 23, 0.22);

  /* Line-art icons, alpha-masked and recolored via currentColor (no network). */
  --icon-plus: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2.5'%20stroke-linecap='round'%3E%3Cpath%20d='M12%205v14'/%3E%3Cpath%20d='M5%2012h14'/%3E%3C/svg%3E");
  --icon-check: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2.5'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M20%206%209%2017l-5-5'/%3E%3C/svg%3E");
  --icon-alert: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M10.29%203.86%201.82%2018a2%202%200%200%200%201.71%203h16.94a2%202%200%200%200%201.71-3L13.71%203.86a2%202%200%200%200-3.42%200z'/%3E%3Cpath%20d='M12%209v4'/%3E%3Cpath%20d='M12%2017h.01'/%3E%3C/svg%3E");
  --icon-info: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Ccircle%20cx='12'%20cy='12'%20r='10'/%3E%3Cpath%20d='M12%2016v-4'/%3E%3Cpath%20d='M12%208h.01'/%3E%3C/svg%3E");
  --icon-search: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Ccircle%20cx='11'%20cy='11'%20r='7'/%3E%3Cpath%20d='m21%2021-4.3-4.3'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141310;
    --surface: #1e1c18;
    --surface-sunken: #1a1814;
    --text: #f2efea;
    --muted: #aba499;
    --border: #34302a;
    --border-strong: #46413a;
    --accent: #5c9bff;
    --on-accent: #141310;
    --link: #82b4ff;
    --success-bg: #16301f;
    --success-text: #7dd6a2;
    --warning-bg: #2e2510;
    --warning-text: #e8c77a;
    --danger-bg: #321414;
    --danger-text: #f2a6a6;
    --danger-border: #5a2a2a;
    --focus: #82b4ff;
    --shadow-1: none;
    --shadow-2: 0 8px 24px -10px rgba(0, 0, 0, 0.6);
  }
}

/* The HTML spec's [hidden] sets display:none in the UA sheet, but any author
   `display` (e.g. .upload-notice { display:flex }) silently overrides it -- which
   is what made hidden notices render as empty bars and the file card show a
   broken-image icon before a file was picked. This restores the intent globally. */
[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 2rem 1.5rem;
  font-family: var(--font-sans);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  /* Let form controls, scrollbars, and the caret adopt the active scheme. */
  color-scheme: light dark;
  -webkit-font-smoothing: antialiased;
}

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

/* --- Top banner + primary nav -------------------------------------------- */
.banner {
  max-width: 64rem;
  margin: 0 auto 1.5rem;
  padding: 0.6rem 0.9rem;
  font-size: var(--fs-sm);
  border-radius: var(--radius);
}

.banner-warning {
  color: var(--warning-text);
  background: var(--warning-bg);
}

.site-nav {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  max-width: 64rem;
  margin: 0 auto 2rem;
}

.site-nav a {
  padding: 0.4rem 0.75rem;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.site-nav a:hover {
  color: var(--text);
  background: var(--surface-sunken);
}

.site-nav a[aria-current="page"] {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* --- Landing -------------------------------------------------------------- */
.landing {
  max-width: 44rem;
  margin: 0 auto;
  padding-top: clamp(1rem, 8vh, 5rem);
}

.landing h1 {
  margin: 0;
  font-size: var(--fs-3xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.landing h1::after {
  content: "";
  display: block;
  width: 2.5rem;
  height: 4px;
  margin-top: 0.9rem;
  background: var(--accent);
  border-radius: 999px;
}

.tagline {
  margin: 1.1rem 0 0;
  font-size: var(--fs-xl);
  font-weight: 400;
  color: var(--text);
  max-width: 32rem;
}

.landing > p:not(.tagline):not(.cta-row) {
  color: var(--muted);
  max-width: 34rem;
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.75rem 0 0;
}

.cta {
  display: inline-flex;
  align-items: center;
  padding: 0.6rem 1.2rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  transition: transform 0.12s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.cta:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
}

.cta-primary {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.cta:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.landing-about {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
}

.landing-about h2 {
  margin: 0 0 0.35rem;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
}

/* --- Browse gallery ------------------------------------------------------- */
.browse {
  max-width: 64rem;
  margin: 0 auto;
}

.masthead {
  margin-bottom: 2rem;
}

.masthead__eyebrow {
  margin: 0;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.masthead h1 {
  margin: 0.3rem 0 0;
  font-size: var(--fs-3xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.masthead__count {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* Search: a single rounded field with a leading glyph and an inline submit. */
.search {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.search__field {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.search__field::before {
  content: "";
  position: absolute;
  left: 0.85rem;
  top: 50%;
  width: 1.05rem;
  height: 1.05rem;
  transform: translateY(-50%);
  background-color: var(--muted);
  -webkit-mask: var(--icon-search) no-repeat center / contain;
  mask: var(--icon-search) no-repeat center / contain;
  pointer-events: none;
}

.search__input {
  width: 100%;
  padding: 0.65rem 0.9rem 0.65rem 2.5rem;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

.search__input::placeholder {
  color: var(--muted);
}

.search__input:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent);
}

.search__submit {
  flex: 0 0 auto;
  padding: 0.65rem 1.25rem;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
}

.search__submit:hover {
  filter: brightness(0.96);
}

.search__submit:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.template-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  margin-top: 2rem;
}

/* Each card is a link to the template's detail page, so reset anchor styling
   and let the body text colors below take over. */
.template-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  transition: transform 0.16s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.template-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
}

.template-card:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.template-card__frame {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--surface-sunken);
  overflow: hidden;
}

.template-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.template-card:hover .template-card__img {
  transform: scale(1.04);
}

.template-card__slots {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  padding: 0.15rem 0.5rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.template-card__body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.9rem 1rem 1rem;
}

.template-card__name {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.template-card__id {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--muted);
  background: transparent;
  border: 0;
  padding: 0;
}

.template-card__desc {
  margin: 0.1rem 0 0;
  font-size: var(--fs-sm);
  color: var(--muted);
  /* Clamp to two lines so cards keep an even rhythm. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.template-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.template-card__tag {
  font-size: var(--fs-xs);
  color: var(--muted);
  padding: 0.1rem 0.5rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.browse-empty {
  grid-column: 1 / -1;
  margin-top: 1rem;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface-sunken);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

/* Gentle staggered entrance for the first rows; later cards just appear. */
@media (prefers-reduced-motion: no-preference) {
  .template-card {
    animation: card-rise 0.4s ease both;
  }
  .template-card:nth-child(1) { animation-delay: 0.02s; }
  .template-card:nth-child(2) { animation-delay: 0.06s; }
  .template-card:nth-child(3) { animation-delay: 0.1s; }
  .template-card:nth-child(4) { animation-delay: 0.14s; }
  .template-card:nth-child(n + 5) { animation-delay: 0.18s; }

  @keyframes card-rise {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
  }
}

/* --- Template detail ------------------------------------------------------ */
.detail {
  max-width: 56rem;
  margin: 0 auto;
}

.detail__back {
  display: inline-block;
  margin-bottom: 1.5rem;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
}

.detail__back:hover {
  color: var(--text);
}

/* Image beside metadata on wide screens; stacked on narrow ones. */
.detail__hero {
  display: grid;
  gap: 1.75rem;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 40rem) {
  .detail__hero {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  }
}

.detail__media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* contain (not cover) so the whole template is visible, unlike the cropped
   gallery thumbnails. */
.detail__img {
  display: block;
  max-width: 100%;
  max-height: 26rem;
  object-fit: contain;
  border-radius: var(--radius);
}

.detail__slot-count {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  padding: 0.15rem 0.55rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.detail__info {
  min-width: 0;
}

.detail__eyebrow {
  margin: 0 0 0.6rem;
}

.detail__source {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.detail__source--friend {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.detail__name {
  margin: 0;
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.detail__id {
  display: inline-block;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--muted);
  background: transparent;
  border: 0;
  padding: 0;
}

.detail__desc {
  margin: 1rem 0 0;
  color: var(--text);
}

.detail__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1.1rem;
}

.detail__tag {
  font-size: var(--fs-xs);
  color: var(--muted);
  padding: 0.15rem 0.55rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.detail__panel {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.detail__panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 1rem;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.detail__panel-meta {
  padding: 0.05rem 0.45rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0;
  color: var(--muted);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.detail__attrs {
  display: grid;
  gap: 0.85rem 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  margin: 0;
}

.detail__attr {
  margin: 0;
}

.detail__attr dt {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.detail__attr dd {
  margin: 0.2rem 0 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.detail__slots {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: slot;
}

.detail__slot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.detail__slot::before {
  counter-increment: slot;
  content: counter(slot);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-sunken);
  border-radius: 999px;
}

.detail__slot-name {
  flex: 1 1 auto;
  font-weight: 500;
}

.detail__slot-pos {
  flex: 0 0 auto;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.detail__empty {
  margin: 0;
  color: var(--muted);
}

.detail__fingerprint {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.detail__fingerprint summary {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.detail__fingerprint .detail__attrs {
  margin-top: 1rem;
}

.detail__fingerprint code {
  font-size: var(--fs-xs);
}
