* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #1a1a1a;
  color: #ddd;
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  font-size: 13px;
  overflow: hidden;
}

body { display: flex; }

/* ===================== Sidebar ===================== */
#sidebar {
  width: 300px;
  flex-shrink: 0;
  background: rgba(20, 20, 20, 0.95);
  border-right: 1px solid #333;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid #2a2a2a;
}

.sidebar-header h1 {
  margin: 0 0 10px 0;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
}

.search-box {
  position: relative;
  margin-bottom: 8px;
}

.search-box input {
  width: 100%;
  height: 30px;
  padding: 5px 30px 5px 10px;
  background: #171717;
  color: #e8e8e8;
  border: 1px solid #343434;
  border-radius: 4px;
  outline: none;
  font-size: 12px;
  transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.search-box input:hover { border-color: #474747; }
.search-box input:focus {
  background: #1d1d1d;
  border-color: #70a6d8;
  box-shadow: 0 0 0 2px rgba(112, 166, 216, 0.16);
}

.search-box button {
  position: absolute;
  top: 50%;
  right: 5px;
  width: 22px;
  height: 22px;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #999;
  cursor: pointer;
  font-size: 17px;
  line-height: 20px;
  transition: background-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.search-box button:hover {
  background: #2b2b2b;
  color: #fff;
  transform: translateY(-50%) scale(1.05);
}

.actions { display: flex; gap: 6px; }

.actions button {
  flex: 1;
  padding: 5px 8px;
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #3a3a3a;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  transition: background-color 140ms ease, border-color 140ms ease, transform 90ms ease;
}
.actions button:hover { background: #353535; border-color: #4a4a4a; }
.actions button:active { transform: translateY(1px); }

#filters { flex: 1; overflow-y: auto; padding: 4px 0; }

.filter-group {
  border-bottom: 1px solid #262626;
  transition: opacity 160ms ease;
}

#filters.searching .filter-group.search-empty { display: none; }

.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  background: #1f1f1f;
  transition: background-color 140ms ease;
}
.group-header:hover { background: #252525; }

.group-header .chevron {
  width: 12px; font-size: 10px; color: #888;
  transition: transform 160ms ease;
}
.filter-group.collapsed .chevron { transform: rotate(-90deg); }

.group-title { flex: 1; font-weight: 600; color: #fff; font-size: 13px; }
.group-count { color: #888; font-size: 11px; }

.resource-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  max-height: 2200px;
  overflow: hidden;
  opacity: 1;
  transition: max-height 220ms cubic-bezier(0.22, 1, 0.36, 1), opacity 160ms ease, padding 160ms ease;
}

.filter-group.collapsed .resource-list {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.resource-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 24px;
  min-height: 28px;
  max-height: 36px;
  cursor: pointer;
  font-size: 12px;
  overflow: hidden;
  transform: translateX(0);
  transition:
    background-color 140ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease,
    transform 160ms ease,
    max-height 170ms ease,
    padding 170ms ease;
}
.resource-list li:hover {
  background: #232323;
  transform: translateX(2px);
}
.resource-list li.highlight {
  background: #2a3520;
  box-shadow: inset 3px 0 0 #8bc34a;
}
.resource-list li.search-hidden {
  max-height: 0;
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-8px);
}
#filters.dim-others .resource-list li { opacity: 0.35; }
#filters.dim-others .resource-list li.highlight { opacity: 1; }
#filters.tracking .resource-list li { opacity: 0.28; }
#filters.tracking .resource-list li.tracked {
  opacity: 1;
  background: #1f3344;
  box-shadow: inset 3px 0 0 #64b5f6, 0 0 18px rgba(100, 181, 246, 0.08);
}
#filters .resource-list li.search-hidden {
  opacity: 0;
  pointer-events: none;
}

.resource-list input[type="checkbox"] { margin: 0; cursor: pointer; flex-shrink: 0; }

.resource-list .lvl {
  display: inline-block;
  min-width: 32px;
  padding: 1px 5px;
  background: #2a2a2a;
  color: #aaa;
  border-radius: 3px;
  font-size: 10px;
  text-align: center;
  font-family: 'Consolas', monospace;
  flex-shrink: 0;
}

.icon-wrap {
  width: 20px; height: 20px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-icon {
  width: 20px; height: 20px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.sidebar-icon.fallback {
  width: 12px; height: 12px;
  border-radius: 50%;
}
.fallback-ore       { background: #e07a3c; border-radius: 2px !important; }
.fallback-plant     { background: #5cb85c; }
.fallback-structure { background: #a0764a; }

.resource-list .name { flex: 1; }
.resource-list .count { color: #777; font-size: 11px; flex-shrink: 0; }

.sidebar-footer {
  padding: 8px 16px;
  border-top: 1px solid #2a2a2a;
  font-size: 11px;
  color: #777;
}

/* ===================== Viewport ===================== */
#viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0c0c0c;
  cursor: grab;
}
#viewport.dragging { cursor: grabbing; }
#viewport.over-marker { cursor: pointer; }
#viewport.dragging.over-marker { cursor: grabbing; }
#viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.36);
}

#canvas {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  contain: layout paint;
  z-index: 1;
}

#map {
  display: block;
  width: 2000px; height: 2000px;
  user-select: none;
  -webkit-user-drag: none;
}

#markers {
  position: absolute; top: 0; left: 0;
  width: 2000px; height: 2000px;
  pointer-events: none;
  contain: layout paint;
}

/* ===================== Markers ===================== */
#marker-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  z-index: 2;
}

.hint {
  position: absolute;
  bottom: 40px; right: 14px;
  background: rgba(0, 0, 0, 0.65);
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 11px;
  color: #aaa;
  pointer-events: none;
  z-index: 4;
}

.creator-credit {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 4;
  padding: 4px 10px;
  color: #d8d8d8;
  background: rgba(0, 0, 0, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  font-size: 11px;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
}

/* ===================== Tooltip ===================== */
#tooltip {
  position: fixed;
  left: 0;
  top: 0;
  --tooltip-x: 0px;
  --tooltip-y: 0px;
  background: rgba(15, 15, 15, 0.97);
  border: 1px solid #555;
  border-radius: 5px;
  padding: 10px 12px;
  font-size: 12px;
  pointer-events: none;
  z-index: 1000;
  max-width: 280px;
  line-height: 1.55;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  contain: layout paint style;
  opacity: 0;
  transform: translate3d(var(--tooltip-x), calc(var(--tooltip-y) + 4px), 0) scale(0.98);
  transition: opacity 120ms ease, transform 120ms cubic-bezier(0.22, 1, 0.36, 1), border-color 160ms ease;
  will-change: transform, opacity;
}

#tooltip.is-visible {
  opacity: 1;
  transform: translate3d(var(--tooltip-x), var(--tooltip-y), 0) scale(1);
}

/* ===================== Dialog ===================== */
.modal-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  color: #e6e6e6;
  background: transparent;
  border: 0;
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(2px);
}

