@font-face {
  font-family: 'Nouveau IBM ANSI Art 8x16';
  src: url('Nouveau_IBM_ANSI_Art_8x16.woff2') format('woff2'),
    url('Nouveau_IBM_ANSI_Art_8x16.ttf') format('truetype');
}

@font-face {
  font-family: 'Nouveau IBM ANSI Art 9x16';
  src: url('Nouveau_IBM_ANSI_Art_9x16.woff2') format('woff2'),
    url('Nouveau_IBM_ANSI_Art_9x16.ttf') format('truetype');
}


html {
  scroll-behavior: smooth;
}

/* Scope all layout/UI under .cp437-viewer to avoid affecting the rest of the page */
.cp437-viewer * {
  box-sizing: border-box;
}

/* Viewer page layout (viewer.html): full-height app when .cp437-viewer is direct child of body */
html:has(body > .cp437-viewer),
body:has(> .cp437-viewer) {
  margin: 0;
  overflow: hidden;
  height: 100%;
}

.cp437-viewer {
  --cp437-char-width: 8px;
  --cp437-char-height: 16px;
  --cp437-display-scale: 1;
  margin: 0;
  background: #000;
  color: #aaa;
  font-family: 'Nouveau IBM ANSI Art 8x16', 'Consolas', 'Monaco', monospace;
  min-height: 100vh;
  font-size: 1rem;
  line-height: 1.25;
}

/* Full-page viewer layout */
body>.cp437-viewer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  box-sizing: border-box;
}

body>.cp437-viewer #ansi-wrapper {
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
}

.cp437-viewer #ansi-viewport {
  position: relative;
  overflow: hidden;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* Line-by-line block reveal: overlay at viewport bottom, does not capture pointer. */
.cp437-viewer .cp437-line-reveal-overlay {
  position: absolute;
  bottom: 0;
  left: auto;
  right: 0;
  pointer-events: none;
  display: none;
  box-sizing: border-box;
}

.cp437-viewer #ansi-container {
  position: relative;
  will-change: transform;
}

.cp437-viewer .ansi-loop-spacer {
  flex-shrink: 0;
  width: 100%;
  background: #000;
}

.cp437-viewer .ansi-scrollbar {
  flex-shrink: 0;
  width: 20px;
  padding: 6px 3px;
  box-sizing: border-box;
  opacity: 0;
  pointer-events: auto;
  transition: opacity 0.2s ease;
  z-index: 2;
  position: relative;
  display: flex;
  flex-direction: column;
}

.cp437-viewer .ansi-scrollbar:hover,
.cp437-viewer .ansi-scrollbar.visible {
  opacity: 1;
}

.cp437-viewer .ansi-scrollbar-track {
  position: absolute;
  right: 3px;
  top: 6px;
  bottom: 6px;
  width: 12px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  transition: background 0.2s ease;
}

.cp437-viewer .ansi-scrollbar:hover .ansi-scrollbar-track,
.cp437-viewer .ansi-scrollbar.visible .ansi-scrollbar-track {
  background: rgba(255, 255, 255, 0.2);
}

.cp437-viewer .ansi-scrollbar-thumb {
  position: absolute;
  right: 0;
  width: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.35);
  min-height: 32px;
  transition: background 0.15s ease;
}

.cp437-viewer .ansi-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.65);
}

.cp437-viewer .ansi-scrollbar:hover .ansi-scrollbar-thumb,
.cp437-viewer .ansi-scrollbar.visible .ansi-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.5);
}

.cp437-viewer .cp437-title {
  color: #fff;
  margin: 0 0 10px 0;
  font-size: 1.5rem;
}

.cp437-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.cp437-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.cp437-viewer .cp437-btn,
.cp437-viewer input[type="file"].cp437-file-input {
  background: transparent;
  color: #fff;
  border: none;
  padding: 0 0.35em;
  margin: 0;
  cursor: pointer;
  font-family: 'Nouveau IBM ANSI Art 8x16', 'Consolas', 'Monaco', monospace;
  font-size: 1rem;
  line-height: 1.25;
  min-height: 0;
  border-radius: 0;
  text-decoration: none;
  display: inline;
}

.cp437-viewer .cp437-btn::before,
.cp437-viewer .cp437-btn::after {
  display: inline;
  font-family: inherit;
}

.cp437-viewer .cp437-btn::before {
  content: "[";
  margin-right: 0.15em;
}

.cp437-viewer .cp437-btn::after {
  content: "]";
  margin-left: 0.15em;
}

.cp437-viewer .cp437-btn:hover {
  color: #ffffaa;
}

