* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #000000; overflow: hidden; }
::selection { background: #FFCC00; color: #000000; }

@keyframes mblink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes mflicker {
  0% { opacity: 1; } 4% { opacity: 0.94; } 8% { opacity: 0.99; }
  12% { opacity: 0.96; } 16% { opacity: 1; } 35% { opacity: 0.98; }
  40% { opacity: 0.93; } 44% { opacity: 1; } 60% { opacity: 0.97; }
  64% { opacity: 1; } 80% { opacity: 0.96; } 84% { opacity: 0.99; } 100% { opacity: 1; }
}
@keyframes mslowblink { 0%, 70% { opacity: 1; } 71%, 100% { opacity: 0.25; } }
@keyframes catpulse {
  0% { text-shadow: 0 0 2px currentColor; }
  40% { text-shadow: 0 0 18px currentColor, 0 0 30px currentColor; }
  100% { text-shadow: 0 0 6px currentColor; }
}

#screen {
  position: fixed; inset: 0; background: #000000; overflow: hidden;
  font-family: 'Share Tech Mono', monospace; text-transform: uppercase;
  color: #FFFFFF; cursor: crosshair;
}
#screen.retro { animation: mflicker 6s steps(1) infinite; }

#bg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.screen-corner { position: absolute; width: 30px; height: 30px; z-index: 20; border: 0 solid #FFFFFF; }
.screen-corner-tl { top: 14px; left: 14px; border-top-width: 2px; border-left-width: 2px; }
.screen-corner-tr { top: 14px; right: 14px; border-top-width: 2px; border-right-width: 2px; }
.screen-corner-bl { bottom: 14px; left: 14px; border-bottom-width: 2px; border-left-width: 2px; }
.screen-corner-br { bottom: 14px; right: 14px; border-bottom-width: 2px; border-right-width: 2px; }

#scanlines {
  position: absolute; inset: 0; z-index: 50; pointer-events: none; display: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0) 0px, rgba(0,0,0,0) 2px, rgba(0,0,0,0.28) 3px, rgba(0,0,0,0.28) 4px);
}
#screen.retro #scanlines { display: block; }
#vignette {
  position: absolute; inset: 0; z-index: 51; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.55) 100%);
}

#status-bar {
  position: absolute; top: 14px; left: 60px; right: 60px; height: 32px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; letter-spacing: 2px; z-index: 20; flex-wrap: wrap;
}
.status-left, .status-right { display: flex; gap: 16px; align-items: center; }
.status-right { gap: 28px; }
#status-pulse {
  display: inline-block; width: 10px; height: 10px; background: #00FF00;
  animation: mslowblink 2s steps(1) infinite;
}
.status-dim { color: rgba(255,255,255,0.45); }
.status-active { color: #00FF00; }
#audio-toggle, #retro-toggle { cursor: pointer; color: rgba(255,255,255,0.45); }
#audio-toggle.on, #retro-toggle.on { color: #00FF00; }
#clock-group { display: flex; gap: 12px; }

@media (max-width: 640px) {
  .hide-mobile { display: none; }
  #clock-group { flex-direction: column; gap: 2px; align-items: flex-end; font-size: 11px; }
}

#panel-group {
  position: absolute; z-index: 30; display: flex; flex-direction: column; gap: 14px; min-height: 0;
  left: 50%; width: 780px; top: 78px; bottom: 54px; transform: translateX(-50%);
}
#panel-group.collapsed { bottom: auto; }
@media (max-width: 640px) {
  #panel-group { left: 16px; right: 16px; width: auto; top: 92px; bottom: 16px; transform: none; }
  #panel-group.collapsed { bottom: auto; }
}

.panel-corner { position: absolute; width: 12px; height: 12px; border: 0 solid #FFFFFF; }
.panel-corner-lg { width: 16px; height: 16px; }
.panel-corner-tl { top: -2px; left: -2px; border-top-width: 2px; border-left-width: 2px; }
.panel-corner-tr { top: -2px; right: -2px; border-top-width: 2px; border-right-width: 2px; }
.panel-corner-bl { bottom: -2px; left: -2px; border-bottom-width: 2px; border-left-width: 2px; }
.panel-corner-br { bottom: -2px; right: -2px; border-bottom-width: 2px; border-right-width: 2px; }

#legend {
  position: relative; background: rgba(0,0,0,0.86); border: 1px dashed rgba(255,255,255,0.65); flex-shrink: 0;
}
.panel-header {
  padding: 6px 12px; border-bottom: 1px dashed rgba(255,255,255,0.3);
  font-size: 11px; letter-spacing: 2px; color: rgba(255,255,255,0.55);
}
#legend-buttons { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
.legend-btn {
  cursor: pointer; padding: 7px 12px; border: 1px solid rgba(255,204,0,0.5);
  color: #FFCC00; font-size: 12px; letter-spacing: 1px; background: none;
  font-family: inherit; text-transform: uppercase;
}
.legend-btn:hover { background: rgba(255,204,0,0.15); }

