/* charlesray.us: typewritten paper, photographs first. */
:root {
  --paper: #f4f0e6;
  --ink: #1c1a17;
  --muted: #6b655a;
  --rule: rgba(28, 26, 23, 0.16);
  --ribbon: #b1261c; /* the red half of a typewriter ribbon */
  --card: #fbf8f1;
  --shade: rgba(20, 18, 15, 0.94);
  --gap: clamp(14px, 2.2vw, 28px);
  --type: "Courier Prime", "Courier New", Courier, monospace;
  --display: "Special Elite", "Courier Prime", "Courier New", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16150f;
    --ink: #ece6d8;
    --muted: #a39b8a;
    --rule: rgba(236, 230, 216, 0.16);
    --ribbon: #e0574b;
    --card: #1e1d17;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--type);
  font-size: 17px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: min(1440px, 100% - 2 * var(--gap)); margin: 0 auto; padding-top: 88px; }
body[data-page="feed"] main { width: min(800px, 100% - 2 * var(--gap)); }
body[data-page="post"] main { width: min(960px, 100% - 2 * var(--gap)); }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ribbon); }
button { font: inherit; color: inherit; }
img { display: block; max-width: 100%; height: auto; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--paper); padding: 6px 10px; }
:focus-visible { outline: 2px dashed var(--ribbon); outline-offset: 3px; }

/* ---------- Header and the hamburger menu ---------- */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px var(--gap);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px dashed var(--rule);
}
.name { font-family: var(--display); font-size: clamp(1.25rem, 3vw, 1.6rem); text-decoration: none; letter-spacing: 0.08em; text-transform: uppercase; }
.burger {
  position: relative; z-index: 41;
  width: 44px; height: 44px; padding: 10px 8px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: none; border: 0; cursor: pointer;
}
.burger span { display: block; height: 2px; background: var(--ink); transition: transform 0.25s, opacity 0.2s; }
.burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(10px) rotate(45deg); }
.burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-10px) rotate(-45deg); }
.menu {
  position: fixed; inset: 0; z-index: 40;
  background: var(--paper);
  display: flex; flex-direction: column; justify-content: center; align-items: flex-end;
  padding: 90px calc(var(--gap) + 8px) var(--gap);
  animation: menu-in 0.2s ease-out;
}
.menu[hidden] { display: none; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-8px); } }
.menu ul { list-style: none; margin: 0; padding: 0; text-align: right; }
.menu li + li { margin-top: 0.2em; }
.menu a { font-family: var(--display); font-size: clamp(2.4rem, 9vw, 4.5rem); text-decoration: none; line-height: 1.2; }
.menu a[aria-current="page"] { color: var(--ribbon); }
.menu a[aria-current="page"]::before { content: "› "; }
.menu-note { color: var(--muted); max-width: 34ch; text-align: right; margin-top: 2em; }
body.menu-open { overflow: hidden; }

