/* ============================================
   tkbits.net — Green Phosphor CRT Terminal
   ============================================ */

:root {
  --phosphor: #7aff6b;
  --phosphor-dim: #0a7a3a;
  --phosphor-bright: #a6ffab;
  --bg: #0a0a0a;
  --scanline-opacity: 0.08;
  --vignette-opacity: 0.45;
  --font: 'Courier New', Courier, monospace;
  --font-size: clamp(9px, min(calc((100vw - 9.75rem) / 48), calc((100vh - 12.5rem) / 31.25)), 24px);
  --line-h: 1.25;
  --glow: 0 0 5px rgba(122, 255, 107, 0.35);
  --glow-strong: 0 0 10px rgba(122, 255, 107, 0.55), 0 0 22px rgba(122, 255, 107, 0.22);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--phosphor);
  font-family: var(--font);
  line-height: var(--line-h);
}

/* Font-size goes on body only so rem stays at the browser default (16px) */
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: var(--font-size);
  background: radial-gradient(ellipse at 50% 28%, #171a1c 0%, #0b0d0e 55%, #050606 100%);
}

/* Desk — flex row holding the monitor and any future objects */
#desk {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
}

/* Beige CRT monitor — IBM 5151-style monochrome display (pure CSS) */
#monitor {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#monitor-case {
  position: relative;
  padding: 1.5rem 1.7rem 1.3rem;
  border-radius: 10px;
  border: 1px solid #b3ab93;
  background:
    linear-gradient(90deg,
      #c6bfa9 0%, #d9d2bb 6%, #e7e1cb 30%,
      #ece6d1 50%, #e7e1cb 70%, #d9d2bb 94%, #c6bfa9 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -4px 9px rgba(120, 110, 85, 0.32),
    inset 4px 0 7px rgba(120, 110, 85, 0.15),
    inset -4px 0 7px rgba(120, 110, 85, 0.15),
    0 26px 55px rgba(0, 0, 0, 0.6),
    0 10px 20px rgba(0, 0, 0, 0.45);
}

/* Top ventilation grille — recessed row of vertical slots */
#vent-grille {
  width: 80%;
  height: 1rem;
  margin: 0 auto 0.95rem;
  border-radius: 3px;
  background: repeating-linear-gradient(
    90deg,
    #6f6753 0, #6f6753 2px,
    #cfc8b1 2px, #cfc8b1 5px
  );
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.5),
    inset 0 -1px 0 rgba(255, 255, 255, 0.45);
}

/* Front face — screen (left) + recessed control strip (right) */
#front-face {
  display: flex;
  align-items: stretch;
}

/* Recessed dark bezel the CRT glass sits in */
#screen-frame {
  position: relative;
  padding: 1.2rem;
  border-radius: 8px;
  background: #2b2823;
  box-shadow:
    inset 4px 4px 9px rgba(0, 0, 0, 0.65),
    inset -2px -2px 6px rgba(255, 255, 255, 0.05),
    inset 0 0 0 1px #1b1915,
    0 1px 0 rgba(255, 255, 255, 0.4);
}

/* Right-hand recessed control strip: badge on top, knobs below */
#control-panel {
  width: 2.9rem;
  margin-left: 1rem;
  padding: 0.95rem 0;
  border-radius: 6px;
  background: linear-gradient(180deg, #d7d1bc, #c6bfa8);
  box-shadow:
    inset 2px 0 5px rgba(0, 0, 0, 0.16),
    inset -2px 0 5px rgba(0, 0, 0, 0.16),
    inset 0 2px 6px rgba(0, 0, 0, 0.28),
    inset 0 -1px 0 rgba(255, 255, 255, 0.4);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
}

/* Spacers keep the badge up top while pushing the knobs to lower-middle */
.cp-spacer {
  flex-basis: 0;
  width: 0;
  height: 0;
}
.cp-spacer.top {
  flex-grow: 2.2;
}
.cp-spacer.bottom {
  flex-grow: 1;
}

/* "TKB Personal Computer Display" badge */
#ibm-badge {
  width: 2.15rem;
  padding: 0.4rem 0.25rem 0.35rem;
  border-radius: 3px;
  text-align: center;
  background: linear-gradient(180deg, #f3f0e5, #e1dcc6);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.3),
    inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

#ibm-badge .ibm-logo {
  display: block;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 800;
  font-size: 0.74rem;
  letter-spacing: 0.01em;
  color: #17150f;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

#ibm-badge .ibm-text {
  display: block;
  margin-top: 0.18rem;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 600;
  font-size: 0.33rem;
  line-height: 1.3;
  letter-spacing: 0.01em;
  color: #2c2a22;
}

/* Rotary adjustment knobs — brightness pointer + contrast ticks */
#knob-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.05rem;
}

