/* CSS Variables for theme colors and font sizes */
:root {
  --color-bg: #111;
  --color-fg: #eee;
  --color-accent: #0f0;
  --color-input-bg: #0f0;
  --color-input-fg: #000;
  --font-family-mono: 'Courier New', Courier, monospace;
  --font-size-base: 16px;
  --space-xs: 0.25em;
  --space-sm: 0.5em;
  --space-md: 1em;
  --space-lg: 2em;
}

body {
  background: var(--color-bg);
  color: var(--color-fg);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-base);
}
/* Blinking block caret used across the app */
@keyframes caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.block-caret {
  display: inline-block;
  width: 1ch;
  height: 1em;
  line-height: 1;
  background: #0f0;
  color: #000; /* if we ever print a glyph inside */
  animation: caret-blink 1s steps(1, start) infinite;
}
/* Hide native I-beam caret on elements that opt-in to block caret */
.use-block-caret {
  caret-color: transparent !important;
}
/* Also hide native caret on all input-box class elements */
.input-box {
  caret-color: transparent !important;
}
/* #bottom-bar display set to none initially; game.js shows it after login */
/* === Restored from index.html.backup === */
#locked-display {
  display: none;
  padding: 0;
  margin: 0;
  text-align: left;
  font-family: var(--font-family-mono);
  font-size: inherit;
  line-height: 1.2em;
}
#locked-display.show {
  display: block;
}
#countdown-timer {
  font-size: inherit;
  color: #0f0;
  margin: 0;
  font-weight: normal;
  text-shadow: none;
  font-family: var(--font-family-mono);
}
#input-area {
  display: none;
  white-space: nowrap;
}
input[type="file"] {
  color: #0f0;
  background: #000;
  border: none;
  height: 1em;
  line-height: 1;
  font-family: var(--font-family-mono);
  font-size: inherit;
  padding: 0;
  margin: 0;
  accent-color: #0f0;
}
input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button {
  background: #0f0;
  color: #000;
  border: none;
  height: 1em;
  line-height: 1;
  padding: 0 0.5ch;
  margin-right: 1ch;
  font-family: var(--font-family-mono);
  font-size: inherit;
  font-weight: 700;
  font-synthesis: weight;
  text-shadow: 0 0 1px #000;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover,
input[type="file"]::-webkit-file-upload-button:hover {
  background: #000;
  color: #0f0;
  font-weight: 400;
  text-shadow: 0 0 1px #0f0;
}
#photo-gallery {
  display: none;
}
.centered-text {
  display: inline;
  text-align: left;
}
.centered-box {
  display: inline;
  text-align: left;
}
/*
  main.css
  All core styles for the Terminal app UI, including layout, terminal grid, buttons, and visual effects.
  Split into logical sections for easier future modularization if needed.
*/

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html, body {
  width: 100%;
  height: 100%;
  max-width: none;
  overflow: hidden !important; /* lock page scrolling; inner terminal scrolls instead */
  touch-action: none; /* block panning/zoom at page level; allow it in screen container */
  position: fixed; /* iOS/Android hard lock against body scroll */
  top: 0;
  left: 0;
  right: 0;
  margin: 0;
  padding: 0;
  background: #111;
  color: #eee;
  font-family: var(--font-family-mono);
  font-size: 16px;
  line-height: 1;
  letter-spacing: 0;
  font-variant-ligatures: none;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: auto;
  box-sizing: border-box;
  overscroll-behavior: none; /* prevent viewport from being scrolled off-screen */
  overflow-anchor: none; /* disable scroll anchoring that can shift layout */
}

.input-box {
  background: var(--color-input-bg) !important;
  color: var(--color-input-fg) !important;
  font-weight: bold !important;
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
  padding-left: var(--space-sm) !important;
  padding-right: 0 !important;
  margin: 0 !important;
  height: var(--space-md) !important;
  line-height: var(--space-md) !important;
  font-size: inherit !important;
  font-family: var(--font-family-mono) !important;
  display: inline-block !important;
  vertical-align: middle !important;
  caret-color: var(--color-input-fg) !important;
}
.input-box::placeholder {
  color: #000 !important;
  opacity: 1 !important;
}
.input-box:focus {
  background: #0f0 !important;
  color: #000 !important;
  font-weight: bold !important;
  outline: none !important;
}
#login-error {
  color: #0f0;
  min-height: 1em;
  line-height: 1;
  white-space: pre;
  font-family: var(--font-family-mono);
  font-size: inherit;
  margin-top: 0;
  display: block;
}
html, body, #terminal-container, #terminal {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -ms-text-size-adjust: none;
}
/* Adjusted for more reasonable width (e.g., 960px for 12px font) */
/* 80x25 Terminal Container - PURE CHARACTER GRID */
#terminal-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* width and height set dynamically by JS based on viewport */
  outline: 2px solid #0f0;
  background: #000;
  font-family: var(--font-family-mono);
  font-size: 16px !important;
  line-height: 1;
  padding: 0;
  display: flex;
  flex-direction: column;
  box-sizing: content-box;
  max-width: 100vw !important;
  max-height: 100vh !important;
  outline: 2px solid #0f0;
  box-sizing: content-box !important;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 25em;
}