.modal-panel {
  background: rgba(18, 18, 18, 0.98);
  border: 1px solid #3b3b3b;
  border-radius: 6px;
  padding: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.modal-title {
  margin-bottom: 10px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.modal-panel p {
  margin: 6px 0;
  color: #cfcfcf;
  line-height: 1.55;
}

.modal-panel code {
  display: block;
  margin: 10px 0 16px;
  padding: 8px 10px;
  background: #0f0f0f;
  border: 1px solid #303030;
  border-radius: 4px;
  color: #9fc9ef;
  font-family: Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-actions button {
  min-width: 76px;
  height: 30px;
  padding: 0 12px;
  color: #ddd;
  background: #2a2a2a;
  border: 1px solid #3c3c3c;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, transform 90ms ease;
}

.modal-actions button:hover {
  background: #353535;
  border-color: #4a4a4a;
}

.modal-actions button:active { transform: translateY(1px); }

.modal-actions button.primary {
  color: #fff;
  background: #2f6698;
  border-color: #3d7db7;
}

.modal-actions button.primary:hover {
  background: #3978b3;
  border-color: #5090cc;
}

/* ===================== Intro ===================== */
.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  --intro-radius: 0px;
  --intro-feather: 72px;
  background: #000;
  color: #fff;
  opacity: 1;
  pointer-events: auto;
  overflow: hidden;
  contain: layout paint style;
  will-change: background;
}

.intro-overlay.revealing {
  background:
    radial-gradient(
      circle at center,
      transparent var(--intro-radius),
      rgba(0, 0, 0, 0.98) calc(var(--intro-radius) + var(--intro-feather))
    );
}

.intro-content {
  display: grid;
  justify-items: center;
  transform: translateZ(0);
  pointer-events: none;
}

.intro-title {
  font-size: clamp(56px, 10vw, 136px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 0 28px rgba(255, 255, 255, 0.18), 0 8px 32px rgba(0, 0, 0, 0.75);
  animation: introTitle 2600ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.intro-creator {
  margin-top: 14px;
  color: rgba(255, 255, 255, 0.82);
  font-size: clamp(15px, 2.1vw, 26px);
  font-weight: 500;
  letter-spacing: 0;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.72);
  animation: introCreator 2300ms 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes introTitle {
  0% {
    opacity: 0;
    filter: blur(10px);
    transform: translateY(18px) scale(0.95);
  }
  18%, 62% {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    filter: blur(4px);
    transform: translateY(-10px) scale(1.03);
  }
}

@keyframes introCreator {
  0% {
    opacity: 0;
    filter: blur(8px);
    transform: translateY(12px);
  }
  24%, 66% {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    filter: blur(4px);
    transform: translateY(-6px);
  }
}

.tt-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #333;
}

.tt-icon { width: 36px; height: 36px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.tt-icon-img {
  width: 36px; height: 36px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.tt-icon-img.fallback { width: 24px; height: 24px; }

.tt-name { font-size: 14px; font-weight: 600; color: #fff; }
.tt-meta { color: #888; font-size: 11px; margin-top: 1px; }

.tt-coord {
  font-family: 'Consolas', monospace;
  font-size: 11px;
  color: #888;
  margin-bottom: 6px;
}

.tt-row {
  display: flex;
  gap: 8px;
  padding: 1px 0;
}

.tt-label {
  color: #888;
  width: 38px;
  flex-shrink: 0;
}

.tt-drops-title {
  margin-top: 6px;
  margin-bottom: 4px;
  color: #888;
  font-size: 11px;
}

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

.tt-drops li {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 1px 0;
}

.tt-drop-item { color: #ddd; }
.tt-drop-amount { color: #999; font-family: 'Consolas', monospace; font-size: 11px; }
.tt-drop-cond {
  margin-left: auto;
  font-size: 10.5px;
  font-family: 'Consolas', monospace;
  padding: 1px 6px;
  border-radius: 3px;
}
.cond-always  { background: #2d5a2d; color: #b8e0b8; }
.cond-chance  { background: #5a4a2d; color: #e0c890; }
.cond-mastery { background: #3a3a5a; color: #b0b8e0; }
.cond-expr    { background: #444;    color: #bbb;    }

/* ===================== Scrollbar ===================== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #1a1a1a; }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a4a; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
