/* CSS Reset and Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg-color: #00303e;
  --text-color: #f8f8f2;
  --keyword-color: #66d9ef;
  --method-color: #a6e22e;
  --key-color: #fd971f;
  --string-color: #efe158;
  --special-color: #ae81ff;
  --link-color: #ec007c;
  --link-hover-bg: #0096c1;
  --link-hover-text: #00303e;
  --indent-size: 2ch;
}

html {
  height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: clamp(1rem, 5vw, 3rem);
  background: #1a1a1a;
  color: var(--text-color);
  font-family: 'Fira Code', 'Monaco', 'Courier New', monospace;
  font-size: 16px;
  line-height: 1.6;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Terminal Window */
.terminal-window {
  max-width: 900px;
  width: 100%;
  background: var(--bg-color);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Terminal Header */
.terminal-header {
  background: #003847;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid #004456;
}

.terminal-buttons {
  display: flex;
  gap: 0.5rem;
}

.terminal-button {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.terminal-button.close {
  background: #ff5f56;
}

.terminal-button.minimize {
  background: #ffbd2e;
}

.terminal-button.maximize {
  background: #27c93f;
}

.terminal-title {
  color: #8899a6;
  font-size: 14px;
  flex: 1;
  text-align: center;
  user-select: none;
}

/* Terminal Content */
.terminal-content {
  padding: clamp(1rem, 3vw, 1.5rem);
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  line-height: 1.6;
}

/* Terminal Footer (Vim status bar) */
.terminal-footer {
  background: #003847;
  padding: 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: #8899a6;
  border-top: 1px solid #004456;
}

.footer-mode {
  color: var(--text-color);
  font-weight: 500;
}

.footer-info {
  color: #8899a6;
}

pre {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

code {
  font-family: inherit;
  font-size: inherit;
  display: block;
}

/* Line Styles */
.line {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}

.line.empty {
  min-height: 1em;
}

/* Cursor */
.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1.2em;
  background-color: var(--string-color);
  margin-left: 0.1em;
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
}

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

/* Indentation */
.indent {
  padding-left: calc(var(--indent-size) * 1);
}

.indent-2 {
  padding-left: calc(var(--indent-size) * 2);
}

.indent-3 {
  padding-left: calc(var(--indent-size) * 3);
}

/* Syntax Highlighting */
.def {
  color: var(--keyword-color);
  font-weight: 500;
}

.def_name {
  color: var(--method-color);
  font-weight: 500;
}

.hash_key {
  color: var(--key-color);
}

.string {
  color: var(--string-color);
}

.s2 {
  color: var(--special-color);
}

/* Links */
a {
  color: var(--link-color);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: rgba(236, 0, 124, 0.6);
  transition: background-color 0.2s ease, color 0.2s ease, text-decoration-color 0.2s ease;
  padding: 0.1em 0.2em;
  margin: -0.1em -0.2em;
  border-radius: 2px;
}

a:hover,
a:focus {
  background-color: var(--link-hover-bg);
  color: var(--link-hover-text);
  text-decoration-color: var(--link-hover-text);
  outline: none;
}

a:focus-visible {
  outline: 2px solid var(--link-color);
  outline-offset: 2px;
}

/* Mobile Optimizations */
@media screen and (max-width: 768px) {
  body {
    font-size: 14px;
    padding: 0;
    align-items: flex-start;
    /* Use dynamic viewport height for mobile browsers */
    min-height: 100dvh;
  }

  .terminal-window {
    border-radius: 0;
    /* Use dynamic viewport height that accounts for mobile browser UI */
    min-height: 100dvh;
    height: 100dvh;
    max-width: 100%;
    /* Add safe area padding for notched/rounded screens */
    padding-bottom: env(safe-area-inset-bottom);
  }

  .terminal-header {
    padding: 0.5rem 0.75rem;
    /* Safe area for notches/camera cutouts */
    padding-top: max(0.5rem, env(safe-area-inset-top));
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }

  .terminal-title {
    font-size: 12px;
  }

  .terminal-content {
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    /* Ensure content doesn't get cut off at bottom */
    padding-bottom: max(1rem, calc(env(safe-area-inset-bottom) + 0.5rem));
  }

  .terminal-footer {
    font-size: 11px;
    padding: 0.4rem 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    /* Keep footer above rounded screen edges */
    padding-bottom: max(0.4rem, calc(env(safe-area-inset-bottom) + 0.25rem));
  }

  :root {
    --indent-size: 1.5ch;
  }
  
  /* Fallback for browsers that don't support dvh */
  @supports not (height: 100dvh) {
    .terminal-window {
      min-height: 100vh;
      height: 100vh;
    }
  }
}

@media screen and (max-width: 480px) {
  body {
    font-size: 13px;
  }

  .terminal-button {
    width: 10px;
    height: 10px;
  }

  .terminal-title {
    font-size: 11px;
  }

  .terminal-content {
    padding: 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    /* Slightly reduce bottom padding on very small screens */
    padding-bottom: max(0.75rem, calc(env(safe-area-inset-bottom) + 0.25rem));
  }

  .terminal-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    font-size: 10px;
    padding: 0.35rem 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    /* Ensure footer text stays above rounded corners */
    padding-bottom: max(0.35rem, calc(env(safe-area-inset-bottom) + 0.25rem));
  }

  .line {
    white-space: pre-wrap;
  }

  a {
    display: inline-block;
    margin: 0.1em 0;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  a:hover,
  a:focus {
    outline: 2px solid currentColor;
  }
}
