@font-face {
  font-family: "Anton";
  src: url("/assets/Anton-Regular-9324206c.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Roboto Subtitle";
  src: url("/assets/Roboto-Bold-a59ceaab.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #faf7f0;
  --surface: #ffffff;
  --ink: #17151a;
  --muted: #6b6672;
  --line: #e6e0d4;
  --accent: #ff4f2b;
  --accent-ink: #ffffff;
  --accent-soft: #ffe7e0;
  --danger: #c8102e;
  --success: #1e7b45;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 8px 24px rgb(0 0 0 / 0.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Anton", Impact, "Arial Narrow", sans-serif;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141217;
    --surface: #1e1b22;
    --ink: #f3f0ea;
    --muted: #a39dab;
    --line: #34303a;
    --accent-soft: #3a1f19;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.3);
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
}

img { max-width: 100%; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.15; margin: 0; }
h1 { font-family: var(--display); font-weight: 400; font-size: clamp(2rem, 4vw, 2.75rem); letter-spacing: 0.01em; text-transform: uppercase; }

.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.eyebrow { margin: 0; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
.stack { display: grid; gap: 1rem; }
.narrow { max-width: 36rem; margin: 0 auto; display: grid; gap: 1.5rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-family: var(--display);
  font-size: 1.8rem;
  text-transform: uppercase;
  text-decoration: none;
  letter-spacing: 0.02em;

  span { color: var(--accent); }
}

.site-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.1rem;

  > a:not(.button) { text-decoration: none; font-weight: 600; }
  > a:not(.button):hover { color: var(--accent); }
  form { display: contents; }
}

.site-nav__person { color: var(--muted); }

.site-menu-toggle {
  display: none;
  padding: 0.4rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

@media (max-width: 640px) {
  .site-menu-toggle { display: inline-flex; }

  .site-nav {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    border-top: 1px solid var(--line);

    > a:not(.button), > .site-nav__person, > form > .button, > .button {
      padding: 0.8rem 0.25rem;
      border-bottom: 1px solid var(--line);
    }
    > form > .button, > .button {
      justify-content: flex-start;
      width: 100%;
      border: 0;
      border-bottom: 1px solid var(--line);
      border-radius: 0;
      background: transparent;
      color: var(--ink);
      font-weight: 600;
    }
  }

  .site-menu-toggle[aria-expanded="true"] + .site-nav { display: flex; }
}

.page { padding: clamp(1rem, 4vw, 2.5rem); max-width: 1280px; margin: 0 auto; }

/* Flash */
.flash {
  max-width: 1280px;
  margin: 1rem auto 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  width: calc(100% - 2 * clamp(1rem, 4vw, 2.5rem));
}
.flash--notice { background: color-mix(in srgb, var(--success) 14%, var(--surface)); color: var(--success); }
.flash--alert { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;

  &:hover { filter: brightness(1.06); }
  &:active { transform: translateY(1px); }
}
.button--quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.button--quiet:hover { border-color: var(--ink); }
.button--danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.button--wide { width: 100%; }
.button--small { padding: 0.35rem 0.85rem; font-size: 0.9rem; }

/* Forms */
.field { display: grid; gap: 0.35rem; }
.field label { font-weight: 700; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;

  &:focus { outline: none; border-color: var(--accent); }
}
textarea { resize: vertical; }
input[type="file"] { font: inherit; }

.form-errors {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
  font-weight: 600;

  ul { margin: 0; padding-left: 1.2rem; }
}

/* Auth */
.auth-card {
  max-width: 26rem;
  margin: 2rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 1.25rem;

  p { margin: 0; }
}
.auth-card__footer { font-size: 0.95rem; color: var(--muted); }

/* Library */
.library { display: grid; gap: 1.25rem; }
.library__header { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 0.5rem 1rem; margin-bottom: 1.25rem; }
.library .library__header { margin-bottom: 0; }
.library__header p { margin: 0; flex-basis: 100%; }

.search { display: grid; gap: 0.9rem; }
.search__bar { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.search__bar input[type="search"] { flex: 1 1 18rem; font-size: 1.05rem; padding: 0.85rem 1rem; }

.segmented {
  display: inline-flex;
  margin: 0;
  padding: 4px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);

  input { position: absolute; opacity: 0; pointer-events: none; }
  span { display: block; padding: 0.45rem 0.95rem; border-radius: 999px; font-weight: 700; cursor: pointer; }
  input:checked + span { background: var(--ink); color: var(--bg); }
  input:focus-visible + span { outline: 2px solid var(--accent); }
}

.tag-toggle {
  summary {
    display: inline-block;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
    list-style: none;
  }
  summary::-webkit-details-marker { display: none; }
  summary:hover { color: var(--accent); }
  .tag-toggle__hide { display: none; }
  &[open] .tag-toggle__show { display: none; }
  &[open] .tag-toggle__hide { display: inline; }
  .tag-filter { margin-top: 0.6rem; }
}

.tag-filter { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; padding: 0; border: 0; }

.chip {
  input { position: absolute; opacity: 0; pointer-events: none; }
  span, &.chip--link {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
  }
  span:hover, &.chip--link:hover { border-color: var(--accent); }
  input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
  input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
}

.tag-list { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; margin: 0; padding: 0; }

.results-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin-bottom: 0.75rem; }
.results-count { margin: 0; font-size: 0.95rem; }

.browse-all {
  margin: 1.5rem 0 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);

  a { color: inherit; }
  a:hover { color: var(--accent); }
}

turbo-frame[aria-busy="true"] .picture-grid { opacity: 0.55; transition: opacity 0.2s; }

.picture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
  gap: 1rem;
}

