:root {
  --bg: #0d1117; --panel: #161b22; --border: #30363d; --fg: #e6edf3; --muted: #8b949e;
  --green: #3fb950; --red: #f85149; --amber: #d29922; --link: #58a6ff;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--panel);
}
header .brand { font-weight: 700; font-size: 18px; color: var(--fg); }
header .tag { color: var(--muted); font-size: 13px; }
header .user { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; }
header .user .me { color: var(--fg); display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
header .user .avatar { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border); }
header .user .navlink { color: var(--muted); }
main { max-width: 960px; margin: 0 auto; padding: 24px; }
footer { max-width: 960px; margin: 40px auto; padding: 0 24px; color: var(--muted); font-size: 13px; }

h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 28px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.empty { color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; }
.back, .clone { color: var(--muted); margin: 0 0 16px; }
.hash, .cmsg, .msg { color: var(--fg); }

ul.repos, ul.branches, ol.timeline { list-style: none; padding: 0; margin: 0; }
ul.repos li, ol.timeline li, ul.branches li {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--panel);
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: baseline;
}
ul.repos li a, ol.timeline li a { font-weight: 600; }
ol.timeline li a, ul.branches .hash { font-family: ui-monospace, monospace; }
.msg, .cmsg { flex-basis: 100%; }

.grief {
  border: 1px solid var(--border); border-left: 3px solid var(--amber); border-radius: 8px;
  padding: 12px 14px; margin: 16px 0; background: var(--panel);
}
.grief .g-d { color: var(--red); font-weight: 600; }
.grief .g-b { color: var(--green); font-weight: 600; }
.grief .g-r { color: var(--amber); font-weight: 600; }
.grief .g-where, .grief .g-top { color: var(--muted); font-size: 13px; margin-top: 6px; }

.cmeta { margin: 0 0 16px; }
.file { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px; overflow: hidden; }
.file .fh { padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--border); font-family: ui-monospace, monospace; font-size: 13px; }
.file .err { padding: 8px 14px; color: var(--red); }
.chunk { padding: 8px 14px 2px; color: var(--muted); font-size: 12px; }
ul.changes { list-style: none; margin: 0; padding: 4px 14px 10px; }
ul.changes li { font-family: ui-monospace, monospace; font-size: 12.5px; padding: 1px 0; }
.ch-added { color: var(--green); }
.ch-removed { color: var(--red); }
.ch code { color: var(--fg); }
.note { color: var(--muted); }
.more { color: var(--muted); font-size: 12px; padding: 4px 14px; }

