:root {
  color-scheme: dark;
  --bg: #10151a;
  --panel: #171e24;
  --panel-2: #202932;
  --ink: #f2f6ee;
  --muted: #9aa8a0;
  --line: #33414a;
  --line-strong: #52636d;
  --accent: #e4b35d;
  --accent-2: #7ed481;
  --danger: #d86c63;
  --cell: 32px;
  --board-cols: 32;
  --board-rows: 20;
  --asset-card: 48px;
  --asset-thumb: 38px;
  --asset-number-line: 10px;
  --map-background-color: #79bf63;
}

* {
  box-sizing: border-box;
}

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

body.world-page {
  --world-hud: rgba(12, 20, 24, .86);
  --world-border: #6aaad6;
  --world-ocean: #277fba;
  --world-land: #74c756;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px),
    #071014;
  background-size: 32px 32px;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #25313a;
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
  cursor: pointer;
}

button:hover,
button.active {
  border-color: var(--accent);
  color: #fff0c9;
}

button.primary-action {
  border-color: #5f9d61;
  background: #2d6f38;
  color: #f1fff0;
}

button.primary-action:hover {
  border-color: var(--accent-2);
  color: #ffffff;
}

button.danger-action {
  border-color: #7c3e3b;
  background: #3a2427;
  color: #ffd5cf;
}

button.danger-action:hover {
  border-color: var(--danger);
  color: #fff0ed;
}

.editor-shell {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px),
    #10151a;
  background-size: 32px 32px;
}

.topbar {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 24, 29, .96);
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}

.canvas-panel,
.asset-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 44px rgba(0, 0, 0, .28);
}

.canvas-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.canvas-head,
.asset-head {
  min-height: 58px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(24, 32, 38, .92);
}

.canvas-head strong,
.asset-head strong {
  display: block;
  font-size: 15px;
}

.canvas-head span,
.asset-head span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.canvas-stats {
  display: flex;
  gap: 8px;
}

.canvas-stats span {
  margin: 0;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #c9d5cc;
  background: #11181d;
}

.map-frame {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: #0c1115;
}

.map-board {
  position: relative;
  width: calc(var(--board-cols) * var(--cell));
  height: calc(var(--board-rows) * var(--cell));
  margin: 0 auto;
  border: 2px solid #5e6f78;
  background-color: var(--map-background-color);
  background-image:
    linear-gradient(rgba(0, 0, 0, .18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, .18) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  image-rendering: pixelated;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .36);
}

.grid-cell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  background-repeat: repeat;
  background-size: var(--cell) var(--cell);
  image-rendering: pixelated;
}

.grid-cell.drop-target {
  outline: 2px solid rgba(255, 236, 157, .92);
  outline-offset: -2px;
}

.stamp {
  position: absolute;
  z-index: 3;
  display: block;
  image-rendering: pixelated;
  object-fit: contain;
  user-select: none;
  cursor: move;
}

.stamp.selected {
  filter: drop-shadow(0 0 0 #fff) drop-shadow(0 0 8px rgba(255, 220, 115, .95));
}

.stamp.blocking::after {
  content: "";
}

.asset-panel {
  display: grid;
  grid-template-rows: auto 1fr;
}

.asset-head {
  align-items: start;
}

.asset-controls {
  display: grid;
  grid-template-columns: minmax(132px, .85fr) minmax(150px, 1fr) minmax(110px, .8fr) auto;
  gap: 8px;
}

#assetSearch,
#packageSelect,
#purposeSelect {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #10171c;
  color: var(--ink);
  outline: none;
}

#deleteAssetMode {
  white-space: nowrap;
  padding: 0 10px;
}

#deleteAssetMode.active {
  border-color: var(--danger);
  background: #593033;
  color: #fff0ed;
}

#assetSearch:focus,
#packageSelect:focus,
#purposeSelect:focus {
  border-color: var(--accent);
}

.saved-map-bar {
  min-height: 48px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto auto minmax(140px, 1.2fr) auto auto;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: #141c22;
}