.cp437-viewer .cp437-btn:focus-visible {
  outline: 1px dotted #ffffaa;
  outline-offset: 1px;
}

.cp437-file-input-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.cp437-file-input-wrapper input[type="file"] {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.cp437-info {
  background: #2a2a4a;
  padding: 10px 15px;
  border-radius: 4px;
  font-size: 13px;
  color: #888;
}

.cp437-info span {
  color: #fff;
}

.cp437-info .cp437-btn {
  margin-left: 10px;
  padding: 4px 10px;
  font-size: 12px;
}

.cp437-sauce-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0.2s, opacity 0.2s;
}

.cp437-sauce-modal[aria-hidden="false"] {
  visibility: visible;
  opacity: 1;
}

.cp437-sauce-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.cp437-sauce-modal-content {
  position: relative;
  background: #2a2a4a;
  border: 1px solid #5a5a8c;
  border-radius: 8px;
  padding: clamp(12px, 4vw, 20px);
  max-width: min(480px, calc(100vw - 40px));
  width: 100%;
  max-height: 80vh;
  max-height: 80dvh;
  overflow: auto;
}

.cp437-sauce-modal-content {
  font-family: inherit;
}

.cp437-sauce-modal-content h2 {
  margin: 0 0 12px 0;
  font-size: 1.1rem;
  color: #fff;
}

.cp437-sauce-modal-content pre {
  margin: 0 0 16px 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: #ccc;
  white-space: pre-wrap;
  word-break: break-word;
}

.cp437-sauce-modal-content .cp437-btn {
  display: block;
  margin-left: auto;
}

.cp437-sauce-modal-content .cp437-sauce-empty {
  color: #888;
  font-style: italic;
}

/* Options modal: consistent 8x16 font, mobile-friendly layout */
.cp437-sauce-modal-content.options-modal-content {
  padding: clamp(12px, 4vw, 20px);
  max-height: 85vh;
  max-height: 85dvh;
}

.options-modal-content {
  letter-spacing: 0.1em;
  font-kerning: auto;
}

.cp437-sauce-modal-content.options-modal-content .options-section {
  margin-bottom: 20px;
}

.cp437-sauce-modal-content.options-modal-content .options-section:last-of-type {
  margin-bottom: 0;
}

.cp437-sauce-modal-content.options-modal-content label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cp437-sauce-modal-content.options-modal-content label:not(:first-of-type) {
  margin-top: 10px;
}

.options-modal-content .modal-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-kerning: auto;
  color: #8a8ab8;
  margin: 0 0 10px 0;
}

.options-modal-content .options-section:not(:first-child) .modal-section-title {
  margin-top: 20px;
}

.options-modal-content .file-info-card {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(90, 90, 140, 0.4);
  border-radius: 6px;
  padding: clamp(10px, 3vw, 14px);
  font-size: 0.8125rem;
}

.options-modal-content .file-info-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
}

.options-modal-content .file-info-row:last-of-type {
  margin-bottom: 0;
}

.options-modal-content .file-info-label {
  color: #8a8ab8;
  min-width: 5.5em;
  flex-shrink: 0;
}

.options-modal-content .file-info-value {
  color: #e0e0f0;
  word-break: break-all;
}

.options-modal-content .file-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.options-modal-content .file-actions .cp437-btn {
  flex: 1;
  min-width: 120px;
  margin-left: 0;
}

.options-modal-content .primary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.options-modal-content .primary-actions .cp437-btn {
  margin-left: 0;
  width: 100%;
}

.options-modal-content .modal-close-x {
  position: absolute;
  top: clamp(8px, 2vw, 12px);
  right: clamp(8px, 2vw, 12px);
  padding: 0;
  border: none;
  background: transparent;
  color: #aaa;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  font-family: 'Nouveau IBM ANSI Art 8x16', 'Consolas', 'Monaco', monospace;
}

.options-modal-content .modal-close-x:hover {
  color: #ffffaa;
}

.options-modal-content .modal-close-x:focus-visible {
  outline: 1px dotted #ffffaa;
  outline-offset: 2px;
}

/* Line-by-line scroll: left-to-right reveal for newly visible row (ANSI-style) */
.cp437-line-reveal {
  overflow: hidden;
  animation: cp437-line-reveal 70ms ease-out forwards;
}

@keyframes cp437-line-reveal {
  from {
    clip-path: inset(0 100% 0 0);
  }

  to {
    clip-path: inset(0 0 0 0);
  }
}

/* Viewer hint (overlay text): 8x16, matches initial/art font */
.cp437-viewer #viewer-hint {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  text-align: left;
  color: #666;
  font-size: 1rem;
  line-height: 1;
  font-family: 'Nouveau IBM ANSI Art 8x16', 'Consolas', 'Monaco', monospace;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.cp437-viewer #viewer-hint.visible {
  opacity: 1;
}

