/* The site is dark only */
:root {
  color-scheme: dark;
  --bg: #15171a;
  --text: #e6e8eb;
  --muted: #8b929b;
  --line: #2a2e33;
  --accent: #6ea8fe;
  --hover: #a5c8ff;
  --code-bg: #1f2226;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px;
}

main.wrap { flex: 1; padding-top: 48px; padding-bottom: 64px; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--hover); text-decoration-thickness: 2px; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}
.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  padding-top: 20px;
  padding-bottom: 20px;
}
.site-title {
  color: var(--text);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  text-decoration: none;
}
.site-header nav { margin-left: auto; }
.me-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 180px;
  padding: 3px 10px 3px 6px;
  border-radius: 999px;
  background: var(--code-bg);
  color: var(--text);
  font: 600 14px var(--sans);
  text-decoration: none;
  white-space: nowrap;
}
.me-chip[hidden] { display: none; }
.me-chip:hover { color: var(--hover); }
.me-chip .me-name { overflow: hidden; text-overflow: ellipsis; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 4px 20px; font-size: 15px; }
.site-header nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
.site-header nav a.active { color: var(--text); }
.site-header nav a:hover { color: var(--hover); }

/* Footer */
.site-footer {
  border-top: 1px solid var(--line);
  font: 14px var(--sans);
}
.site-footer .wrap { display: flex; justify-content: flex-end; padding-top: 20px; padding-bottom: 28px; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--hover); }

.emoji { font-style: normal; display: inline-block; }
.post-header h1 .emoji, .page-title .emoji { margin-right: 0.45em; }
a:hover .emoji, button:hover .emoji { animation: wiggle 0.45s ease-in-out; }
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-10deg); }
  50% { transform: rotate(8deg); }
  75% { transform: rotate(-4deg); }
}
@media (prefers-reduced-motion: reduce) {
  a:hover .emoji, button:hover .emoji { animation: none; }
}

/* Spinning ASCII donut on the home page */
.donut {
  margin: 0 0 24px;
  font: 10px/1 var(--mono);
  color: var(--muted);
  text-align: center;
  white-space: pre;
  overflow: hidden;
  user-select: none;
}

/* Home page daily fact + ISS line */
.today { margin-top: 32px; }
.today .live { color: var(--accent); font-weight: 600; }