.knob {
  position: relative;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #4a463c, #211e18 66%, #141109);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.28),
    inset 0 -2px 3px rgba(0, 0, 0, 0.6),
    0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Brightness knob — single indicator pointer */
.knob-bright::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 13%;
  width: 2px;
  height: 38%;
  transform: translateX(-50%);
  border-radius: 1px;
  background: #e9e4d5;
}

/* Contrast knob — ring of tick marks */
.knob-contrast::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-conic-gradient(from -6deg,
    rgba(233, 228, 213, 0.75) 0deg 4deg,
    transparent 4deg 36deg);
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 64% 90%, transparent 95%);
  mask: radial-gradient(circle, transparent 60%, #000 64% 90%, transparent 95%);
}

/* Flat box base + feet shadow */
#monitor-base {
  width: 90%;
  height: 0.6rem;
  margin: -0.15rem auto 0;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, #b7b09a 0%, #948c74 60%, #7d755f 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 9px 16px rgba(0, 0, 0, 0.45);
}

/* CRT Screen — 80x25 character grid (canonical MDA / Hercules text mode) */
#crt-screen {
  position: relative;
  width: 80ch;
  height: calc(25 * var(--line-h) * 1em);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 8px;
  text-shadow: var(--glow);
  background:
    radial-gradient(ellipse at 30% 15%, rgba(180, 255, 200, 0.06) 0%, transparent 42%),
    radial-gradient(ellipse at center, rgba(0, 255, 65, 0.04) 0%, transparent 65%);
  box-shadow:
    inset 0 0 46px rgba(0, 0, 0, 0.5),
    inset 0 0 8px rgba(0, 0, 0, 0.55),
    inset 0 2px 6px rgba(255, 255, 255, 0.04);
  animation: crtPowerOn 0.65s ease-out both;
}

/* Scanline Overlay */
#crt-screen::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, var(--scanline-opacity)) 2px,
    rgba(0, 0, 0, var(--scanline-opacity)) 4px
  );
  pointer-events: none;
  z-index: 10;
}

/* Vignette (dark edges) */
#crt-screen::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, var(--vignette-opacity)) 100%);
  pointer-events: none;
  z-index: 11;
}

/* Boot logo — streamed into output at boot, scrolls away with content */
.logo-wrapper {
  text-align: center;
  animation: lineIn 0.3s ease-out;
}

.logo-block {
  display: inline-block;
  text-align: left;
  white-space: pre;
  color: var(--phosphor-bright);
  text-shadow: var(--glow-strong);
  font-family: var(--font);
}

.output-line.logo-title {
  color: var(--phosphor-dim);
  text-align: center;
  letter-spacing: 0.15em;
}

/* Control Bar — touch-friendly buttons below the monitor */
#control-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  flex-shrink: 0;
  border-top: 1px solid rgba(122, 255, 107, 0.15);
  background: rgba(10, 10, 10, 0.6);
}

.ctrl-btn {
  font-family: var(--font);
  font-size: 0.9em;
  padding: 0.4em 0.9em;
  background: transparent;
  border: 1px solid var(--phosphor-dim);
  color: var(--phosphor);
  cursor: pointer;
  text-shadow: var(--glow);
  transition: border-color 0.2s, color 0.2s, text-shadow 0.2s;
  border-radius: 2px;
  letter-spacing: 0.05em;
}

.ctrl-btn:hover {
  border-color: var(--phosphor-bright);
  color: var(--phosphor-bright);
  text-shadow: var(--glow-strong);
}

.ctrl-btn:active {
  background: rgba(122, 255, 107, 0.1);
  border-color: var(--phosphor-bright);
}

/* Output Area — remaining rows */
#output-area {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#output-area::-webkit-scrollbar {
  display: none;
}

.output-line {
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: calc(var(--line-h) * 1em);
  animation: lineIn 0.14s ease-out;
}

.output-line.header {
  color: var(--phosphor-bright);
  text-shadow: var(--glow);
  font-weight: bold;
}

.output-line.section {
  color: var(--phosphor);
  text-shadow: var(--glow);
}

.output-line.dim {
  color: var(--phosphor-dim);
}

.output-line.link {
  color: var(--phosphor-bright);
}

.output-line.error {
  color: #ff4444;
  text-shadow: 0 0 5px rgba(255, 68, 68, 0.3);
}

.output-line.success {
  color: #44ff44;
}

.output-line.command-ref {
  color: var(--phosphor-bright);
  cursor: pointer;
}

.output-line.command-ref:hover {
  text-shadow: var(--glow-strong);
}

/* Input Area — bottom row, continuous with output */
#input-area {
  display: flex;
  align-items: baseline;
  height: calc(var(--line-h) * 1em);
  line-height: var(--line-h);
  flex-shrink: 0;
}

