*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #f2a900;
  --accent-dim: #c48800;
  --danger: #f85149;
  --success: #3fb950;
  --sidebar-w: 300px;
  --admin-panel-w: min(360px, 92vw);
}

html,
body {
  margin: 0;
  height: 100%;
  font-family:
    'Segoe UI',
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body.embed-mode .brand,
body.embed-mode .app-footer {
  display: none;
}

body.embed-mode .topbar {
  padding-block: 0.45rem;
  min-height: 52px;
}

body.embed-mode .layout {
  height: calc(100% - 52px);
}

body.admin-active .map-container {
  margin-right: var(--admin-panel-w);
  transition: margin-right 0.2s ease;
  cursor: crosshair;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  z-index: 1000;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 120px;
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.brand-icon {
  font-size: 1.25rem;
}

.map-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  flex: 1;
}

.map-tab {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}

.map-tab:hover {
  color: var(--text);
  border-color: var(--muted);
}

.map-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
  font-weight: 600;
}

.search-wrap {
  position: relative;
  min-width: 220px;
  flex: 0 1 320px;
}

#searchInput {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

#searchInput:focus {
  outline: none;
  border-color: var(--accent);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 2000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.search-results.hidden {
  display: none;
}

.search-results li {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.88rem;
}

.search-results li:hover,
.search-results li.active {
  background: var(--surface2);
}

.search-results .poi-type {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.layout {
  display: flex;
  height: calc(100vh - 56px);
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.panel h2 {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  cursor: pointer;
  font-size: 0.88rem;
}

.layer-toggle input {
  accent-color: var(--accent);
}

.coord-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.coord-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.coord-row .label {
  color: var(--muted);
}

.coord-row strong {
  font-family: 'Consolas', 'Courier New', monospace;
  color: var(--accent);
}

.btn-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.btn {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.82rem;
  cursor: pointer;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--bg);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-dim);
}

.panel-hint p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

.map-container {
  flex: 1;
  background: #1a1a1a;
  position: relative;
}

.map-load-error {
  position: absolute;
  z-index: 1000;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 420px;
  padding: 1rem 1.25rem;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: rgba(13, 17, 23, 0.95);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

.map-load-error code {
  color: var(--accent);
  font-size: 0.8rem;
}

.leaflet-container {
  background: #1a1a1a;
  font-family: inherit;
}

.grid-label {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: rgba(242, 169, 0, 0.55);
  font-weight: 700;
  font-size: 11px;
  text-shadow:
    0 0 4px #000,
    0 0 2px #000;
}

.poi-label {
  background: rgba(13, 17, 23, 0.82) !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  color: var(--text) !important;
  font-size: 11px !important;
  font-weight: 600;
  padding: 2px 6px !important;
  white-space: nowrap;
}

.poi-label::before {
  display: none;
}

.vehicle-icon {
  background: rgba(63, 185, 80, 0.9);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
}

.boat-icon {
  background: transparent !important;
  border: none !important;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  text-shadow:
    0 0 4px #000,
    0 0 2px #000;
}

.pin-icon {
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  width: 14px !important;
  height: 14px !important;
  margin: -7px 0 0 -7px !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.secret-room-icon {
  background: #f4424b;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 12px !important;
  height: 12px !important;
  margin: -6px 0 0 -6px !important;
  box-shadow: 0 0 6px rgba(244, 66, 75, 0.7);
}

.mortar-pin-from {
  background: #ff6b35;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 14px !important;
  height: 14px !important;
  margin: -7px 0 0 -7px !important;
}

.mortar-pin-to {
  background: #ff3333;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 14px !important;
  height: 14px !important;
  margin: -7px 0 0 -7px !important;
}

.mortar-ok {
  color: var(--success);
}
.mortar-bad {
  color: var(--danger);
}

.admin-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.85rem 0;
}

.admin-visibility-section {
  margin-bottom: 0.5rem;
}

.admin-visibility-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0.5rem 0;
}

.admin-visibility-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.55rem;
  background: var(--surface2);
}

.admin-visibility-group-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 0.35rem;
}

.admin-visibility-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  padding: 0.2rem 0;
  cursor: pointer;
}

.admin-visibility-item input {
  flex-shrink: 0;
}

.admin-visibility-item.is-child {
  padding-left: 1rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.feature-hidden {
  display: none !important;
}

body.admin-preview-mode [data-feature].feature-hidden {
  display: block !important;
  opacity: 0.45;
  outline: 1px dashed rgba(242, 169, 0, 0.7);
  outline-offset: 2px;
}

body.admin-preview-mode label.layer-toggle.feature-hidden {
  display: flex !important;
}

.admin-panel {
  border-color: rgba(88, 166, 255, 0.35);
}

.admin-panel-body {
  margin-top: 0.5rem;
}

body.admin-active .admin-panel-body:not(.hidden) {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  z-index: 1500;
  width: var(--admin-panel-w);
  margin: 0;
  padding: 1rem;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.35);
}

body.embed-mode.admin-active .admin-panel-body:not(.hidden) {
  top: 52px;
}

body.admin-active .admin-point-list {
  max-height: min(280px, 32vh);
}

