/* ======================================================================
   Retro Terminal (80s Phosphor CRT) — full theme, built from scratch
   ====================================================================== */

:where(:root) {
  /* Base colors (--p-fg, --p-bg, --p-hi, --p-glow, --p-scan, --p-vig) come from
     data/phosphors.yaml via partials/phosphor-head.html. Everything below is derived,
     so a palette only needs fg + bg. Per-palette overrides win (higher specificity). */
  --phosphor: var(--p-fg);
  --phosphor-bright: color-mix(in srgb, var(--p-fg) 70%, var(--p-hi));
  --phosphor-dim: color-mix(in srgb, var(--p-fg) var(--p-dim), var(--p-bg));
  --phosphor-dimmer: color-mix(in srgb, var(--p-fg) 30%, var(--p-bg));
  --crt-bg: var(--p-bg);
  --crt-bg-panel: color-mix(in srgb, var(--p-fg) 7%, var(--p-bg));
  --crt-bg-panel-2: color-mix(in srgb, var(--p-fg) 12%, var(--p-bg));
  --crt-border: color-mix(in srgb, var(--p-fg) 35%, var(--p-bg));
  --crt-border-bright: var(--p-fg);
  --crt-white: color-mix(in srgb, var(--p-fg) 10%, var(--p-hi));
  --crt-shadow: 0 0 2px color-mix(in srgb, var(--p-fg) var(--p-glow), transparent),
                0 0 6px color-mix(in srgb, var(--p-fg) calc(var(--p-glow) / 2), transparent);
  --crt-hl: color-mix(in srgb, var(--p-fg) 14%, transparent);
  --p-dim: 55%; --p-fg: #33ff33; --p-bg: #050d05; --p-hi: #fff; --p-glow: 80%; --p-scan: 0.15; --p-vig: 0.55; --crt-err: #ff5555;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--crt-bg);
}

body {
  color: var(--phosphor);
  font-family: "Share Tech Mono", "Courier New", monospace;
  font-size: 17px;
  line-height: 1.65;
  position: relative;
  min-height: 100vh;
}

/* glow reserved for large/short text: headers, nav chrome, titles.
   Long body copy stays shadow-free so it doesn't blur/tire the eyes. */
.glow,
h1, h2, h3, h4, h5, h6,
.terminal-header,
.sidebar-title,
.post-pager-label,
.error-ascii {
  text-shadow: var(--crt-shadow);
}

/* skip link */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--crt-bg-panel);
  color: var(--phosphor-bright);
  padding: 8px 14px;
  border: 1px solid var(--crt-border-bright);
  z-index: 10001;
}

.skip-link:focus {
  left: 10px;
  top: 10px;
}

/* CRT scanline + vignette overlay */
body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 9999;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 1px,
    rgba(0, 0, 0, var(--p-scan)) 2px,
    rgba(0, 0, 0, var(--p-scan)) 3px
  );
  mix-blend-mode: multiply;
}

body::after {
  content: "";
  pointer-events: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 9998;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 60%, rgba(0,0,0,var(--p-vig)) 100%);
}

/* phones: push the fade outward and cap its strength so the page doesn't read as a spotlight.
   Scanlines (body::before) are intentionally untouched. */
@media only screen and (max-width: 600px) {
  body::after {
    background: radial-gradient(ellipse at center, rgba(0,0,0,0) 80%, rgba(0,0,0,min(var(--p-vig), 0.15)) 100%);
  }
}

@keyframes crt-flicker {
  0%, 100% { opacity: 1; }
  48% { opacity: 1; }
  50% { opacity: 0.96; }
  52% { opacity: 1; }
}

body {
  animation: crt-flicker 6s infinite;
}

/* focus states (keyboard accessibility) */
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--phosphor-bright);
  outline-offset: 2px;
}

a {
  color: var(--phosphor-bright);
  text-decoration: none;
}

a:hover, a:focus {
  color: var(--crt-white);
  text-decoration: underline;
}

a.no-underline {
  text-decoration: none;
}