.picture-card {
  display: grid;
  gap: 0.5rem;
  text-decoration: none;

  &:hover .picture-card__image { transform: translateY(-3px) rotate(-0.6deg); box-shadow: var(--shadow); border-color: var(--accent); }
}

.picture-card__image {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;

  img { width: 100%; height: 100%; object-fit: cover; display: block; }
}

.picture-card__name { font-weight: 700; font-size: 0.95rem; line-height: 1.3; }

.badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.1rem 0.5rem;
  border-radius: 6px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.empty {
  display: grid;
  justify-items: center;
  gap: 1rem;
  padding: 3rem 1rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;

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

/* Picture detail and meme editor share a two-column layout */
.picture-detail, .editor {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(18rem, 2fr);
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: start;

  @media (max-width: 800px) { grid-template-columns: 1fr; }
}

.picture-detail__image img { width: 100%; border-radius: var(--radius); display: block; }
.picture-detail__info p { margin: 0; }

.editor__panel {
  display: grid;
  gap: 1.25rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  top: 6rem;

  @media (max-width: 800px) { position: static; }
}
.editor__panel textarea { font-size: 1.05rem; }

/* Meme detail and gallery */
.meme-detail { display: grid; gap: 1.25rem; justify-items: center; }
.meme-detail__image { max-width: min(100%, 760px); }
/* The live preview sizes itself from its container (container-type), so it needs a set width here. */
.meme-detail__image:has(.meme-stage) { width: min(100%, 760px); }
.meme-detail__image > img { display: block; width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); }
.meme-detail__note { max-width: 32rem; margin: 0; color: var(--muted); text-align: center; }
.meme-detail__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; align-items: center; }

.rendering { display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; color: var(--muted); font-weight: 600; }
.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.meme-grid {
  columns: 4 260px;
  column-gap: 1rem;
}

.meme-card {
  display: block;
  margin-bottom: 1rem;
  break-inside: avoid;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--line);
  transition: border-color 0.15s ease;

  &:hover { border-color: var(--accent); }
}
.meme-card__link { display: block; }
.meme-card__link > img { display: block; width: 100%; }
.meme-card__copy {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);

  &:hover { color: var(--accent); filter: none; }
}

/* Text box editor on the picture form */
.box-editor {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 1rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);

  legend { padding: 0 0.4rem; font-weight: 700; }
  p { margin: 0; font-size: 0.95rem; }
}

.box-editor__stage {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  touch-action: none;
  user-select: none;

  img { display: block; max-width: 100%; max-height: 70vh; border-radius: 6px; }
}

.box-editor__box {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #fff;
  border-radius: 4px;
  background: rgb(255 79 43 / 0.18);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.5);
  cursor: move;
  overflow: hidden;

  &:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
}

.box-editor__box--selected { border-style: solid; border-color: var(--accent); background: rgb(255 79 43 / 0.3); }

.box-editor__label {
  padding: 0 0.3rem;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  text-shadow: 0 1px 2px #000, 0 0 2px #000;
  overflow: hidden;
  text-overflow: ellipsis;
}

.box-editor__box .box-editor__number { position: absolute; top: 2px; left: 2px; }

.box-editor__number {
  display: inline-grid;
  place-items: center;
  min-width: 1.4rem;
  height: 1.4rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 800;
}

.box-editor__handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-top-left-radius: 4px;
  cursor: nwse-resize;
}

.box-editor__list { display: grid; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.box-editor__list:empty { display: none; }

.box-editor__row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem;
  border-radius: 10px;

  input { flex: 1; min-width: 0; }
}

.box-editor__row--selected { background: var(--accent-soft); }
.box-editor__status:empty { display: none; }

.editor__picture-tools {
  display: grid;
  justify-items: start;
  gap: 0.6rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);

  p { margin: 0; font-size: 0.95rem; }
}
