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

:root {
  --fg: #c8c8c8;
  --fg-bright: #e0e0e0;
  --fg-muted: #606060;
  --accent: #00ff41;
  --accent-dim: #00cc33;
  --bg: #0c0c0c;
  --card-bg: #111111;
  --border: #2a2a2a;
  --hover-bg: #1a1a1a;
  /* ASCII-art tint (used by ascii.js for low-saturation pixels) */
  --ascii-r: 60;
  --ascii-g: 255;
  --ascii-b: 80;
}

/* ── Commodore 64 theme — light blue on dark blue ──────── */
[data-theme="c64"] {
  --fg: #a5a1f7;
  --fg-bright: #d4d2ff;
  --fg-muted: #6c5eb5;
  --accent: #b5b1ff;
  --accent-dim: #8780f6;
  --bg: #3e31a2;
  --card-bg: #483aaa;
  --border: #6c5eb5;
  --hover-bg: #5d52bb;
  --ascii-r: 135;
  --ascii-g: 130;
  --ascii-b: 255;
}

/* ── Amstrad CPC 6128 theme — GT65 phosphor green ──────── */
[data-theme="amstrad"] {
  --fg: #8ee54a;
  --fg-bright: #c4ff7a;
  --fg-muted: #3a6e1a;
  --accent: #b3e632;
  --accent-dim: #7eb520;
  --bg: #000800;
  --card-bg: #001500;
  --border: #2a4510;
  --hover-bg: #0a1a0a;
  --ascii-r: 150;
  --ascii-g: 230;
  --ascii-b: 60;
}

html {
  font-family: "JetBrains Mono", "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 18px;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* subtle CRT scanline overlay */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
}

main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

/* two-column layout */
.layout {
  display: flex;
  gap: 1.5rem;
  align-items: stretch;
  max-width: 1100px;
  width: 100%;
  height: calc(100dvh - 6rem);
  max-height: 700px;
}

/* terminal window */
.terminal {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    0 0 40px rgba(0, 255, 65, 0.03),
    0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.terminal--portrait {
  flex: 0 0 auto;
  width: 460px;
}

.terminal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--hover-bg);
  border-bottom: 1px solid var(--border);
}

