:root {
  --bg: #f5f5f5;
  --ink: #2d3142;
  --muted: #4f5d75;
  --soft: #7a8399;
  --hairline: rgba(45,49,66,.14);
  --accent: #eb6c36;
  --font-sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, Consolas, Menlo, monospace;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  padding-bottom: 60px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--hairline);
  background: white;
  color: var(--ink);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 14px;
}
button:hover { background: #eee; }

input, select {
  font-family: inherit;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 14px;
  background: white;
}

code { font-family: var(--font-mono); }

/* Top bar */
.top-bar {
  position: sticky;
  top: 56px;
  background: rgba(245, 245, 245, 0.95);
  backdrop-filter: blur(8px);
  z-index: 100;
  border-bottom: 1px solid var(--hairline);
  padding: 12px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}
.top-bar h1 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.status-label { font-size: 13px; color: var(--soft); }
.drop-zone {
  border: 1px dashed var(--soft);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--soft);
  position: relative;
  overflow: hidden;
  background: white;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragover { background: var(--hairline); border-color: var(--ink); color: var(--ink); }
.drop-zone input[type="file"] {
  position: absolute; top: 0; left: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;
}

/* Sections */
.section { padding: 24px; border-bottom: 1px solid var(--hairline); }

/* Headline */
.headline-strip { display: flex; gap: 32px; flex-wrap: wrap; }
.headline-stat { display: flex; flex-direction: column; }
.stat-val { font-family: var(--font-mono); font-size: 24px; font-weight: bold; }
.stat-val.accent { color: var(--accent); }
.stat-lbl { color: var(--soft); font-size: 11px; text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; }

/* UpSet */
.upset-container { display: flex; overflow-x: auto; padding: 24px; align-items: flex-start; border-bottom: 1px solid var(--hairline); }
.upset-left { display: flex; flex-direction: column; padding-right: 16px; border-right: 1px solid var(--hairline); padding-top: 132px; }
.upset-row { display: flex; align-items: center; justify-content: flex-end; height: 24px; cursor: pointer; outline: none; }
.upset-row:hover .row-label, .upset-row:focus .row-label { color: var(--accent); }
.row-label { font-size: 13px; margin-right: 12px; text-align: right; user-select: none; }
.row-bar-wrap { width: 120px; background: var(--hairline); height: 12px; border-radius: 2px; }
.row-bar { background: var(--muted); height: 100%; border-radius: 2px; }
.row-count { font-family: var(--font-mono); font-size: 12px; margin-left: 8px; color: var(--soft); width: 24px; }

.upset-right { display: flex; gap: 8px; padding-left: 16px; }
.upset-group { display: flex; flex-direction: column; align-items: center; border-radius: 6px; background: rgba(0,0,0,0.03); padding: 4px; }
.upset-group.alt { background: transparent; }
.group-label { height: 20px; line-height: 20px; margin-bottom: 4px; font-size: 10px; color: var(--soft); font-weight: bold; letter-spacing: 1px; }
.group-cols { display: flex; gap: 4px; padding: 0 4px; }

.combo-col { display: flex; flex-direction: column; align-items: center; cursor: pointer; outline: none; border-radius: 4px; padding: 0 2px; }
.combo-col:hover, .combo-col:focus { background: rgba(235,108,54,0.05); }
.col-top { height: 108px; width: 16px; position: relative; }
.col-bar { position: absolute; bottom: 0; left: 0; width: 100%; background: var(--muted); border-radius: 2px 2px 0 0; }
.combo-col:hover .col-bar { background: var(--accent); }
.col-count { position: absolute; bottom: calc(var(--h) + 4px); left: 0; width: 16px; text-align: center; font-family: var(--font-mono); font-size: 11px; color: var(--soft); writing-mode: vertical-rl; transform: rotate(180deg); }
.combo-col:hover .col-count { color: var(--accent); }

.dots { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; position: relative; }
.dot { width: 16px; height: 16px; border-radius: 50%; background: var(--bg); border: 2px solid var(--hairline); z-index: 2; box-sizing: border-box; outline: none; }
.dot:focus { box-shadow: 0 0 0 2px rgba(235,108,54,0.5); }
.dot.filled { background: var(--ink); border-color: var(--ink); }
.combo-col:hover .dot.filled { background: var(--accent); border-color: var(--accent); }
.dot-line { position: absolute; width: 2px; background: var(--ink); left: 7px; z-index: 1; }
.combo-col:hover .dot-line { background: var(--accent); }

/* Thesis column */
.combo-col.thesis .col-bar { background: transparent; border: 1px dashed var(--accent); width: 14px; left: 1px; }
.combo-col.thesis .dot.filled { background: var(--accent); border-color: var(--accent); }
.combo-col.thesis .dot-line { background: var(--accent); }
.thesis-lbl { color: var(--accent); font-weight: bold; font-size: 10px; writing-mode: vertical-rl; transform: rotate(180deg); position: absolute; bottom: calc(var(--h) + 4px); left: 0; white-space: nowrap; margin-bottom: 4px; }

/* Filter Bar */
.filter-bar { padding: 16px 24px; border-bottom: 1px solid var(--hairline); display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.chip { display: inline-flex; align-items: center; background: white; border: 1px solid var(--hairline); border-radius: 16px; padding: 4px 12px; font-size: 13px; cursor: pointer; user-select: none; outline: none; }
.chip:focus { border-color: var(--accent); }
.chip.active { background: rgba(235,108,54,0.1); border-color: var(--accent); color: var(--accent); font-weight: 500; }
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; border-right: 1px solid var(--hairline); padding-right: 12px; }

.active-filters { padding: 0 24px 16px; display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--hairline); }

