/* base.css — structural styles shared by every diary style.
 *
 * Styles in this library override the custom properties below (and may add
 * their own component flourishes). base.css should stay theme-neutral:
 * layout, spacing, and behavior live here; personality lives in the styles.
 */

:root {
  --bg: #f4f2ec;
  --bg-card: #fffdf7;
  --ink: #26251f;
  --ink-soft: #6e6a5e;
  --accent: #33523f;
  --accent-2: #d99a2b;
  --rule: #ddd6c6;
  --spine-bg: #33523f;
  --spine-ink: #f4f2ec;
  --osd-bg: rgba(38, 37, 31, 0.06);
  --osd-ink: #4c493f;
  --shadow: 0 1px 3px rgba(30, 28, 20, 0.12);
  --radius: 6px;
  --font-display: Georgia, "Times New Roman", serif;
  --font-body: Georgia, "Times New Roman", serif;
  --font-mono: "Courier New", Courier, monospace;
  --thumb-frame: none;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
}

body.lb-open { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ---- Masthead ---- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 2.25rem 2rem 1.25rem;
  max-width: 1240px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.diary-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  line-height: 1.05;
}

.diary-subtitle {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.style-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* ---- Toolbar ---- */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 2rem;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  max-width: 1240px;
  margin: 0 auto;
}

.toolbar input,
.toolbar select,
.style-picker select {
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
}

.toolbar .f-keyword { flex: 1 1 220px; min-width: 160px; }

.toolbar .f-date {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.toolbar button {
  background: none;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
}

.toolbar button:hover { border-color: var(--accent); color: var(--accent); }

.result-count { margin-left: auto; font-size: 0.85rem; color: var(--ink-soft); }

/* ---- Layout: shelf + entries ---- */

.layout {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 2rem;
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem;
}

/* The shelf: two decades of years stacked like a pile of labeled tapes. */
.shelf {
  position: sticky;
  top: 4.4rem;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}

.spine {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.42rem 0.6rem;
  border: none;
  border-radius: 3px;
  background: var(--spine-bg);
  color: var(--spine-ink);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-align: left;
}

.spine-count { font-size: 0.68rem; opacity: 0.75; }

.spine:hover { filter: brightness(1.12); }

.spine-active {
  background: var(--accent-2);
  color: var(--ink);
}

.spine-empty { opacity: 0.35; cursor: default; }
.spine-empty:hover { filter: none; }

/* ---- Year / month structure ---- */

/* Land scroll targets below the sticky toolbar (height measured by viewer.js). */
.year-section,
.entry {
  scroll-margin-top: calc(var(--toolbar-h, 3.6rem) + 0.75rem);
}

.year-heading {
  margin: 2.5rem 0 0.5rem;
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 700;
  border-bottom: 2px solid var(--rule);
  padding-bottom: 0.3rem;
}

.year-section:first-child .year-heading { margin-top: 0; }

.month-heading {
  margin: 1.6rem 0 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.month-entries {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* ---- Entry cards ---- */

.entry {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem;
  content-visibility: auto;
  contain-intrinsic-size: auto 190px;
}

.thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  padding: 0;
  border: var(--thumb-frame);
  border-radius: calc(var(--radius) - 2px);
  overflow: hidden;
  background: #000;
  align-self: start;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.thumb:hover img { transform: scale(1.05); }

.badge {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.8rem;
  line-height: 1.4;
}

.entry-body { min-width: 0; }

.osd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  color: var(--osd-ink);
  background: var(--osd-bg);
  border-radius: 3px;
  padding: 0.12rem 0.45rem;
  margin-bottom: 0.35rem;
}

.entry-title {
  margin: 0.1rem 0 0.25rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
}

.entry-meta {
  margin: 0 0 0.5rem;
  font-size: 0.83rem;
  color: var(--ink-soft);
}

.by-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: inherit;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s;
}

.by-link:hover { text-decoration-color: var(--accent); }

.entry-desc { margin: 0; font-size: 0.95rem; }

.entry-tags { margin: 0.6rem 0 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }

.tag {
  border: 1px solid var(--rule);
  background: none;
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 0.1rem 0.6rem;
  color: var(--ink-soft);
}

.tag:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Empty state ---- */

.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--ink-soft);
}

.empty-clear {
  margin-top: 0.5rem;
  border: 1px solid var(--rule);
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 0.45rem 1rem;
}

.empty-clear:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Lightbox ---- */

.lightbox { position: fixed; inset: 0; z-index: 100; display: flex; }

.lightbox[hidden] { display: none; }

.lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 12, 10, 0.82);
}

.lb-panel {
  position: relative;
  margin: auto;
  width: min(920px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  padding: 0;
}

.lb-close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  z-index: 2;
  width: 2.2rem;
  height: 2.2rem;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
}

.lb-stage { background: #000; }

.lb-stage video { display: block; width: 100%; max-height: 68vh; }

.lb-fallback { color: #ddd; padding: 3rem 2rem; text-align: center; margin: 0; }

.lb-caption { margin: 0; padding: 1rem 1.3rem 1.3rem; }

.lb-caption h2 {
  margin: 0.4rem 0 0.2rem;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.lb-meta { margin: 0; color: var(--ink-soft); font-size: 0.88rem; }

/* Photo album renderer */

.album { position: relative; }

.album-photo { display: block; width: 100%; max-height: 62vh; object-fit: contain; }

.album-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.85);
  color: #eee;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.album-nav button {
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: none;
  color: #eee;
  border-radius: 3px;
  width: 2rem;
  height: 2rem;
  font-size: 1.1rem;
  line-height: 1;
}

.album-nav button:hover { border-color: #fff; }

/* ---- Responsive ---- */

@media (max-width: 900px) {
  .masthead { flex-direction: column; align-items: flex-start; padding: 1.5rem 1rem 1rem; }
  .toolbar { padding: 0.6rem 1rem; }
  .layout { grid-template-columns: 1fr; padding: 1rem 1rem 3rem; gap: 0; }
  .shelf {
    position: sticky;
    top: var(--toolbar-h, 3.6rem);
    z-index: 15;
    flex-direction: row;
    overflow-x: auto;
    max-height: none;
    padding: 0.4rem 0 0.4rem;
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
    margin-bottom: 1rem;
    /* hide the scrollbar on mobile — the strip is still scrollable */
    scrollbar-width: none;
  }
  .shelf::-webkit-scrollbar { display: none; }
  .spine { flex: 0 0 auto; }
  /* Offset scroll targets by both the sticky toolbar and the sticky shelf. */
  .year-section,
  .entry {
    scroll-margin-top: calc(var(--toolbar-h, 3.6rem) + var(--shelf-h, 2.5rem) + 0.75rem);
  }
}

@media (max-width: 560px) {
  .entry { grid-template-columns: 1fr; }
  .thumb { max-width: 100%; }
}

/* ---- Motion preferences ---- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .thumb img { transition: none; }
  .thumb:hover img { transform: none; }
}
