:root {
  color-scheme: dark;
  --mantle: #181825;
  --base: #1e1e2e;
  --surface: #313244;
  --text: #cdd6f4;
  --muted: #a6adc8;
  --blue: #89b4fa;
  --green: #a6e3a1;
  --red: #f38ba8;
  --mono: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { background: var(--base); color: var(--text); font-family: var(--mono); }
html, body { height: 100%; overflow: hidden; }
body { margin: 0; min-width: 280px; }
a { color: var(--blue); text-underline-offset: .2em; }
a:hover { color: #b4befe; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
::selection { background: #45475a; color: var(--text); }
.noscript-fallback, .fatal-copy { background: var(--base); color: var(--text); line-height: 1.7; margin: 0 auto; max-width: 42rem; padding: 2rem 1.25rem; }
.noscript-fallback h1, .fatal-copy h1 { font-size: 1.25rem; margin: 0 0 .75rem; }
.noscript-fallback ul, .fatal-copy ul { margin: .5rem 0; padding-left: 1.25rem; }
/* UX-08: the no-script/fatal-error fallbacks are full-document content, so
   they must scroll even though the terminal page locks body scrolling. */
html:has(.noscript-fallback), body:has(.noscript-fallback),
html:has(.fatal-copy), body:has(.fatal-copy) { height: auto; overflow: auto; }
/* SOL-010: terminal-themed 404 served under style-src 'self' (no inline styles). */
.error-page { line-height: 1.7; margin: 0 auto; max-width: 42rem; padding: clamp(1.25rem, 3vw, 2.5rem); }
.error-page h1 { font-size: 1.125rem; margin: 0 0 .5rem; }
.error-page p { margin: .5rem 0; }
.error-page .muted { color: var(--muted); }
.noscript-fallback .retry-button, .terminal-retry { background: var(--surface); border: 1px solid var(--blue); border-radius: .375rem; color: var(--text); cursor: pointer; font: inherit; margin-top: 1rem; padding: .5rem 1rem; }

.terminal-page { overflow: hidden; }
.terminal-shell {
  background: var(--base);
  display: flex;
  flex-direction: column;
  height: 100svh;
  height: 100dvh;
  position: relative;
}
/* Commands share a baseline; editing controls stay secondary. */
.quick-actions {
  align-items: center;
  border-bottom: 1px solid var(--surface);
  display: flex;
  flex: none;
  gap: .25rem;
  padding: .75rem clamp(1.25rem, 3vw, 2.5rem);
  padding-top: calc(.75rem + env(safe-area-inset-top));
  padding-left: calc(clamp(1.25rem, 3vw, 2.5rem) + env(safe-area-inset-left));
  padding-right: calc(clamp(1.25rem, 3vw, 2.5rem) + env(safe-area-inset-right));
  flex-wrap: wrap;
}
.quick-actions button {
  background: transparent;
  border: 0;
  border-radius: .25rem;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: .8125rem;
  min-height: 44px;
  padding: .5rem .625rem;
  touch-action: manipulation;
}
.portfolio-actions, .editing-actions { display: flex; flex-wrap: wrap; align-items: center; }
.editing-actions { margin-left: auto; }
.quick-actions button[data-quick-action^="__"] { color: var(--muted); }
.quick-actions button[data-quick-action="__read__"] { color: var(--blue); }
.quick-actions button:hover { background: var(--surface); color: var(--text); }
.quick-actions button:focus-visible { outline-offset: -2px; }
.quick-actions button[aria-expanded="true"] { background: var(--surface); }
.reading-mode {
  background: var(--base);
  inset: 0;
  position: absolute;
  z-index: 10;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.reading-mode[hidden] { display: none; }
.reading-scroll {
  line-height: 1.75;
  margin: 0 auto;
  max-width: 64rem;
  padding: 0 clamp(1.25rem, 5vw, 4rem) calc(3rem + env(safe-area-inset-bottom));
  padding-left: calc(clamp(1.25rem, 5vw, 4rem) + env(safe-area-inset-left));
  padding-right: calc(clamp(1.25rem, 5vw, 4rem) + env(safe-area-inset-right));
  font-size: .9375rem;
  overflow-wrap: anywhere;
}
.reading-topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(1rem + env(safe-area-inset-top)) 0 1rem;
  color: var(--muted);
  font-size: .8125rem;
}
.reading-intro { padding: 3rem 0; }
.reading-scroll h2 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.2;
  letter-spacing: -.055em;
  margin: 0 0 1rem;
  text-wrap: balance;
}
.reading-scroll h2:focus { outline: none; }
.reading-scroll h2:focus-visible { outline: 2px solid var(--blue); outline-offset: 8px; }
.reading-scroll .reading-role { font-size: 1.0625rem; color: var(--text); }
.reading-tagline { color: var(--muted); }
.reading-scroll section {
  display: grid;
  grid-template-columns: 8rem minmax(0, 1fr);
  gap: 2rem;
  padding: 2rem 0;
  border-top: 1px solid var(--surface);
}
.reading-scroll h3 { font-size: .8125rem; font-weight: 400; color: var(--muted); margin: .2rem 0 0; }
.reading-scroll h4 { font-size: 1.125rem; line-height: 1.5; margin: 0 0 .5rem; letter-spacing: -.025em; }
.reading-scroll p { margin: 0 0 .75rem; }
.reading-scroll p:last-child { margin-bottom: 0; }
.reading-scroll ul { list-style: none; margin: 0; padding: 0; }
.reading-projects { display: grid; gap: 2.5rem; }
.reading-technologies { color: var(--muted); font-size: .8125rem; }
.reading-links { display: flex; flex-wrap: wrap; gap: .25rem 1.5rem; }
.reading-links a { display: inline-flex; align-items: center; min-height: 44px; touch-action: manipulation; }
.reading-skills { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 1rem 1.5rem; margin: 0; }
.reading-skills dt { color: var(--text); }
.reading-skills dd { color: var(--muted); margin: 0; }
.reading-close {
  background: transparent;
  border: 1px solid var(--surface);
  border-radius: .25rem;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: .8125rem;
  min-height: 44px;
  padding: .5rem .875rem;
  touch-action: manipulation;
}
.reading-close:hover { background: var(--surface); }
.reading-footer { padding-top: 1rem; }
.terminal-viewport {
  background: var(--base);
  cursor: text;
  flex: 1;
  min-height: 0;
  overscroll-behavior: none;
  overflow: hidden;
  /* SOL-016: safe-area insets are ADDED to the designed padding on every
     side, independent of width, so notched landscape phones are covered
     without shrinking desktop spacing (insets are 0 where unsupported). */
  padding-bottom: calc(clamp(1.25rem, 3vw, 2.5rem) + var(--safe-area-inset-bottom, env(safe-area-inset-bottom)));
  padding-left: calc(clamp(1.25rem, 3vw, 2.5rem) + var(--safe-area-inset-left, env(safe-area-inset-left)));
  padding-right: calc(clamp(1.25rem, 3vw, 2.5rem) + var(--safe-area-inset-right, env(safe-area-inset-right)));
  padding-top: calc(clamp(1.25rem, 3vw, 2.5rem) + var(--safe-area-inset-top, env(safe-area-inset-top)));
  position: relative;
  touch-action: manipulation;
  width: 100%;
}
.terminal-screen {
  color: var(--terminal-fg, var(--text));
  font-family: var(--mono);
  /* SOL-012: rows must clear 24px uniformly so link targets fit the grid
     without overlap (15px floor x 1.6 = 24px; rows only grow from here). */
  font-size: clamp(.9375rem, .9rem + .2vw, 1.0625rem);
  font-variant-ligatures: none;
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  height: 100%;
  line-height: 1.6;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: pre;
  width: 100%;
}
.terminal-row { height: 1.6em; min-width: max-content; }
.terminal-cell { display: inline-block; min-width: 1ch; }
.terminal-cell.is-wide { width: 2ch; }
.terminal-cell.is-bold { font-weight: 700; }
.terminal-cell.is-italic { font-style: italic; }
.terminal-cell.is-dim { opacity: .58; }
.terminal-cell.is-underlined { text-decoration: underline; text-underline-offset: .16em; }
.terminal-cell.is-struck { text-decoration: line-through; }
.terminal-cell.is-underlined.is-struck { text-decoration: underline line-through; }
.terminal-cell.is-hidden { color: transparent !important; }
.terminal-link { color: var(--blue); line-height: inherit; }
/* Keep the cursor on the text baseline, excluding the row's leading. */
.terminal-cursor { background: var(--green) !important; color: var(--base) !important; line-height: 1.2; vertical-align: baseline; }
.terminal-cursor.is-blinking { animation: cursor-blink 1.1s step-end 4; }
/* The proxy textarea holds DOM focus. Indicate keyboard focus on the
   viewport without inflating the cursor or changing terminal geometry. */
.terminal-viewport:has(.terminal-input:focus-visible) { box-shadow: inset 0 0 0 1px var(--blue); }
.terminal-viewport:not(:focus-within) .terminal-cursor { animation: none; opacity: .45; }
.cursor-bar { box-shadow: inset 2px 0 var(--green); background: transparent !important; color: inherit !important; }
.cursor-underline { box-shadow: inset 0 -2px var(--green); background: transparent !important; color: inherit !important; }
.cursor-hollow { box-shadow: inset 0 0 0 1px var(--green); background: transparent !important; color: inherit !important; }
.terminal-input {
  bottom: .5rem;
  /* UX-07: the proxy input keeps its good attributes (label, autocomplete,
     autocapitalize, autocorrect, spellcheck) and gains a readable 16px size
     (no iOS focus zoom) plus caret-adjacent geometry: bottom-left of the
     usable rectangle, next to the painted prompt, so the browser follows the
     editing line — not a detached top corner — when the keyboard opens. */
  font-size: 16px;
  height: 1px;
  left: 1rem;
  opacity: .01;
  overflow: hidden;
  padding: 0;
  pointer-events: none;
  position: absolute;
  resize: none;
  width: 1px;
}
/* OMEN-009: the 1px textarea takes script focus after any click, so the
   global :focus-visible outline would draw a stray artifact box at its
   corner; the viewport :has() inset border above is the terminal's indicator. */
.terminal-input:focus-visible { outline: none; }
.cell-measure {
  font-family: var(--mono);
  font-size: clamp(.9375rem, .9rem + .2vw, 1.0625rem);
  font-variant-ligatures: none;
  font-weight: 400;
  left: -9999px;
  line-height: 1.6;
  position: fixed;
  top: -9999px;
  visibility: hidden;
}
.loading-copy { color: var(--text); line-height: 1.8; }
.loading-copy span { color: var(--muted); }
.has-error .terminal-screen { color: var(--red); }
@keyframes cursor-blink { 0%, 48% { opacity: 1; } 49%, 100% { opacity: .15; } }

@media (max-width: 720px) {
  .quick-actions { gap: 0; padding-top: calc(.375rem + env(safe-area-inset-top)); padding-bottom: .375rem; }
  .quick-actions button { padding-inline: .5rem; font-size: .75rem; }
  .portfolio-actions, .editing-actions { width: 100%; }
  .editing-actions { margin-left: 0; }
  .reading-intro { padding: 2rem 0; }
  .reading-scroll section { grid-template-columns: minmax(0, 1fr); gap: 1rem; padding: 1.75rem 0; }
  .reading-scroll h3 { color: var(--blue); }
  .reading-skills { grid-template-columns: minmax(0, 1fr); gap: .25rem; }
  .reading-skills dd { margin-bottom: 1rem; }
  .reading-skills dd:last-child { margin-bottom: 0; }
}

.sr-only { clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }
/* Mirrored output links (SOL-001) live inside the clipped accessible log, so
   unclipping only the focused child cannot escape the ancestor's 1px clip.
   Reveal the log itself as a visible panel while it contains focus, so
   sighted keyboard users get a perceivable focus target. */
[data-accessible-log]:focus-within {
  background: var(--surface);
  border: 1px solid var(--blue);
  border-radius: .5rem;
  bottom: 1rem;
  clip: auto;
  clip-path: none;
  color: var(--text);
  height: auto;
  left: 1rem;
  line-height: 1.6;
  max-height: 40vh;
  max-width: min(42rem, calc(100vw - 2rem));
  overflow: auto;
  padding: .75rem 1rem;
  position: fixed;
  white-space: normal;
  width: auto;
  z-index: 20;
}
/* Mirrored output links (SOL-001) become visible when focused so sighted
   keyboard users can see where Tab landed. */
[data-accessible-log] a {
  border-radius: .25rem;
  display: inline-block;
  line-height: 1.6;
  min-height: 24px;
  min-width: 24px;
  padding: .125rem .375rem;
}
[data-accessible-log] a:focus-visible,
[data-accessible-log] a:focus {
  background: var(--base);
  border-radius: .25rem;
  outline: 2px solid var(--blue);
  outline-offset: 3px;
  padding: .25rem .5rem;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .terminal-cursor { animation: none; }
}