.cp437-viewer label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #aaa;
}

.cp437-viewer select {
  background: #3a3a5c;
  color: #fff;
  border: 1px solid #5a5a8c;
  padding: 6px 10px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.25;
}

.cp437-viewer select option {
  font-family: inherit;
}

.cp437-viewer .cp437-url-input {
  background: #000;
  color: #fff;
  border: 1px solid #5a5a8c;
  padding: 4px 6px;
  border-radius: 0;
  font-family: 'Nouveau IBM ANSI Art 8x16', 'Consolas', 'Monaco', monospace;
  font-size: 1rem;
  line-height: 1.25;
}

.cp437-viewer .cp437-url-input::placeholder {
  color: #666;
}

.cp437-viewer input[type="range"] {
  width: 100px;
}

.cp437-viewer #ansi-wrapper {
  width: 100%;
}

.cp437-viewer #ansi-container {
  background: #000;
  padding: 0;
  overflow: hidden;
  display: inline-block;
  min-height: 200px;
  font-size: 0;
  line-height: 0;
}

.cp437-viewer #ansi-display-wrapper {
  position: relative;
  display: inline-block;
  transform-origin: left top;
  will-change: transform;
}

.cp437-viewer #ansi-display-wrapper #ansi-display {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  position: relative;
  z-index: 1;
}

/*
 * Canvas tiles: pattern pass uses nearest-neighbor in render437.js; text/blocks use smoothing.
 * Let the browser scale the canvas with filtering when the wrapper zooms so sub-8px cells
 * stay readable. Pattern layers for short files are separate DOM (.cp437-pattern-layer), not
 * these canvases; long-file pattern is baked at device res with no extra CSS scale.
 */
.cp437-viewer #ansi-display canvas {
  image-rendering: auto;
}

/* Selectable text overlay (canvas mode): transparent over canvas, allows selection/copy. */
.cp437-viewer .cp437-text-overlay {
  -webkit-user-select: text;
  user-select: text;
}

.cp437-viewer #ansi-display.cp437-font-8x16 {
  font-family: 'Nouveau IBM ANSI Art 8x16';
}

.cp437-viewer #ansi-display.cp437-font-9x16 {
  font-family: 'Nouveau IBM ANSI Art 9x16';
}

.cp437-viewer #ansi-display {
  font-size: 16px;
  line-height: 16px;
  letter-spacing: 0;
  white-space: pre;
  margin: 10px 0;
  padding: 0;
  display: inline-block;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
  font-kerning: none;
  font-feature-settings: "kern" 0;
  transform-origin: left top;
  contain: layout style paint;
}

/* Pattern + canvas: align content with container pattern layer (no top/bottom margin) */
.cp437-viewer #ansi-display.cp437-pattern-canvas {
  margin-top: 0;
  margin-bottom: 0;
}

/* When only the placeholder is shown, constrain width so text wraps on mobile */
.cp437-viewer #ansi-container:has(#drop-zone-placeholder) {
  width: 100%;
  max-width: 100%;
}

.cp437-viewer #ansi-display-wrapper:has(#drop-zone-placeholder) {
  width: 100%;
}

.cp437-viewer #ansi-display:has(#drop-zone-placeholder) {
  width: 100%;
  max-width: 100%;
  white-space: normal;
}

.cp437-viewer #drop-zone-placeholder {
  display: block;
  box-sizing: border-box;
  width: 80%;
  max-width: 100%;
  margin: 10px auto;
  padding: clamp(1rem, 4vw, 2.5rem);
  color: #666;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  word-break: break-word;
}

.cp437-viewer #drop-zone-placeholder span {
  font-size: 1rem;
}

.cp437-viewer #drop-zone-placeholder .drop-zone-label {
  display: inline-block;
  padding: 0.4em 0.75em;
  border: 8px double #5a5a8c;
  margin-bottom: 0.75em;
}

/* Mobile: smaller text and stacked hints so everything fits on screen */
@media (max-width: 480px) {
  .cp437-viewer #drop-zone-placeholder {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
  }

  .cp437-viewer #drop-zone-placeholder span {
    display: block;
    margin-top: 0.35em;
  }

  .cp437-viewer #drop-zone-placeholder span:first-child {
    margin-top: 0;
  }

  .cp437-viewer #drop-zone-placeholder .cp437-btn {
    margin: 0.25em 0;
  }
}

.cp437-row {
  display: block;
  height: 16px;
  line-height: 16px;
  font-size: 16px;
  overflow: visible;
  margin: 0;
  padding: 0;
  contain: layout style;
}