/* Table */
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 12px 16px; border-bottom: 2px solid var(--hairline); font-size: 11px; color: var(--soft); text-transform: uppercase; cursor: pointer; user-select: none; font-weight: 600; letter-spacing: 0.5px; }
th:hover { color: var(--ink); }
td { padding: 12px 16px; border-bottom: 1px solid var(--hairline); font-size: 14px; vertical-align: top; }
tr.paper-row { cursor: pointer; outline: none; }
tr.paper-row:hover, tr.paper-row:focus { background: rgba(0,0,0,0.02); }
tr.expanded { background: rgba(0,0,0,0.02); }
.col-dims { width: 60px; font-weight: bold; font-family: var(--font-mono); }
.col-dims.high { color: var(--accent); }
.col-cit { width: 35%; }
.col-year { width: 60px; }
.col-type { width: 120px; }
.col-matrix { width: 120px; }
.matrix-wrap { display: flex; gap: 3px; }
.dim-sq { width: 12px; height: 12px; border: 1px solid var(--hairline); box-sizing: border-box; background: white; }
.dim-sq.f { background: var(--ink); border-color: var(--ink); }
.col-rel { width: 60px; }
.col-spk { width: 60px; }
.col-d3 { width: 80px; }

/* Detail Panel */
.detail-panel { background: white; padding: 24px; border-bottom: 1px solid var(--hairline); box-shadow: inset 0 4px 6px rgba(0,0,0,0.02); margin: 0; }
.detail-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 24px; margin-bottom: 24px; }
.detail-meta > div { font-size: 14px; }
.detail-meta label { display: block; color: var(--soft); font-size: 11px; text-transform: uppercase; margin-bottom: 4px; font-weight: 600; }
.abstract-box { background: var(--bg); padding: 16px; border-radius: 6px; font-size: 14px; margin-bottom: 24px; border: 1px solid var(--hairline); line-height: 1.6; }
.links { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.links a { color: var(--accent); text-decoration: none; font-size: 14px; font-weight: 500; }
.links a:hover { text-decoration: underline; }

.error-msg { background: #fee; color: #c00; padding: 12px 24px; font-size: 14px; font-weight: 500; border-bottom: 1px solid #fcc; }
footer { padding: 32px 24px; text-align: center; color: var(--soft); font-size: 12px; }

.col-rev { width: 110px; white-space: nowrap; }
.rev-yes { color: #2e7d4f; font-weight: 600; font-size: 12px; }
.rev-no { color: #7a8399; }
footer strong { color: #eb6c36; }

/* Mobile Layout */
@media (max-width: 760px) {
  /* Headline strip */
  .headline-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
  }
  
  /* UpSet sticky rows */
  .upset-container {
    padding: 16px;
  }
  .upset-left {
    position: sticky;
    left: 0;
    z-index: 10;
    background: var(--bg);
    padding-right: 8px;
    padding-top: 132px;
  }
  .row-label { font-size: 11px; margin-right: 8px; }
  .row-bar-wrap { width: 60px; }
  
  /* Filter bar wraps */
  .filter-bar {
    gap: 8px;
  }
  
  /* Type chips */
  .types-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .type-chip {
    display: inline-flex;
    align-items: center;
    background: white;
    border: 1px solid var(--hairline);
    border-radius: 16px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    outline: none;
  }
  .type-chip.active {
    background: rgba(235,108,54,0.1);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 500;
  }

  /* Table becomes stacked cards */
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr:not(.paper-row) { padding: 0; border: 0; margin: 0; background: transparent; }
  tr.paper-row { 
    position: relative;
    padding: 16px;
    border: 1px solid var(--hairline);
    margin-bottom: 12px;
    border-radius: 8px;
    background: white;
  }
  .col-cit { width: 100%; font-weight: 600; padding: 0 0 8px 0; border: none; }
  .col-dims, .col-year, .col-type, .col-rel, .col-spk, .col-d3, .col-rev { 
    display: inline-block;
    width: auto;
    padding: 0;
    margin-right: 12px;
    font-size: 13px;
    color: var(--soft);
    border: none;
  }
  .col-dims::before { content: "Dims: "; }
  .col-year::before { content: "Year: "; }
  .col-type::before { content: "Type: "; }
  .col-rel::before { content: "Rel: "; }
  .col-spk::before { content: "Spk: "; }
  .col-d3::before { content: "D3: "; }
  
  .col-matrix {
     padding: 8px 0 0 0;
     border: none;
  }
  .matrix-wrap {
     flex-wrap: wrap;
  }
  .col-rev {
     padding-top: 8px;
     display: block;
  }

  /* Detail Panel as Bottom Sheet */
  .detail-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 2000;
    border-radius: 16px 16px 0 0;
    box-sizing: border-box;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
  }
  .abstract-box {
    font-size: 15px;
  }
}

.types-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.type-chip {
  display: inline-flex;
  align-items: center;
  background: white;
  border: 1px solid var(--hairline);
  border-radius: 16px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  outline: none;
}
.type-chip.active {
  background: rgba(235,108,54,0.1);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

.mobile-close-btn {
  display: none;
}
@media (max-width: 760px) {
  .mobile-close-btn {
    display: block;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.05);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    text-align: center;
    padding: 0;
    color: var(--ink);
  }
  .detail-panel { padding-top: 48px; }
}

/* Dimension legend: hidden on desktop (names are on the rows), shown on phones */
.dim-legend { display: none; }
/* Type filter as a collapsible group */
.types-details { display: inline-block; }
.types-details summary { cursor: pointer; padding: 6px 12px; border: 1px solid var(--hairline); border-radius: 16px; background: white; font-size: 13px; list-style: none; }
.types-details summary::-webkit-details-marker { display: none; }
.types-details[open] summary { border-color: var(--accent); color: var(--accent); }
.types-details .types-chip-list { padding: 8px 0 0; }
@media (max-width: 760px) {
  /* rows: code only, one line, narrow sticky column so the chart gets the width */
  .upset-left { padding-top: 132px; padding-right: 6px; }
  .upset-row { height: 24px; }
  .row-label { font-size: 12px; margin-right: 6px; white-space: nowrap; font-family: var(--font-mono); font-weight: 600; }
  .row-name { display: none; }
  .row-bar-wrap { width: 40px; }
  .row-count { width: 20px; font-size: 11px; margin-left: 4px; }
  .dim-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 16px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--hairline); }
  .dim-legend b { font-family: var(--font-mono); color: var(--ink); margin-right: 4px; }
  .types-chip-list { max-height: 160px; overflow-y: auto; }
}

@media (max-width: 760px) {
  /* the page header is tall on phones; let it scroll away so the chart is not hidden under it */
  .top-bar { position: static; }
}

@media (max-width: 760px), (pointer: coarse) {
  /* on touch screens the whole column is the tap target; individual dots are too small to aim at */
  .combo-col .dot { pointer-events: none; }
  .combo-col { padding: 0 4px; }
}

/* Desktop fixes (9 Oct): the left column must never shrink or wrap; the Type control aligns with the inputs */
.upset-left { flex: 0 0 auto; }
.row-label { white-space: nowrap; }
.filter-bar > * { align-self: center; }
.types-details summary { height: 34px; display: inline-flex; align-items: center; box-sizing: border-box; }
.types-details { position: relative; }
.types-details .types-chip-list { position: absolute; top: 40px; left: 0; z-index: 20; background: white; border: 1px solid var(--hairline); border-radius: 8px; padding: 8px; min-width: 260px; display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 760px) {
  .types-details .types-chip-list { position: static; border: 0; padding: 8px 0 0; min-width: 0; }
}
.types-details { display: inline-flex; align-items: center; height: 34px; margin: 0; border: 0; border-radius: 0; background: none; } /* undo the page-level details box from site.css */
.filter-bar input, .filter-bar select, .filter-bar button { height: 34px; box-sizing: border-box; }
