*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #141414;
  --surface: #1c1c1c;
  --border: #2a2a2a;
  --text-primary: #d4d4d4;
  --text-muted: #555;
  --text-category: #444;
  --text-description: #3a3a3a;
  --accent: #d4d4d4;
  --hover-bg: #1f1f1f;
  --font: 'SF Mono', 'Fira Mono', 'Consolas', monospace;

  /* Layout tokens — mobile first */
  --padding-x: 16px;
  --type-col-w: 0px;
}

/* ── RESPONSIVE BREAKPOINTS ── */

/* Tablet */
@media (min-width: 768px) {
  :root {
    --padding-x: 48px;
    --type-col-w: 96px; /* 80px col + 16px gap */
  }
}

/* Desktop */
@media (min-width: 1100px) {
  :root {
    --padding-x: 124px;
    --type-col-w: 116px; /* 100px col + 16px gap */
  }
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  line-height: 1;
  overflow-x: hidden;
}

/* ── HERO ── */
.hero {
  width: 100%;
  min-height: 38vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-top: 0;
  padding-bottom: 40px;
  padding-left: calc(var(--padding-x) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--padding-x) + env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--border);
}

@media (min-width: 768px) {
  .hero { margin-top: 232px; }
}

.hero-title {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 900;
  font-size: clamp(32px, 7.8vw, 130px);
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: #ffffff;
  text-transform: uppercase;
  text-wrap: pretty;
  margin-bottom: 16px;
}

.hero-sub {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 0.7vw, 12px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.hero-accent {
  color: #e02020;
}

.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-left: calc(var(--padding-x) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--padding-x) + env(safe-area-inset-right, 0px));
}

/* ── TOPBAR ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

@media (min-width: 768px) {
  .topbar { gap: 32px; padding: 20px 0 16px; }
}

/* "type" label — visible on all sizes */
.version {
  display: block;
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  /* mobile: col-category(80px) - topbar gap(16px) = 64px */
  width: 64px;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .version {
    font-size: 14px;
    color: var(--text-primary);
    /* col-category(80px) - topbar gap(32px) = 48px */
    width: 48px;
  }
}

@media (min-width: 1100px) {
  .version {
    /* col-category(100px) - topbar gap(32px) = 68px */
    width: 68px;
  }
}

.sort-controls {
  display: flex;
  gap: 16px;
  flex: 1;
}

@media (min-width: 768px) {
  .sort-controls { gap: 24px; }
}

.sort-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  text-align: left;
  letter-spacing: 0.02em;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

/* date button — hidden on mobile (col-date is hidden there) */
.sort-btn[data-sort="date"] {
  display: none;
}

@media (min-width: 768px) {
  .sort-btn {
    font-size: 14px;
  }
  .sort-btn[data-sort="date"] {
    display: inline-block;
    width: 56px; /* 80px col - 24px padding-right = 56px content */
  }
}

.sort-btn.active { color: var(--text-primary); }
.sort-btn:hover  { color: var(--text-primary); }

.sort-btn .arrow {
  display: inline-block;
  transition: transform 0.2s;
}

.sort-btn.asc  .arrow { transform: rotate(0deg); }
.sort-btn.desc .arrow { transform: rotate(180deg); }

.search-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  letter-spacing: 0.02em;
  transition: color 0.15s;
  margin-left: auto;
  -webkit-tap-highlight-color: transparent;
}

.search-btn:hover { color: var(--text-primary); }

/* ── SEARCH BAR ── */
.search-bar {
  display: none;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.search-bar.open { display: block; }

.search-bar input {
  width: 100%;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  letter-spacing: 0.02em;
  /* Prevent iOS zoom on focus */
  font-size: max(16px, 14px);
}

@media (min-width: 768px) {
  .search-bar input { font-size: 14px; }
}

.search-bar input::placeholder { color: var(--text-muted); }

/* ── TABLE ── */
.table-wrapper { flex: 1; }

table {
  width: 100%;
  border-collapse: collapse;
}

tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

tbody tr:hover { background: var(--hover-bg); }

td {
  padding: 30px 0;
  vertical-align: middle;
  font-size: 14px;
}

@media (min-width: 768px) {
  td {
    padding: 10px 0;
    font-size: 14px;
  }
}

/* Borders on date, name, description within a group */
.col-date,
.col-name,
.col-description {
  border-bottom: 1px solid var(--border);
}

/* Last row of each group: full border including category column */
tr.group-end .col-category {
  border-bottom: 1px solid var(--border);
}

/* category column — visible on mobile, stays on tablet+ */
.col-category {
  display: table-cell;
  color: var(--text-category);
  font-size: 11px;
  width: 80px;
  padding-right: 16px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

@media (min-width: 1100px) {
  .col-category { width: 100px; }
}

/* date column — hidden on mobile */
.col-date {
  display: none;
}

@media (min-width: 768px) {
  .col-date {
    display: table-cell;
    color: var(--text-muted);
    width: 80px;
    padding-right: 24px;
    letter-spacing: 0.02em;
    white-space: nowrap;
  }
}

/* name column */
.col-name {
  color: var(--text-primary);
  letter-spacing: 0.01em;
  padding-right: 16px;
}

@media (min-width: 768px) {
  .col-name { width: 200px; padding-right: 32px; }
}

@media (min-width: 1100px) {
  .col-name { width: 220px; }
}

/* description column — hidden on mobile */
.col-description {
  display: none;
}

@media (min-width: 768px) {
  .col-description {
    display: table-cell;
    color: var(--text-description);
    font-size: 11px;
    letter-spacing: 0.01em;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (min-width: 1100px) {
  .col-description { max-width: 340px; }
}


/* ── FLOATING PREVIEW — desktop only ── */
.preview {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  display: none;
}

@media (min-width: 768px) {
  .preview { display: block; }
}

.preview.visible { opacity: 1; }

.preview img {
  display: block;
  width: 280px;
  height: 200px;
  object-fit: cover;
}

.preview.no-image img { display: none; }

/* ── MOBILE SCROLL PREVIEW ── */
#mob-preview {
  display: none;
}

@media (max-width: 767px) {
  /* Preview image — fixed right side, vertically centred */
  #mob-preview {
    display: block;
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 54vw;
    height: calc(54vw * 0.5625); /* 16:9 */
    background-size: cover;
    background-position: center;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    z-index: 4;
  }

  #mob-preview.loaded { opacity: 1; }

  /* Name colour transitions */
  .col-name { transition: color 0.25s ease, opacity 0.25s ease; }

  /* Active row — bright white */
  tbody tr.mob-active .col-name {
    color: #fff !important;
    opacity: 1 !important;
  }

  /* Inactive rows — dimmed */
  tbody tr:not(.mob-active) .col-name {
    color: #444 !important;
    opacity: 0.6;
  }

  /* Type column — sticky left so it stays visible */
  .col-category {
    position: sticky;
    left: 0;
    background: var(--bg);
    z-index: 2;
  }

  /* Hero — sticky at top on mobile */
  .hero {
    position: sticky;
    top: 0;
    z-index: 6;
    background: var(--bg);
    min-height: unset;
    padding-top: 32px;
    padding-bottom: 24px;
  }
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