#prompt {
  color: var(--phosphor-bright);
  text-shadow: var(--glow);
  margin-right: 0.5em;
  white-space: nowrap;
}

#command-input {
  flex: 1;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--phosphor);
  outline: none;
  font: inherit;
  padding: 0;
  caret-color: var(--phosphor);
  text-shadow: var(--glow);
}

#command-input::placeholder {
  color: var(--phosphor-dim);
  opacity: 0.5;
}

/* ASCII Box Drawing */
.ascii-border {
  color: var(--phosphor-dim);
}

/* WarGames board — centered via text-align, not space-padding */
.output-line.board,
.output-line.board-header,
.output-line.board-winner,
.output-line.board-draw,
.output-line.board-hint {
  text-align: center;
  white-space: pre;
}

.output-line.board {
  color: var(--phosphor);
  text-shadow: var(--glow);
}

.output-line.board-header {
  color: var(--phosphor-dim);
}

.output-line.board-winner {
  color: var(--phosphor-bright);
  text-shadow: var(--glow-strong);
  font-weight: bold;
}

.output-line.board-draw {
  color: var(--phosphor-dim);
}

.output-line.board-hint {
  color: var(--phosphor-dim);
}

/* Blog Entry Styling */
.blog-entry {
  margin: 1rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--phosphor-dim);
}

.blog-entry .date {
  color: var(--phosphor-dim);
  font-size: 0.85em;
}

.blog-entry .title {
  color: var(--phosphor-bright);
  text-shadow: var(--glow);
  margin-top: 0.25rem;
}

/* Responsive — phone: strip the monitor bezel, fill the screen */
@media (max-width: 600px) {
  :root {
    /* No bezel on mobile — font can use nearly the full viewport */
    --font-size: clamp(9px, min(calc(100vw / 48), calc((100dvh - 5rem) / 31.25)), 24px);
  }

  body {
    height: 100dvh;
    overflow-x: auto;
  }

  #desk {
    gap: 0;
    justify-content: flex-start;
    align-items: stretch;
  }

  #monitor {
    width: 100%;
  }

  /* Strip the beige monitor — just show the screen */
  #monitor-case {
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    border-radius: 0;
    width: 100%;
  }

  #front-face {
    display: block;
  }

  #screen-frame {
    padding: 0;
    border-radius: 0;
    background: var(--bg);
    box-shadow: none;
    width: 100%;
  }

  #vent-grille, #control-panel, #monitor-base {
    display: none;
  }

  #crt-screen {
    border-radius: 0;
    /* 48em matches the font formula's 48 divisor exactly, so the screen
       fits 100vw. 80ch would overflow because ch (actual '0' width) is
       slightly wider than the 0.6em the formula assumes. */
    width: 100vw;
    box-shadow: none;
  }

  #control-bar {
    padding: 0.4rem 0.4rem;
    gap: 0.35rem;
  }

  .ctrl-btn {
    font-size: 0.85em;
    padding: 0.45em 0.7em;
  }
}

/* One-time CRT power-on */
@keyframes crtPowerOn {
  0% { transform: scaleY(0.004); filter: brightness(2.5); }
  30% { transform: scaleY(0.004); filter: brightness(2.5); }
  75% { transform: scaleY(0.92); filter: brightness(1.5); }
  100% { transform: scaleY(1); filter: brightness(1); }
}

/* New output lines fade in instead of popping */
@keyframes lineIn {
  from { opacity: 0; }
}

/* Slow scanline sweep (subtle motion, not flicker) */
.crt-sweep {
  position: absolute;
  left: 0;
  top: -25%;
  width: 100%;
  height: 22%;
  background: linear-gradient(to bottom, transparent, rgba(0, 255, 65, 0.035) 50%, transparent);
  pointer-events: none;
  z-index: 12;
  animation: crtSweep 9s linear infinite;
}

@keyframes crtSweep {
  from { transform: translateY(0); }
  to { transform: translateY(668%); }
}

/* Gentle opacity pulse (reused by JS "press any key to exit" hints) */
@keyframes ledPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Curved glass glare over the tube */
.crt-glare {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 90% at 22% 8%, rgba(255, 255, 255, 0.10) 0%, rgba(255, 255, 255, 0.04) 32%, transparent 58%),
    linear-gradient(115deg, transparent 32%, rgba(255, 255, 255, 0.05) 46%, transparent 60%);
  pointer-events: none;
  z-index: 9;
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  #crt-screen,
  .output-line,
  .crt-sweep {
    animation: none;
  }
  .crt-sweep {
    display: none;
  }
}

/* Selection color */
::selection {
  background: var(--phosphor);
  color: var(--bg);
}