/* Mobile-first CSS Reset and Optimizations */
* {
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
  -webkit-touch-callout: none; /* Disable callout on iOS */
}

/* Accessibility: Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link for keyboard navigation - visually hide but keep accessible */
.skip-link {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  background: #000;
  color: #fff;
  text-decoration: none;
  z-index: 1000;
  border-radius: 4px;
  font-size: 14px;
}

/* Only show skip link when explicitly activated via keyboard shortcut */
.skip-link.activated {
  position: absolute;
  width: auto;
  height: auto;
  padding: 8px;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  border: 0;
  top: 6px;
  left: 6px;
}

.skip-link.activated:focus {
  top: 6px;
}

/*
 * Header buttons are purely decorative terminal window controls
 * They are intentionally non-interactive as they have no functionality
 * This prevents misleading user interactions with non-functional elements
 */
.buttons div {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .cursor.blink {
    animation: none;
  }
}

html {
    height: 100%;
    width: 100%;
    /* Prevent horizontal scrolling on mobile */
    overflow-x: hidden;
    /* Smooth scrolling for better mobile UX */
    scroll-behavior: smooth;
}

html,
body {
  font-size: 13px; /* Mobile-first: even smaller base font size */
  font-family: Lato, sans-serif;
  min-height: 100% !important;
  width: 100%;
  margin: 0;
  padding: 0;
  line-height: 1.4em;
}

div {
  display: inline-block;
}

h1 {
  font-size: 1em;
}

h1,
h2,
h3,
h4,
h5,
p {
  margin-bottom: 1em;
  font-size: medium;
}

/* Keep prompt spans on same line, but allow line breaks in content */
#resultParaId .result-content {
  white-space: pre-line;
}

/* Loading indicator styles */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-family: 'Fira Mono', monospace;
  font-size: 0.8rem;
  color: #98d7ff;
}

.loading-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid transparent;
  border-top: 2px solid #98d7ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  will-change: transform; /* Performance optimization */
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Error display styles */
.error-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 87, 51, 0.1);
  border: 1px solid rgba(255, 87, 51, 0.3);
  border-radius: 4px;
  margin: 0.5rem 0;
  font-family: 'Fira Mono', monospace;
  font-size: 0.8rem;
  color: #ff5733;
}

.error-retry {
  background: #ff5733;
  color: white;
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.7rem;
  margin-left: auto;
}

.error-retry:hover,
.error-retry:focus {
  background: #e74c3c;
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Keyboard shortcuts dialog */
.keyboard-shortcuts {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.95);
  border: 2px solid #98d7ff;
  border-radius: 8px;
  padding: 1.5rem;
  z-index: 1000;
  max-width: 400px;
  width: 90%;
  font-family: 'Fira Mono', monospace;
  color: #fff;
}

.keyboard-shortcuts h2 {
  margin-top: 0;
  color: #98d7ff;
  font-size: 1.1rem;
}

.keyboard-shortcuts ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.keyboard-shortcuts li {
  margin: 0.5rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.keyboard-shortcuts kbd {
  background: #333;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 0.2rem 0.4rem;
  font-size: 0.8rem;
  min-width: 60px;
  text-align: center;
}

#closeShortcuts {
  background: #98d7ff;
  color: #000;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Fira Mono', monospace;
  float: right;
}

#closeShortcuts:hover,
#closeShortcuts:focus {
  background: #7bc3f7;
  outline: 2px solid #fff;
  outline-offset: 2px;
}

a {
  color: #98d7ff;
  text-decoration: none;
}

a:hover {
  opacity: 1;
  border-bottom: 1px solid #5db0e5;
}

img {
  display: block;
  max-width: 100%;
}

body {
  background: linear-gradient(20deg, #FF5733 30%, #3498DB 30%);
  background-size: cover;
  margin: 0;
  padding: 0.5rem; /* Reduced padding for mobile */
  display: flex;
  flex-direction: row;
  align-items: center;
  box-sizing: border-box;
  min-height: 100vh; /* Ensure full viewport height */
}

input {
  all: inherit;
  /* Mobile-specific input improvements */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border: none;
  outline: none;
  background: transparent;
  /* Prevent zoom on iOS when focusing input */
  font-size: max(16px, 1em);
}

/* input#inputId{
  border: 0.5px solid;
  border-color: black;
} */

.vignette {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: radial-gradient(transparent 0, rgba(0, 0, 0, 0.2));
  z-index: 0;
}

.content {
  min-height: 22rem;
  border-radius: 0.3rem;
  background: linear-gradient(10deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.6));
  max-width: 100%;
  width: 90%;
  height: 90%;
  box-sizing: border-box;
  color: #eee;
  margin: 0 auto;
  box-shadow: 0 0 5rem rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-bottom-color: rgba(0, 0, 0, 0.4);
  border-top: none;
  font-size: 0.9em;
  position: relative;
  z-index: 1;
}