#screen-container {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  box-sizing: border-box;
}
@media (hover: none), (pointer: coarse) {
  #terminal-container {
    outline: none !important;
    border: 2px solid #0f0 !important;
    box-sizing: border-box !important;
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: auto !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    transform: none !important;
  }
  #screen-container {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    box-sizing: border-box !important;
  }
}

/* Removed experimental overlays; border is drawn directly on container (mobile) or outline (desktop) */

/* NO mobile responsive - breaks terminal aesthetic */
/* Remove all mobile-specific styling */
html, body {
  overflow-x: hidden !important;
  overflow-y: hidden !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
}

/* On touch/coarse devices, suppress the desktop outline to avoid double border */
@media (hover: none), (pointer: coarse) {
  #terminal-container,
  #terminal-container:focus {
    outline: none !important;
    border: 2px solid #0f0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
}
#terminal-container *,
#terminal-container button,
#terminal-container input {
  font-family: var(--font-family-mono) !important;
  font-size: inherit;
  line-height: 1 !important;
  box-sizing: border-box;
}
#top-bar {
  height: 1em;
  line-height: 1;
  overflow: hidden;
  white-space: nowrap;
  background: #000;
  color: #0f0;
  padding: 0;
  margin: 0;
  border-bottom: none;
  flex-shrink: 0;
  visibility: hidden; /* Hidden but space reserved until game starts */
}
#screen-container {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: #000;
  padding: 0;
  margin: 0;
  overscroll-behavior: none; /* fully disable rubber-banding and scroll chaining */
  scroll-behavior: auto;
  touch-action: pan-y; /* allow vertical panning for content scroll */
  -webkit-overflow-scrolling: touch; /* smooth momentum scrolling on iOS */
  position: relative; /* establish stacking context for scroll container */
  z-index: 1; /* ensure content can scroll above any underlying layers */
  font-family: var(--font-family-mono);
  outline: none; /* no focus ring that could affect measurements */
}
#bottom-bar {
  height: 1em;
  line-height: 1;
  overflow: hidden;
  background: #000;
  color: #0f0;
  padding: 0;
  /* Respect iOS home indicator safe area so buttons aren't obscured */
  padding-bottom: env(safe-area-inset-bottom);
  margin: 0;
  border-top: none;
  flex-shrink: 0;
  visibility: hidden; /* Hidden but space reserved until game starts */
  display: flex;
  flex-direction: column;
}

#bottom-bar-content {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--space-sm);
  height: var(--space-md);
  line-height: 1;
  overflow-x: auto;
  overflow-y: hidden;
}

.term-btn {
  height: 1em !important;
  line-height: 1 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  background: none !important;
  color: var(--color-input-fg) !important;
  cursor: pointer !important;
  display: inline !important;
  vertical-align: baseline !important;
  text-transform: none !important;
  box-shadow: none !important;
  transition: none !important;
  font-weight: 700 !important;
  font-synthesis: weight !important;
  font-family: var(--font-family-mono) !important;
  box-sizing: content-box !important;
  /* Mobile: Prevent stuck :active state and accidental gestures */
  -webkit-tap-highlight-color: transparent !important;
  touch-action: manipulation !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

.ascii-btn {
  font-family: var(--font-family-mono) !important;
  font-size: inherit;
  line-height: 1;
  color: #000 !important;
  background: #0f0 !important;
  border: none !important;
  padding: 0 0 !important;
  margin: 0 !important;
  display: inline-block !important;
  vertical-align: baseline !important;
  box-sizing: content-box !important;
  font-weight: bold !important;
  opacity: 1 !important;
  text-align: center !important;
  letter-spacing: 0 !important;
  white-space: pre !important;
  /* Mobile: Prevent stuck :active state and accidental gestures */
  -webkit-tap-highlight-color: transparent !important;
  touch-action: manipulation !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  transition: background 0.1s ease, color 0.1s ease !important;
}

.ascii-btn:hover {
  background: #000 !important;
  color: #0f0 !important;
  font-weight: normal !important;
  cursor: pointer !important;
}

/* Mobile: Auto-reset active state after 500ms */
.ascii-btn:active {
  animation: reset-active-state 0.5s forwards !important;
}

@keyframes reset-active-state {
  0% {
    background: #000 !important;
    color: #0f0 !important;
  }
  99% {
    background: #000 !important;
    color: #0f0 !important;
  }
  100% {
    background: #0f0 !important;
    color: #000 !important;
  }
}
@media (hover: hover) and (pointer: fine) {
  .term-btn:hover {
    background: #000 !important;
    color: var(--color-accent) !important;
    font-weight: 400 !important;
  }
}
.term-btn:disabled {
  background: var(--color-input-bg) !important;
  color: var(--color-input-fg) !important;
  cursor: not-allowed !important;
  opacity: 1 !important;
}
.term-btn:active {
  background: #000 !important;
  color: var(--color-accent) !important;
  font-weight: 400 !important;
  /* Mobile: Auto-reset after 500ms */
  animation: reset-term-btn-active 0.5s forwards !important;
}
.term-btn:focus {
  outline: none !important;
}

@keyframes reset-term-btn-active {
  0%, 99% {
    background: #000 !important;
    color: var(--color-accent) !important;
  }
  100% {
    background: none !important;
    color: var(--color-input-fg) !important;
  }
}


/* MUST come after .term-btn to override display property */
.hidden {
  display: none !important;
}

#recovery-area {
  display: inline;
  white-space: nowrap;
}

