:root {
  --paper: #eceae4;
  --ink: #10100f;
  --red: #e21b1b;
  --line: 2px solid var(--ink);
  --mono: "IBM Plex Mono", "Courier New", monospace;
  --display: "Archivo Black", "Arial Black", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--paper); color: var(--ink); font-family: var(--mono); }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }

.grain {
  position: fixed;
  inset: 0;
  z-index: 100;
  opacity: .035;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.topbar {
  min-height: 72px;
  border-bottom: var(--line);
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: stretch;
}
.brand, .system-state, .topbar form { display: flex; align-items: center; padding: 0 24px; }
.brand { gap: 14px; font-family: var(--display); text-decoration: none; font-size: 1.15rem; }
.brand sup { color: var(--red); font: 600 .55rem var(--mono); vertical-align: top; }
.brand-mark { background: var(--ink); color: var(--paper); padding: 8px 7px; }
.system-state { border-left: var(--line); border-right: var(--line); font-size: .7rem; letter-spacing: .08em; }
.status-dot { width: 8px; height: 8px; margin-right: 9px; background: #238b45; }
.text-button { min-height: 44px; border: 0; background: none; cursor: pointer; font-size: .7rem; font-weight: 600; }
.text-button:hover { color: var(--red); }

main { flex: 1; }
.eyebrow { display: block; font-size: .72rem; font-weight: 600; letter-spacing: .1em; margin-bottom: 24px; }
h1, h2, p { margin-top: 0; }
h1, h2 { font-family: var(--display); text-transform: uppercase; }

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  border-bottom: var(--line);
}
.hero-grid > div { padding: clamp(40px, 6vw, 88px) 24px 28px; }
.hero-grid h1 {
  font-size: clamp(4.5rem, 12vw, 11.5rem);
  line-height: .78;
  letter-spacing: -.07em;
  margin: 0;
}
.stats { margin: 0; border-left: var(--line); display: grid; }
.stats div { padding: 20px 24px; border-bottom: var(--line); display: flex; justify-content: space-between; align-items: baseline; }
.stats div:last-child { border: 0; }
.stats dt { font-size: .7rem; letter-spacing: .1em; }
.stats dd { margin: 0; font-family: var(--display); font-size: clamp(1.8rem, 4vw, 4rem); letter-spacing: -.05em; }

.alert { border-bottom: var(--line); display: flex; gap: 16px; padding: 13px 24px; font-size: .8rem; font-weight: 600; }
.alert span { font-family: var(--display); }
.alert-success span { color: #1f713b; }
.alert-error { background: var(--red); color: var(--paper); border-color: var(--ink); }

.section-grid { display: grid; grid-template-columns: minmax(280px, 1fr) 2fr; border-bottom: var(--line); }
.section-heading { padding: 48px 24px; position: relative; }
.section-heading > span { color: var(--red); font-size: .72rem; font-weight: 600; }
.section-heading h2 { font-size: clamp(2.2rem, 4vw, 4rem); line-height: .9; letter-spacing: -.05em; margin: 72px 0 20px; }
.section-heading p { max-width: 34ch; font-size: .8rem; line-height: 1.55; }
.project-list { border-left: var(--line); }
.project-row {
  min-height: 112px;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 120px 48px;
  align-items: stretch;
  border-bottom: var(--line);
  text-decoration: none;
  transition: background-color 160ms ease, color 160ms ease;
}
.project-row:last-child { border-bottom: 0; }
.project-row > span { display: flex; align-items: center; padding: 14px; border-right: var(--line); }
.project-row > span:last-child { border: 0; }
.project-row:hover { background: var(--ink); color: var(--paper); }
.row-index, .project-data { font-size: .68rem; letter-spacing: .06em; }
.project-name { font-family: var(--display); font-size: clamp(1.25rem, 2.5vw, 2.3rem); text-transform: uppercase; flex-direction: column; align-items: flex-start !important; justify-content: center; }
.project-name small { font: 500 .65rem var(--mono); color: var(--red); margin-top: 5px; }
.row-arrow { font-size: 1.5rem; justify-content: center; }
.empty-state { padding: 64px 24px; }
.empty-state strong { font-family: var(--display); font-size: 1.4rem; }
.empty-state p { font-size: .8rem; margin: 12px 0 0; }

.create-grid { display: grid; grid-template-columns: minmax(280px, 1fr) 2fr; background: var(--ink); color: var(--paper); }
.section-heading.inverse { border-right: 2px solid var(--paper); }
.create-form { padding: 48px 24px; display: grid; gap: 28px; align-content: center; }
label { display: block; font-size: .7rem; font-weight: 600; letter-spacing: .08em; margin-bottom: 9px; }
label span { opacity: .55; }
input {
  width: 100%;
  min-height: 54px;
  border: 2px solid currentColor;
  border-radius: 0;
  padding: 0 14px;
  color: inherit;
  background: transparent;
  outline: 0;
}
input:focus { border-color: var(--red); }
.button {
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 18px;
  border: 2px solid var(--ink);
  border-radius: 0;
  text-decoration: none;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease;
}
.button:active { transform: translate(2px, 2px); }
.button-primary { background: var(--red); color: var(--paper); border-color: var(--red); }
.button-light { background: var(--paper); color: var(--ink); border-color: var(--paper); }
.button-light:hover { background: var(--red); border-color: var(--red); color: var(--paper); }
.button-outline { background: transparent; color: var(--ink); }
.button-outline:hover { background: var(--ink); color: var(--paper); }
.button-danger { background: var(--red); color: var(--paper); border-color: var(--red); }

.login-shell { display: grid; grid-template-columns: 1.45fr .55fr; min-height: calc(100vh - 40px); }
.login-title { padding: clamp(40px, 6vw, 90px) 24px; display: flex; flex-direction: column; justify-content: space-between; }
.login-title h1 { font-size: clamp(5rem, 14vw, 13rem); line-height: .78; letter-spacing: -.08em; margin: auto 0; }
.login-title p { max-width: 46ch; font-size: .75rem; }
.login-panel { border-left: var(--line); padding: 24px; display: flex; flex-direction: column; justify-content: center; position: relative; overflow: hidden; }
.panel-index { position: absolute; top: 24px; right: 24px; font-size: .7rem; }
.stack { display: grid; gap: 16px; position: relative; z-index: 1; }
.barcode { position: absolute; left: 24px; right: 24px; bottom: 24px; height: 64px; background: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 5px, var(--ink) 5px 6px, transparent 6px 12px); }

.key-page { min-height: calc(100vh - 112px); display: grid; grid-template-columns: .42fr 1fr; }
.key-number { background: var(--red); color: var(--paper); font-family: var(--display); font-size: clamp(5rem, 12vw, 12rem); line-height: .78; letter-spacing: -.08em; padding: 40px 24px; }
.key-content { padding: clamp(40px, 7vw, 96px) 24px; }
.key-content h1 { font-size: clamp(3.2rem, 8vw, 8rem); line-height: .84; letter-spacing: -.06em; }
.key-content > p { max-width: 58ch; font-size: .8rem; line-height: 1.6; }
.key-box { border: var(--line); display: grid; grid-template-columns: 1fr auto; margin: 40px 0 18px; }
.key-box code { padding: 20px; overflow-wrap: anywhere; align-self: center; }
.key-box .button { border-width: 0 0 0 2px; }

.project-hero { display: grid; grid-template-columns: 1fr auto; min-height: 310px; border-bottom: var(--line); }
.project-hero > div:first-child { padding: 28px 24px; display: flex; flex-direction: column; justify-content: flex-end; }
.project-hero h1 { font-size: clamp(3.5rem, 9vw, 9rem); line-height: .85; letter-spacing: -.065em; margin: 0; overflow-wrap: anywhere; }
.project-hero .eyebrow { margin: auto 0 24px; }
.back-link { font-size: .7rem; font-weight: 600; text-decoration: none; align-self: flex-start; }
.back-link:hover { color: var(--red); }
.project-code { min-width: 260px; border-left: var(--line); background: var(--red); color: var(--paper); padding: 24px; font-family: var(--display); font-size: clamp(4rem, 8vw, 8rem); line-height: .78; text-align: right; }

.control-strip { display: grid; grid-template-columns: 1fr 1fr; border-bottom: var(--line); }
.upload-control { border-right: var(--line); }
.upload-control input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.file-button { min-height: 104px; margin: 0; padding: 18px 24px; display: grid; grid-template-columns: auto 1fr; column-gap: 18px; align-content: center; cursor: pointer; }
.file-button > span { grid-row: span 2; align-self: center; font: 400 2.5rem var(--mono); opacity: 1; }
.file-button strong { font: 1.2rem var(--display); }
.file-button small { margin-top: 5px; }
.file-button:hover { background: var(--ink); color: var(--paper); }
.search-control { display: grid; grid-template-columns: 1fr auto; padding: 16px 24px; }
.search-control label { grid-column: 1 / -1; }
.search-control input { border-right: 0; min-height: 46px; }
.search-control button { width: 54px; border: var(--line); background: var(--red); color: var(--paper); cursor: pointer; }

.media-section { padding: 0 24px 64px; }
.media-header { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: .68rem; }
.media-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: var(--line); border-left: var(--line); }
.media-card { min-width: 0; border-right: var(--line); border-bottom: var(--line); display: grid; grid-template-rows: auto 1fr auto; }
.media-preview { aspect-ratio: 4/3; border: 0; border-bottom: var(--line); padding: 0; overflow: hidden; position: relative; background: #d4d2cc; cursor: zoom-in; }
.media-preview img { width: 100%; height: 100%; display: block; object-fit: cover; filter: saturate(.85); transition: transform 240ms cubic-bezier(.22, 1, .36, 1); }
.media-preview:hover img { transform: scale(1.025); }
.media-preview span { position: absolute; right: 0; bottom: 0; background: var(--ink); color: var(--paper); padding: 8px 10px; font: 600 .6rem var(--mono); opacity: 0; transition: opacity 120ms ease; }
.media-preview:hover span { opacity: 1; }
.media-meta { padding: 14px; display: grid; gap: 7px; min-width: 0; }
.media-meta strong { font-family: var(--display); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-meta samp { font: 500 .62rem var(--mono); letter-spacing: .03em; overflow: hidden; text-overflow: ellipsis; }
.media-actions { display: grid; grid-template-columns: 1fr auto; border-top: var(--line); }
.media-actions button { min-height: 42px; border: 0; background: none; padding: 0 12px; font-size: .65rem; font-weight: 600; cursor: pointer; }
.media-actions > button { text-align: left; }
.media-actions form { border-left: var(--line); }
.media-actions button:hover { background: var(--ink); color: var(--paper); }
.media-actions .danger:hover { background: var(--red); }
.media-empty { border: var(--line); }
.pagination { min-height: 64px; border: var(--line); border-top: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; }
.pagination > * { display: flex; align-items: center; justify-content: center; padding: 12px; font-size: .68rem; font-weight: 600; text-decoration: none; }
.pagination a:first-child { justify-content: flex-start; }
.pagination a:last-child { justify-content: flex-end; }
.pagination a:hover { background: var(--ink); color: var(--paper); }

.audit-section { display: grid; grid-template-columns: minmax(280px, 1fr) 2fr; border-top: var(--line); }
.audit-list { border-left: var(--line); }
.audit-row { min-height: 56px; display: grid; grid-template-columns: 180px 1fr 1fr 70px; border-bottom: var(--line); align-items: center; }
.audit-row:last-child { border-bottom: 0; }
.audit-row > * { min-width: 0; padding: 12px 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .65rem; border-right: var(--line); }
.audit-row > *:last-child { border-right: 0; text-align: center; }
.audit-row strong { font-family: var(--display); font-size: .72rem; }

.danger-zone { border-top: var(--line); display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: end; padding: 48px 24px; }
.danger-zone h2 { margin: 0; font-size: 2rem; }
.danger-zone .eyebrow { margin-bottom: 12px; }

dialog { width: min(90vw, 1100px); max-height: 90vh; border: var(--line); padding: 46px 16px 16px; background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgb(16 16 15 / .82); }
dialog img { width: 100%; max-height: 72vh; object-fit: contain; display: block; background: #d4d2cc; }
dialog p { font-size: .7rem; margin: 12px 0 0; }
.dialog-close { position: absolute; top: 0; right: 0; min-height: 36px; border: 0; border-left: var(--line); border-bottom: var(--line); background: var(--red); color: var(--paper); cursor: pointer; font-size: .65rem; }

.error-page { display: grid; grid-template-columns: 1fr 1fr; min-height: calc(100vh - 40px); }
.error-code { background: var(--red); color: var(--paper); font: clamp(8rem, 25vw, 25rem)/.8 var(--display); letter-spacing: -.1em; padding: 24px; overflow: hidden; }
.error-page > div { padding: 48px 24px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
.error-page h1 { font-size: clamp(3rem, 7vw, 7rem); line-height: .88; letter-spacing: -.06em; }
.error-page p { font-size: .8rem; line-height: 1.6; max-width: 50ch; }
.error-page .button { margin-top: 24px; }

.footer { min-height: 40px; border-top: var(--line); display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 0 24px; font-size: .6rem; letter-spacing: .08em; }

@media (max-width: 850px) {
  .system-state { display: none; }
  .topbar { grid-template-columns: 1fr auto; }
  .topbar form { border-left: var(--line); padding: 0 12px; }
  .hero-grid, .section-grid, .create-grid, .login-shell, .key-page { grid-template-columns: 1fr; }
  .audit-section { grid-template-columns: 1fr; }
  .audit-list { border-left: 0; border-top: var(--line); }
  .stats, .project-list, .login-panel { border-left: 0; border-top: var(--line); }
  .section-heading.inverse { border-right: 0; border-bottom: 2px solid var(--paper); }
  .login-panel { min-height: 420px; }
  .key-number { font-size: 5rem; }
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .danger-zone { grid-template-columns: 1fr; align-items: stretch; }
  .danger-zone .button { width: 100%; }
}

@media (max-width: 560px) {
  .brand { padding: 0 12px; }
  .brand > span:last-child { display: none; }
  .hero-grid h1 { font-size: 4rem; }
  .project-row { grid-template-columns: 42px minmax(0, 1fr) 40px; }
  .project-data { display: none !important; }
  .project-hero { grid-template-columns: 1fr; }
  .project-code { display: none; }
  .control-strip { grid-template-columns: 1fr; }
  .upload-control { border-right: 0; border-bottom: var(--line); }
  .media-section { padding-inline: 12px; }
  .media-header { align-items: flex-start; flex-direction: column; justify-content: center; }
  .audit-row { grid-template-columns: 1fr auto; }
  .audit-row > * { border-right: 0; }
  .audit-row span, .audit-row samp { display: none; }
  .media-grid { grid-template-columns: 1fr; }
  .media-preview span { opacity: 1; }
  .key-box { grid-template-columns: 1fr; }
  .key-box .button { border-width: 2px 0 0; }
  .error-page { grid-template-columns: 1fr; }
  .error-code { font-size: 8rem; }
  .footer span:nth-child(2) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

@media (forced-colors: active) {
  .status-dot, .button-primary, .button-danger, .search-control button { forced-color-adjust: none; }
}