#terminal {
  position: relative; background: rgba(0,0,0,0.88); border: 1px dashed rgba(255,255,255,0.65);
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
}
#terminal.collapsed { flex: 0 0 auto; }
#terminal.collapsed #terminal-body { display: none; }
.terminal-header {
  display: flex; justify-content: space-between; padding: 6px 14px;
  border-bottom: 1px dashed rgba(255,255,255,0.3); font-size: 11px;
  letter-spacing: 2px; color: rgba(255,255,255,0.55);
}
.terminal-header-right { display: flex; align-items: center; gap: 12px; }
#terminal-collapse-toggle { padding: 3px 8px; font-size: 10px; letter-spacing: 1px; }
#terminal-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column;
  padding: 12px 16px; font-size: 14px; line-height: 1.55;
}
/* Keep output anchored to the bottom when short, but scrollable when it overflows. */
#terminal-lines { margin-top: auto; }
#terminal-body::-webkit-scrollbar { width: 6px; }
#terminal-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); }
.term-line { white-space: pre-wrap; letter-spacing: 1px; }
.term-line a { color: inherit; text-decoration: underline; }
#prompt-cursor {
  display: inline-block; width: 9px; height: 17px; background: #FFFFFF;
  margin-left: 2px; align-self: center; animation: mblink 1.06s linear infinite;
}
#terminal-prompt { display: flex; }
.prompt-caret { color: #FFCC00; margin-right: 9px; }

#reticle {
  position: absolute; left: 0; top: 0; width: 132px; height: 164px; z-index: 15;
  will-change: transform; pointer-events: none; transform: translate(-400px, -400px);
}
#reticle-label {
  position: absolute; bottom: 100%; left: -1px; margin-bottom: 7px;
  font-size: 11px; letter-spacing: 2px; white-space: nowrap; color: var(--subj-color, rgba(255,255,255,0.55));
}
.reticle-box { position: absolute; inset: 0; border: 1px dashed var(--subj-color, rgba(255,255,255,0.55)); }
.corner { position: absolute; width: 12px; height: 12px; border: 0 solid var(--subj-color, rgba(255,255,255,0.55)); }
.corner-tl { top: -2px; left: -2px; border-top-width: 2px; border-left-width: 2px; }
.corner-tr { top: -2px; right: -2px; border-top-width: 2px; border-right-width: 2px; }
.corner-bl { bottom: -2px; left: -2px; border-bottom-width: 2px; border-left-width: 2px; }
.corner-br { bottom: -2px; right: -2px; border-bottom-width: 2px; border-right-width: 2px; }
.tick { position: absolute; background: var(--subj-color, rgba(255,255,255,0.55)); }
.tick-top { top: -1px; left: 50%; width: 2px; height: 7px; transform: translateX(-50%); }
.tick-bottom { bottom: -1px; left: 50%; width: 2px; height: 7px; transform: translateX(-50%); }
.tick-left { left: -1px; top: 50%; width: 7px; height: 2px; transform: translateY(-50%); }
.tick-right { right: -1px; top: 50%; width: 7px; height: 2px; transform: translateY(-50%); }

#cat-frame {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; font-family: 'Share Tech Mono', monospace; font-size: 10px; line-height: 1.15;
  color: var(--subj-color, rgba(255,255,255,0.55)); text-shadow: 0 0 8px currentColor;
  letter-spacing: 0; white-space: pre; text-transform: none;
}
#cat-frame.pulse { animation: catpulse 0.6s ease-out; }