.st { font-size: 11px; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; font-weight: 700; }
.st-modified { background: #1f2937; color: var(--amber); }
.st-added { background: #11271b; color: var(--green); }
.st-removed { background: #2a1416; color: var(--red); }

/* rendered world maps */
.map { margin: 16px 0; }
.map .map-box { max-width: 512px; }
.maps { display: flex; flex-wrap: wrap; gap: 16px; margin: 16px 0; }
.maps figure { margin: 0; flex: 1; min-width: 220px; }
.maps figcaption { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; margin-bottom: 6px; }

.map-box {
  position: relative; min-height: 150px; overflow: hidden;
  border: 1px solid var(--border); border-radius: 8px; background: #11161c;
}
.map-box img { width: 100%; height: auto; image-rendering: pixelated; display: block; }
.map-box.loading img { visibility: hidden; min-height: 150px; }
.map-status {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  gap: 10px; color: var(--muted); font-size: 13px; text-align: center; padding: 12px;
}
.map-box.loading .map-status, .map-box.error .map-status { display: flex; }
.map-box.error .map-status { color: var(--red); }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--link);
  border-radius: 50%; animation: spin .8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* time-machine scrubber */
.scrubber { display: flex; align-items: center; gap: 14px; margin: 4px 0 6px; }
.scrubber input[type=range] { flex: 1; accent-color: var(--link); height: 4px; cursor: pointer; }
.scrubber #tm-play {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.scrubber #tm-play:hover { border-color: var(--link); }
.scrubber #tm-when { font-family: ui-monospace, monospace; font-size: 12px; white-space: nowrap; }

.actions { font-size: 13px; }
.actions a { color: var(--link); }
ol.timeline li .actions { flex-basis: 100%; }
p.actions { margin: 0 0 16px; }

form.find { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }
form.find select, form.find input, form.find button {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; font: inherit;
}
form.find input { flex: 1; min-width: 200px; }
form.find button { cursor: pointer; font-weight: 600; }
form.find button:hover { border-color: var(--link); }

/* visibility + ownership badges */
.vis { font-size: 11px; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; font-weight: 700; }
.vis-private { background: #2a1416; color: var(--red); }
.vis-public { background: #11271b; color: var(--green); }
.owner { color: var(--muted); font-size: 13px; }

/* collaborator role badges */
.role { font-size: 11px; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; font-weight: 700; background: #1f2937; color: var(--muted); }
.role-owner { background: #1d2b3a; color: var(--link); }
.role-admin { background: #2a1b33; color: #c77dff; }
.role-maintain { background: #13282b; color: #4dd0c0; }
.role-write { background: #11271b; color: var(--green); }
.role-read { background: #1f2937; color: var(--muted); }

/* visibility toggle + token revoke — small inline forms */
form.settings, form.revoke { display: inline; margin: 0 0 16px; }
form.settings button, form.revoke button {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px; font: inherit; cursor: pointer;
}
form.revoke { margin: 0; }
form.revoke button { padding: 2px 8px; font-size: 12px; color: var(--muted); }
form.revoke button:hover, form.settings button:hover { border-color: var(--red); }

/* freshly-minted token callout */
.flash {
  border: 1px solid var(--border); border-left: 3px solid var(--green); border-radius: 8px;
  padding: 12px 14px; margin: 16px 0; background: var(--panel);
}
.flash .token { color: var(--green); font-size: 14px; word-break: break-all; }
.flash .g-where { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* Timeline map thumbnails (#27) */
ol.timeline li a.thumb { display: inline-block; margin-right: 8px; vertical-align: middle; flex: 0 0 auto; }
ol.timeline li a.thumb img { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; background: #1a1a1a; display: block; }

/* Accessibility (#28) */
.skip { position: absolute; left: -9999px; top: 0; background: var(--green); color: #000; padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--green); outline-offset: 2px;
}

/* Mobile (#28): the diff tables scroll instead of overflowing, the before/after maps stack, tighter padding */
@media (max-width: 600px) {
  main, footer { padding: 16px; }
  .maps { flex-direction: column; }
  table { display: block; overflow-x: auto; max-width: 100%; }
  ol.timeline li { flex-wrap: wrap; }
}

/* Drag-and-drop upload (#26) */
.upload-drop { border: 2px dashed var(--border); border-radius: 10px; padding: 28px; text-align: center; margin: 16px 0; }
.upload-drop.drag { border-color: var(--green); background: rgba(0,200,80,.06); }
.upload-drop input[type=file] { margin: 10px 0; color: var(--muted); }
.map img[src^="data:"] { max-width: 100%; height: auto; display: block; border-radius: 6px; }

/* repo-page parity (#repo-page-parity): card description, card avatar, clone copy button, README */
ul.repos li .desc { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 13px; }
.desc { color: var(--fg); margin: 0 0 16px; }
.desc.empty a, p.empty a { color: var(--link); }
img.avatar.sm { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border); vertical-align: middle; }

button.copy {
  background: var(--panel); color: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px; font: inherit; font-size: 12px; cursor: pointer;
}
button.copy:hover { border-color: var(--link); color: var(--fg); }

section.readme {
  border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; margin: 16px 0; background: var(--panel);
}
section.readme h1, section.readme h2, section.readme h3 { text-transform: none; letter-spacing: 0; color: var(--fg); }
section.readme h1, section.readme h2 { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
section.readme code { background: #11161c; padding: .15em .35em; border-radius: 4px; }
section.readme pre { background: #11161c; padding: 12px; border-radius: 6px; overflow-x: auto; }
section.readme pre code { background: none; padding: 0; }
section.readme table { border-collapse: collapse; }
section.readme th, section.readme td { border: 1px solid var(--border); padding: 4px 10px; }
section.readme img { max-width: 100%; }

/* edit-details form (column layout overriding form.find's row) */
form.edit-details { flex-direction: column; align-items: stretch; }
form.edit-details .fld { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
form.edit-details textarea {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font: inherit; font-family: ui-monospace, monospace; resize: vertical;
}
form.edit-details button { align-self: flex-start; }
