@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600&family=Fraunces:wght@500;700&display=swap");

:root {
  --ink: #141410;
  --ink-soft: #2c2a26;
  --paper: #f5f1ea;
  --paper-strong: #fffaf3;
  --accent: #e07a1f;
  --accent-dark: #bb5f12;
  --teal: #1f7a7a;
  --muted: #8a8378;
  --line: #e6ddcf;
  --shadow: 0 18px 60px rgba(20, 20, 16, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
}

h1, h2, h3 {
  font-family: "Fraunces", "Georgia", serif;
  margin: 0 0 0.35rem 0;
}

p {
  margin: 0.2rem 0 0.8rem 0;
  color: var(--ink-soft);
}

button, input, select {
  font-family: inherit;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(circle at top left, #fbeed8 0%, transparent 45%),
    radial-gradient(circle at 30% 70%, #f2e4d2 0%, transparent 55%),
    linear-gradient(140deg, #f8f3ea 0%, #f3ede1 60%, #efe6d5 100%);
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(0.5px);
  opacity: 0.6;
}

.orb-a {
  width: 380px;
  height: 380px;
  top: -120px;
  right: -40px;
  background: radial-gradient(circle, rgba(224, 122, 31, 0.35), transparent 70%);
}

.orb-b {
  width: 420px;
  height: 420px;
  bottom: -180px;
  left: -80px;
  background: radial-gradient(circle, rgba(31, 122, 122, 0.35), transparent 70%);
}

.orb-c {
  width: 260px;
  height: 260px;
  top: 35%;
  left: 55%;
  background: radial-gradient(circle, rgba(224, 122, 31, 0.25), transparent 70%);
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  color: var(--muted);
}

.lead {
  max-width: 560px;
  font-size: 1.05rem;
}

.hero-card {
  background: var(--paper-strong);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  min-width: 200px;
}

.hero-card__title {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.hero-card__body {
  margin-top: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.hero-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.user-row {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
}

.label {
  color: var(--muted);
  font-size: 0.8rem;
}

.panel {
  background: rgba(255, 252, 247, 0.7);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
}

.panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

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

.card {
  background: var(--paper-strong);
  border-radius: 16px;
  padding: 1.2rem;
  border: 1px solid var(--line);
}

.card.wide {
  grid-column: 1 / -1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.8rem;
  margin-top: 0.8rem;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 0.35rem;
}

input, select {
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fffdf9;
  color: var(--ink);
}

input:focus, select:focus {
  outline: 2px solid rgba(224, 122, 31, 0.4);
  border-color: var(--accent);
}

.btn {
  background: var(--accent);
  color: #fffaf3;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 20px rgba(224, 122, 31, 0.2);
}

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

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.form-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-header--with-actions {
  gap: 0.8rem;
}

.form-header--with-actions .btn {
  white-space: nowrap;
}

.form-actions {
  display: flex;
  gap: 0.7rem;
  margin-top: 1rem;
}

.form-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.pill {
  background: rgba(31, 122, 122, 0.12);
  color: var(--teal);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
}

.bot-list {
  display: grid;
  gap: 0.9rem;
}

.bot-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  background: #fffefb;
}

.bot-card h4 {
  margin: 0 0 0.35rem 0;
}

.bot-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.bot-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

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

.stat-card {
  background: var(--paper-strong);
  border-radius: 16px;
  padding: 1rem;
  border: 1px solid var(--line);
}

.stat-title {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.65rem;
  color: var(--muted);
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 600;
  margin-top: 0.4rem;
}

.stat-meta {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.user-table th,
.user-table td {
  text-align: left;
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--line);
}

.user-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.limit-input {
  max-width: 110px;
}

.admin-pill {
  background: rgba(224, 122, 31, 0.15);
  color: var(--accent-dark);
}

.send-pill {
  background: rgba(224, 122, 31, 0.18);
  color: var(--accent-dark);
}

.recv-pill {
  background: rgba(31, 122, 122, 0.18);
  color: var(--teal);
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: row;
  gap: 1rem;
}

.toggle input {
  width: auto;
}

.packet-table-wrap {
  overflow-x: auto;
}

.packet-table {
  font-size: 0.82rem;
}

.packet-table td {
  vertical-align: top;
}

.packet-select-head,
.packet-select-cell {
  width: 60px;
  text-align: center;
}

.packet-select {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.packet-row--selected {
  background: rgba(224, 122, 31, 0.08);
}

.packet-details summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 600;
}

.packet-details pre,
.packet-details code {
  display: block;
  margin-top: 0.4rem;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff8ee;
  font-family: Consolas, "Liberation Mono", Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

.packet-footer {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(20, 20, 16, 0.45);
  backdrop-filter: blur(4px);
  z-index: 10;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: var(--paper-strong);
  border-radius: 18px;
  padding: 1.4rem;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  width: min(420px, 100%);
}

.modal-card.wide {
  width: min(1100px, 100%);
}

.edit-modal-card {
  width: min(900px, 100%);
  max-height: 90vh;
  overflow: auto;
}

.map-modal-card {
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
}

.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
  min-height: 0;
}

.map-canvas-panel {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;
  min-height: 0;
}

.map-canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf9;
  padding: 0.6rem;
  overflow: auto;
  max-height: 65vh;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.map-canvas-wrap canvas {
  display: block;
  image-rendering: pixelated;
}

.map-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.map-control {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.map-control--slider {
  flex: 1 1 240px;
}

.map-control--slider input[type="range"] {
  flex: 1;
  min-width: 120px;
}

.map-control input[type="checkbox"],
.map-control input[type="range"] {
  accent-color: var(--accent);
}

.map-control-value {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: inline-block;
}

.legend-dot.self {
  background: var(--teal);
  border-color: rgba(31, 122, 122, 0.5);
}

.legend-dot.npc {
  background: #bb5f12;
  border-color: rgba(187, 95, 18, 0.6);
}

.legend-dot.target {
  background: #bb2d2d;
  border-color: rgba(187, 45, 45, 0.6);
}

.legend-dot.path {
  background: #e07a1f;
  border-radius: 4px;
  border-color: rgba(224, 122, 31, 0.6);
}

.legend-dot.idle {
  background: #7aa5a5;
  border-radius: 4px;
  border-color: rgba(31, 122, 122, 0.4);
}

.legend-dot.player {
  background: #3e6b8f;
  border-color: rgba(62, 107, 143, 0.5);
}

.map-details {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffefb;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  max-height: 65vh;
  overflow: auto;
  min-width: 0;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.map-detail {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
}

.map-detail span:last-child {
  color: var(--ink-soft);
  text-align: right;
}

.map-npc-list {
  display: grid;
  gap: 0.4rem;
  font-size: 0.8rem;
}

.map-npc-item {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  background: rgba(31, 122, 122, 0.08);
}

.map-npc-item.target {
  background: rgba(224, 122, 31, 0.16);
}

.map-npc-item small {
  color: var(--muted);
}

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem;
}

.map-toolbar__field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  min-width: 200px;
}

.map-toolbar__field select {
  min-width: 220px;
}

.map-editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.3fr) minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
}

.map-editor-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
}

.map-editor-panel {
  background: var(--paper-strong);
  border-radius: 14px;
  padding: 0.9rem;
  border: 1px solid var(--line);
}

.tab-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tab-btn {
  background: #fffdf9;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: #fffaf3;
  border-color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.map-editor-section {
  margin-bottom: 0.8rem;
}

.map-editor-section h4 {
  margin: 0 0 0.4rem 0;
  font-size: 0.9rem;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  margin: 0.2rem 0;
}

.map-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.6rem;
}

.map-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.map-editor-list {
  width: 100%;
  min-height: 180px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fffdf9;
  padding: 0.4rem;
}

.map-editor-canvas-wrap {
  max-height: 70vh;
}

.map-editor-controls {
  font-size: 0.75rem;
}

.map-editor-details {
  margin-top: 0.8rem;
}

.legend-dot.walkable {
  background: #cfe8cf;
  border-color: #b9d6b9;
}

.legend-dot.blocked {
  background: #f0c1c1;
  border-color: #e2a6a6;
}

.legend-dot.warp {
  background: #4a90e2;
  border-color: #3b7fc7;
}

.legend-dot.spec {
  background: #f4c07a;
  border-color: #e2a45b;
}

.legend-dot.spec-block {
  background: #e36b6b;
  border-color: #c95b5b;
}

.legend-dot.selection {
  background: #141410;
  border-color: #141410;
}

.modal-form {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.8rem;
}

.modal-open {
  overflow: hidden;
}

.key-output {
  font-size: 0.85rem;
  color: var(--ink);
}

.key-output.muted {
  color: var(--muted);
}

.key-list {
  list-style: none;
  padding: 0;
  margin: 0.6rem 0 0;
  display: grid;
  gap: 0.5rem;
}

.key-list code {
  display: inline-block;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  background: #fff7ec;
  border: 1px solid var(--line);
}

@media (max-width: 760px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }
}

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

  .map-canvas-wrap,
  .map-details {
    max-height: 50vh;
  }

  .map-editor-layout {
    grid-template-columns: 1fr;
  }

  .map-editor-canvas-wrap,
  .map-editor-details {
    max-height: 50vh;
  }
}

@media (max-width: 640px) {
  .map-modal-card {
    padding: 1rem;
    max-height: 95vh;
  }

  .map-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .map-controls {
    font-size: 0.75rem;
  }

  .map-canvas-wrap {
    max-height: 55vh;
  }

  .map-details {
    max-height: 40vh;
  }

  .map-legend {
    font-size: 0.7rem;
    gap: 0.4rem 0.8rem;
  }

  .legend-dot {
    width: 0.55rem;
    height: 0.55rem;
  }

  .map-toolbar__field {
    min-width: 160px;
  }
}