.admin-map-label {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  color: var(--text);
}

.admin-list-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0.25rem 0 0.35rem;
}

.admin-subheading {
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.75rem 0 0.35rem;
}

.admin-ferry-info {
  margin-bottom: 0.65rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.admin-ferry-list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  font-size: 0.78rem;
}

.admin-ferry-list li {
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 0.35rem;
  background: var(--surface2);
}

.admin-ferry-list li strong {
  display: block;
  color: #3498db;
  margin-bottom: 0.15rem;
}

.admin-ferry-list li small {
  color: var(--muted);
}

.admin-status {
  font-size: 0.78rem;
  color: var(--accent);
  margin: 0.35rem 0 0.65rem;
  min-height: 1.2em;
}

.admin-point-list {
  list-style: none;
  margin: 0 0 0.65rem;
  padding: 0;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.admin-point-item {
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.82rem;
}

.admin-point-item:last-child {
  border-bottom: none;
}

.admin-point-item:hover {
  background: var(--surface2);
}

.admin-point-item.active {
  background: rgba(88, 166, 255, 0.15);
  border-left: 3px solid #58a6ff;
}

.admin-point-item small {
  color: var(--muted);
  font-size: 0.72rem;
}

.admin-empty {
  padding: 0.65rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.admin-form .field-row input,
.admin-form .field-row select,
.admin-panel-body > .field-row select {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 0.3rem 0.45rem;
  font-size: 0.82rem;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.admin-import-label {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.admin-delete {
  color: var(--danger) !important;
}

.admin-drag-icon {
  background: #58a6ff;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 14px !important;
  height: 14px !important;
  margin: -7px 0 0 -7px !important;
  box-shadow: 0 0 8px rgba(88, 166, 255, 0.8);
  cursor: grab;
}

.admin-drag-icon.selected {
  background: #f2a900;
  box-shadow: 0 0 8px rgba(242, 169, 0, 0.9);
}

.admin-drag-icon.boat {
  background: transparent !important;
  border: none !important;
  font-size: 16px;
  line-height: 18px;
  text-align: center;
  text-shadow: 0 0 4px #000;
  width: 18px !important;
  height: 18px !important;
  margin: -9px 0 0 -9px !important;
  box-shadow: none;
}

.admin-drag-icon.boat.selected {
  filter: drop-shadow(0 0 4px #f2a900);
}

.admin-drag-icon.vehicle {
  background: rgba(63, 185, 80, 0.95);
  box-shadow: 0 0 6px rgba(63, 185, 80, 0.8);
}

.admin-drag-icon.vehicle.selected {
  background: #f2a900;
  box-shadow: 0 0 8px rgba(242, 169, 0, 0.9);
}

.admin-drag-icon.secret {
  background: rgba(155, 89, 182, 0.95);
  box-shadow: 0 0 6px rgba(155, 89, 182, 0.8);
}

.admin-drag-icon.secret.selected {
  background: #f2a900;
  box-shadow: 0 0 8px rgba(242, 169, 0, 0.9);
}

.sub-panel {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.sub-panel.hidden,
.zone-controls.hidden,
.hidden {
  display: none;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
}

.field-row span:first-child {
  color: var(--muted);
  flex-shrink: 0;
}

.field-row input[type='number'],
.field-row select {
  width: 110px;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
}

.field-row input[type='range'] {
  flex: 1;
}

.field-group {
  margin: 0.65rem 0;
}

.field-label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.radio-row {
  display: flex;
  gap: 1rem;
  font-size: 0.82rem;
  margin-bottom: 0.45rem;
}

.radio-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.btn-sm {
  width: 100%;
  margin-top: 0.25rem;
}

.zone-panel {
  border-color: rgba(242, 169, 0, 0.35);
}

.zone-main-toggle {
  font-size: 0.92rem;
}

.zone-hint {
  margin: 0.5rem 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
}

.mode-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.65rem;
}

.mode-tab {
  flex: 1;
  padding: 0.4rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.mode-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.phase-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.phase-header strong {
  color: var(--accent);
  font-size: 0.82rem;
}

.phase-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.phase-info {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.55;
}

.phase-info strong {
  color: var(--text);
}

.zone-blue {
  stroke: #3b82f6;
  fill: rgba(59, 130, 246, 0.12);
}

.zone-white {
  stroke: #ffffff;
  fill: rgba(255, 255, 255, 0.06);
  stroke-dasharray: 6 4;
}

.zone-center-icon {
  background: #3b82f6;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 10px !important;
  height: 10px !important;
  margin: -5px 0 0 -5px !important;
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.8);
}

.fine-grid-line {
  pointer-events: none;
}

.app-footer {
  margin-top: auto;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer-brand {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.app-credits {
  font-size: 0.72rem;
  color: var(--muted);
}

.app-credits summary {
  cursor: pointer;
  user-select: none;
  color: var(--text);
}

.app-credits summary:hover {
  color: var(--accent);
}

.app-credits ul {
  margin: 0.45rem 0 0;
  padding-left: 1.1rem;
  line-height: 1.45;
}

.app-credits a {
  color: var(--accent);
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 38vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .map-container {
    min-height: 50vh;
  }
}
