/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* NOS Teletekst Custom Font - required for correct box-drawing characters */
@font-face {
  font-family: 'teletekstmono';
  src: url('/teletekst-mono.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

html, body {
  height: 100%;
  background: #000;
}

body {
  position: relative;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1.2em;
  color: #fff;
  width: 100%;
  margin: 0;
}

/* App Layout */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Content Area */
.content-area {
  flex: 1;
  overflow: auto;
  padding: 8px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-left: max(8px, env(safe-area-inset-left), env(safe-area-inset-right));
  padding-right: max(8px, env(safe-area-inset-left), env(safe-area-inset-right));
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Swipe navigation (#89). pinch-zoom hands both pan axes to the app and
     keeps pinch-zoom native, which is what the gesture needs: a page is always
     25 rows and the size budget below fits them, so the content area has
     nothing to scroll and a vertical drag is a subpage step, never a scroll.
     While this said pan-y, iOS read a vertical drag as a scroll, cancelled the
     touch, and the subpage swipe never ran. touch-action: none is still wrong,
     because it would also kill zoom on the text. overscroll-behavior keeps a
     committed drag from rubber-banding the page. */
  touch-action: pinch-zoom;
  overscroll-behavior: contain;
}

.teletekst-pre {
  font-family: "teletekstmono", monospace;
  /* Size budget, both axes. Width: 40 NOS columns at 0.6em advance, so
     25 units with slack. Height: a page is 25 rows, addTopBuffer() prepends 2
     more, and line-height 1.05 makes 27 rows cost 28.35em, hence the divisor
     28.5. The 88px reserve is the nav bar (69px: 1.56rem controls plus 32px of
     padding) plus this element's 16px of padding. Reserving less (80px / 28)
     clipped the bottom row on height-constrained, i.e. wide and short,
     viewports. svh instead of dvh keeps the budget on the always-visible
     viewport, so iOS cannot rescale the page while the URL bar collapses.
     On a notched phone the safe-area padding is taller than the 8px per side
     counted above, so the last declaration subtracts whatever the insets add
     beyond it. Without that the 25 rows overflow, and because the app now owns
     the vertical axis (#89), a scrolled-away bottom row would be unreachable. */
  font-size: min(calc((100vw - 16px) / 25), calc((100vh - 88px) / 28.5));
  font-size: min(calc((100vw - 16px) / 25), calc((100svh - 88px) / 28.5));
  font-size: min(
    calc((100vw - 16px) / 25),
    calc((100svh - 88px - max(0px, env(safe-area-inset-top) - 8px) - max(0px, env(safe-area-inset-bottom) - 8px))
      / 28.5)
  );
  white-space: pre;
  line-height: 1.05;
}

/* Link styling - exactly like original NOS */
.teletekst-pre a {
  text-decoration: none;
  color: inherit;
}

/* Status Messages */
.status-message {
  text-align: center;
  padding: 40px 20px;
  font-family: "teletekstmono", monospace;
  font-size: 1.2rem;
}

.hidden {
  display: none !important;
}

/* .vh class - exactly like original NOS (accessible hidden) */
.vh {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

/* Color Classes - EXACTLY like original NOS (no prefixes) */
.red { color: #f00; }
.green { color: #0f0; }
.yellow { color: #ff0; }
.blue { color: #00f; }
.magenta { color: #f0f; }
.cyan { color: #0ff; }
.white { color: #fff; }

/* Background colors - EXACTLY like original NOS */
.bg-red { background: #f00; }
.bg-green { background: #0f0; }
.bg-yellow { background: #ff0; }
.bg-blue { background: #00f; }
.bg-magenta { background: #f0f; }
.bg-cyan { background: #0ff; }
.bg-white { background: #fff; }

/* Navigation Controls */
.nav-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 16px 8px;
  font-family: "teletekstmono", monospace;
  font-size: min(calc((100vw - 16px) / 18), 1.56rem);
  flex-shrink: 0;
}

.nav-controls.hidden {
  display: none !important;
}

.nav-btn {
  text-decoration: none;
  color: #fff;
  padding: 6px 12px;
  background: transparent;
  cursor: pointer;
  font-family: "teletekstmono", monospace;
  font-size: 1em;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  border: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.nav-btn.disabled {
  color: #444;
  cursor: default;
  pointer-events: none;
}

.nav-btn:active:not(.disabled) {
  background: #fff;
  color: #000;
}

/* Edge breathing room: nudge the outermost buttons away from the screen edges */
#nav-share {
  padding-left: 20px;
}

#nav-gemini {
  padding-right: 20px;
}

.nav-page {
  color: #ff0;
  font-weight: bold;
  min-width: 5ch;
  text-align: center;
  font-family: "teletekstmono", monospace;
  font-size: 1em;
  background: transparent;
  border: none;
  padding: 4px 4px;
  width: 5ch;
  caret-color: #ff0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;
}

.nav-page::placeholder {
  color: #ff0;
}

.nav-page:focus {
  background: rgba(255, 255, 255, 0.1);
}

/* Keyboard focus indicator (#28). The appearance resets above remove the UA
   outline, so every focusable control paints its own high-contrast ring. Yellow
   is the Teletekst highlight and reads clearly on black and over the .bg-* fills;
   :focus-visible keeps the ring off mouse and touch interaction. */
.nav-btn:focus-visible,
.nav-page:focus-visible,
.teletekst-pre a:focus-visible {
  outline: 2px solid #ff0;
  outline-offset: 2px;
}

/* Gemini nav link */
.nav-gemini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 6px;
  color: #fff;
  text-decoration: none;
  transition: color 0.2s;
}

.nav-gemini:active {
  background: transparent;
  color: #ab8bff;
}

/* Narrow screens (iPhones ~375-430px): the base one-row nav is too wide and
   overflows (controls flush to the edges) or wraps. Shrink the controls just
   enough that all 7 fit on ONE centered line, so the Share (left) and ChatGPT
   (right) edge padding stays visible without wrapping. Larger screens keep the
   base (bigger) sizing above. */
@media (max-width: 430px) {
  .nav-controls {
    gap: 12px;
    padding: 14px 6px;
    font-size: min(calc((100vw - 16px) / 21), 1.3rem);
  }
  .nav-btn {
    padding: 6px 8px;
  }
  .nav-page {
    min-width: 5ch;
    width: 5ch;
    padding: 4px 2px;
  }
  #nav-share {
    padding-left: 16px;
  }
  #nav-gemini {
    padding-right: 16px;
  }
}

/* Toast */
.gemini-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #ab8bff;
  font-family: 'teletekstmono', monospace;
  font-size: 0.9rem;
  padding: 10px 20px;
  border: 1px solid #444;
  border-radius: 6px;
  z-index: 999;
  white-space: nowrap;
}
.gemini-toast.hidden {
  display: none !important;
}