.saved-map-bar label {
  color: #cbd7d0;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.saved-map-bar input,
.saved-map-bar select {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #10171c;
  color: var(--ink);
  outline: none;
}

.saved-map-bar input:focus,
.saved-map-bar select:focus {
  border-color: var(--accent);
}

.asset-list {
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--asset-card));
  grid-auto-rows: calc(var(--asset-card) + var(--asset-number-line));
  align-content: start;
  justify-content: start;
  column-gap: 8px;
  row-gap: 6px;
}

.asset-card {
  position: relative;
  width: var(--asset-card);
  height: calc(var(--asset-card) + var(--asset-number-line));
  min-width: var(--asset-card);
  min-height: calc(var(--asset-card) + var(--asset-number-line));
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  text-align: center;
  display: grid;
  grid-template-rows: var(--asset-card) var(--asset-number-line);
  place-items: center;
  overflow: visible;
}

.asset-list.delete-mode .asset-card {
  cursor: default;
}

.asset-card.active {
  background: transparent;
}

.asset-card img {
  width: var(--asset-thumb);
  height: var(--asset-thumb);
  max-width: var(--asset-thumb);
  max-height: var(--asset-thumb);
  object-fit: contain;
  object-position: center;
  image-rendering: pixelated;
  display: block;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #2a343b;
  padding: 4px;
}

.asset-card.active img {
  border-color: var(--accent);
  background: #2c352f;
}

.asset-delete-button {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 2;
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  border: 1px solid rgba(255, 210, 204, .9);
  border-radius: 50%;
  background: #6c2e31;
  color: #fff3f0;
  font-size: 14px;
  line-height: 16px;
  display: grid;
  place-items: center;
}

.asset-delete-button:hover {
  border-color: #ffffff;
  background: #9c3e41;
  color: #ffffff;
}

.asset-card span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.asset-card small {
  position: static;
  align-self: end;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: #9aa8a0;
  font-size: 7px;
  line-height: 1;
  font-weight: 400;
  letter-spacing: 0;
  pointer-events: none;
  text-align: center;
}

.asset-card.asset-note {
  aspect-ratio: auto;
  width: 118px;
  min-height: 68px;
  padding: 10px;
  place-items: start;
  text-align: left;
}

.asset-card.asset-note span {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  display: block;
  color: #d9e5d9;
  font-size: 12px;
}

.world-map-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 12, 15, .82);
}

.world-map-overlay[hidden] {
  display: none;
}

.world-page-shell {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  background: radial-gradient(circle at 50% 45%, rgba(39, 127, 186, .12), transparent 62%);
}

.world-map-panel {
  width: min(1120px, 96vw);
  height: min(820px, 92vh);
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid #536875;
  border-radius: 8px;
  background: #111a1f;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .5);
  overflow: hidden;
}

.world-map-topbar {
  min-height: 64px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(106, 170, 214, .36);
  background: rgba(20, 30, 35, .96);
}

.world-page-hud {
  background: var(--world-hud);
  backdrop-filter: blur(8px);
}

.world-map-topbar strong {
  display: block;
  font-size: 20px;
  line-height: 1;
}

.world-map-topbar span {
  display: block;
  margin-top: 8px;
  color: #b9c9c5;
  font-size: 12px;
}

.world-map-stage {
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: 18px 24px 24px;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, .018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .018) 1px, transparent 1px),
    #081218;
  background-size: 24px 24px;
}

.world-map-surface {
  --world-cols: 24;
  --world-rows: 16;
  --world-cell-px: 32px;
  position: relative;
  width: 768px;
  height: 512px;
  min-width: 320px;
  min-height: 260px;
  aspect-ratio: var(--world-cols) / var(--world-rows);
  border: 6px solid #0a3550;
  outline: none;
  overflow: hidden;
  image-rendering: pixelated;
  background: #176fb1;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, .48),
    inset 0 0 0 2px rgba(255, 255, 255, .16);
}

