:root {
  --bg: #121216;
  --card: #1b1c22;
  --text: #ececf2;
  --accent: #a41d2d;
  --muted: #9d9fb0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: radial-gradient(circle at top, #1b1c28, var(--bg));
  color: var(--text);
}

header,
main {
  width: min(980px, 92vw);
  margin: 0 auto;
}

header {
  padding: 2rem 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
}

.object-header-content {
  display: grid;
  gap: 0.6rem;
}

.title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.object-description {
  margin: 0;
  color: #d9dbe8;
  line-height: 1.45;
  max-width: 72ch;
}

nav {
  display: flex;
  gap: 0.8rem;
}

a {
  color: #ffd3d8;
}

nav a {
  text-decoration: none;
  background: #272836;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
}

main {
  background: color-mix(in srgb, var(--card), transparent 8%);
  padding: 1.25rem;
  border-radius: 14px;
  margin-bottom: 2rem;
}

.object-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.object-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  column-gap: 0.9rem;
  align-items: center;
  border-bottom: 1px solid #313241;
  padding: 0.8rem 0;
}

.category-filter {
  display: flex;
  gap: 0.7rem;
  align-items: end;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.category-filter label {
  min-width: 220px;
}

.category-filter select,
.category-filter button {
  width: auto;
}

.category-filter button {
  padding: 0.65rem 1rem;
}

.object-main {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
}

.object-text {
  text-align: left;
}

.category-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  line-height: 1;
}

.object-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.badge {
  background: #2e3143;
  color: #c8cbdf;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.86rem;
}

.badge-tag {
  background: #2b2d3e;
  border: 1px solid #43465e;
  text-decoration: none;
}

.object-title-row .badge-tag,
.object-title-row .badge-tag:link,
.object-title-row .badge-tag:visited,
.object-title-row .badge-tag:hover,
.object-title-row .badge-tag:active {
  text-decoration: none;
}

.active-tag-filter {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.clear-filter-button {
  text-decoration: none;
  background: #2e3143;
  color: #ececf2;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
}

.tags {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0;
}

.tags li {
  background: #2b2d3e;
  border: 1px solid #43465e;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1rem;
}

.image-grid figure {
  margin: 0;
  background: #242634;
  border-radius: 8px;
  overflow: hidden;
}

.image-grid img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  object-position: left top;
  background: #10121b;
}

.admin-layout {
  display: grid;
  gap: 1.5rem;
}

.admin-form {
  display: grid;
  gap: 1rem;
}

.admin-section {
  border: 1px solid #34384a;
  border-radius: 12px;
  padding: 1rem;
  background: #171a24;
  display: grid;
  gap: 0.8rem;
}

.grouped-form {
  background: #1c2030;
  border: 1px solid #3e455f;
  border-radius: 10px;
  padding: 1rem;
}

.editing-active {
  border-color: #9b7a1c;
  box-shadow: 0 0 0 2px color-mix(in srgb, #9b7a1c, transparent 70%);
}

.edit-state {
  margin: 0;
  background: #3b3116;
  border: 1px solid #9b7a1c;
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  color: #f0e0ad;
}

label {
  display: grid;
  gap: 0.4rem;
}

fieldset {
  border: 1px solid #404459;
  border-radius: 8px;
  padding: 0.7rem;
  margin: 0;
}

legend {
  color: #c8cbdf;
  padding: 0 0.3rem;
}

input,
textarea,
select,
button {
  width: 100%;
  padding: 0.65rem;
  border-radius: 8px;
  border: 1px solid #404459;
  background: #181a24;
  color: var(--text);
}

button {
  background: #36507a;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.btn-success {
  background: #1f7a45;
}

.btn-warning {
  background: #9b7a1c;
  color: #171206;
}

button.danger {
  background: #8a2d36;
}

.card {
  display: grid;
  gap: 0.9rem;
}

.compact-form {
  max-width: 520px;
}

.inline-form {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.inline-form input {
  flex: 1;
}

.inline-form button {
  width: auto;
  min-width: 100px;
}

.checkbox-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem;
}

.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  justify-content: flex-start;
}

.checkbox-item input {
  width: auto;
  margin: 0;
}

.tag-manager {
  display: grid;
  gap: 1rem;
}

.tag-editor-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.7rem;
}

.tag-editor-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
}

.error {
  color: #ff9aa5;
}

.success {
  color: #9ff6b2;
}

.field-help,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.tag-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0;
}

.tag-list li {
  background: #2b2d3e;
  border: 1px solid #43465e;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
}


.existing-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.8rem;
}

.existing-image-item {
  display: grid;
  gap: 0.4rem;
  align-content: start;
}

.existing-image-item input {
  width: auto;
  margin: 0;
}

.existing-image-item img {
  width: 100%;
  max-height: 120px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #3e455f;
}

.map-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  align-items: start;
}

#map {
  min-height: 560px;
  border-radius: 10px;
  border: 1px solid #3e455f;
}

#map.map-error {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: #1b1f2d;
  color: #ffccd3;
  text-align: center;
}

.map-location-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.8rem;
}

.map-location-list li {
  border: 1px solid #3e455f;
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  background: #1b1f2d;
}

@media (max-width: 860px) {
  .map-layout {
    grid-template-columns: 1fr;
  }

  #map {
    min-height: 420px;
  }
}

.relation-canvas {
  position: relative;
  width: 800px;
  height: 800px;
  border: 1px solid #3e455f;
  border-radius: 12px;
  background: #131724;
  overflow: hidden;
}

.relation-lines {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.relation-line {
  stroke: #ffd3d8;
  stroke-width: 2;
  marker-end: url(#arrowHead);
}

.canvas-object {
  position: absolute;
  min-width: 96px;
  max-width: 180px;
  padding: 0.55rem 0.7rem;
  background: #2d3145;
  border: 1px solid #4f5776;
  color: #ececf2;
  user-select: none;
  cursor: move;
  text-align: center;
  z-index: 1;
}

.canvas-object.is-person {
  border-radius: 999px;
  background: #3a314a;
}

.canvas-object.is-entity {
  border-radius: 8px;
}

.canvas-object.dragging {
  box-shadow: 0 0 0 2px color-mix(in srgb, #8fa7e0, transparent 50%);
}

.save-layout-btn {
  margin-top: 0.8rem;
  max-width: 220px;
}

.canvas-layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr;
  gap: 1rem;
  align-items: start;
}

.canvas-panel {
  border: 1px solid #3e455f;
  border-radius: 10px;
  background: #171b29;
  padding: 0.75rem;
}

.canvas-panel h2 {
  margin-top: 0;
}

.canvas-toggle-list {
  list-style: none;
  margin: 0;
  padding: 0;
  padding-inline-start: 0;
  display: grid;
  gap: 0.45rem;
  max-height: 720px;
  overflow: auto;
}

.canvas-toggle-item {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid #2f354a;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: #1d2232;
}

.canvas-state-badge.is-active {
  background: #2b4e36;
  color: #aff6c4;
}

.canvas-state-badge.is-inactive {
  background: #3d3045;
  color: #e6bfd4;
}

.canvas-object.is-hidden,
.relation-line.is-hidden {
  display: none;
}

.canvas-toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.canvas-toolbar .inline-form {
  align-items: end;
}

@media (max-width: 980px) {
  .canvas-layout {
    grid-template-columns: 1fr;
  }

  .relation-canvas {
    width: 100%;
    max-width: 800px;
  }
}
