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

:root {
  --bg:           #0d0f12;
  --panel-bg:     #161a1f;
  --panel-border: #2a2f38;
  --text:         #c8cdd6;
  --text-dim:     #5a6070;
  --warden:       #3a7bd5;
  --colonial:     #4a9e5c;
  --contested:    #6b6b6b;
  --hex-stroke:   #2a2f38;
  --label:        #7a8494;
}

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

#app { position: relative; width: 100vw; height: 100vh; }

/* Panels */
.panel {
  position: fixed;
  z-index: 10;
  background: rgba(22, 26, 31, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 180px;
  backdrop-filter: blur(6px);
}

.panel h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.panel h2.warden   { color: var(--warden); }
.panel h2.colonial { color: var(--colonial); }

.stat-row { display: flex; justify-content: space-between; align-items: center; }
.stat-row .label { color: var(--label); font-size: 12px; }
.stat-row span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }

#panel-war      { top: 8px;    left: 8px; }
#panel-wardens  { top: 8px;    right: 8px; }
#panel-colonials{ bottom: 8px; left: 8px; }
#panel-settings { bottom: 8px; right: 8px; }

/* Hex map */
#hex-viewport {
  position: fixed;
  inset: 0;
  background: var(--panel-bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#hex-grid { width: 100%; height: 100%; }

/* SVG hex elements */
.hex-cell { cursor: default; transition: opacity 0.15s; }
.hex-cell:hover { opacity: 0.85; }

.hex-cell > polygon {
  stroke: var(--hex-stroke);
  stroke-width: 0.4;
}

.hex-cell.warden   > polygon { fill: var(--warden); }
.hex-cell.colonial > polygon { fill: var(--colonial); }
.hex-cell.contested > polygon { fill: var(--contested); }
.hex-cell.unknown  polygon { fill: #1e2430; }

.hex-cell.has-voronoi polygon { fill: none; }

.hex-name {
  fill: rgba(255,255,255,0.9);
  font-size: 2.3px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: auto;
  pointer-events: none;
}

.hex-stat {
  fill: rgba(255,255,255,0.7);
  font-size: 2.0px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  text-anchor: middle;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.dot-warden   { fill: var(--warden);   filter: drop-shadow(0 0 0.4px rgba(0,0,0,0.8)); }
.dot-colonial { fill: var(--colonial); filter: drop-shadow(0 0 0.4px rgba(0,0,0,0.8)); }

/* Display mode buttons */
#display-mode-btns {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mode-btn {
  background: #1e2430;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  color: var(--label);
  font-size: 11px;
  font-family: inherit;
  padding: 5px 8px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.mode-btn:hover {
  background: #252d3a;
  color: var(--text);
}

.mode-btn.active {
  background: #1e3048;
  border-color: var(--warden);
  color: #fff;
  font-weight: 600;
}

/* Stockpile marker pulse */
.sp-pulse { animation: sp-pulse 2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes sp-pulse { 0%,100%{opacity:.55;transform:scale(1)} 50%{opacity:.08;transform:scale(1.5)} }

/* Stockpile overlay — no fullscreen dim, just a positional wrapper */
.sp-overlay { display: none; }
.sp-overlay.active { display: block; animation: sp-fadein .15s ease; }
@keyframes sp-fadein { from{opacity:0} to{opacity:1} }

/* Stockpile panel — self-positioned next to clicked icon */
.sp-panel {
  position: fixed;
  z-index: 500;
  width: 440px;
  max-width: calc(100vw - 16px);
  background: #1e1e1e;
  border: 1px solid #444;
  box-shadow: 0 8px 40px rgba(0,0,0,.8), inset 0 1px 0 rgba(255,255,255,.04);
  font-family: 'Share Tech Mono', 'Courier New', monospace;
  animation: sp-slideup .18s ease;
}
@keyframes sp-slideup { from{transform:translateY(8px);opacity:0} to{transform:translateY(0);opacity:1} }

.sp-header { background: #2a2a2a; border-bottom: 1px solid #3a3a3a; padding: 6px 10px 0; }

/* Title row: hex name + help icon */
.sp-title-row { display: flex; align-items: center; justify-content: space-between; padding-bottom: 5px; }
.sp-title { font-size: 16px; color: #d4c99a; letter-spacing: 3px; text-transform: uppercase; font-weight: 600; }

/* Help button */
.sp-help-wrap { position: relative; flex-shrink: 0; }
.sp-help-btn {
  width: 18px; height: 18px; border-radius: 50%;
  background: #383838; border: 1px solid #5a5a5a;
  color: #888; font-size: 11px; font-weight: 700; font-family: inherit;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
  line-height: 1; padding: 0;
}
.sp-help-btn:hover { background: #4a4a3a; border-color: #7a7a5a; color: #d4c99a; }

/* Tooltip */
.sp-help-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 260px;
  background: #1a1a1a;
  border: 1px solid #555;
  box-shadow: 0 6px 24px rgba(0,0,0,.8);
  padding: 10px 12px;
  font-size: 11px;
  color: #bbb;
  line-height: 1.6;
  z-index: 600;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
.sp-help-wrap:hover .sp-help-tooltip { display: block; }
.sp-help-tooltip strong { display: block; color: #d4c99a; font-size: 12px; margin-bottom: 6px; letter-spacing: 1px; text-transform: uppercase; }
.sp-help-tooltip ul { padding-left: 14px; }
.sp-help-tooltip li { margin-bottom: 4px; }
.sp-help-tooltip em { color: #d4c99a; font-style: normal; }
.sp-help-tooltip kbd {
  background: #333; border: 1px solid #555; border-radius: 3px;
  padding: 0 4px; font-size: 10px; color: #ccc; font-family: inherit;
}

.sp-items-row { display: flex; align-items: center; justify-content: space-between; padding-bottom: 3px; }
.sp-items-label { font-size: 11px; color: #888; letter-spacing: 2px; }
.sp-tabs-row { display: flex; align-items: center; padding: 4px 0 5px; }
.sp-tabs { display: flex; gap: 2px; }
.sp-tab {
  background: #383838; border: 1px solid #4a4a4a; width: 28px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #aaa; transition: background .15s, border-color .15s;
}
.sp-tab:hover, .sp-tab.active { background: #4a4a3a; border-color: #7a7a5a; color: #d4c99a; }
.sp-tab img { display: block; width: 18px; height: 18px; object-fit: contain; filter: brightness(.65) saturate(.4); transition: filter .15s; }
.sp-tab:hover img, .sp-tab.active img { filter: brightness(1) saturate(1); }
.sp-sort-wrap { display: flex; align-items: center; gap: 4px; }
.sp-sort-select {
  background: #333; border: 1px solid #555; color: #bbb;
  font-size: 11px; padding: 2px 18px 2px 5px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 4px center;
}

/* Storage selector */
.sp-storage-select {
  background: #333; border: 1px solid #555; color: #bbb;
  font-size: 11px; padding: 2px 5px; cursor: pointer; font-family: inherit;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center; padding-right: 20px;
  max-width: 150px;
}
.sp-storage-select:focus { outline: 1px solid #7a7a5a; }

/* Scrollable wrapper — scrollbar lives here, outside the item grid */
.sp-grid-wrap {
  background: #181818;
  max-height: calc(5 * ((440px - 8px - 5 * 3px) / 6) + 4 * 3px + 8px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #4a4a3a #1e1e1e;
}
.sp-grid-wrap::-webkit-scrollbar { width: 6px; }
.sp-grid-wrap::-webkit-scrollbar-track { background: #1e1e1e; }
.sp-grid-wrap::-webkit-scrollbar-thumb { background: #4a4a3a; border-radius: 3px; }
.sp-grid-wrap::-webkit-scrollbar-thumb:hover { background: #6a6a5a; }

/* Grid — no scrollbar, no overflow, just layout */
.sp-grid {
  padding: 4px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
  background: #181818;
}

.sp-slot {
  background: #2c2c2c; border: 1px solid #3a3a3a; aspect-ratio: 1;
  position: relative; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color .15s, background .15s; overflow: visible;
}
.sp-slot:hover { border-color: #6a6a5a; background: #363636; z-index: 100; }
.sp-slot.demanded { border-color: #7a3a3a; box-shadow: inset 0 0 6px rgba(200,60,60,.25); }
.sp-slot.demanded:hover { border-color: #aa4a4a; }

/* Game image icon */
.sp-slot-img { width: 68%; height: 68%; object-fit: contain; filter: brightness(.82) saturate(.6); transition: filter .15s; user-select: none; }
.sp-slot:hover .sp-slot-img { filter: brightness(1.1) saturate(1); }


.sp-slot-count { position: absolute; bottom: 2px; right: 3px; font-size: 10px; color: #c8c8b0; line-height: 1; text-shadow: 1px 1px 2px #000; }
.sp-slot-count.large { font-size: 9px; color: #a8d8a8; }

/* Demand badge */
.sp-demand-badge {
  position: absolute; top: 1px; left: 2px;
  font-size: 9px; color: #e05050; line-height: 1;
  text-shadow: 0 0 4px rgba(0,0,0,.9);
}

/* Shared item name tooltip — fixed, above everything */
.sp-item-tooltip {
  display: none;
  position: fixed;
  background: #111;
  border: 1px solid #555;
  color: #ccc;
  font-size: 10px;
  padding: 3px 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 600;
  transform: translateX(-50%);
}
.sp-item-tooltip.visible { display: block; }

/* Actions row */
.sp-actions-row {
  background: #2a2a2a;
  border-top: 1px solid #3a3a3a;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.sp-actions-left {
  display: flex;
  gap: 2px;
}

.sp-actions-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
  overflow: hidden;
}

.sp-action-btn {
  background: #383838;
  border: 1px solid #4a4a4a;
  width: 28px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  padding: 0;
  flex-shrink: 0;
}
.sp-action-btn:hover { background: #4a4a3a; border-color: #7a7a5a; }
.sp-action-btn.active { background: #4a4a3a; border-color: #7a7a5a; }
.sp-action-btn:disabled { background: #272727; border-color: #333; cursor: not-allowed; opacity: .4; }
.sp-action-btn:disabled img { filter: brightness(.35) saturate(0); }
.sp-action-btn:disabled:hover { background: #272727; border-color: #333; }
.sp-action-btn img { display: block; width: 18px; height: 18px; object-fit: contain; filter: brightness(.65) saturate(.4); transition: filter .15s; }
.sp-action-btn:hover img, .sp-action-btn.active img { filter: brightness(1) saturate(1); }

.sp-action-close img { filter: brightness(.65) saturate(.4) sepia(.3) hue-rotate(-10deg); }
.sp-action-close:hover { background: #4a3535; border-color: #7a4a4a; }
.sp-action-close:hover img { filter: brightness(1) saturate(.8) sepia(.3) hue-rotate(-10deg); }

/* Code display (ViewCode panel) */
.sp-code-display {
  display: none;
  font-size: 10px;
  color: #a8c8a8;
  background: #1a1a1a;
  border: 1px solid #3a3a3a;
  padding: 2px 8px;
  letter-spacing: 1px;
  font-family: 'Share Tech Mono', 'Courier New', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
  min-width: 0;
  flex: 1;
  cursor: default;
  user-select: all;
}
.sp-code-display.visible { display: block; }

/* Footer */
.sp-footer { background: #252525; border-top: 1px solid #333; padding: 5px 10px; display: flex; justify-content: space-between; align-items: center; }
.sp-footer-info { font-size: 10px; color: #666; }
