:root {
  --bg: #f4efe3;
  --bg2: #dcebe3;
  --ink: #201d17;
  --muted: #5f5a50;
  --line: #d8cfbf;
  --accent: #1b6c5e;
  --accent2: #96531f;
  --danger: #a73b31;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, var(--bg), var(--bg2));
}

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 72px 14px 40px;
}

.hero h1 {
  margin: 0 0 6px;
}

.hero p {
  margin: 0 0 14px;
  color: var(--muted);
}

.card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  padding: 14px;
  margin-bottom: 12px;
}

.card.inside {
  margin-top: 10px;
  margin-bottom: 0;
}

.hidden {
  display: none;
}

.grid {
  display: grid;
  gap: 10px;
}

#loginSection .grid {
  max-width: 420px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
}

button {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  margin: 10px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

button.secondary {
  background: var(--accent2);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.danger {
  background: var(--danger);
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.admin-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  min-width: 0;
}

.menu-item {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 2px;
  border-bottom: 2px solid transparent;
}

.menu-item:hover {
  color: var(--accent);
}

.menu-item.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.user-box {
  display: grid;
  justify-items: end;
}

.logout-btn {
  margin: 6px 0 0;
}

.between {
  justify-content: space-between;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 12px;
}

.item h4 {
  margin: 0;
}

.mono {
  font-family: Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

.status {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  width: min(1100px, calc(100vw - 20px));
  margin-top: 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  font-size: 13px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
}

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-subtitle {
  margin-top: 4px;
}

.item-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 10px;
  align-items: center;
}

.result-main {
  min-width: 0;
}

.result-main h4 {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-main .item-subtitle {
  margin-top: 2px;
}

.trail-color-preview {
  width: 56px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.trail-color-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: #f7f3ea;
  font-size: 12px;
}

.maps-link {
  font-size: 13px;
  text-decoration: none;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--accent);
  padding: 8px 14px;
  margin: 10px;
  white-space: nowrap;
}

.photo-main-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.photo-upload-preview {
  display: block;
  width: min(100%, 280px);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-top: 8px;
}

.form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.section-title {
  margin: 8px 0 4px;
  font-size: 14px;
  font-weight: 700;
  color: #3f3a30;
}

.section-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.section-grid-data {
  grid-template-columns: repeat(3, minmax(230px, 1fr));
}

.trail-meta-grid {
  grid-template-columns: repeat(3, minmax(230px, 1fr));
}

.story-meta-grid {
  grid-template-columns: repeat(3, minmax(230px, 1fr));
}

.story-meta-grid textarea {
  font-family: Consolas, monospace;
}

.story-pair-list,
.story-nodes,
.story-choice-list {
  display: grid;
  gap: 10px;
}

.story-node-card,
.story-choice-card,
.story-choice-section {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 12px;
}

.story-node-card[open],
.story-choice-card[open] {
  background: #fff;
}

.story-node-card > summary,
.story-choice-card > summary {
  cursor: pointer;
  font-weight: 700;
  color: #3b372f;
  list-style: none;
}

.story-node-card > summary::-webkit-details-marker,
.story-choice-card > summary::-webkit-details-marker {
  display: none;
}

.story-collapsible-summary::before {
  content: "▸ ";
}

.story-node-card[open] > .story-collapsible-summary::before,
.story-choice-card[open] > .story-collapsible-summary::before {
  content: "▾ ";
}

.story-collapsible-body {
  margin-top: 10px;
}

.story-pair-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.story-choice-grid {
  margin-top: 8px;
}

.story-choice-section {
  margin-top: 10px;
}

.story-choice-section > .muted {
  margin-bottom: 8px;
}

.story-choice-section > button {
  justify-self: start;
}

.story-node-card textarea {
  font-family: Consolas, monospace;
}

.story-overview {
  display: grid;
  gap: 10px;
}

.story-overview-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.story-overview-tile {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}

.story-overview-issues,
.story-overview-ok {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

.story-overview-issues {
  border: 1px solid #e1b4ae;
  background: #fff2ef;
  color: #8d3128;
}

.story-overview-ok {
  border: 1px solid #b9d4cd;
  background: #eff9f6;
  color: #2f5c52;
}

.story-mermaid {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8f6f2;
  padding: 8px;
  overflow: auto;
  min-height: 120px;
  max-height: 480px;
}

.story-mermaid svg {
  max-width: 100%;
  height: auto;
}

.story-mermaid-panel {
  display: grid;
  gap: 8px;
}

.story-mermaid-toolbar {
  justify-content: flex-start;
}

.story-mermaid-toolbar button {
  margin: 4px;
}

.story-mermaid-panel-fullscreen {
  position: fixed;
  inset: 16px;
  z-index: 2500;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.18);
}

.story-mermaid-panel-fullscreen .story-mermaid {
  min-height: 0;
  height: calc(100vh - 120px);
  max-height: none;
}

.story-mermaid-fallback {
  margin: 0;
  white-space: pre;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.story-mermaid-code-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfaf5;
  padding: 10px 12px;
}

.story-mermaid-code-wrap > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.story-mermaid-code {
  margin: 10px 0 0;
  max-height: 280px;
  overflow: auto;
  white-space: pre;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.field-full {
  grid-column: 1 / -1;
}

.boolean-field {
  justify-items: start;
}

.boolean-field input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.readonly {
  background: #ece7df;
  color: #6d665a;
}

.trail-castle-list {
  display: grid;
  gap: 8px;
}

.trail-castle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 10px 12px;
}

.trail-castle-name {
  min-width: 0;
  font-size: 14px;
}

.trail-castle-actions {
  flex-wrap: nowrap;
}

.trail-castle-actions button {
  margin: 2px;
  padding: 6px 10px;
}

.pagination-row {
  justify-content: center;
}

.users-grid-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(130px, 1fr) minmax(180px, 1.2fr) minmax(120px, 0.9fr) auto;
  gap: 10px;
  align-items: center;
}

.users-cell-guid {
  font-size: 12px;
  word-break: break-all;
}

.reports-results {
  margin-top: 8px;
}

.reports-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}