.world-map-surface::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(rgba(232, 250, 255, .30) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 250, 255, .30) 1px, transparent 1px);
  background-size:
    calc(100% / var(--world-cols)) calc(100% / var(--world-rows)),
    calc(100% / var(--world-cols)) calc(100% / var(--world-rows));
}

.world-cell {
  position: absolute;
  z-index: 1;
  display: block;
  pointer-events: none;
}

.world-cell.ocean {
  background: #1d73b8;
}

.world-cell.land {
  background: #cfb8f4;
}

.world-cell.ocean.v1 {
  background: #1769aa;
}

.world-cell.ocean.v2 {
  background: #247fc4;
}

.world-cell.ocean.v3 {
  background: #1b6fb1;
}

.world-cell.ocean.v4 {
  background: #2a85c8;
}

.world-cell.land.v1 {
  background: #d8c5f8;
}

.world-cell.land.v2 {
  background: #c8adf0;
}

.world-cell.land.v3 {
  background: #e1cffb;
}

.world-cell.land.v4 {
  background: #c1a4ec;
}

.world-cell.land.mapped {
  background: #63b844;
}

.world-cell.land.mapped.v1 {
  background: #75c851;
}

.world-cell.land.mapped.v2 {
  background: #56a83d;
}

.world-cell.land.mapped.v3 {
  background: #88d35b;
}

.world-cell.land.mapped.v4 {
  background: #6fbd48;
}

.world-map-marker {
  position: absolute;
  z-index: 4;
  width: calc(82% / var(--world-cols));
  height: calc(82% / var(--world-rows));
  min-width: 0;
  min-height: 0;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
}

.world-map-marker:hover,
.world-map-marker:focus {
  box-shadow: inset 0 0 0 2px rgba(255, 231, 107, .75);
  outline: none;
}

.world-player {
  position: absolute;
  z-index: 5;
  width: calc(78% / var(--world-cols));
  height: calc(78% / var(--world-rows));
  transform: translate(-50%, -50%);
  background:
    linear-gradient(#1b1b22 0 0) 50% 16% / 44% 24% no-repeat,
    linear-gradient(#e8bb77 0 0) 50% 42% / 56% 34% no-repeat,
    linear-gradient(#2b637b 0 0) 50% 78% / 64% 34% no-repeat;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .55));
  pointer-events: none;
}

.world-map-tooltip {
  position: absolute;
  z-index: 7;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid #6f7e72;
  border-radius: 6px;
  background: rgba(12, 19, 22, .94);
  color: #f2f8ef;
  font-size: 12px;
  font-weight: 760;
  pointer-events: none;
  white-space: nowrap;
}

@media (max-height: 520px) {
  .world-page-shell {
    grid-template-rows: 58px minmax(0, 1fr);
  }

  .world-map-topbar {
    min-height: 58px;
    padding: 8px 12px;
  }

  .world-map-topbar strong {
    font-size: 16px;
  }

  .world-map-topbar span {
    margin-top: 4px;
  }

  .world-map-stage {
    padding: 10px 12px 12px;
  }

  .world-map-surface {
    width: calc(100vw - 24px);
    height: calc(100vh - 82px);
    min-height: 180px;
  }
}

.statusbar {
  min-height: 36px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: #12191e;
  color: var(--muted);
  font-size: 12px;
}

.statusbar span:first-child {
  color: #dfe9db;
}

@media (max-width: 720px) {
  :root {
    --asset-card: 44px;
    --asset-thumb: 34px;
  }

  .saved-map-bar {
    grid-template-columns: 1fr 1fr;
  }

  .saved-map-bar label {
    align-self: end;
  }
}

@media (max-width: 560px) {
  .topbar {
    height: auto;
    align-items: start;
    flex-direction: column;
  }

  .workspace {
    padding: 10px;
    gap: 10px;
  }

  :root {
    --asset-card: 42px;
    --asset-thumb: 32px;
  }

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