.cp437-row span {
  position: relative;
  font-family: inherit;
  -webkit-font-smoothing: inherit;
  -moz-osx-font-smoothing: inherit;
  margin-bottom: -1px;
  padding-bottom: 1px;
  margin-right: -0.5px;
  padding-right: 0.5px;
}

.cp437-row span.cp437-cell-solid {
  margin-bottom: 0;
  padding-bottom: 0;
}

.cp437-row.cp437-row-above-shade span {
  margin-bottom: 0;
  padding-bottom: 0;
}

.cp437-row span[class*="shade-"] {
  background-repeat: repeat;
  margin-right: 0;
  padding-right: 0;
}

.cp437-row span[class*="shade-m"],
.cp437-row span[class*="shade-d"] {
  image-rendering: pixelated;
  background-origin: padding-box;
  background-clip: padding-box;
}

.cp437-row span[class*="shade-"] {
  margin-bottom: 0;
  padding-bottom: 0;
}

.cp437-row span[class*="shade-m"],
.cp437-row span[class*="shade-d"] {
  margin-right: -0.5px;
  padding-right: 0.5px;
  margin-bottom: -1px;
  padding-bottom: 1px;
}

.cp437-row span[class*="shade-m"]::after,
.cp437-row span[class*="shade-d"]::after {
  display: none;
}

.cp437-row.cp437-row-below-solid span[class*="shade-m"]::before,
.cp437-row.cp437-row-below-solid span[class*="shade-d"]::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -1px;
  height: 1px;
  background-color: inherit;
  background-image: inherit;
  background-repeat: inherit;
  background-size: inherit;
  background-position: inherit;
}

.cp437-row span[class*="shade-hu"]::after,
.cp437-row span[class*="shade-hl"]::after {
  display: none;
}

/* VGA 16-color palette - foreground colors */
.cp437-viewer .f0 {
  color: #000000;
}

.cp437-viewer .f1 {
  color: #0000AA;
}

.cp437-viewer .f2 {
  color: #00AA00;
}

.cp437-viewer .f3 {
  color: #00AAAA;
}

.cp437-viewer .f4 {
  color: #AA0000;
}

.cp437-viewer .f5 {
  color: #AA00AA;
}

.cp437-viewer .f6 {
  color: #AA5500;
}

.cp437-viewer .f7 {
  color: #AAAAAA;
}

.cp437-viewer .f8 {
  color: #555555;
}

.cp437-viewer .f9 {
  color: #5555FF;
}

.cp437-viewer .f10 {
  color: #55FF55;
}

.cp437-viewer .f11 {
  color: #55FFFF;
}

.cp437-viewer .f12 {
  color: #FF5555;
}

.cp437-viewer .f13 {
  color: #FF55FF;
}

.cp437-viewer .f14 {
  color: #FFFF55;
}

.cp437-viewer .f15 {
  color: #FFFFFF;
}

/* VGA 16-color palette - background colors */
.cp437-viewer .b0 {
  --bg: #000000;
  background-color: var(--bg);
}

.cp437-viewer .b1 {
  --bg: #0000AA;
  background-color: var(--bg);
}

.cp437-viewer .b2 {
  --bg: #00AA00;
  background-color: var(--bg);
}

.cp437-viewer .b3 {
  --bg: #00AAAA;
  background-color: var(--bg);
}

.cp437-viewer .b4 {
  --bg: #AA0000;
  background-color: var(--bg);
}

.cp437-viewer .b5 {
  --bg: #AA00AA;
  background-color: var(--bg);
}

.cp437-viewer .b6 {
  --bg: #AA5500;
  background-color: var(--bg);
}

.cp437-viewer .b7 {
  --bg: #AAAAAA;
  background-color: var(--bg);
}

.cp437-viewer .b8 {
  --bg: #555555;
  background-color: var(--bg);
}

.cp437-viewer .b9 {
  --bg: #5555FF;
  background-color: var(--bg);
}

.cp437-viewer .b10 {
  --bg: #55FF55;
  background-color: var(--bg);
}

.cp437-viewer .b11 {
  --bg: #55FFFF;
  background-color: var(--bg);
}

.cp437-viewer .b12 {
  --bg: #FF5555;
  background-color: var(--bg);
}

.cp437-viewer .b13 {
  --bg: #FF55FF;
  background-color: var(--bg);
}

.cp437-viewer .b14 {
  --bg: #FFFF55;
  background-color: var(--bg);
}

.cp437-viewer .b15 {
  --bg: #FFFFFF;
  background-color: var(--bg);
}