:root {
  color-scheme: light;
  --ink: #101113;
  --paper: #fbfbf8;
  --paper-2: #eef3f1;
  --line: #d6ddd8;
  --muted: #606763;
  --green: #25785e;
  --red: #b84646;
  --blue: #386fb0;
  --yellow: #c9961a;
  --violet: #7657a6;
  --shadow: 0 22px 70px rgba(16, 17, 19, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  background: var(--paper);
  color: var(--ink);
}

button,
textarea,
input {
  font: inherit;
}

.atlas-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  width: 100%;
  max-width: 100vw;
  min-height: 100dvh;
  overflow: hidden;
}

.canvas-stage {
  position: relative;
  min-width: 0;
  min-height: 100dvh;
  background:
    linear-gradient(90deg, rgba(16, 17, 19, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(16, 17, 19, 0.045) 1px, transparent 1px),
    var(--paper);
  background-size: 44px 44px;
}

#trace-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  cursor: crosshair;
}

.stage-overlay {
  position: absolute;
  inset: 24px 24px auto 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  pointer-events: none;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.wordmark-mark {
  width: 36px;
  height: 36px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background:
    linear-gradient(135deg, transparent 46%, var(--ink) 47%, var(--ink) 53%, transparent 54%),
    linear-gradient(45deg, transparent 46%, var(--ink) 47%, var(--ink) 53%, transparent 54%),
    var(--yellow);
  flex: 0 0 auto;
  box-shadow: 6px 6px 0 var(--green);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 0.9;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.status-strip {
  display: grid;
  grid-auto-flow: column;
  gap: 10px;
  align-items: center;
  max-width: min(58vw, 560px);
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 251, 248, 0.86);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.status-strip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-strip span + span {
  border-left: 1px solid var(--line);
  padding-left: 10px;
}

.memory-panel {
  display: grid;
  grid-template-rows: auto auto auto auto auto auto minmax(140px, 1fr);
  min-width: 0;
  max-height: 100dvh;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.93);
  box-shadow: var(--shadow);
  overflow: auto;
}

.panel-header,
.detail-band,
.composer-band,
.tools-band,
.world-band,
.kit-band,
.timeline-band,
.provenance-band,
.archive-band {
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0 0 12px;
  font-size: clamp(1.9rem, 3.1vw, 2.8rem);
  line-height: 0.96;
  overflow-wrap: anywhere;
}

.selected-line {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-meta span {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

#selected-body {
  margin-bottom: 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.composer-band h2,
.tools-band h2,
.world-band h2,
.kit-band h2,
.timeline-band h2,
.provenance-band h2,
.archive-band h2 {
  margin-bottom: 12px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading h2 {
  margin-bottom: 0;
}

.section-heading span {
  min-width: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  outline: none;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
}

textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(37, 120, 94, 0.16);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(108px, 1.16fr);
  gap: 8px;
  margin-top: 10px;
}

.tool-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  min-height: 40px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--ink);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 3px solid rgba(56, 111, 176, 0.36);
  outline-offset: 2px;
}

button.secondary {
  border-color: var(--blue);
  background: var(--blue);
}

button.secondary[aria-pressed="true"] {
  border-color: var(--green);
  background: var(--green);
}

button.quiet {
  border-color: var(--line);
  background: white;
  color: var(--muted);
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.storage-note {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.fingerprint-note {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.35;
}

#world-links {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

#timeline-list {
  display: grid;
  gap: 8px;
  max-height: 240px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.kit-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
}

.kit-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kit-steps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.kit-steps li {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.25;
}

.kit-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--green);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--green);
  color: white;
  font-size: 0.86rem;
  font-weight: 900;
  text-decoration: none;
}

.kit-link:hover {
  transform: translateY(-1px);
}

.kit-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.kit-actions .kit-link,
.kit-actions button {
  width: 100%;
}

.kit-status {
  min-height: 19px;
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-all;
  line-break: anywhere;
}

.timeline-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}

.timeline-phase {
  display: inline-grid;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--green);
  border-radius: 8px;
  color: var(--green);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1;
}

.timeline-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.timeline-copy strong,
.timeline-copy small {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-all;
  line-break: anywhere;
}

.timeline-copy strong {
  font-size: 0.86rem;
  line-height: 1.25;
}

.timeline-copy small {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.38;
}

.timeline-evidence {
  width: fit-content;
  color: var(--blue);
  font-size: 0.74rem;
  font-weight: 800;
  text-decoration: none;
}

.timeline-evidence:hover {
  text-decoration: underline;
}

.world-link {
  display: grid;
  gap: 3px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
  color: var(--ink);
  text-decoration: none;
}

.world-link:hover {
  border-color: var(--blue);
  transform: translateY(-1px);
}

.world-link strong,
.world-link small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.world-link strong {
  font-size: 0.86rem;
  line-height: 1.25;
}

.world-link small {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

#ledger-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.ledger-item {
  display: grid;
  grid-template-columns: minmax(62px, auto) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}

.ledger-commit {
  color: var(--green);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1.35;
}

.ledger-copy {
  min-width: 0;
}

.ledger-copy strong,
.ledger-copy small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ledger-copy strong {
  font-size: 0.86rem;
  line-height: 1.25;
}

.ledger-copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
}

.archive-band {
  min-height: 0;
  overflow: auto;
}

#trace-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.trace-item {
  width: 100%;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
  color: var(--ink);
  text-align: left;
}

.trace-item:hover,
.trace-item[aria-current="true"] {
  border-color: var(--ink);
  transform: none;
}

.trace-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid var(--ink);
  border-radius: 50%;
}

.trace-item strong,
.trace-item small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace-item strong {
  font-size: 0.94rem;
  line-height: 1.15;
}

.trace-item small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
}

@media (max-width: 860px) {
  .atlas-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 58dvh auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .canvas-stage,
  #trace-canvas {
    min-height: 58dvh;
  }

  .stage-overlay {
    inset: 16px 16px auto;
    flex-direction: column;
  }

  .status-strip {
    max-width: 100%;
  }

  .memory-panel {
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }

  .archive-band {
    overflow: visible;
  }
}

@media (max-width: 520px) {
  .panel-header,
  .detail-band,
  .composer-band,
  .tools-band,
  .world-band,
  .kit-band,
  .timeline-band,
  .provenance-band,
  .archive-band {
    padding: 18px;
  }

  .button-row,
  .tool-row,
  .kit-actions {
    grid-template-columns: 1fr;
  }

  .status-strip {
    grid-auto-flow: row;
    gap: 6px;
  }

  .status-strip span + span {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 6px;
  }
}
