/* viewer.css — memo timeline viewer */

/* -------------------------------------------------------------------------
   CSS custom properties (light mode defaults)
   ---------------------------------------------------------------------- */
:root {
  --bg: #fafaf8;
  --fg: #1a1a18;
  --muted: #888880;
  --border: #e2e2dc;
  --code-bg: #1e1e1e;
  --code-fg: #d4d4d4;
  --tag-bg: #f0f0eb;
  --tag-fg: #555550;
  --link-card-bg: #f5f5f0;
  --link-url-fg: #888880;
  --rail-color: #d8d8d2;
  --circle-bg: var(--bg);
  --action-fg: #888880;
  --sep-fg: #b0b0a8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --fg: #e8e8e0;
    --muted: #6a6a62;
    --border: #2e2e28;
    --code-bg: #0d0d0d;
    --code-fg: #d4d4d4;
    --tag-bg: #252520;
    --tag-fg: #aaa89e;
    --link-card-bg: #1e1e18;
    --link-url-fg: #6a6a62;
    --rail-color: #333330;
    --circle-bg: var(--bg);
    --action-fg: #6a6a62;
    --sep-fg: #4a4a42;
  }
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-serif, "Songti SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.7;
}

a {
  color: inherit;
}

/* -------------------------------------------------------------------------
   Layout wrapper
   ---------------------------------------------------------------------- */
.timeline {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

/* -------------------------------------------------------------------------
   Date separator
   ---------------------------------------------------------------------- */
.date-sep {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: 16px;
  padding-bottom: 16px;
  margin-top: 40px;
  margin-bottom: 40px;
  background: var(--bg);
  /* Hairline bottom border gives visual separation from memo content below */
  box-shadow: 0 1px 0 var(--border);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--sep-fg);
  user-select: none;
  /* Extend bg flush to viewport edges so no gap shows on either side */
  margin-left: -24px;
  margin-right: -24px;
  padding-left: 24px;
  padding-right: 24px;
}

/* First day group needs no top breathing room — it sits at the list top */
.timeline > .day-group:first-child .date-sep {
  margin-top: 16px;
}

/* -------------------------------------------------------------------------
   Day group — contains the vertical rail + memo cards
   ---------------------------------------------------------------------- */
.day-group {
  position: relative;
}

.rail {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--rail-color);
}

.memos-in-group {
  padding-left: 24px;
}

/* -------------------------------------------------------------------------
   Memo card
   ---------------------------------------------------------------------- */
.memo-card {
  position: relative;
  padding: 0 0 40px;
}

/* Hollow circle on the rail */
.memo-card::before {
  content: "";
  position: absolute;
  left: -30px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--rail-color);
  background: var(--circle-bg);
}

/* -------------------------------------------------------------------------
   Card top row: ID + tags + time
   ---------------------------------------------------------------------- */
.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}

.memo-id {
  font-weight: 700;
  color: var(--fg);
  text-decoration: none;
}

.memo-id:hover {
  opacity: 0.7;
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--tag-bg);
  color: var(--tag-fg);
  font-size: 11px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.memo-time {
  margin-left: auto;
  color: var(--muted);
  white-space: nowrap;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}

.memo-edited {
  font-style: italic;
  color: var(--muted);
  margin-left: 4px;
}

/* -------------------------------------------------------------------------
   Body — markdown-rendered
   ---------------------------------------------------------------------- */
.memo-body {
  font-size: 15px;
  line-height: 1.75;
  overflow-wrap: anywhere; /* break long URLs / no-space strings; code blocks unaffected (overflow-x: auto) */
}

.memo-body h1,
.memo-body h2,
.memo-body h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 1.1em 0 0.3em;
}

.memo-body p {
  margin: 0.5em 0;
}

.memo-body ul,
.memo-body ol {
  padding-left: 1.4em;
  margin: 0.5em 0;
}

.memo-body li {
  margin: 0.2em 0;
}

.memo-body a {
  color: var(--fg);
  text-underline-offset: 2px;
}

.memo-body strong {
  font-weight: 700;
}

.memo-body em {
  font-style: italic;
}

.memo-body img {
  max-width: 360px;
  max-height: 280px;
  object-fit: cover;
  border-radius: 6px;
  cursor: zoom-in;
  display: inline-block;
  margin: 6px 8px 6px 0;
  transition: opacity 0.15s;
}

.memo-body img:hover {
  opacity: 0.85;
}

/* -------------------------------------------------------------------------
   Lightbox
   ---------------------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.lightbox.open {
  display: flex;
}

@media (prefers-color-scheme: dark) {
  .lightbox {
    background: rgba(0, 0, 0, 0.92);
  }
}

.lightbox-img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
}

.memo-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.2em 0;
}

/* Inline code */
.memo-body code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  background: var(--tag-bg);
  padding: 1px 5px;
  border-radius: 3px;
}

/* -------------------------------------------------------------------------
   Code blocks — custom wrapper
   ---------------------------------------------------------------------- */
.code-block-wrapper {
  position: relative;
  margin: 1em 0;
  border-radius: 6px;
  overflow: hidden;
  background: var(--code-bg);
}

.code-lang-label {
  position: absolute;
  top: 8px;
  left: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: #888;
  user-select: none;
  pointer-events: none;
}

.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  padding: 2px 8px;
  background: #333330;
  color: #ccc;
  border: 1px solid #555;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s;
}

.code-copy-btn:hover {
  background: #444440;
}

.code-copy-btn.copied {
  color: #7fba7a;
  border-color: #7fba7a;
}

.code-block-wrapper pre {
  margin: 0;
  padding: 36px 12px 14px;
  overflow-x: auto;
  background: transparent;
}

.code-block-wrapper pre code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--code-fg);
  background: transparent;
  padding: 0;
  border-radius: 0;
}

/* -------------------------------------------------------------------------
   Link cards
   ---------------------------------------------------------------------- */
.link-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 0;
}

.link-card {
  display: block;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--link-card-bg);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

.link-card:hover {
  border-color: var(--muted);
}

.link-card-title {
  font-weight: 600;
  font-size: 14px;
  display: block;
  margin-bottom: 2px;
  word-break: break-all;
}

.link-card-url {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--link-url-fg);
  word-break: break-all;
  overflow-wrap: anywhere; /* belt-and-suspenders: ensure long URLs never overflow card border */
}

/* -------------------------------------------------------------------------
   Action row
   ---------------------------------------------------------------------- */
.card-actions {
  display: flex;
  gap: 16px;
  margin-top: 12px;
}

.action-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--action-fg);
  transition: color 0.15s;
}

.action-btn:hover {
  color: var(--fg);
}

.action-btn.flash {
  color: var(--fg);
}