.dots {
  display: flex;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot--red { background: #ff5f57; }
.dot--yellow { background: #febc2e; }
.dot--green { background: #28c840; }

.terminal-title {
  color: var(--fg-bright);
  opacity: 0.65;
  font-size: 0.75rem;
}

.terminal-body {
  padding: 1.75rem 1.5rem;
  background: var(--card-bg);
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* portrait image */
.terminal-body--portrait {
  padding: 0;
  overflow: hidden;
  position: relative;
  background: #000;
  height: 500px;
}

#ascii-art {
  width: 100%;
  height: 100%;
  flex: 1;
  margin: 0;
  padding: 0;
  font-family: "JetBrains Mono", "SF Mono", "Fira Code", monospace;
  font-size: 6px;
  line-height: 1.0;
  letter-spacing: 0;
  overflow: hidden;
  background: #000;
  animation: crt-flicker 3s ease-out forwards;
}

/* CRT power-on flicker */
@keyframes crt-flicker {
  0%   { opacity: 0; filter: brightness(0) saturate(0); }
  3%   { opacity: 0; }
  4%   { opacity: 0.6; filter: brightness(2) saturate(0); }
  5%   { opacity: 0; }
  8%   { opacity: 0; }
  9%   { opacity: 0.4; filter: brightness(1.8) saturate(0); }
  10%  { opacity: 0; }
  15%  { opacity: 0; }
  16%  { opacity: 0.7; filter: brightness(1.5) saturate(0.3); }
  18%  { opacity: 0.1; filter: brightness(0.3); }
  22%  { opacity: 0.1; }
  23%  { opacity: 0.8; filter: brightness(1.3) saturate(0.5); }
  25%  { opacity: 0.3; filter: brightness(0.5); }
  30%  { opacity: 0.5; filter: brightness(0.8) saturate(0.6); }
  35%  { opacity: 0.9; filter: brightness(1.2) saturate(0.8); }
  38%  { opacity: 0.4; filter: brightness(0.6); }
  42%  { opacity: 0.85; filter: brightness(1.1) saturate(0.9); }
  50%  { opacity: 0.95; filter: brightness(1.0) saturate(1); }
  55%  { opacity: 0.7; filter: brightness(0.85); }
  60%  { opacity: 1; filter: brightness(0.95); }
  70%  { opacity: 0.92; filter: brightness(0.88); }
  80%  { opacity: 1; filter: brightness(0.9); }
  100% { opacity: 1; filter: brightness(0.9); }
}

/* horizontal glitch bars that sweep during flicker */
.terminal-body--portrait::after,
.terminal-body--portrait .glitch-bar-2,
.terminal-body--portrait .glitch-bar-3 {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(0, 255, 65, 0.15);
  box-shadow: 0 0 12px rgba(0, 255, 65, 0.3);
  pointer-events: none;
  z-index: 2;
}

.terminal-body--portrait::after {
  animation: crt-sweep-1 3s ease-out forwards;
}

.glitch-bar-2 {
  height: 2px !important;
  background: rgba(0, 255, 65, 0.1) !important;
  animation: crt-sweep-2 3s ease-out forwards;
}

.glitch-bar-3 {
  height: 4px !important;
  background: rgba(0, 255, 65, 0.08) !important;
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.2) !important;
  animation: crt-sweep-3 3s ease-out forwards;
}

@keyframes crt-sweep-1 {
  0%   { top: 0%; opacity: 0; }
  4%   { top: 30%; opacity: 1; }
  5%   { opacity: 0; }
  9%   { top: 50%; opacity: 1; }
  10%  { opacity: 0; }
  16%  { top: 20%; opacity: 0.8; }
  18%  { opacity: 0; }
  23%  { top: 60%; opacity: 0.7; }
  25%  { opacity: 0; }
  35%  { top: 40%; opacity: 0.5; }
  50%  { top: 70%; opacity: 0.3; }
  70%  { top: 90%; opacity: 0.1; }
  100% { top: 100%; opacity: 0; }
}

@keyframes crt-sweep-2 {
  0%   { top: 100%; opacity: 0; }
  6%   { top: 70%; opacity: 0.8; }
  7%   { opacity: 0; }
  12%  { top: 40%; opacity: 0.9; }
  13%  { opacity: 0; }
  20%  { top: 80%; opacity: 0.6; }
  22%  { opacity: 0; }
  30%  { top: 25%; opacity: 0.5; }
  40%  { top: 55%; opacity: 0.3; }
  55%  { top: 15%; opacity: 0.2; }
  75%  { top: 5%; opacity: 0.1; }
  100% { top: 0%; opacity: 0; }
}

@keyframes crt-sweep-3 {
  0%   { top: 50%; opacity: 0; }
  3%   { top: 45%; opacity: 0; }
  8%   { top: 65%; opacity: 0.7; }
  9%   { opacity: 0; }
  14%  { top: 35%; opacity: 0.6; }
  16%  { opacity: 0; }
  24%  { top: 75%; opacity: 0.5; }
  26%  { opacity: 0; }
  33%  { top: 50%; opacity: 0.4; }
  45%  { top: 85%; opacity: 0.2; }
  65%  { top: 95%; opacity: 0.1; }
  100% { top: 100%; opacity: 0; }
}

/* terminal output lines */
.output {
  margin-bottom: 0.35rem;
}

.line {
  margin-bottom: 0.2rem;
  line-height: 1.5;
}

.prompt {
  color: var(--accent);
  margin-right: 0.5rem;
}

h1.result {
  font-size: 1rem;
  font-weight: 500;
  color: var(--fg-bright);
  padding-left: 1.25rem;
  margin-bottom: 0.2rem;
}

.result.muted {
  color: var(--fg-muted);
  padding-left: 1.25rem;
  margin-bottom: 0.2rem;
}

/* link list */
.links {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 0.5rem;
}

.links a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.625rem;
  border-radius: 4px;
  color: var(--fg);
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}

.links a:hover {
  background: var(--hover-bg);
  color: var(--accent);
}

.links a:hover .prefix {
  color: var(--accent);
}

.links a:hover .path {
  color: var(--fg-muted);
}

.prefix {
  color: var(--accent-dim);
  flex-shrink: 0;
}

.label {
  color: var(--fg-bright);
  min-width: 7rem;
}

.path {
  color: var(--fg-muted);
  font-size: 0.8rem;
}

/* interactive input */
.input-line {
  display: flex;
  align-items: center;
  line-height: 1.6;
  margin-top: 0.2rem;
  flex-shrink: 0;
  position: relative;
}

#terminal-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
  margin: 0;
  font-size: inherit;
  font-family: inherit;
}

.input-mirror-text {
  color: var(--fg);
  white-space: pre;
}

.block-cursor {
  display: inline-block;
  width: 0.55rem;
  height: 1.1rem;
  background: var(--accent);
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

#terminal-output {
  flex: 1;
}

/* screen-reader-only: visible to crawlers, hidden visually */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* footer */
footer {
  text-align: center;
  padding: 1.5rem 2rem;
  color: var(--fg-muted);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

/* mobile — stack vertically */
@media (max-width: 800px) {
  .layout {
    flex-direction: column;
    align-items: stretch;
    height: auto;
    max-height: none;
  }
  .terminal {
    width: 100%;
    max-height: 60dvh;
  }
  .terminal--portrait {
    width: 100%;
    max-width: none;
    order: -1;
    height: 250px;
    max-height: 40dvh;
  }
  .terminal-body--portrait {
    height: auto;
    min-height: 0;
    flex: 1;
  }
  html { font-size: 15px; }
  main { padding: 1rem; }
  .terminal-body { padding: 1rem; }
  .path { display: none; }
}