hr {
  border: none;
  border-top: 1px dashed var(--crt-border);
  margin: 20px 0;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--phosphor-bright);
  font-family: "VT323", "Share Tech Mono", "Courier New", monospace;
  font-weight: normal;
  letter-spacing: 0.5px;
  margin-top: 1.4em;
  margin-bottom: 0.6em;
}

h1 { font-size: 1.9em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }

p { margin: 0 0 1em 0; }

ul, ol { padding-left: 1.4em; }

blockquote {
  border-left: 3px solid var(--crt-border);
  margin: 1em 0;
  padding: 0.2em 1em;
  color: var(--phosphor-dim);
}

img {
  max-width: 100%;
  border: 1px solid var(--crt-border);
}

figure {
  text-align: center;
  margin: 1.4em 0;
}

figcaption {
  font-size: 0.85em;
  color: var(--phosphor-dim);
  margin-top: 6px;
}

/* ---------------- layout ---------------- */

.flex-wrapper {
  display: flex;
  flex-direction: row;
  justify-content: center;
  column-gap: 36px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.flex-main {
  width: 100%;
  max-width: 740px;
  min-width: 0;
}

.flex-sidebar {
  width: 280px;
  flex-shrink: 0;
  border-left: 1px dashed var(--crt-border);
  padding-left: 22px;
}

main {
  padding-bottom: 50px;
}

/* ---------------- terminal header ---------------- */

.terminal-header {
  margin-bottom: 24px;
}

.terminal-header-bar {
  background: var(--crt-bg-panel-2);
  border-bottom: 1px solid var(--crt-border);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.terminal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.terminal-dot-red { background: #5c1f1f; }
.terminal-dot-yellow { background: #5c531f; }
.terminal-dot-green { background: var(--phosphor-dim); }

.terminal-header-label {
  margin-left: 10px;
  font-size: 0.8em;
  color: var(--phosphor-dim);
}

.terminal-prompt-line {
  background: var(--crt-bg-panel);
  padding: 16px 14px;
  font-size: 1em;
  word-break: break-word;
}

.blog-title-special-user { color: var(--phosphor-bright); font-weight: bold; }
.blog-title-special-at { color: var(--phosphor-dim); }
.blog-title-special-host-text { color: var(--crt-white); }
.blog-title-special-path { color: var(--phosphor-dim); }
.blog-title-special-chars { color: var(--phosphor-bright); margin: 0 6px; }
.blog-title-command { color: var(--phosphor); }

.terminal-nav {
  display: flex;
  gap: 2px;
  background: var(--crt-bg-panel-2);
  border-top: 1px solid var(--crt-border);
  padding: 0 14px;
}

.terminal-nav-link {
  display: inline-block;
  padding: 8px 12px;
  font-size: 0.85em;
  color: var(--phosphor-dim);
  border-right: 1px dashed var(--crt-border);
}

.terminal-nav-link:hover {
  color: var(--crt-white);
  text-decoration: none;
}

.terminal-nav-link.is-active {
  color: var(--phosphor-bright);
  background: var(--crt-bg-panel);
}

.blink {
  animation: blinker 1s step-start infinite;
}

@keyframes blinker { 50% { opacity: 0; } }

/* ---------------- feed / post cards ---------------- */

.feed-intro {
  color: var(--phosphor-dim);
  font-size: 0.9em;
  margin-bottom: 16px;
}

.list-header {
  margin-bottom: 20px;
}

.list-prompt {
  display: block;
  color: var(--phosphor-dim);
  font-size: 0.85em;
  margin-bottom: 4px;
}

.post-feed {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.post-card {
  border: 1px solid var(--crt-border);
  background: var(--crt-bg-panel);
  padding: 16px 18px;
  transition: border-color 0.15s ease;
}

.post-card:hover {
  border-color: var(--crt-border-bright);
}

.post-card-title {
  margin: 0 0 6px 0;
  font-size: 1.15em;
}

.post-card-excerpt {
  color: var(--phosphor-bright);
  font-size: 0.95em;
  margin: 10px 0 8px 0;
}

.post-card-more {
  font-size: 0.85em;
  color: var(--phosphor-dim);
}

.post-card-more:hover {
  color: var(--crt-white);
}

.summary-tags {
  font-size: 0.8em;
  color: var(--phosphor-dim);
}

.summary-tags time {
  margin-right: 6px;
}

.summary-tags a {
  color: var(--phosphor-dim);
  margin-right: 4px;
}

.summary-tags a:hover {
  color: var(--crt-white);
}

/* ---------------- single post ---------------- */

.post-breadcrumb {
  margin-bottom: 14px;
  font-size: 0.85em;
}

.post-breadcrumb a {
  color: var(--phosphor-dim);
}

.post-breadcrumb-sep {
  color: var(--phosphor-dim);
  margin: 0 6px;
}

.post-body p,
.post-body li {
  color: var(--phosphor-bright);
}

.post-body a {
  color: var(--phosphor-bright);
  text-decoration: underline;
  text-decoration-color: var(--phosphor-dim);
}

.post-pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 36px;
  border-top: 1px dashed var(--crt-border);
  padding-top: 16px;
}

.post-pager-link {
  display: flex;
  flex-direction: column;
  max-width: 48%;
}

.post-pager-prev { text-align: right; margin-left: auto; }

.post-pager-label {
  font-size: 0.8em;
  color: var(--phosphor-dim);
}

.post-pager-title {
  color: var(--phosphor-bright);
  font-size: 0.9em;
}

/* ---------------- recipes ---------------- */

.recipe-badge {
  display: inline-block;
  color: var(--crt-bg);
  background: var(--phosphor-dim);
  font-size: 0.72em;
  padding: 1px 6px;
  margin-right: 6px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.recipe-card-meta {
  display: flex;
  gap: 14px;
  font-size: 0.85em;
  color: var(--phosphor-dim);
  margin: 6px 0;
}

.recipe-description {
  color: var(--phosphor-bright);
  font-style: italic;
  margin: 10px 0 16px 0;
}

.recipe-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1px;
  background: var(--crt-border);
  border: 1px solid var(--crt-border);
  margin: 18px 0 28px 0;
}

.recipe-stat {
  background: var(--crt-bg-panel);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.recipe-stat-key {
  font-size: 0.7em;
  color: var(--phosphor-dim);
  letter-spacing: 0.5px;
}

.recipe-stat-val {
  font-size: 1.05em;
  color: var(--phosphor-bright);
}

.recipe-body-grid {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 32px;
  align-items: start;
}

.recipe-section-heading {
  color: var(--crt-white);
  font-size: 1.05em;
  letter-spacing: 1px;
  border-bottom: 1px dashed var(--crt-border);
  padding-bottom: 8px;
  margin: 0 0 12px 0;
}

.recipe-ingredients {
  border: 1px solid var(--crt-border);
  background: var(--crt-bg-panel);
  padding: 14px 16px;
}

.recipe-ingredient-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.recipe-ingredient {
  margin-bottom: 10px;
}

.recipe-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.recipe-check-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.recipe-check-box {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border: 1px solid var(--phosphor-dim);
  background: var(--crt-bg);
  position: relative;
}

.recipe-check-input:checked + .recipe-check-box {
  border-color: var(--phosphor-bright);
  background: var(--phosphor-dim);
}

.recipe-check-input:checked + .recipe-check-box::after {
  content: "x";
  position: absolute;
  top: -4px;
  left: 2px;
  color: var(--crt-white);
  font-size: 0.9em;
}

.recipe-check-input:focus-visible + .recipe-check-box {
  outline: 2px solid var(--phosphor-bright);
  outline-offset: 2px;
}

.recipe-check-label {
  color: var(--phosphor-bright);
  font-size: 0.92em;
}

.recipe-check-input:checked ~ .recipe-check-label {
  color: var(--phosphor-dim);
  text-decoration: line-through;
}

.recipe-reset-btn {
  margin-top: 10px;
  background: none;
  border: 1px dashed var(--crt-border);
  color: var(--phosphor-dim);
  font-family: inherit;
  font-size: 0.78em;
  padding: 6px 10px;
  cursor: pointer;
}

.recipe-reset-btn:hover {
  color: var(--crt-white);
  border-color: var(--crt-border-bright);
}

.recipe-steps ol {
  padding-left: 1.6em;
}

.recipe-steps li {
  margin-bottom: 0.9em;
}

@media (max-width: 640px) {
  .recipe-body-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------------- sidebar ---------------- */

.sidebar-section {
  margin-bottom: 28px;
}

.sidebar-title {
  color: var(--crt-white);
  font-weight: normal;
  letter-spacing: 1px;
  border-bottom: 1px dashed var(--crt-border);
  padding-bottom: 8px;
  margin: 0 0 12px 0;
  font-size: 1.1em;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sidebar-tag {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid var(--crt-border);
  font-size: 0.78em;
  white-space: nowrap;
  color: var(--phosphor-dim);
}

.sidebar-tag:hover {
  border-color: var(--crt-border-bright);
  color: var(--crt-white);
}

.tag-sm { font-size: 0.72em; opacity: 0.8; }
.tag-md { font-size: 0.85em; color: var(--phosphor); }
.tag-lg { font-size: 0.98em; color: var(--phosphor-bright); border-color: var(--phosphor-dim); }
.tag-xl { font-size: 1.1em; color: var(--crt-white); border-color: var(--phosphor-bright); font-weight: bold; }

.tag-cloud-full {
  gap: 10px;
}

.tag-count {
  opacity: 0.6;
  font-size: 0.85em;
}

.sidebar-postlist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-year {
  color: var(--phosphor-dim);
  font-size: 0.8em;
  margin: 14px 0 4px 0;
  letter-spacing: 1px;
}

.sidebar-year:first-child {
  margin-top: 0;
}

.sidebar-item {
  padding-bottom: 6px;
  font-size: 0.88em;
  padding-left: 10px;
}

.sidebar-item a {
  color: var(--phosphor);
}

.sidebar-item a:hover {
  color: var(--crt-white);
}

/* ---------------- footer ---------------- */

.site-footer {
  border-top: 1px solid var(--crt-border);
  margin-top: 20px;
}

.foot-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px 28px;
}

.flex-footer-container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}

.flex-footer-about {
  font-size: 0.9em;
  line-height: 1.5;
}

.footer-prompt {
  color: var(--phosphor-dim);
}

.footer-name {
  letter-spacing: 0.03em;
  font-weight: bold;
}

.flex-footer-nav {
  color: var(--phosphor-dim);
}

.flex-footer-nav a {
  color: var(--phosphor-dim);
  text-decoration: none;
  border-bottom: 1px dotted var(--phosphor-dim);
}

.flex-footer-nav a:hover {
  color: var(--crt-white);
  border-bottom-color: var(--crt-white);
}

.flex-footer-social-icons {
  display: flex;
  align-items: baseline;
}

.footer-social-icons {
  width: 20px;
  height: 20px;
  margin-left: 10px;
  fill: var(--phosphor-dim);
  vertical-align: middle;
}

.footer-social-icons:hover {
  fill: var(--crt-white);
}

/* ---------------- 404 ---------------- */

.error-page {
  text-align: center;
  padding-top: 40px;
}

.error-ascii {
  color: var(--phosphor-bright);
  font-size: 0.85em;
  white-space: pre;
  overflow-x: auto;
}

.error-line {
  margin: 6px 0;
}

/* ---------------- code blocks (chroma) ---------------- */

code {
  font-family: "Share Tech Mono", "Courier New", monospace;
  font-size: 0.95em;
}

.chroma {
  background-color: var(--crt-bg-panel) !important;
  border: 1px solid var(--crt-border);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 1em 0;
}

p > code,
li > code {
  background-color: var(--crt-bg-panel);
  border: 1px solid var(--crt-border);
  padding: 1px 5px;
}

.chroma .k, .chroma .kc, .chroma .kd, .chroma .kn, .chroma .kr, .chroma .kt {
  color: var(--phosphor-bright);
  font-weight: bold;
}

.chroma .kp { color: var(--phosphor-bright); }

.chroma .s, .chroma .s1, .chroma .s2, .chroma .sa, .chroma .sb, .chroma .sc,
.chroma .sd, .chroma .se, .chroma .sh, .chroma .si, .chroma .sx, .chroma .sr,
.chroma .ss {
  color: var(--crt-white);
}

.chroma .c, .chroma .c1, .chroma .cm, .chroma .cs, .chroma .cp, .chroma .cpf {
  color: var(--crt-comment, var(--phosphor-dim));
  font-style: italic;
}

.chroma .nf, .chroma .nc, .chroma .nn, .chroma .nb, .chroma .nd {
  color: var(--phosphor-bright);
}

.chroma .mi, .chroma .mf, .chroma .mo, .chroma .mh, .chroma .il {
  color: var(--crt-white);
}

.chroma .o, .chroma .ow { color: var(--phosphor-bright); }

.chroma .err { color: var(--crt-err); background-color: transparent; }

.chroma .lnt, .chroma .ln { color: var(--phosphor-dim); }

.chroma .hl { background-color: var(--crt-hl); }

/* ---------------- responsive ---------------- */

@media only screen and (max-width: 900px) {
  .flex-wrapper {
    flex-direction: column;
    padding: 0 16px;
  }

  .flex-main { max-width: 100%; }

  .flex-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px dashed var(--crt-border);
    padding-left: 0;
    padding-top: 16px;
    margin-top: 10px;
  }

  .post-pager {
    flex-direction: column;
  }

  .post-pager-link,
  .post-pager-prev {
    max-width: 100%;
    text-align: left;
    margin-left: 0;
  }

  body { font-size: 16px; }
}

/* ---------------- phosphor switcher ---------------- */
.phosphor-switch {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 0.8em;
}
.phosphor-switch-label { color: var(--phosphor-dim); margin-right: 4px; }
.phosphor-switch-label .lbl-mob { display: none; }
.phosphor-select-wrap { display: contents; }
.phosphor-chip {
  width: 14px;
  height: 14px;
  border: 1px solid var(--crt-border);
  display: inline-block;
  vertical-align: middle;
}
::view-transition-group(root) { animation-duration: 0.15s; }
.phosphor-select {
  font: inherit;
  color: var(--phosphor-dim); /* same dim tone as the "screen:" / "$ screen --set" label */
  text-shadow: var(--crt-shadow); /* same glow as the label (iOS renders it on native selects) */
  background-color: var(--crt-bg-panel);
  border: 1px solid var(--crt-border);
  border-radius: 0;
  padding: 2px 22px 2px 6px;
  cursor: pointer;
  max-width: 100%;
  /* iOS Safari/Chrome otherwise draw a rounded native pill with a black arrow */
  -webkit-appearance: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--phosphor-dim) 50%),
    linear-gradient(135deg, var(--phosphor-dim) 50%, transparent 50%);
  background-position: calc(100% - 12px) 55%, calc(100% - 7px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.phosphor-select:hover { color: var(--phosphor-bright); border-color: var(--phosphor-dim); }
.phosphor-select:focus-visible { outline: 2px solid var(--phosphor-bright); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { body { animation: none; } }

/* phones, option A "terminal prompt": row 1 = dots + host; row 2 = "$ screen --set [chip C64 blue v]".
   The chip moves inside the dropdown's left edge so nothing floats on its own. */
@media only screen and (max-width: 600px) {
  .terminal-header-bar { flex-wrap: wrap; row-gap: 6px; }
  .terminal-header-label { white-space: nowrap; }
  .phosphor-switch { margin-left: 0; flex: 1 1 100%; flex-wrap: nowrap; gap: 16px; }
  .phosphor-switch-label { margin-right: 0; white-space: nowrap; }
  .phosphor-switch-label .lbl-desk { display: none; }
  .phosphor-switch-label .lbl-mob { display: inline; }
  .phosphor-select-wrap { display: block; position: relative; flex: 1 1 auto; min-width: 0; }
  .phosphor-select-wrap .phosphor-chip {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    width: 16px; height: 16px; pointer-events: none;
  }
  .phosphor-select {
    width: 100%; padding: 8px 30px 8px 34px; border: 0; background-color: transparent;
    font-size: inherit; /* matches the "$ screen --set" label (12.8px). Note: iOS Safari may zoom the page when a field under 16px is tapped */
    background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  }
}
