:root {
  --paper: #f6f3ea;
  --ink: #1a1a1a;
  --ink-muted: #4a4a4a;
  --line: #d8d0c0;
  --shell-max: 1000px;
  --shell-gutter: 1rem;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Literata", "Georgia", "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.7;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main.page-shell {
  flex: 1;
}

a {
  color: inherit;
}

.site-header {
  border-bottom: 1px solid var(--line);
  padding: 1rem 0;
  margin-bottom: 2rem;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1rem 0;
  margin-top: auto;
}

.site-footer-text {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.page-shell {
  width: min(var(--shell-max), calc(100vw - (2 * var(--shell-gutter))));
  margin: 0 auto;
}

.site-header .page-shell {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.site-title {
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.site-nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  font-size: 0.9rem;
}

.site-nav a,
.link-button {
  color: var(--ink-muted);
  text-decoration: none;
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.site-nav a:hover,
.link-button:hover {
  color: var(--ink);
  text-decoration: underline;
}

.read-view h1,
.admin-panel h1 {
  font-size: 1.8rem;
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 1.5rem;
}

.read-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.read-back {
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
}

.read-back:hover {
  color: var(--ink);
}

.read-back[hidden] {
  display: none;
}

.prose p {
  margin: 0 0 1rem;
}

.prose a.iperlink,
.prose a {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.lede {
  color: var(--ink-muted);
}

.read-meta {
  margin-bottom: 0.75rem;
}

.read-map-link {
  font-size: 0.85rem;
  color: var(--ink-muted);
  text-decoration: none;
}

.read-map-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

body.map-page main.page-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.map-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 1rem;
}

.map-reader {
  width: 100%;
  margin-bottom: 1rem;
  max-height: 38vh;
  overflow-y: auto;
}

.map-hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.map-hint.hidden {
  display: none;
}

.map-reader-content.hidden {
  display: none;
}

.map-reader-content h1,
.map-reader-content .read-title {
  font-size: 1.8rem;
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 1rem;
}

.map-reader-meta {
  margin: 1.25rem 0 0;
}

.map-canvas-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 20rem;
  overflow: hidden;
}

.map-level-rail {
  position: relative;
  flex: 0 0 1.5rem;
  align-self: stretch;
  border: 1px solid var(--line);
  border-right: 0;
  background: #fffdf8;
  overflow: hidden;
}

.map-level-count {
  position: absolute;
  right: 0.2rem;
  left: 0;
  transform: translateY(-50%);
  font-size: 10px;
  line-height: 1;
  text-align: right;
  color: var(--ink-muted);
  pointer-events: none;
  user-select: none;
}

.map-graph-area {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 20rem;
  min-width: 0;
}

#cy {
  flex: 1;
  width: 100%;
  min-height: 20rem;
  border: 1px solid var(--line);
  background: #fffdf8;
}

.map-fit-all {
  position: absolute;
  right: 0.65rem;
  bottom: 0.65rem;
  z-index: 2;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.map-fit-all:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.admin-panel.narrow {
  max-width: 24rem;
}

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stack-form label {
  display: block;
  margin-bottom: 1rem;
}

.stack-form label span {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin-bottom: 0.35rem;
}

.stack-form input[type="text"],
.stack-form input[type="password"],
.stack-form input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  padding: 0.55rem 0.65rem;
  font: inherit;
}

.checkbox-row {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-row input {
  width: auto;
}

.btn,
.btn-secondary,
.btn-danger {
  display: inline-block;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
}

.btn-danger {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--line);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.form-error {
  color: #6b0000;
}

.form-success {
  color: #1f4d1f;
}

.form-success-banner {
  margin: 0 0 1.5rem;
  padding: 0.9rem 1.1rem;
  border: 2px solid #3a7a3a;
  border-radius: 2px;
  background: #e8f4e8;
  color: #1a4d1a;
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.45;
  animation:
    form-success-in 0.5s ease-out,
    form-success-pulse 1.4s ease-in-out 0.5s 2;
}

.form-success-banner::before {
  content: "✓ ";
  font-weight: 700;
}

@keyframes form-success-in {
  from {
    opacity: 0;
    transform: translateY(-0.65rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes form-success-pulse {
  0%,
  100% {
    background: #e8f4e8;
    box-shadow: 0 0 0 0 rgba(58, 122, 58, 0);
  }

  50% {
    background: #d0ead0;
    box-shadow: 0 0 0 6px rgba(58, 122, 58, 0.18);
  }
}

@media (prefers-reduced-motion: reduce) {
  .form-success-banner {
    animation: none;
  }
}

.database-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.database-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.database-section-danger .lede strong {
  color: #6b0000;
}

.database-import-form {
  max-width: 32rem;
}

.database-cli {
  margin: 0.75rem 0 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  background: #fffdf8;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

.database-cli code {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
}

.doc-list-search {
  margin-bottom: 1.25rem;
}

.doc-list-search label span {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin-bottom: 0.35rem;
}

.doc-list-search input[type="search"] {
  width: 100%;
  max-width: 28rem;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  padding: 0.55rem 0.65rem;
  font: inherit;
}

.doc-search-panel.hidden,
#doc-list-default.hidden {
  display: none;
}

.doc-search-summary {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.doc-table tbody tr:hover {
  background: #fffdf8;
}

.doc-table th,
.doc-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.4rem;
  text-align: left;
  vertical-align: top;
}

.doc-table th.sortable a {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.doc-table th.sortable a:hover {
  color: var(--ink);
  text-decoration: underline;
}

.doc-table th.sortable.sorted-asc a,
.doc-table th.sortable.sorted-desc a {
  font-weight: 600;
}

.doc-table .sort-indicator {
  font-size: 0.75rem;
  line-height: 1;
}

.doc-table-pagination {
  margin-top: 1.25rem;
  padding-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem 1.5rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.doc-table-pagination-summary {
  margin: 0;
}

.doc-table-pagination-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.doc-table-pagination-controls a {
  color: var(--ink-muted);
  text-decoration: none;
}

.doc-table-pagination-controls a:hover {
  color: var(--ink);
  text-decoration: underline;
}

.doc-table-pagination-controls .disabled {
  opacity: 0.45;
}

.doc-table-pagination-current {
  color: var(--ink);
}

.doc-table code {
  font-size: 0.8rem;
}

.doc-table .actions {
  white-space: nowrap;
}

.doc-table .actions a {
  margin-right: 0.75rem;
  font-size: 0.85rem;
}

.badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--line);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.delete-form {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.inline-form {
  display: inline;
}