.tw-window {
  position: absolute; top: 0; left: 0; width: 70px; height: 70px; z-index: 16;
  cursor: pointer; will-change: transform;
}
.tw-window.blinking { animation: mblink 0.3s steps(1) infinite; }
.tw-box { position: absolute; inset: 0; border: 1px dashed var(--tw-edge-color, rgba(255,255,255,0.4)); background: rgba(0,0,0,0.35); }
.tw-corner { position: absolute; width: 9px; height: 9px; border: 0 solid var(--tw-corner-color, rgba(255,255,255,0.4)); }
.tw-corner-tl { top: -2px; left: -2px; border-top-width: 2px; border-left-width: 2px; }
.tw-corner-tr { top: -2px; right: -2px; border-top-width: 2px; border-right-width: 2px; }
.tw-corner-bl { bottom: -2px; left: -2px; border-bottom-width: 2px; border-left-width: 2px; }
.tw-corner-br { bottom: -2px; right: -2px; border-bottom-width: 2px; border-right-width: 2px; }
.tw-tick { position: absolute; background: var(--tw-edge-color, rgba(255,255,255,0.4)); }
.tw-tick-top { top: -1px; left: 50%; width: 2px; height: 6px; transform: translateX(-50%); }
.tw-tick-bottom { bottom: -1px; left: 50%; width: 2px; height: 6px; transform: translateX(-50%); }
.tw-tick-left { left: -1px; top: 50%; width: 6px; height: 2px; transform: translateY(-50%); }
.tw-tick-right { right: -1px; top: 50%; width: 6px; height: 2px; transform: translateY(-50%); }
.tw-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 9px; letter-spacing: 1px; padding: 4px;
  color: var(--tw-corner-color, rgba(255,255,255,0.4));
}
.tw-window.scanning .tw-label,
.tw-window.revealed .tw-label { animation: catpulse 0.6s ease-out; }
.tw-window.scanning .tw-box,
.tw-window.revealed .tw-box { animation: boxpulse 0.6s ease-out; }

@keyframes boxpulse {
  0% { box-shadow: 0 0 2px var(--tw-edge-color, rgba(255,255,255,0.4)); }
  40% { box-shadow: 0 0 14px var(--tw-edge-color, rgba(255,255,255,0.4)), 0 0 22px var(--tw-edge-color, rgba(255,255,255,0.4)); }
  100% { box-shadow: 0 0 4px var(--tw-edge-color, rgba(255,255,255,0.4)); }
}

#error-panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 560px; max-width: calc(100% - 32px); z-index: 30;
  background: rgba(0,0,0,0.88); border: 1px dashed rgba(255,0,0,0.55);
  padding: 22px 26px; font-size: 14px; line-height: 1.65; letter-spacing: 1px;
}
#error-panel .panel-corner { border-color: #FF0000; }
#error-panel .error-code { color: #FF0000; }
#error-panel .error-dim { color: rgba(255,255,255,0.55); }
#error-panel .error-quote { color: #FFFFFF; margin: 14px 0; }
#error-panel .error-cursor {
  display: inline-block; width: 9px; height: 15px; background: #FF0000;
  vertical-align: text-bottom; margin-left: 2px; animation: mblink 1.06s linear infinite;
}
#error-panel .legend-btn { display: inline-block; text-decoration: none; margin-top: 18px; }

@keyframes bsfill { from { width: 0%; } to { width: 100%; } }

#boot-splash {
  position: fixed; inset: 0; z-index: 999; background: #000000;
  font-family: 'Share Tech Mono', monospace; text-transform: uppercase;
  padding: 60px; letter-spacing: 2px; font-size: 14px;
  opacity: 1; transition: opacity 350ms linear;
}
#boot-splash.fading { opacity: 0; }
#boot-lines { display: flex; flex-direction: column; gap: 10px; }
.boot-line { color: rgba(255,255,255,0.55); }
.boot-line-active { color: #00FF00; }
#boot-cursor {
  display: inline-block; width: 9px; height: 15px; background: #00FF00;
  margin-left: 6px; vertical-align: text-bottom; animation: mblink 1.06s linear infinite;
}
#boot-bar {
  position: absolute; left: 60px; bottom: 40px; width: 260px; height: 12px;
  border: 1px solid rgba(0,255,0,0.4); padding: 2px; max-width: calc(100% - 124px);
}
#boot-bar-fill {
  height: 100%; width: 0%; background: repeating-linear-gradient(
    90deg, #00FF00 0px, #00FF00 6px, rgba(0,0,0,0) 6px, rgba(0,0,0,0) 9px
  );
  animation-name: bsfill; animation-timing-function: linear; animation-fill-mode: forwards;
}
