:root {
  --bg: #f7f6f2;
  --text: #18181b;
  --muted: #71717a;
  --border: #e4e4e7;
  --hover: #f4f4f5;
  --ring: #a1a1aa;
  --gutter: 5.5rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113;
    --text: #ececef;
    --muted: #8b8b95;
    --border: #27272a;
    --hover: #222226;
    --ring: #71717a;
  }
}

:root[data-theme="dark"] {
  --bg: #111113;
  --text: #ececef;
  --muted: #8b8b95;
  --border: #27272a;
  --hover: #222226;
  --ring: #71717a;
}

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

html {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 6rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2.5rem;
  padding-left: var(--gutter);
}

.brand {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.topbar:hover .topbar-actions,
.topbar:focus-within .topbar-actions {
  opacity: 1;
}

@media (hover: none) {
  .topbar-actions {
    opacity: 1;
  }
}

.status-msg {
  font-size: 0.75rem;
  color: var(--muted);
  margin-right: 0.35rem;
}

.text-btn {
  appearance: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.12s ease, background-color 0.12s ease, opacity 0.12s ease;
}

.text-btn:focus-visible {
  box-shadow: 0 0 0 1.5px var(--border);
}

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

.text-btn.is-off {
  opacity: 0.55;
}

.doc {
  outline: none;
  min-height: calc(100vh - 10rem);
  padding-left: var(--gutter);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.doc.is-empty > p:first-child:empty::before,
.doc.is-empty > p:first-child:has(> br:only-child)::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.doc > p,
.doc > div:not(.date-block) {
  margin: 0 0 0.55rem;
  min-height: 1.65rem;
}

.doc > ul,
.doc > ol {
  margin: 0.25rem 0 0.65rem;
  padding-left: 2rem;
}

.doc > ul > li,
.doc > ol > li {
  margin: 0.18rem 0;
  min-height: 1.65rem;
}

/* Left gutter time labels (fixed layout, no shift when hidden) */
.doc > p[data-time],
.doc > div[data-time]:not(.date-block),
.doc > figure.image-block[data-time],
.doc > ul > li[data-time],
.doc > ol > li[data-time] {
  position: relative;
}

.doc.show-times > p[data-time]::before,
.doc.show-times > div[data-time]:not(.date-block)::before,
.doc.show-times > figure.image-block[data-time]::before,
.doc.show-times > ul > li[data-time]::before,
.doc.show-times > ol > li[data-time]::before {
  content: attr(data-time);
  position: absolute;
  left: calc(-1 * var(--gutter));
  width: calc(var(--gutter) - 0.9rem);
  height: 1.65rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  user-select: none;
  pointer-events: none;
  top: 0;
}

.doc.show-times > ul > li[data-time]::before,
.doc.show-times > ol > li[data-time]::before {
  left: calc(-1 * var(--gutter) - 2rem);
}

/* Date block (/d or /date) */
.date-block {
  margin: 1.35rem 0 0.65rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
  user-select: none;
  cursor: pointer;
}

.doc > .date-block:first-child {
  margin-top: 0;
}

/* Inline image block */
.image-block {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0.75rem 0;
  display: block;
  user-select: none;
}

.image-delete {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  border-radius: 999px;
  background: rgba(24, 24, 27, 0.72);
  color: #fcfcfb;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background-color 0.12s ease;
}

.image-block:hover .image-delete,
.image-delete:focus-visible {
  opacity: 1;
}

.image-delete:hover {
  background: rgba(24, 24, 27, 0.9);
}

.image-block img {
  display: block;
  max-width: 100%;
  max-height: 520px;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  cursor: zoom-out;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-img {
  width: auto;
  height: auto;
  max-width: 94vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.image-block.is-broken {
  padding: 0.6rem 0.8rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.image-block.is-broken img {
  display: none;
}

.date-block.is-selected {
  background: var(--hover);
  border-radius: 4px;
}

.image-block.is-selected img,
.image-block.is-broken.is-selected {
  border-color: var(--muted);
}

@media (max-width: 560px) {
  :root {
    --gutter: 4.25rem;
  }

  .page {
    padding: 1.5rem 1rem 4rem;
  }

  .topbar {
    flex-wrap: wrap;
    margin-bottom: 1.75rem;
  }

  .doc.show-times > p[data-time]::before,
  .doc.show-times > div[data-time]:not(.date-block)::before,
  .doc.show-times > figure.image-block[data-time]::before,
  .doc.show-times > ul > li[data-time]::before,
  .doc.show-times > ol > li[data-time]::before {
    width: calc(var(--gutter) - 0.65rem);
    font-size: 0.68rem;
  }
}