/* Guestbook */
.guestbook { font-family: var(--sans); }
.sign-form { padding: 20px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 36px; }
.sign-form[hidden] { display: none; }
.name-field { display: block; margin-bottom: 18px; }
.name-field span, .pic-picker legend { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding: 0; }
.name-field input {
  width: 100%; max-width: 320px;
  padding: 8px 12px;
  font: 16px var(--sans);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.name-field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.pic-picker { border: 0; margin: 0 0 18px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.pic-picker label { cursor: pointer; }
.pic-picker input { position: absolute; opacity: 0; pointer-events: none; }
.pic-picker label span {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  font-size: 26px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
}
.pic-picker label:hover span { border-color: var(--muted); }
.pic-picker input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.pic-picker input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.sign-form button {
  padding: 9px 18px;
  font: 600 15px var(--sans);
  color: var(--bg);
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
.sign-form button:hover { background: var(--hover); }
.sign-form button:disabled { opacity: 0.6; cursor: default; }
.sign-form { font-family: var(--sans); }
.form-msg { color: #f87171; font-size: 14px; margin: 10px 0 0; }
.form-msg:empty { display: none; }
.signed-msg, .owner-msg { font-size: 18px; margin: 0 0 36px; }
.owner-in button {
  padding: 8px 16px;
  font: 600 14px var(--sans);
  color: var(--text);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.owner-in button:hover { border-color: var(--muted); }
.signed-msg strong { color: var(--accent); }
.guestbook-entries { list-style: none; margin: 0; padding: 0; }
.guestbook-entries li { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.guestbook-entries .pic {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 22px;
  border-radius: 8px;
  background: var(--code-bg);
}
.guestbook-entries .name { font-weight: 600; overflow-wrap: anywhere; }
.guestbook-entries .num { color: var(--muted); font-size: 14px; font-weight: 600; }
.guestbook-entries time { margin-left: auto; flex: 0 0 auto; color: var(--muted); font-size: 14px; }

/* Sign-to-react box and who reacted */
.react-sign { margin-top: 20px; font-family: var(--sans); }
.react-sign[hidden] { display: none; }
.react-sign > p { margin: 0 0 10px; font-size: 15px; }
.react-sign .sign-form { margin-bottom: 0; }

.sign-nudge { margin: 12px 0 0; font: 15px var(--sans); }
.sign-nudge a { text-decoration: none; }

.go-home { font: 17px var(--sans); margin-top: 32px; }
.go-home a { text-decoration: none; }
.post-list .emoji { margin-right: 0.75em; }

/* Headings */
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.01em; }
.page-title, .post-header h1, .intro h1 { font-size: 34px; margin: 0 0 8px; }

.section-label {
  font: 600 13px var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 48px 0 12px;
}

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

/* Post lists */
.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li {
  display: flex;
  gap: 20px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.post-list time {
  flex: 0 0 64px;
  color: var(--muted);
  font: 14px var(--sans);
  font-variant-numeric: tabular-nums;
}
.post-list a { color: var(--text); text-decoration: none; font-weight: 600; }
.post-reactions {
  flex: 0 0 auto;
  margin-left: auto;
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: var(--code-bg);
  color: var(--muted);
  font: 700 18px/1 var(--sans);
  font-variant-numeric: tabular-nums;
}
.post-reactions:empty { display: none; }
.post-reactions .stack { display: inline-flex; }
.post-reactions .stack span {
  position: relative;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  margin-left: -7px;
  font-size: 16px;
  line-height: 1;
}
.post-reactions .stack span:first-child { margin-left: 0; z-index: 3; }
.post-reactions .stack span:nth-child(2) { z-index: 2; }
.post-reactions .stack span:nth-child(3) { z-index: 1; }

.post-reactions + .thumb { margin-left: 16px; }
.post-list .thumb { flex: 0 0 auto; margin-left: auto; align-self: center; line-height: 0; }
.post-list .thumb img { width: 64px; height: 48px; object-fit: cover; border-radius: 4px; }
.post-list a:hover { color: var(--hover); }
.more { font-family: var(--sans); font-size: 15px; }

/* Posts */
.post-header { margin-bottom: 32px; }
.post-header time { color: var(--muted); font: 15px var(--sans); }

.prose { overflow-wrap: break-word; }
.prose img, .prose video { max-width: 100%; height: auto; border-radius: 4px; }
.prose figure { margin: 32px 0; }
.prose figcaption { color: var(--muted); font: 14px var(--sans); text-align: center; margin-top: 8px; }
.prose h2 { font-size: 26px; margin: 40px 0 12px; }
.prose h3 { font-size: 21px; margin: 32px 0 8px; }
.prose blockquote {
  margin: 24px 0;
  padding: 2px 0 2px 20px;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-style: italic;
}
.prose code { font: 0.85em var(--mono); background: var(--code-bg); padding: 2px 5px; border-radius: 3px; }
.prose pre { background: var(--code-bg); padding: 16px; border-radius: 6px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 40px 0; }
.prose table { border-collapse: collapse; width: 100%; font-size: 16px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }

/* Emoji reactions under posts */
.reactions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 48px; }
.reactions[hidden] { display: none; }
.reactions button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 600 14px var(--sans);
  cursor: pointer;
}
.reactions button:hover { border-color: var(--muted); }
.reactions button.mine { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.reactions .emoji { font-size: 18px; line-height: 1; }
.reactions .count:empty { display: none; }
.reactions button { position: relative; }
.reactions .who {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(calc(-50% + var(--nudge, 0px)));
  z-index: 5;
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font: 600 13px var(--sans);
  white-space: nowrap;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.4);
  pointer-events: none;
}
.reactions .who::after {
  content: "";
  position: absolute;
  top: 100%; left: calc(50% - var(--nudge, 0px));
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--text);
}
.reactions button:hover .who:not(:empty), .reactions button:focus-visible .who:not(:empty),
.reactions button.show-who .who:not(:empty) { display: flex; }
/* Stop long-press from selecting text or opening the phone's copy menu */
.reactions button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font: 15px var(--sans);
}
.post-nav a { text-decoration: none; }

/* Sidebar of all posts: hangs left of the post on wide screens, sits below it otherwise */
.post-sidebar { margin-top: 56px; font: 14px/1.4 var(--sans); }
.post-sidebar .section-label { margin-top: 0; }
.post-sidebar ul { list-style: none; margin: 0; padding: 0; }
.post-sidebar li { padding: 7px 0; border-bottom: 1px solid var(--line); }
.post-sidebar a { color: var(--text); text-decoration: none; }
.post-sidebar a:hover { color: var(--hover); }
.post-sidebar li.current span { font-weight: 600; }
.post-sidebar li.current { border-left: 2px solid var(--accent); padding-left: 10px; }
.post-sidebar time { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.post-sidebar li { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; align-items: center; }
.post-sidebar li > a, .post-sidebar li > span:not(.post-reactions), .post-sidebar time { grid-column: 1; }
.post-sidebar .post-reactions { grid-column: 2; grid-row: 1 / span 2; margin-left: 0; padding: 2px 7px 2px 6px; font-size: 12px; gap: 2px; }
.post-sidebar .post-reactions .stack span { width: 15px; height: 15px; margin-left: -5px; font-size: 12px; }
.post-sidebar .post-reactions .stack span:first-child { margin-left: 0; }

@media (min-width: 1200px) {
  .post-layout {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr);
    column-gap: 56px;
    margin-left: -256px;
  }
  .post-layout .post { grid-column: 2; grid-row: 1; }
  .post-sidebar {
    grid-column: 1; grid-row: 1;
    align-self: start;
    position: sticky; top: 32px;
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    margin-top: 8px;
  }
}

@media (max-width: 520px) {
  body { font-size: 16px; }
  main.wrap { padding-top: 32px; }
  .page-title, .post-header h1, .intro h1 { font-size: 28px; }
  .post-list li { gap: 14px; }

  /* Header: menu on its own row with bigger tap targets */
  .site-header .wrap { padding-top: 14px; padding-bottom: 8px; row-gap: 2px; }
  .site-header nav { gap: 0 14px; font-size: 14px; order: 2; flex-basis: 100%; margin-left: 0; }
  .me-chip { order: 1; margin-left: auto; max-width: 150px; font-size: 13px; }
  .site-header nav a { padding: 8px 0; }

  /* All seven reactions on one row, as big tap targets */
  .reactions { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
  .reactions button { justify-content: center; gap: 3px; min-height: 42px; padding: 6px 0; font-size: 12px; }
  .reactions .emoji { font-size: 17px; }

  .pic-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
  .pic-picker label span { width: auto; aspect-ratio: 1; height: auto; }
  .sign-form { padding: 16px; }
  .guestbook-entries li { gap: 10px; }
  .guestbook-entries time { font-size: 13px; }
}

@media (max-width: 360px) {
  /* Keep the menu on one line; on the very narrowest phones it can slide sideways */
  .site-header nav { gap: 0 9px; font-size: 12.5px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .site-header nav::-webkit-scrollbar { display: none; }
  .site-header nav a { white-space: nowrap; }
  .donut { font-size: 9px; }
}
