:root {
  --bg-color: #000;
  --text-color: #fff;
  --terminal-green: #4af626;
  --crt-flicker: #1210101a;
  --screen-inset: 2vmin;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-color);
  color: var(--text-color);
  font-family: "Press Start 2P", monospace;
}

/* ---------- CRT shell ---------- */

.tv-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-color);
  overflow: hidden;
}
/* the content layer carries the screen colour so it collapses with the picture */
.tv-screen.light .tv-content,
.tv-screen.desktop .tv-content {
  background: #ededed;
}
.tv-screen.boot .tv-content {
  background: #000;
}

.tv-content {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(12.5vh + var(--screen-inset)) calc(6.5vw + var(--screen-inset))
    calc(9vh + var(--screen-inset)) calc(7vw + var(--screen-inset));
  transform-origin: 50% 50%;
  will-change: transform;
}
.tv-screen.switching .stars {
  display: none;
}

/* ---------- transitions ---------- */

/* the glowing line / dot left behind when the picture collapses */
.tv-beam {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  width: 86%;
  height: 2px;
  border-radius: 50%;
  background: #fff;
  box-shadow:
    0 0 12px 4px #fff,
    0 0 40px 10px #bfe8ff;
  opacity: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* white bloom while the picture collapses / opens (cheaper than filter on content) */
.tv-flash {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: radial-gradient(ellipse at center, #fff 0%, #e8f6ff 45%, transparent 80%);
  opacity: 0;
  pointer-events: none;
}

.tv-static {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  opacity: 0;
  pointer-events: none;
}

/* brief RGB split and jitter right after the picture comes back */
.tv-content.glitch * { text-shadow: -2px 0 #ff003c99, 2px 0 #00e5ff99; }
.tv-content.glitch > * { animation: jitter 0.32s steps(5) both; }
@keyframes jitter {
  0% { transform: translateX(-6px) skewX(4deg); clip-path: inset(10% 0 55% 0); }
  25% { transform: translateX(5px); clip-path: inset(0 0 0 0); }
  50% { transform: translateX(-2px); clip-path: inset(40% 0 20% 0); }
  75% { transform: translateX(1px); clip-path: inset(0 0 0 0); }
  100% { transform: none; clip-path: none; }
}

/* terminal lines "print" one after another */
.reveal {
  animation: print-in 0.42s steps(10) backwards;
  animation-delay: calc(var(--i, 0) * 70ms + 180ms);
}
@keyframes print-in {
  from {
    clip-path: inset(0 100% 0 0);
    opacity: 0.2;
  }
  to {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
}

/* explorer icons pop in left-to-right */
.win-icon {
  animation: icon-in 0.22s steps(3) backwards;
  animation-delay: calc(var(--i, 0) * 55ms + 60ms);
}
@keyframes icon-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.85);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.win-window.opening {
  animation: win-open 0.24s steps(5) both;
}
.viewer-window {
  animation: win-open 0.2s steps(4) both;
}
@keyframes win-open {
  from {
    transform: scale(0.2);
    opacity: 0;
    outline: 2px dotted #000;
    outline-offset: 4px;
  }
  60% {
    opacity: 1;
  }
  to {
    transform: none;
    opacity: 1;
    outline: 2px dotted transparent;
  }
}

/* ---------- boot sequence ---------- */

.boot {
  width: 100%;
  height: 100%;
  padding: 0.5rem 1rem;
  text-align: left;
  font-size: clamp(0.5rem, 1.2vw, 0.72rem);
  line-height: 2;
  color: #cfcfcf;
  white-space: pre-wrap;
  cursor: pointer;
}
.boot .ok {
  color: var(--terminal-green);
}
.boot .brand {
  color: #fff;
}
.boot-bar {
  margin-top: 1rem;
  width: min(420px, 100%);
  height: 1.1em;
  padding: 2px;
  border: 2px solid #cfcfcf;
}
.boot-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: repeating-linear-gradient(
    90deg,
    var(--terminal-green) 0 10px,
    transparent 10px 13px
  );
}
.boot-skip {
  margin-top: 1.5rem;
  color: #666;
}

.stars {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: none;
}
.tv-screen.terminal .stars {
  display: block;
}

/* bezel: an SVG monitor case stretched over the viewport; the screen opening
   sits at left 7% / right 6.5% / top 12.5% / bottom 9% (see index.html) */
.tv-border {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}
.tv-border svg {
  display: block;
  width: 100%;
  height: 100%;
}

.tv-flicker {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: var(--crt-flicker);
  animation: flicker 0.15s infinite;
}

.tv-scanlines {
  position: fixed;
  inset: 0;
  z-index: 51;
  pointer-events: none;
  background:
    linear-gradient(#12101000 50%, #00000040 50%) 0 0 / 100% 2px,
    linear-gradient(90deg, #ff00000f, #00ff0005, #0000ff0f) 0 0 / 3px 100%;
}

@keyframes flicker {
  0% {
    opacity: 0.18;
  }
  10% {
    opacity: 0.45;
  }
  20% {
    opacity: 0.12;
  }
  40% {
    opacity: 0.5;
  }
  60% {
    opacity: 0.2;
  }
  80% {
    opacity: 0.6;
  }
  100% {
    opacity: 0.3;
  }
}

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

/* ---------- Landing ---------- */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 72%;
  color: #000;
  text-align: center;
}
.landing-title {
  font-size: clamp(1.6rem, 8vw, 6rem);
  letter-spacing: 0.02em;
  color: #111;
  text-shadow:
    4px 4px 0 #666,
    0 0 14px rgba(0, 0, 0, 0.35);
  margin-top: 10vh;
}
.landing-hint {
  font-family: inherit;
  font-size: clamp(0.8rem, 2vw, 1.2rem);
  letter-spacing: 0.1em;
  color: #000;
  background: none;
  border: 0;
  cursor: pointer;
}
.landing-cursor {
  animation: blinker 2s ease-in-out infinite;
  text-shadow: 0 0 8px #00000080;
}
.landing-footer {
  font-size: clamp(0.5rem, 1.2vw, 0.7rem);
  color: #222;
}

/* ---------- Windows 98 explorer ---------- */

.win-window {
  display: flex;
  flex-direction: column;
  width: 900px;
  max-width: 100%;
  height: 600px;
  max-height: 100%;
  color: #000;
  background: silver;
  border: 2px solid #404040;
  border-color: #fff #404040 #404040 #fff;
  box-shadow:
    4px 4px #000,
    inset 1px 1px #dfdfdf;
  text-align: left;
}
.win-titlebar {
  display: flex;
  flex-shrink: 0;
  justify-content: space-between;
  align-items: center;
  height: 28px;
  padding: 0 3px;
  background: linear-gradient(90deg, navy, #1084d0);
}
.win-title {
  color: #fff;
  font-size: 10px;
  letter-spacing: 0.03em;
  padding-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.win-controls {
  display: flex;
  gap: 2px;
}
.win-ctrl,
.win-toolbar-btn {
  font-family: inherit;
  color: #000;
  background: silver;
  border: 2px solid #404040;
  border-color: #fff #404040 #404040 #fff;
  cursor: pointer;
}
.win-ctrl {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 10px;
  line-height: 1;
}
.win-ctrl:active,
.win-toolbar-btn:active {
  border-color: #404040 #fff #fff #404040;
}
.win-toolbar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  background: silver;
  border-bottom: 1px solid gray;
}
.win-toolbar-btn {
  padding: 3px 10px;
  font-size: 9px;
}
.win-toolbar-btn:disabled {
  color: gray;
  cursor: default;
}
.win-address {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.win-address-label {
  font-size: 9px;
}
.win-address-path {
  flex: 1;
  min-width: 0;
  padding: 2px 6px;
  font-size: 9px;
  background: #fff;
  border: 2px solid #fff;
  border-color: gray #fff #fff gray;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.win-content {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  margin: 4px 6px;
  padding: 16px;
  overflow-y: auto;
  background: #fff;
  border: 2px solid #fff;
  border-color: gray #fff #fff gray;
}
.win-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 110px;
  padding: 12px 4px;
  font: inherit;
  color: inherit;
  text-align: center;
  text-decoration: none;
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
}
.win-icon:focus-visible {
  outline: 1px dotted #000;
  outline-offset: -3px;
}
.win-icon:hover {
  background: #0000aa14;
  border: 1px dotted #00a;
}
.win-icon.selected:not(:hover) {
  background: #00a;
  border: 1px dotted #fff;
  outline: 2px solid #00a;
  outline-offset: -2px;
}
.win-icon.selected:not(:hover) .win-icon-label {
  color: #fff;
  background: #00a;
}
.win-icon-img {
  font-size: 56px;
  line-height: 1;
}
.win-icon-label {
  font-size: 9px;
  padding: 1px 3px;
  word-break: break-word;
}
.win-statusbar {
  flex-shrink: 0;
  padding: 3px 8px;
  font-size: 9px;
  background: silver;
  border-top: 1px solid gray;
}

/* text / file viewer dialog */
.viewer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: inherit;
}
.viewer-window {
  display: flex;
  flex-direction: column;
  width: min(600px, 100%);
  max-height: 100%;
  color: #000;
  background: silver;
  border: 2px solid #404040;
  border-color: #fff #404040 #404040 #fff;
  box-shadow:
    4px 4px #000,
    inset 1px 1px #dfdfdf;
  text-align: left;
}
.viewer-text {
  margin: 8px 6px;
  padding: 12px;
  max-height: 58vh;
  overflow-y: auto;
  font-family: inherit;
  font-size: 10px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff;
  border: 2px solid #fff;
  border-color: gray #fff #fff gray;
}
.viewer-text a {
  color: #00a;
}
.viewer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 6px 8px;
}

/* ---------- Terminal pages ---------- */

.terminal-page {
  width: 100%;
  max-width: 860px;
  height: 100%;
  overflow-y: auto;
  padding: 1rem 1.25rem 3rem;
  text-align: left;
  font-size: clamp(0.55rem, 1.3vw, 0.75rem);
  line-height: 1.9;
  scrollbar-width: thin;
  scrollbar-color: var(--terminal-green) transparent;
}
.nav-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.4rem;
  padding: 0.5rem 0 1.5rem;
  font-size: clamp(0.5rem, 1.1vw, 0.65rem);
}
.nav-bar a {
  color: #aaa;
  text-decoration: none;
}
.nav-bar a:hover,
.nav-bar a.active {
  color: var(--terminal-green);
}
.nav-bar a.active::before {
  content: "> ";
}

.terminal-page h2 {
  margin: 1.6rem 0 0.8rem;
  font-size: clamp(0.8rem, 1.8vw, 1rem);
  font-weight: 400;
  color: var(--terminal-green);
}
.terminal-page h2:first-of-type {
  margin-top: 0.4rem;
}
.terminal-page h2::before {
  content: "> ";
}
.terminal-page p {
  margin-bottom: 0.6rem;
}
.hl {
  color: var(--terminal-green);
}
.dim {
  color: #9a9a9a;
}
.terminal-page ul {
  list-style: none;
}
.terminal-page li::before {
  content: "> ";
  color: var(--terminal-green);
}
.terminal-page a {
  color: var(--terminal-green);
}

.terminal-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .terminal-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.terminal-card {
  padding: 1.2rem;
  border: 1px solid var(--terminal-green);
  background: #4af62608;
}
.terminal-card-title {
  margin-bottom: 0.75rem;
  color: var(--terminal-green);
  font-size: clamp(0.65rem, 1.4vw, 0.8rem);
}
.terminal-card .meta {
  color: #9a9a9a;
  margin-bottom: 0.6rem;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.8rem;
}
.tag {
  padding: 0.15rem 0.45rem;
  font-size: 0.85em;
  color: var(--text-color);
  border: 1px solid #4af62666;
}

.contact-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.contact-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.contact-input {
  padding: 0.6rem 0.75rem;
  font-family: inherit;
  font-size: clamp(0.55rem, 1.2vw, 0.7rem);
  color: var(--terminal-green);
  background: #000;
  border: 1px solid var(--terminal-green);
  outline: none;
}
.contact-input::placeholder {
  color: #4af62680;
}
textarea.contact-input {
  min-height: 7rem;
  resize: vertical;
}
.contact-submit {
  align-self: flex-start;
  padding: 0.6rem 1.5rem;
  font-family: inherit;
  font-size: clamp(0.6rem, 1.3vw, 0.75rem);
  letter-spacing: 0.05em;
  color: var(--terminal-green);
  background: none;
  border: 1px solid var(--terminal-green);
  cursor: pointer;
}
.contact-submit:hover {
  background: #4af62622;
}
.nf-cursor {
  color: var(--terminal-green);
  animation: blinker 0.8s step-end infinite;
}

@media (max-width: 480px) {
  .win-icon {
    width: 75px;
  }
  .win-icon-img {
    font-size: 40px;
  }
  .win-icon-label {
    font-size: 7px;
  }
  .win-title {
    font-size: 8px;
  }
  .terminal-page {
    padding: 0.5rem 0.25rem 3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tv-flicker {
    display: none;
  }
  .reveal,
  .win-icon,
  .win-window.opening,
  .viewer-window,
  .tv-content.glitch > * {
    animation: none;
  }
}