/* ---------- Shared ---------- */
.page-title { font-family: var(--display); font-weight: 400; font-size: clamp(1.8rem, 5vw, 2.8rem); margin: 0.4em 0 0.7em; letter-spacing: 0.02em; }
.meta { color: var(--muted); font-size: 0.85rem; margin: 0; letter-spacing: 0.04em; text-transform: uppercase; }
.empty { color: var(--muted); font-style: italic; padding: 3em 0; }
.chip {
  display: inline-block; padding: 2px 10px; margin: 0 6px 8px 0;
  border: 1px solid var(--rule); border-radius: 2px;
  text-decoration: none; font-size: 0.85rem; background: var(--card);
}
.chip small { color: var(--muted); }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip.on small { color: inherit; opacity: 0.7; }
.badge { background: var(--ribbon); color: #fff; padding: 0 6px; font-size: 0.75rem; }
.foot { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 48px var(--gap) 32px; }
body.is-admin .foot { padding-bottom: 90px; }

/* ---------- Tiles (gallery, portfolio, post photos) ---------- */
.tile { position: relative; margin: 0; }
.tile .open { display: block; cursor: zoom-in; }
.tile img { width: 100%; height: auto; background: var(--rule); }
.star {
  position: absolute; top: 8px; right: 8px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 20px; line-height: 36px; cursor: pointer;
}
.star[aria-pressed="true"] { background: var(--ribbon); }
.star:hover { transform: scale(1.08); }

/* Gallery: justified rows. Each tile grows in proportion to its shape. */
.justified { display: flex; flex-wrap: wrap; gap: 6px; }
.justified .tile { flex: var(--r) 1 calc(var(--r) * 220px); }
.justified .tile img { aspect-ratio: var(--r); object-fit: cover; height: 100%; }
.justified .fill { flex: 1000 1 0; }
@media (max-width: 600px) { .justified .tile { flex-basis: calc(var(--r) * 130px); } }

/* Portfolio: masonry columns, generous. */
.masonry { columns: 3 340px; column-gap: var(--gap); }
.masonry .tile { break-inside: avoid; margin-bottom: var(--gap); }

/* ---------- Gallery tools ---------- */
.g-tools { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.g-tools input, .g-tools select {
  font: inherit; color: inherit; background: var(--card);
  border: 1px solid var(--rule); padding: 8px 12px; border-radius: 2px;
}
.g-tools input { flex: 1 1 260px; }
.g-sort { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.g-tags { margin-bottom: 6px; max-height: 7.5em; overflow: auto; }
.g-tags.open { max-height: none; }
.g-count { color: var(--muted); font-size: 0.85rem; margin: 4px 0 14px; }

/* ---------- Feed ---------- */
.feed { display: grid; gap: 72px; }
.post-card { border-top: 1px dashed var(--rule); padding-top: 28px; }
.post-card:first-child { border-top: 0; padding-top: 0; }
.post-card.is-hidden { opacity: 0.6; }
.card-text h2 { font-family: var(--display); font-weight: 400; font-size: clamp(1.5rem, 4vw, 2.1rem); line-height: 1.2; margin: 0.15em 0 0.3em; }
.card-text h2 a { text-decoration: none; }
.card-text .summary { margin: 0 0 0.6em; }
.card-text .more { margin: 0; font-size: 0.9rem; }
.carousel { position: relative; margin-bottom: 18px; background: var(--card); }
.track {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scroll-behavior: smooth;
  scrollbar-width: none; aspect-ratio: 3 / 2;
}
.track::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; scroll-snap-align: center; display: flex; align-items: center; justify-content: center; }
.slide img { width: 100%; height: 100%; object-fit: contain; }
.car-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(244, 240, 230, 0.88); color: #1c1a17; cursor: pointer; font-size: 1.2rem;
  opacity: 0; transition: opacity 0.2s;
}
.carousel:hover .car-btn, .car-btn:focus-visible { opacity: 1; }
@media (hover: none) { .car-btn { opacity: 0.85; } }
.car-btn.prev { left: 10px; }
.car-btn.next { right: 10px; }
.car-btn[disabled] { visibility: hidden; }
.car-count {
  position: absolute; right: 10px; bottom: 10px;
  background: rgba(20, 18, 15, 0.7); color: #f4f0e6; font-size: 0.75rem; padding: 1px 8px;
}

/* ---------- Post page ---------- */
.post-head { margin: 0.5em 0 1.8em; }
.post-head h1 { font-family: var(--display); font-weight: 400; font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.1; margin: 0.15em 0 0.3em; }
.post-head .summary { font-size: 1.1rem; max-width: 60ch; }
.story { max-width: 68ch; margin: 0 0 2.5em; font-size: 1.05rem; }
.story h2, .story h3 { font-family: var(--display); font-weight: 400; }
.story blockquote { margin: 1.5em 0; padding-left: 1em; border-left: 3px solid var(--ribbon); color: var(--muted); }
.story .inline-photo { margin: 2em 0; width: min(960px, calc(100vw - 2 * var(--gap))); }
.inline-photo figcaption, .post-photo figcaption { color: var(--muted); font-size: 0.85rem; padding-top: 6px; text-align: center; }
.post-photos { display: grid; gap: clamp(18px, 3vw, 40px); }
.post-photo img { max-height: 92vh; width: auto; margin: 0 auto; }
.post-tags { margin-top: 2.5em; }
.back { margin-top: 2em; }

/* ---------- Photo viewer ---------- */
.viewer {
  width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: var(--shade); color: #ece6d8;
}
.viewer::backdrop { background: var(--shade); }
.viewer figure { margin: 0; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 56px 64px 16px; gap: 12px; }
.viewer img { max-width: 100%; max-height: calc(100dvh - 190px); object-fit: contain; flex: 0 1 auto; min-height: 0; }
.viewer figcaption { text-align: center; max-width: 760px; font-size: 0.9rem; }
.viewer figcaption p { margin: 0.2em 0; }
.viewer .v-caption:empty, .viewer .v-tags:empty { display: none; }
.viewer .chip { background: transparent; border-color: rgba(236, 230, 216, 0.3); color: inherit; }
.viewer .v-from { color: #a39b8a; }
.viewer button { position: absolute; background: none; border: 0; color: #ece6d8; font-size: 1.8rem; cursor: pointer; width: 56px; height: 56px; }
.viewer button:hover { color: #fff; }
.v-prev { left: 4px; top: 50%; transform: translateY(-50%); }
.v-next { right: 4px; top: 50%; transform: translateY(-50%); }
.v-close { right: 4px; top: 4px; }
@media (max-width: 600px) { .viewer figure { padding: 56px 8px 12px; } .v-prev, .v-next { top: auto; bottom: 8px; transform: none; } }

/* Admin controls inside the viewer */
.v-admin { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; }
.v-admin input { font: inherit; background: rgba(255, 255, 255, 0.08); color: inherit; border: 1px solid rgba(236, 230, 216, 0.3); padding: 6px 10px; min-width: min(420px, 80vw); }
.viewer .v-admin button, .admin-bar button, .admin-bar a.btn {
  position: static; width: auto; height: auto; font-size: 0.85rem;
  border: 1px solid currentColor; padding: 6px 12px; border-radius: 2px; text-decoration: none;
}
.viewer .v-admin button.on { background: var(--ribbon); border-color: var(--ribbon); color: #fff; }
.v-admin .v-status { color: #a39b8a; font-size: 0.8rem; flex-basis: 100%; }

/* ---------- Admin bar on public pages (only when signed in) ---------- */
.admin-bar {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 35;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center;
  background: var(--ink); color: var(--paper); padding: 8px 14px; font-size: 0.85rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); max-width: calc(100vw - 20px);
}
.admin-bar button, .admin-bar a.btn { background: transparent; color: inherit; cursor: pointer; }
.admin-bar button.primary { background: var(--ribbon); border-color: var(--ribbon); color: #fff; }
.admin-bar button[disabled] { opacity: 0.45; cursor: default; }
.admin-bar .ab-msg { opacity: 0.8; }
.g-tags .chip .edit-tag { margin-left: 4px; cursor: pointer; opacity: 0.6; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
