/*
  terminal.css
  Originally based on bombcheck/Fallout.Terminal-Hacking (no license)
  Heavily modified and re-themed by shamimsulaiman.com (Foundation Terminal)
  For educational and non-commercial use.
  Includes references inspired by Fallout™. All Fallout trademarks are property of Bethesda Softworks.
  --------------------------
  1. Layout & Wrapper
  2. Terminal Frame & Screen
  3. Power States & Internal Terminal UI
  4. Markdown Content
  5. CRT Overlay System
  6. Animations
  7. Responsive Tweaks
*/

/* ============================================================
   1. LAYOUT & WRAPPER
   handles overall page structure and centering for terminal
   ============================================================ */

body {
  display: flex; /* sets up vertical layout */
  flex-direction: column;
  min-height: 100vh;
}

/* main page container when terminal is shown */
main#main:has(.terminal-page) {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 0;
  width: 100%;
  flex: 1;
}

/* wrapper for the full terminal page */
.terminal-page {
  display: flex;
  flex-direction: column;
  align-items: center;    /* center horizontally */
  justify-content: center;/* center vertically */
  min-height: 80vh;
  width: 100%;
  padding: 2rem 0;
  background: transparent;
  color: #00ff00;
  font-family: monospace;
  box-sizing: border-box;
}

/* scrollable wrapper around monitor frame for small screens */
.terminal-wrapper {
  width: 100%;
  overflow-x: auto; /* allows horizontal scroll on small displays */
  overflow-y: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  box-sizing: border-box;
}

/* ============================================================
   2. TERMINAL FRAME & SCREEN
   outer bezel, screen window, and power button placement
   ============================================================ */

/* main monitor frame */
#terminal-background {
  background-image: url('/assets/terminal/img/monitorborder.png');
  width: 930px;
  height: 700px;
  margin: 0 auto;
  position: relative;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transition: background-image 0s, filter 0.4s ease; /* prevents flicker */
}

/* dark frame when powered off */
#terminal-background.off {
  background-image: url('/assets/terminal/img/monitorborder-off.png');
}

/* inner terminal screen */
#terminal {
  width: 750px;
  height: 460px;
  background-color: #153021;
  font-family: monospace;
  font-weight: bold;
  color: #33dd88;
  font-size: 12pt;
  overflow: hidden;
  z-index: 10;
  position: absolute;
  top: 78px;
  left: 50.4%;
  transform: translateX(-50%);
  box-shadow:
    inset 0 0 40px rgba(0, 255, 0, 0.15),
    inset 0 0 120px rgba(0, 255, 0, 0.07),
    0 0 25px rgba(0, 255, 0, 0.15);
  transition: background-color 0.5s ease, box-shadow 0.5s ease;
}

/* screen appearance when monitor is off */
#terminal-background.off #terminal {
  background-color: #0a0a0a;
  background: radial-gradient(circle at center, #111 0%, #000 100%);
  box-shadow:
    inset 0 0 10px rgba(0, 255, 0, 0.02),
    inset 0 0 20px rgba(0, 255, 0, 0.02),
    0 0 0 rgba(0, 255, 0, 0);
}

/* clickable power button overlay */
#powerbutton {
  position: absolute;
  bottom: 45px;
  right: 155px;
  width: 60px;
  height: 60px;
  cursor: pointer;
  z-index: 100;
}

/* ============================================================
   3. POWER STATES & INTERNAL TERMINAL ELEMENTS
   handles power transitions and core interface grid
   ============================================================ */

/* container inside terminal for game interface */
#terminal-interior {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 11;
}

/* word grid columns */
.column {
  float: left;
  margin-top: 30px;
  height: 350px;
  top: 90px;
  margin-left: 20px;
}

/* pointer column */
.pointers {
  width: 51px;
}

/* word column */
.words {
  width: 171px;
}

/* interactive character blocks */
.character {
  padding-left: 2px;
  padding-right: 2px;
  cursor: pointer;
}

/* hover highlight for characters */
.character-hover {
  background-color: #33dd88;
  color: #112211;
}

/* console block on right side */
#console {
  left: 540px;
  width: 10%;
  letter-spacing: 3px;
  float: left;
  margin-left: 10px;
  margin-top: -12px;
}

/* output area for results or system messages */
#output {
  width: 187px;
  height: 300px;
  letter-spacing: 3px;
  float: left;
  margin-left: 10px;
  margin-top: 30px;
}

/* info and attempts headers */
#info {
  width: 80%;
  height: 60px;
  margin-left: 20px;
  position: relative;
  top: 20px;
}

#attempts {
  width: 80%;
  height: 30px;
  margin-left: 20px;
  position: relative;
  top: 20px;
}

/* column offsets */
#column1 { left: 20px; }
#column2 { left: 91px; }
#column3 { left: 282px; }
#column4 { left: 353px; }

/* admin alert section */
#adminalert {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  text-align: center;

  color: #ff3333;
  font-size: 1.5em;
  line-height: 1.5em;
  letter-spacing: 1px;
  animation: alertPulse 2s infinite;
}

.alert-text {
  display: inline-block;
}