#input-area {
  display: none;
  white-space: nowrap;
  margin-left: 0.5ch;
}

input {
  border: none !important;
  font-family: var(--font-family-mono) !important;
  padding: 0 !important; /* avoid fractional offsets */
  margin: 0 !important;
  font-size: inherit !important;
  text-shadow: none !important;
  font-weight: normal !important;
  line-height: 1 !important;
  height: 1em !important;
  box-shadow: none !important;
  transition: none !important;
  box-sizing: content-box !important; /* width is pure character columns */
  background: #000 !important;
  color: #0f0 !important;
  text-transform: none;
}

/* Terminal input component overrides - created by createTerminalInput() */
input.input-box {
  font-weight: bold !important;
  box-sizing: border-box !important;
  background: #0f0 !important;
  color: #000 !important;
}

/* Answer input in the bottom bar: fixed width aligned to grid */
#answer-input {
  width: 40ch;
  min-width: 40ch;
}

input::placeholder {
  color: #0f0 !important;
  opacity: 1 !important;
}

input:focus {
  outline: none;
  background: #000 !important;
  color: #0f0 !important;
}

.error, .success, .warning {
  color: #0f0;
  text-shadow: none;
  line-height: inherit;
  display: inline;
  animation: none;
}

input[type="file"] {
  color: var(--color-accent);
  background: #000;
  border: none;
  height: 1em;
  line-height: 1;
  font-family: var(--font-family-mono);
  font-size: inherit;
  padding: 0;
  margin: 0;
  accent-color: var(--color-accent);
}
input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button {
  background: var(--color-input-bg);
  color: var(--color-input-fg);
  border: none;
  height: 1em;
  line-height: 1;
  padding: 0 0.5ch;
  margin-right: 1ch;
  font-family: var(--font-family-mono);
  font-size: inherit;
  font-weight: 700;
  font-synthesis: weight;
  text-shadow: 0 0 1px #000;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover,
input[type="file"]::-webkit-file-upload-button:hover {
  background: #000;
  color: #0f0;
  font-weight: 400;
  text-shadow: 0 0 1px #0f0;
}

#photo-gallery {
  display: none;
}

.centered-text {
  display: inline;
  text-align: left;
  font-family: var(--font-family-mono);
  padding: var(--space-xs);
}
.centered-box {
  display: inline;
  text-align: left;
  font-family: var(--font-family-mono);
  padding: var(--space-xs);
}
.cursor, .cursor::before {
  display: none !important;
  content: '' !important;
  background: none !important;
  animation: none !important;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}
#timer {
  color: #0f0 !important;
  font-family: var(--font-family-mono);
  font-size: inherit;
  white-space: nowrap;
  display: none;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
}
#timer.show {
  display: inline;
}
#top-bar-content {
  display: inline;
  white-space: nowrap;
}
#gps-indicator {
  display: inline;
  margin-left: 1ch;
  opacity: 1 !important;
  color: #0f0 !important;
  white-space: nowrap;
}

#progress-bar-container {
  display: inline;
}

#terminal {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1;
  padding: 0;
  padding-left: 1ch; /* Left margin: 1 character column */
  margin: 0;
  /* No padding-bottom - screen-container handles spacing */
  text-shadow: 0 0 1px rgba(0, 255, 0, 0.30);
  color: #0f0;
  font-family: var(--font-family-mono);
  font-size: inherit;
  letter-spacing: 0;
  word-spacing: 0;
  text-align: left;
  font-feature-settings: 'liga' 0, 'calt' 0;
  font-variant-ligatures: none;
}

#terminal * {
  line-height: 1;
  font-size: inherit;
  vertical-align: baseline;
  font-feature-settings: 'liga' 0, 'calt' 0;
  font-variant-ligatures: none;
  letter-spacing: 0;
  word-spacing: 0;
  font-kerning: none;
}

#terminal img {
  max-width: 100%;
  height: auto;
  max-height: 20em;
  display: block;
  margin: 10px auto;
  image-rendering: pixelated;
  border: 2px solid #0f0;
  box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
}

/* ASCII scrollbar overlay */
#ascii-scrollbar {
  position: sticky;
  right: 0;
  top: 0;
  width: 1ch;
  height: 100%;
  background: #000;
  color: #0f0;
  font-family: var(--font-family-mono);
  font-size: inherit;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  overflow: hidden;
  z-index: 100;
  font-feature-settings: 'liga' 0, 'calt' 0;
  font-variant-ligatures: none;
  float: right;
}

/* Hide native scrollbar completely - we'll draw ASCII version */
#screen-container::-webkit-scrollbar {
  width: 0;
  height: 0;
}
#screen-container {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