.content header {
  width: 100%;
  height: 2rem;
  position: relative;
  opacity: 0.8;
  box-sizing: border-box;
  padding: 0 4rem 0 0.8rem;
}

.content header h1 {
  font-size: 0.9rem;
  margin: 0 auto;
  text-align: center;
  max-width: 100%;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 0.3rem;
  padding-right: 0.3rem;
  padding-top: 0.4rem;
}

.content header .buttons {
  width: auto;
  float: left;
  padding-top: 0.5rem;
  display: inline-block;
}

.content header .buttons > * {
  display: inline-block;
  border-radius: 50%;
  width: 12px; /* Back to original size */
  height: 12px;
  margin-right: 0.6rem; /* Back to original margin */
  padding: 0.25rem;
  box-sizing: border-box;
  background: lightblue;
  cursor: pointer; /* Add cursor pointer for better UX */
  touch-action: manipulation; /* Optimize for touch */
}

.content header .buttons > *:nth-child(1) {
  background-color: hsl(0, 80%, 60%);
}

.content header .buttons > *:nth-child(2) {
  background-color: hsl(50, 80%, 51%);
}

.content header .buttons > *:nth-child(3) {
  background-color: hsl(86, 58%, 44%);
}

.content header .version {
  position: absolute;
  top: 0.4rem;
  right: 0.8rem;
  font-size: 0.7rem;
  color: #bbb;
  font-family: 'Fira Mono', monospace;
  opacity: 0.7;
  font-weight: normal;
}

.container {
  font-family: 'Fira Mono', monospace;
  font-size: 0.8rem;
  padding: 1rem;
  /* Enable gentle text wrapping for all screen sizes */
  overflow-wrap: break-word;
}

.container .prompt .green {
  color: hsl(85, 72%, 55%);
}

.container .prompt .yellow {
  color: hsl(50, 100%, 61%);
}

.container .prompt .red {
  color: hsl(359, 100%, 67%);
}

.container > *:last-child {
  margin-bottom: 0;
}

/* Enable gentle text wrapping for prompt elements */
.container .prompt {
  overflow-wrap: break-word;
}

.cursor {
  display: inline-block;
  background: #bbb;
  height: 1.2em;
  overflow: hidden;
  vertical-align: text-bottom;
  color: transparent;
}

.blink {
  animation: blinker steps(1) 500ms infinite alternate;
}

.come-in {
  animation: come-in 1000ms cubic-bezier(0.39, 0.575, 0.565, 1);
}

#codeInputField {
  display: inline-block;
  width: 60%;
  padding-right: 10px;
  box-sizing: border-box;
}

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

@keyframes come-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(5rem);
    box-shadow: none;
  }
  to {
    opacity: 1;
  }
}

/* Mobile landscape and small tablets */
@media only screen and (min-width: 480px) {
  html {
    font-size: 14px;
  }

  body {
    padding: 0.75rem;
  }

  .content {
    width: 92%;
  }

  .container {
    font-size: 0.75rem; /* Smaller font for mobile landscape */
    padding: 0.2rem 0.9rem; /* Further reduced top/bottom padding for mobile landscape */
  }

  #codeInputField {
    width: 65%;
  }
}

/* Tablets */
@media only screen and (min-width: 768px) {
  html {
    font-size: 16px;
  }

  body {
    padding: 1rem;
  }

  .content {
    width: 90%;
    min-height: 22rem;
  }

  .content header {
    padding: 0 2rem 0 0.8rem;
  }

  .content header h1 {
    font-size: 0.9rem;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
  }

  .content header .buttons > * {
    width: 12px;
    height: 12px;
    margin-right: 0.6rem;
  }

  .container {
    font-size: 0.8rem;
    padding: 1rem;
  }

  #codeInputField {
    width: 60%;
    font-size: inherit;
  }
}

/* Desktop */
@media only screen and (min-width: 1024px) {
  html {
    font-size: 18px;
  }

  .content {
    width: 90%; /* Restored original desktop width */
  }

  .content header {
    padding: 0 4rem 0 0.8rem;
  }

  /* Reduce gap between header and first prompt on desktop */
  .container {
    padding: 0.2rem 1rem 1rem 1rem; /* Further reduced top padding to 0.2rem for tighter spacing */
  }
}