/* difficulty flashing */
.alert-flash {
  animation: alertPulse 0.8s ease-in-out 2; /* flash twice */
}

/* ============================================================
   4. MARKDOWN CONTENT
   used when .md files are loaded inside the terminal
   ============================================================ */

/* zoom in by pinch */
html, body, #terminal, #markdown-content {
  -webkit-text-size-adjust: none !important;
  text-size-adjust: none !important;
}
.terminal-page {
  touch-action: pinch-zoom;
}

#markdown-content {
  font-family: monospace;
  font-weight: bold;
  color: #33dd88;
  line-height: 1.3;
  padding: 20px;
  white-space: pre !important;
  word-break: normal !important;
  overflow-wrap: normal !important;
  text-wrap: nowrap !important;
  font-size: 14px;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  padding-bottom: 40px;
  box-sizing: border-box;
  scroll-padding-bottom: 60px;
  scrollbar-width: thin;
  scrollbar-color: #33dd88 #153021;
}

/* scrollbar for Chromium-based browsers */
#markdown-content::-webkit-scrollbar {
  width: 6px;
}

#markdown-content::-webkit-scrollbar-track {
  background: #153021;
}

#markdown-content::-webkit-scrollbar-thumb {
  background: #33dd88;
  border-radius: 4px;
}

#markdown-content::-webkit-scrollbar-thumb:hover {
  background: #33dd88;
}

/* preformatted text centering */
#markdown-content pre {
  text-align: center;
}

/* ============================================================
   5. CRT OVERLAY SYSTEM
   adds scanlines, tint, and flicker effects over the terminal
   ============================================================ */

/* make sure the monitor frame provides coordinate space */
#terminal-background {
  position: relative;
}

/* overlay and moving scanline layers */
.crt-overlay,
.crt-scanline {
  position: absolute;
  top: 78px;
  left: 50.4%;
  transform: translateX(-50%);
  width: 750px;
  height: 460px;
  pointer-events: none;
  overflow: hidden;
  z-index: 20; /* above the game display */
  box-sizing: border-box;
  will-change: transform, opacity;
}

/* static scanlines + RGB sub-pixel tint */
.crt-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(#101010 50%, rgba(16,16,16,0.2) 50%),
    linear-gradient(
      90deg,
      rgba(255,0,0,0.03),
      rgba(0,255,0,0.02),
      rgba(0,0,255,0.03)
    );
  background-size: 100% 3px, 6px 100%;
  opacity: 0.4;
  z-index: 1;
}

/* subtle flicker layer */
.crt-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(16,16,16,0.2);
  animation: flicker 0.35s infinite;
  opacity: 0.05;
  z-index: 2;
}

/* moving horizontal sweep band */
.crt-scanline {
  background: linear-gradient(
    to bottom,
    rgba(0, 255, 0, 0) 0%,
    rgba(0, 255, 0, 0.25) 50%,
    rgba(0, 255, 0, 0) 100%
  );
  background-repeat: no-repeat;
  background-size: 100% 80px;
  opacity: 0;
  animation:
    sweep 6s linear infinite,
    fade 6s ease-in-out infinite;
}

/* hide CRT layers when powered off */
#terminal-background.off .crt-overlay,
#terminal-background.off .crt-scanline {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.1s ease-in-out;
}

/* show when powered on */
#terminal-background:not(.off) .crt-overlay,
#terminal-background:not(.off) .crt-scanline {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.1s ease-in-out;
}

/* ============================================================
   6. ANIMATIONS
   sweep band, fade transitions, and screen flicker
   ============================================================ */

/* band movement from top to bottom */
@keyframes sweep {
  0%   { background-position: 0% 0%; }
  100% { background-position: 0% 100%; }
}

/* fade-in/out as the band travels */
@keyframes fade {
  0%, 100% { opacity: 0; }
  10%, 90% { opacity: 0.25; }
  50%      { opacity: 0.35; }
}

/* simplified flicker pattern */
@keyframes flicker {
  0%  { opacity: 0.2; }
  25% { opacity: 0.35; }
  50% { opacity: 0.15; }
  75% { opacity: 0.4; }
  100%{ opacity: 0.25; }
}

/* terminal game difficulty flashing */
@keyframes alertPulse {
  0%   { opacity: 1; text-shadow: 0 0 8px #ff3333; }
  50%  { opacity: 0.3; text-shadow: 0 0 16px #ff6666; }
  100% { opacity: 1; text-shadow: 0 0 8px #ff3333; }
}

/* ============================================================
   7. RESPONSIVE TWEAKS
   scaling and scroll adjustments for smaller screens
   ============================================================ */

/* tablets / smaller laptops */
@media (max-width: 1024px) {
  #terminal-background {
    transform: scale(0.85);
    transform-origin: top center;
  }
}

/* portrait tablets / large phones */
@media (max-width: 768px) {
  #terminal-background {
    transform: scale(0.65);
    transform-origin: top center;
  }
}

/* small phones */
@media (max-width: 480px) {
  #terminal-background {
    transform: scale(0.5);
    transform-origin: top center;
  }

  .terminal-wrapper {
    padding: 1rem 2rem; /* extra side padding */
  }
}