.reports-table {
  width: 100%;
  min-width: 1100px;
  border-collapse: separate;
  border-spacing: 0;
}

.reports-table th,
.reports-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.reports-table thead th {
  background: #f2ede3;
  text-align: left;
  white-space: nowrap;
  font-size: 13px;
  color: #4a4338;
}

.reports-table tbody tr:last-child td {
  border-bottom: 0;
}

.reports-main-row td {
  background: #fff;
  border-bottom: 0;
}

.reports-desc-row td {
  background: #faf8f3;
  border-bottom: 2px solid #d9cfbd;
}

.reports-description-cell {
  white-space: pre-wrap;
  color: #2e2a23;
  font-size: 13px;
  border-left: 4px solid var(--accent);
}

.reports-sort-btn {
  background: transparent;
  color: inherit;
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: 0;
  font-weight: 700;
  cursor: pointer;
}

.reports-sort-btn:hover {
  color: var(--accent);
}

.reports-screen-cell {
  width: 88px;
}

.reports-thumb-btn {
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f2eb;
  overflow: hidden;
  cursor: pointer;
}

.reports-thumb {
  display: block;
  width: 72px;
  height: 72px;
  object-fit: cover;
}

.reports-image-modal {
  position: fixed;
  inset: 0;
  z-index: 2600;
  background: rgba(14, 12, 9, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
}

.reports-image-modal.hidden {
  display: none;
}

.reports-image-frame {
  max-width: min(96vw, 1200px);
  max-height: 92vh;
  display: grid;
  gap: 10px;
  justify-items: end;
}

.reports-image-close {
  margin: 0;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.65);
  color: #fff;
}

.reports-image-preview {
  max-width: min(96vw, 1200px);
  max-height: calc(92vh - 52px);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: #fff;
}

@media (max-width: 980px) {
  .shell {
    padding-top: 84px;
  }

  .status {
    width: calc(100vw - 12px);
    top: 6px;
  }

  .admin-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .user-box {
    justify-items: start;
  }

  .logout-btn {
    margin-top: 6px;
  }

  .section-grid-data {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  }

  .trail-meta-grid {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  }

  .story-meta-grid {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  }

  .story-pair-row {
    grid-template-columns: 1fr;
  }

  .story-mermaid-panel-fullscreen {
    inset: 8px;
    padding: 8px;
  }

  .story-mermaid-panel-fullscreen .story-mermaid {
    height: calc(100vh - 110px);
  }

  .users-grid-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .reports-table {
    min-width: 800px;
  }

  .reports-table th,
  .reports-table td {
    padding: 8px 10px;
  }

  .reports-thumb {
    width: 56px;
    height: 56px;
  }

  .reports-image-modal {
    padding: 10px;
  }

  .reports-image-frame {
    max-width: 100%;
    max-height: 100%;
  }

  .result-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}