/* Mobile-specific improvements */
@media only screen and (max-width: 479px) {
  /* Very small mobile screens - most aggressive space saving */
  body {
    align-items: flex-start;
    padding-top: 0.5rem;
  }

  .content {
    min-height: auto;
    height: auto;
  }

  .container {
    padding: 0.05rem 0.5rem 1rem 0.5rem; /* Minimal top padding, adequate bottom padding for very small screens */
    /* Enable text wrapping for very small screens */
    overflow-wrap: break-word;
  }

  /* Remove all top margin from first prompt */
  .container > p:first-child {
    margin-top: 0;
  }

  /* Ultra-compact spacing between elements */
  .container p {
    margin-top: 0.1rem;
    margin-bottom: 0.3rem;
    /* Enable text wrapping for very small screens */
    overflow-wrap: break-word;
  }

  /* Even tighter button spacing for very small screens */
  .content header .buttons > * {
    margin-right: 0.1rem; /* Very compact spacing for very small screens */
  }
}

@media only screen and (max-width: 767px) {
  /* Reduce font size for mobile */
  html {
    font-size: 13px; /* Smaller base font for mobile */
  }

  /* Fix mobile background coverage and layout */
  body {
    min-height: 100vh;
    background-attachment: fixed; /* Ensure background covers full viewport */
    display: flex;
    align-items: flex-start; /* Align to top instead of center on mobile */
    padding-top: 1rem; /* Add some top padding */
  }

  /* Mobile layout adjustments */
  .content {
    width: 95%; /* Wider on mobile for better space usage */
    min-height: auto; /* Allow content to determine height */
    height: auto; /* Remove fixed height constraint */
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
  }

  /* Smaller header text on mobile */
  .content header h1 {
    font-size: 0.8rem; /* Reduced from 0.9rem for mobile */
    white-space: nowrap; /* Keep header on single line */
    overflow: hidden; /* Hide overflow */
    text-overflow: ellipsis; /* Show ellipsis for long text */
  }

  /* Smaller version text on mobile */
  .content header .version {
    font-size: 0.6rem; /* Smaller version text for mobile */
    top: 0.3rem; /* Adjust position for smaller mobile header */
    right: 0.5rem; /* Closer to edge on mobile */
  }

  /* Reduce gap between header and first prompt on mobile */
  .container {
    font-size: 0.7rem; /* Smaller terminal text on mobile */
    padding: 0.05rem 0.75rem 1.5rem 0.75rem; /* Minimal top padding, adequate bottom padding, maintain side padding */
    /* Enable text wrapping for mobile */
    overflow-wrap: break-word;
  }

  /* Remove top margin from first prompt to eliminate gap */
  .container > p:first-child {
    margin-top: 0;
  }

  /* Reduce margins between prompts on mobile */
  .container p {
    margin-top: 0.2rem;
    margin-bottom: 0.5rem;
    /* Enable text wrapping for prompt paragraphs */
    overflow-wrap: break-word;
  }

  /* Improve text selection on mobile */
  .container .prompt {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
  }

  /* Optimize animations for mobile performance */
  .come-in {
    animation-duration: 800ms; /* Slightly faster for mobile */
  }

  /* Keep buttons at normal size - they're fine for touch as-is */
  /* Bring the three terminal buttons closer together on mobile */
  .content header .buttons > * {
    margin-right: 0.15rem; /* Much tighter spacing on mobile */
  }

  /* Better mobile keyboard handling */
  #codeInputField {
    /* Prevent zoom on focus for iOS */
    font-size: max(16px, 0.9rem);
    /* Better mobile input styling */
    padding: 0.25rem 0.5rem;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.05);
  }

  #codeInputField:focus {
    background: rgba(255, 255, 255, 0.1);
    outline: 1px solid rgba(255, 255, 255, 0.3);
  }
}

/* Enhanced accessibility and focus management */
#codeInputField:focus {
  outline: 2px solid #98d7ff;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Focus styles for interactive elements */
.content header .buttons > div:focus,
button:focus,
[role="button"]:focus {
  outline: 2px solid #98d7ff;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Make terminal window control buttons focusable and interactive */
.content header .buttons > div {
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.content header .buttons > div:hover,
.content header .buttons > div:focus {
  opacity: 0.8;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .content {
    background: #000;
    border: 2px solid #fff;
  }

  .container .prompt .green {
    color: #00ff00;
  }

  .container .prompt .yellow {
    color: #ffff00;
  }

  .container .prompt .red {
    color: #ff0000;
  }

  a {
    color: #00ffff;
  }

  #codeInputField:focus {
    outline: 3px solid #ffffff;
  }
}

/* Performance optimizations */
.cursor {
  will-change: opacity;
}

/* Optimize animations for better performance */
@media (prefers-reduced-motion: no-preference) {
  .cursor.blink {
    animation: blink 1s infinite;
  }

  @keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
  }
}
