/* ============================================================
   C64 Listing Edition — Commodore 64 terminal simulation
   ============================================================ */

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

html, body {
  height: 100%;
  min-height: 100vh;
  background: #1A1ACC;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #7B7FFF;
  overflow-x: hidden;
}

/* --- Scanline overlay ------------------------------------- */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 1px,
    rgba(0, 0, 0, 0.18) 1px,
    rgba(0, 0, 0, 0.18) 2px
  );
  opacity: 0.15;
  pointer-events: none;
  z-index: 9999;
}

/* --- C64 border / outer shell ----------------------------- */
.c64-border {
  background: #1A1ACC;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px 80px;
}

/* --- Inner screen area ------------------------------------ */
.c64-screen {
  background: #000080;
  color: #7B7FFF;
  border-radius: 12px;
  box-shadow: 0 0 60px #4040FF80, 0 0 0 3px #1A1ACC;
  width: 100%;
  max-width: 1100px;
  min-height: calc(100vh - 120px);
  padding: 20px 16px 24px;
  position: relative;
  overflow: hidden;
}

/* --- Boot zone ------------------------------------------- */
.c64-boot {
  margin-bottom: 24px;
  min-height: 120px;
  white-space: pre-wrap;
  word-break: break-word;
}

.c64-boot-text {
  color: #7B7FFF;
  white-space: pre-wrap;
}

.c64-cursor {
  display: inline-block;
  color: #7B7FFF;
  animation: blink 0.5s step-end infinite;
  line-height: 1;
}

@keyframes blink {
  0%, 100% { visibility: visible; }
  50%       { visibility: hidden; }
}

.c64-cursor.hidden {
  display: none;
}

/* --- LIST ALL bar ---------------------------------------- */
.c64-list-all-bar {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.c64-list-all-btn {
  background: #000080;
  color: #FFFFFF;
  border: 1px solid #7B7FFF;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 10px;
  padding: 4px 10px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: background 0.1s, color 0.1s;
}

.c64-list-all-btn:hover {
  background: #7B7FFF;
  color: #000080;
}

.c64-list-all-hint {
  color: #7B7FFF;
  font-size: 9px;
  opacity: 0.6;
}

/* --- Table container ------------------------------------- */
.c64-listing-wrap {
  opacity: 0;
}

.c64-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Table ----------------------------------------------- */
.c64-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

/* Column widths */
.col-line        { width: 6ch; }
.col-name        { width: 22ch; }
.col-years       { width: 8ch; }
.col-cat         { width: 10ch; }
.col-desc        { /* remaining */ }
.col-pgs         { width: 4ch; }

/* Headers */
.c64-table thead tr {
  border-bottom: 2px solid #7B7FFF;
}

.c64-table thead th {
  color: #FFFFFF;
  text-align: left;
  padding: 6px 8px 8px;
  font-size: 11px;
  letter-spacing: 0.05em;
  white-space: nowrap;
  user-select: none;
}

.c64-table thead th.col-years,
.c64-table thead th.col-cat,
.c64-table thead th.col-pgs {
  text-align: center;
}

.c64-table thead th.sortable {
  cursor: pointer;
}

.c64-table thead th.sortable:hover {
  color: #7B7FFF;
}

.c64-table thead th.sort-active {
  color: #FFFFFF;
  text-decoration: underline;
}

/* Data rows */
.c64-table tbody tr.data-row {
  border-bottom: 1px solid rgba(123, 127, 255, 0.15);
  cursor: default;
}

.c64-table tbody tr.data-row td {
  padding: 5px 8px;
  color: #7B7FFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  font-size: 10px;
}

/* LINE number */
td.td-line {
  color: #FFFFFF;
  text-align: right;
  font-size: 10px;
}

/* NAME link */
td.td-name a {
  color: #7B7FFF;
  text-decoration: none;
}

td.td-name a:hover {
  color: #000080;
}

/* YEARS */
td.td-years {
  text-align: center;
}

/* CAT badge */
td.td-cat {
  text-align: center;
}

.cat-badge {
  display: inline-block;
  border: 1px solid #7B7FFF;
  padding: 1px 4px;
  font-size: 9px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* CAT 1-char mobile version (hidden by default) */
.cat-short {
  display: none;
}

/* DESCRIPTION */
td.td-desc {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* PGS */
td.td-pgs {
  text-align: center;
}

/* Section divider rows */
tr.section-divider td {
  color: #FFFFFF;
  padding: 10px 8px 4px;
  font-size: 10px;
  white-space: nowrap;
  border: none;
  overflow: visible;
}

/* --- Tooltip --------------------------------------------- */
.c64-tooltip {
  position: fixed;
  background: #000080;
  color: #FFFFFF;
  border: 1px solid #7B7FFF;
  padding: 8px 12px;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 9px;
  line-height: 1.8;
  max-width: 320px;
  z-index: 9000;
  pointer-events: none;
  opacity: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.c64-tooltip::before {
  content: 'PRINT "';
  color: #7B7FFF;
  display: block;
  margin-bottom: 4px;
}

.c64-tooltip::after {
  content: '"';
  color: #7B7FFF;
  display: block;
  margin-top: 4px;
}

/* --- Status bar ------------------------------------------ */
.c64-status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1A1ACC;
  border-top: 2px solid #7B7FFF;
  color: #7B7FFF;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 9px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  z-index: 1000;
  white-space: nowrap;
}

.status-ready {
  color: #FFFFFF;
}

.status-sites,
.status-sort {
  color: #7B7FFF;
}

.status-link {
  color: #7B7FFF;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.status-link:hover {
  color: #FFFFFF;
  border-bottom-color: #7B7FFF;
}

/* --- Responsive ------------------------------------------ */
@media (max-width: 767px) {
  .col-desc,
  td.td-desc,
  thead th.col-desc {
    display: none;
  }

  .cat-badge {
    display: none;
  }

  .cat-short {
    display: inline;
  }

  .c64-table {
    font-size: 9px;
  }
}

@media (min-width: 768px) and (max-width: 1279px) {
  /* description shown but more truncated — handled in JS */
}

/* --- prefers-reduced-motion ------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .c64-cursor {
    animation: none;
    visibility: visible;
  }

  .c64-listing-wrap {
    opacity: 1;
  }

  .c64-table tbody tr.data-row {
    opacity: 1;
  }
}
