/* Shared by every page: page transitions, scroll-in animations, the terminal, the Bug2
   game, the leaderboard and the posts list. Colour tokens come from each page's :root. */

/* ---- Page transitions (cross-document View Transitions) ---- */
@view-transition { navigation: auto; }
.monogram { view-transition-name: brand; }
::view-transition-old(root) { animation: vt-out .24s steps(4) both; }
::view-transition-new(root) { animation: vt-in .32s steps(5) both; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-6px); filter: blur(1px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px); filter: blur(2px); } }

/* ---- Scroll-in animations: things step into place, pixel style ---- */
.reveal { opacity: 0; transform: translateY(14px); }
.reveal.in { opacity: 1; transform: none; transition: opacity .45s steps(5), transform .45s steps(5); }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  .reveal { opacity: 1; transform: none; }
}

/* ---- Terminal ---- */
.hero-term { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; background: #0d0d0c; color: #e6e3d8; border: 1px solid #000; box-shadow: 4px 4px 0 var(--shadow, #000); font: 500 14px/1 "IBM Plex Mono", monospace; }
.ht-prompt { flex: none; color: #e07a55; cursor: text; }
.hero-term input { flex: 1; min-width: 0; height: 30px; border: 0; outline: none; background: transparent; color: inherit; font: inherit; caret-color: #e07a55; }
.hero-term input::placeholder { color: #8b877c; opacity: 1; }
.hero-term button { flex: none; height: 30px; padding: 0 10px; border: 1px solid #3a3833; background: #1d1c1a; color: #e6e3d8; font: 600 12px/1 "IBM Plex Mono", monospace; cursor: pointer; }
.hero-term button:hover { border-color: #e07a55; color: #e07a55; }
.hero-term:focus-within { outline: 2px dashed var(--accent); outline-offset: 3px; }
.term-btn span:first-child { color: var(--accent-ink); font-weight: 600; letter-spacing: -.05em; }
.term-hint { position: fixed; right: 20px; bottom: 20px; z-index: 65; display: flex; align-items: center; gap: 10px; max-width: min(420px, calc(100vw - 40px)); padding: 12px 14px; background: #0d0d0c; color: #e6e3d8; border: 1px solid #000; box-shadow: 4px 4px 0 rgba(0, 0, 0, .5); font: 500 12px/1.4 "IBM Plex Mono", monospace; text-align: left; cursor: pointer; transform: translateY(16px); opacity: 0; transition: transform .2s steps(3), opacity .2s steps(3); }
.term-hint.show { transform: none; opacity: 1; }
.term-hint .ico { flex: none; color: #e07a55; font-weight: 600; }
.term-hint .txt { flex: 1; }
.term-hint kbd { font: inherit; padding: 0 4px; border: 1px solid #555; }
.term { position: fixed; left: 50%; bottom: 20px; z-index: 70; width: min(720px, calc(100vw - 24px)); height: min(420px, 62vh); display: flex; flex-direction: column; background: #0d0d0c; color: #e6e3d8; border: 1px solid #000; box-shadow: 6px 6px 0 rgba(0, 0, 0, .55); font: 400 13px/1.55 "IBM Plex Mono", ui-monospace, monospace; transform: translate(-50%, 24px); opacity: 0; visibility: hidden; transition: transform .16s steps(3), opacity .16s steps(3), visibility .16s; }
.term.open { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.term-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #1d1c1a; color: #9a968a; font-size: 12px; }
.term-close { background: none; border: 0; color: inherit; font: inherit; font-size: 18px; line-height: 1; cursor: pointer; }
.term-out { flex: 1; overflow: auto; padding: 12px 14px 4px; white-space: pre-wrap; word-break: break-word; }
.term-out .cmd { color: #f0a17f; margin-top: 6px; }
.term-out .dim { color: #8b877c; }
.term-out .err { color: #ff8f7a; }
.term-line { display: flex; gap: 8px; align-items: center; padding: 8px 14px 12px; }
.term-prompt { color: #e07a55; }
.term-line input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: inherit; font: inherit; caret-color: #e07a55; }

/* ---- Making the game easy to find ---- */
.nav-play { position: relative; }
.nav-play i { position: absolute; top: -5px; right: -9px; width: 5px; height: 5px; background: var(--accent); animation: nav-blink 1.4s steps(1) infinite; }
@keyframes nav-blink { 50% { opacity: 0; } }
.pt-track { position: relative; height: 28px; border-bottom: 2px dashed var(--accent-soft); }
.pt-track i { position: absolute; bottom: 2px; display: block; }
.pt-bot { left: 0; width: 16px; height: 14px; background: var(--ink); box-shadow: inset 4px -4px 0 -2px var(--ink); animation: pt-drive 3.2s steps(16) infinite; }
.pt-bot::before, .pt-bot::after { content: ""; position: absolute; top: 4px; width: 3px; height: 3px; background: var(--paper); }
.pt-bot::before { left: 3px; } .pt-bot::after { right: 3px; }
.pt-bean { left: 50px; bottom: 14px !important; width: 8px; height: 11px; border-radius: 4px; background: var(--coffee, #6b3b22); animation: pt-bean 3.2s steps(1) infinite; }
.pt-flag { right: 0; width: 3px; height: 22px; background: var(--ink); }
.pt-flag::after { content: ""; position: absolute; left: 3px; top: 0; width: 10px; height: 7px; background: var(--accent); }
@keyframes pt-drive { 0% { transform: translate(0, 0); } 30% { transform: translate(42px, 0); } 40% { transform: translate(46px, -12px); } 55% { transform: translate(58px, -12px); } 62% { transform: translate(62px, 0); } 85%, 100% { transform: translate(92px, 0); } }
@keyframes pt-bean { 0%, 44% { opacity: 1; } 45%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pt-bot, .pt-bean, .nav-play i { animation: none; } }

/* ---- Coffee run (Bug2 puzzle) ---- */
.game { background: var(--surface); border: 1px solid var(--line); }
.level-strip { display: grid; grid-template-columns: repeat(8, 1fr); border-bottom: 1px dashed var(--line); }
.lvl { display: grid; gap: 2px; justify-items: center; padding: 10px 4px; border: 0; border-right: 1px dashed var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.lvl:last-child { border-right: 0; }
.lvl b { font: 600 13px/1 "IBM Plex Mono", monospace; }
.lvl span { font-size: 11px; letter-spacing: 1px; color: var(--faint); }
.lvl.is-done span { color: var(--accent-ink); }
.lvl:hover { background: var(--sunken); color: var(--ink); }
.lvl.is-on { background: var(--ink); color: var(--paper); }
.lvl.is-on span { color: var(--paper); }
.level-head { padding: 14px 16px 0; }
.level-head h3 { margin: 0; font: 600 22px/1.2 var(--pixel); }
.level-head p { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.game-bar { display: flex; flex-wrap: wrap; gap: 6px 20px; padding: 12px 16px; color: var(--faint); font: 500 11px/1.4 "IBM Plex Mono", monospace; letter-spacing: .1em; text-transform: uppercase; }
.game-bar b { color: var(--ink); font-weight: 600; }
.game canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; touch-action: manipulation; cursor: pointer; border-block: 1px dashed var(--line); }
.game canvas:focus-visible { outline: 2px dashed var(--accent); outline-offset: -2px; }
.game-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; }
.game-controls button, .game-controls select, .score-form button, .score-form input { height: 36px; padding: 0 12px; border: 1px solid var(--ink); background: var(--surface); color: var(--ink); font: 500 12px/1 "IBM Plex Mono", monospace; }
.game-controls .go { background: var(--accent); color: #fff; }
.game-controls .side-btn[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }
.game-controls .spacer { flex: 1; }
.game-legend { display: flex; flex-wrap: wrap; gap: 14px; padding: 0 16px 12px; color: var(--muted); font: 400 12px/1.4 "IBM Plex Mono", monospace; }
.game-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; }
.game-legend .lg-bean { width: 8px; height: 11px; border-radius: 4px; background: var(--coffee, #6b3b22); }
.game-result { min-height: 1.6em; margin: 0; padding: 0 16px 10px; color: var(--muted); font-size: 15px; }
.game-result b { color: var(--accent-ink); letter-spacing: 2px; }
.game-next { padding: 0 16px; }
.game-next .chip { margin-bottom: 12px; padding: 7px 12px; }
.score-form { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 16px; }
.score-form input { flex: 1; min-width: 160px; font-family: "IBM Plex Sans", system-ui, sans-serif; font-size: 14px; }
.score-form button { background: var(--ink); color: var(--paper); }
.board-wrap { margin-top: 24px; }
.board-wrap h3 { margin: 0 0 8px; font: 500 12px/1 "IBM Plex Mono", monospace; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); }
.board { list-style: none; margin: 0; padding: 0; }
.board li { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.board .rank { color: var(--accent-ink); font: 600 13px/1 "IBM Plex Mono", monospace; }
.board .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { color: var(--muted); font: 400 12px/1 "IBM Plex Mono", monospace; }
.board-note { color: var(--faint); font: 400 13px/1.5 "IBM Plex Mono", monospace; margin: 8px 0 0; }
.how { margin-top: 18px; }
.how summary { cursor: pointer; color: var(--muted); font: 500 12px/1.6 "IBM Plex Mono", monospace; }
.how ol { margin: 10px 0 0; padding-left: 20px; color: var(--muted); }
.how li { margin: 6px 0; }
@media (max-width: 640px) {
  .level-strip { grid-template-columns: repeat(4, 1fr); }
  .lvl:nth-child(4) { border-right: 0; }
  .lvl:nth-child(-n+4) { border-bottom: 1px dashed var(--line); }
  .game-controls .side-btn { order: 3; flex-basis: 100%; }
}

/* ---- Labelled content: every link says what it is and what happens ---- */
.kind { display: inline-flex; align-items: center; gap: 5px; padding: 3px 6px; border: 1px solid currentColor; font: 600 10px/1 "IBM Plex Mono", monospace; letter-spacing: .12em; text-transform: uppercase; font-style: normal; white-space: nowrap; vertical-align: 1px; }
.kind-article { color: var(--blue); }
.kind-game { color: var(--accent-ink); }
.kind-project { color: var(--good, #2f7a4f); }
.kind-book, .kind-app { color: var(--coffee, #6b3b22); }
:root[data-theme="dark"] .kind-book, :root[data-theme="dark"] .kind-app { color: var(--crema, #d4a373); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .kind-book, :root:not([data-theme="light"]) .kind-app { color: var(--crema, #d4a373); } }
.kind-link { color: var(--muted); }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 8px; }
.meta-row small { color: var(--faint); font: 500 11px/1.3 "IBM Plex Mono", monospace; letter-spacing: .06em; }
.cta { display: inline-block; margin-top: 10px; color: var(--accent-ink); font: 600 12px/1 "IBM Plex Mono", monospace; letter-spacing: .02em; }
a:hover .cta { text-decoration: underline; text-underline-offset: 3px; }
.now .k { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.now .cta { margin-top: 12px; }

/* ---- Runnable sections: a # comment, the command, then its output ---- */
section.chapter > .term-head { margin-bottom: 22px; }
.term-head h2 .hash { color: var(--accent); margin-right: .1em; }
.term-sub { margin: 8px 0 0; color: var(--muted); font: 400 14px/1.6 "IBM Plex Mono", monospace; max-width: 68ch; }
.term-sub a { color: inherit; }
.term-p { color: var(--accent); margin-right: 2px; }
.cmd-toggle { display: flex; align-items: baseline; gap: 10px; width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.cmd-toggle code { font: inherit; }
.cmd-text.typing::after { content: "▌"; color: #e07a55; }
.cmd-hint { margin-left: auto; align-self: center; padding: 4px 8px; border: 1px solid #3a3833; background: #1d1c1a; color: #e6e3d8; font: 600 11px/1.2 "IBM Plex Mono", monospace; letter-spacing: .02em; white-space: nowrap; }
.cmd-toggle:hover .cmd-hint, .cmd-toggle:focus-visible .cmd-hint { background: #e07a55; border-color: #e07a55; color: #fff; }
.next-prompt { margin: 22px 0 0; padding: 12px 14px; background: #0d0d0c; color: #e6e3d8; border: 1px solid #000; box-shadow: 3px 3px 0 var(--shadow, #000); font: 500 15px/1.3 "IBM Plex Mono", monospace; }
.next-prompt .term-p { color: #e07a55; }
.next-prompt + .cmd-out, .next-prompt + .story-wrap { margin-top: 22px; }
#projectList { margin-top: 14px; }
.story .short { display: none; }
.js .story-wrap:has(.story:not(.is-open)) .story-line { display: none; }
.js .cmd-out:not(.is-open) { display: none; }
.cmd-out.is-open { animation: cmd-in .35s steps(5); }
@keyframes cmd-in { from { opacity: 0; transform: translateY(-6px); } }
@media print { .js .cmd-out { display: block !important; } .next-prompt { display: none; } }
@media (max-width: 640px) { .cmd-toggle { flex-wrap: wrap; } .cmd-hint { margin-left: 0; } }
@media (prefers-reduced-motion: reduce) { .cmd-out.is-open { animation: none; } }

/* ---- Project cards ---- */
.pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pgrid + .pgrid { margin-top: 12px; }
.pcard { display: flex; flex-direction: column; gap: 8px; padding: 16px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.pcard .meta-row { margin: 0; }
.pcard b { font: 600 17px/1.3 "IBM Plex Sans", system-ui, sans-serif; }
.pcard .desc { color: var(--muted); font-size: 14px; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pcard-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pcard-foot small { color: var(--faint); font: 400 11px/1.4 "IBM Plex Mono", monospace; }
.pcard-foot .cta { margin: 0; }
.pcard:hover { border-color: var(--ink); }
.pcard:hover b { color: var(--accent-ink); }
.more-link { margin: 16px 0 0; font: 500 12px/1.4 "IBM Plex Mono", monospace; }
.more-link a { color: var(--muted); }
@media (max-width: 640px) { .pgrid { grid-template-columns: 1fr; } }

/* ---- Writing (latest posts) ---- */
.posts { display: grid; gap: 12px; }
.post { display: grid; grid-template-columns: 220px 1fr; background: var(--surface); border: 1px solid var(--line); text-decoration: none; overflow: hidden; }
.post.no-cover { grid-template-columns: 1fr; }
.post-cover { width: 100%; height: 100%; min-height: 150px; object-fit: cover; display: block; border-right: 1px solid var(--line); background: var(--sunken); }
.post-body { display: block; padding: 18px 20px; }
@media (max-width: 640px) { .post { grid-template-columns: 1fr; } .post-cover { aspect-ratio: 16 / 9; min-height: 0; height: auto; border-right: 0; border-bottom: 1px solid var(--line); } }
.post:hover { border-color: var(--ink); }
.post b { display: block; margin-top: 2px; font: 600 20px/1.3 var(--pixel); }
.post .desc { display: block; margin-top: 6px; color: var(--muted); font-size: 15px; line-height: 1.55; }
.post:hover b { color: var(--accent-ink); }

@media print {
  .term { display: none !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
}
