/* The map editor (界面 六「地图编辑」; src/UI/map-editor.js): the 编辑地图 button on the control line and the sandbox panel,
   which takes the side panel's place while it is open (the map stays clear). Buttons are bordered as the control line's
   存档 / 读档 / 推进. */

.controlbar #map-editor-toggle {
  border-color: #b9c4bd;
  background: #fffdf6;
  color: var(--ink);
}

.controlbar #map-editor-toggle:hover {
  border-color: var(--teal);
}

.controlbar #map-editor-toggle.active {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

/* while the sandbox is open the run, save, load and scenario controls rest (app.js) */
:root[data-map-editing] :is(#play-button, #advance-button, #advance-days, #save-button, #load-button, [data-inspector]):disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* the side panel shows only the editor while it is open */
:root[data-map-editing] .inspector > :not(#map-editor) {
  display: none !important;
}

.map-editor {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  color: #41514c;
  font-size: var(--font-medium);
}

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

.map-editor[aria-busy="true"] {
  cursor: progress;
}

/* the editor's sections (地形, 边线, 城市, 地图, 所选城市, 国家): 15px section titles, so bold (界面.md 一 "15px栏目标题统一加粗") */
.map-editor b {
  font-size: var(--font-medium);
  font-weight: 700;
  color: var(--ink);
}

.map-editor button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  /* one height for every button, and one gap (8px) in every grid, so all the third-wide buttons are one size and all the
     half-wide ones another (human 2026-11-02: "all the 1/3 wide button should have same size, so do 1/2 button") */
  box-sizing: border-box;
  height: 32px;
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid #b9c4bd;
  border-radius: 3px;
  background: #fffdf6;
  color: var(--ink);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.map-editor button:hover:not(:disabled) {
  border-color: var(--teal);
}

.map-editor button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.map-editor button.active,
.map-editor button.primary {
  border-color: #526c63;
  background: #526c63;
  color: #fffdf6;
}

.map-editor-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.map-editor-palette {
  display: grid;
  gap: 4px;
}

.map-editor-palette b {
  min-height: 22px;
}

.map-editor-palette button {
  justify-content: flex-start;
  min-width: 0;
}

/* the map itself in thirds, as the tools: the title, 连路 under 边线 and 周期边界 at the right (human 2026-11-03: "move 周期边界
   to right, make 连线 to replace current location") */
.map-editor-map {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid #d7ddd8;
}

/* 周期边界 is an on/off switch, not a tool: on, a light fill with a green border, so the one dark-filled button is the chosen tool
   (human 2026-11-08: "why 连路 is green?") */
.map-editor #map-editor-wrap.active {
  border-color: var(--teal);
  background: #e3ebe5;
  color: var(--teal);
}

.map-editor-map > [data-map-tool="connect"] {
  justify-content: flex-start;
  min-width: 0;
}

.map-editor-fields {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
  padding-top: 10px;
  border-top: 1px solid #d7ddd8;
}


.map-editor button[hidden] {
  display: none;
}

/* 返回 and 进入 while the map is fixed by 跳转 (城市 or 国家), in the last two sixths */
.map-editor-jump-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}
.map-editor-jump-row[hidden] { display: none; }
.map-editor-jump-row > #map-editor-back { grid-column: 5; }
.map-editor-jump-row > #map-editor-enter { grid-column: 6; }
.map-editor-jump-row > button { min-width: 0; overflow: hidden; padding: 0 3px; }

/* Each label on its control's line, in sixths: [label][control, two sixths][label][control, two sixths], the label centred in its
   sixth (human 2026-11-08: "the input window should be 1/3 in length and in the same line as its name. e.g. 城市 [未选城市], here
   "城市" is in the middle of the 1/6 remained length"; for the editor, in place of 界面 一's label above its input). 城市 and
   国家 are buttons: 跳转 (human: "跳转 should be realized by 城市 title and 国家 title remained, both renew as button"). */
.map-editor-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr) minmax(0, 2fr);
  gap: 0;
  align-items: center;
}
.map-editor-row > .map-editor-cell { display: contents; }
.map-editor-row :is(.map-editor-label, .map-editor-cell > span) {
  justify-self: center;
  max-width: calc(100% - 4px);
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-editor-row > .map-editor-label-button {
  justify-self: center;
  min-width: 0;
  max-width: calc(100% - 6px);
  padding: 0 6px;
  white-space: nowrap;
}
.map-editor-row > .map-editor-wide { grid-column: 3 / span 2; min-width: 0; }

/* the dim line between the city lines and the nation lines (human 2026-11-08: "add such a dim line between 城市 lines and 国家
   lines") */
.map-editor-rule {
  width: 100%;
  height: 0;
  margin: 2px 0;
  border: 0;
  border-top: 1px solid #d7ddd8;
}

.map-editor-fields select,
.map-editor-fields input:not([type="color"]) {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 6px;
  border: 1px solid #b9c4bd;
  border-radius: 3px;
  background: #fffdf6;
  color: var(--ink);
  font: inherit;
}

.map-editor-fields input[type="color"] {
  box-sizing: border-box;
  width: 100%;
  height: 32px;
  padding: 2px;
  border: 1px solid #b9c4bd;
  border-radius: 3px;
  background: #fffdf6;
  cursor: pointer;
}

.map-editor-fields :is(select, input):disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* the city and nation lists (src/UI/dropdown.js): a button styled as the inputs, its list always below it (human
   2026-11-03: "the expand bar should always expand below") */
.map-editor .dropdown-button {
  justify-content: space-between;
  width: 100%;
  min-width: 0;
  padding: 0 6px;
  gap: 6px;
}

.map-editor .dropdown-button:disabled {
  opacity: 0.5;
}

.map-editor .dropdown-button.open {
  border-color: var(--teal);
}

.dropdown-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* the caret */
.dropdown-button::after {
  content: "";
  flex: 0 0 auto;
  border-top: 5px solid #657183;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.dropdown-list {
  position: fixed;
  z-index: 60;
  box-sizing: border-box;
  margin: 0;
  padding: 3px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  border: 1px solid #b9c4bd;
  border-radius: 3px;
  background: #fffdf6;
  box-shadow: 0 6px 16px rgba(0, 30, 66, 0.16);
  color: var(--ink);
  font-size: var(--font-medium);
}

.dropdown-list[hidden] {
  display: none;
}

.dropdown-list > li {
  overflow: hidden;
  padding: 0 8px;
  line-height: 28px;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}

/* the chosen item by its background, not bold (human 2026-11-03: "why bold … the rule didn't told you how to do?") */
.dropdown-list > li[aria-selected="true"] {
  background: #eef1eb;
  color: #244943;
}

.dropdown-list > li.highlight {
  background: #e3ebe5;
}

.map-editor-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.map-editor-footer {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid #d7ddd8;
}

#map-editor-status {
  min-width: 0;
  min-height: 3em;
  margin: 0;
  color: var(--muted);
  font-size: var(--font-small);
  line-height: 1.45;
}

#map-editor-status[data-tone="refused"] {
  color: #a23b2a;
}

.map-editor-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

/* the tools' swatches */
.map-tool-swatch {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 18px;
  height: 15px;
}

.map-tool-swatch.terrain {
  height: 20.78px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: #f4f1e8;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 80% auto;
}

.map-tool-swatch.terrain.land { background: var(--terrain-land), #efe9d6; }
.map-tool-swatch.terrain.sea { background: var(--terrain-sea); }
.map-tool-swatch.terrain.mountain { background: var(--terrain-mountain), #f4f1e8; background-position: center; background-repeat: no-repeat; background-size: 80% auto; }
.map-tool-swatch.terrain.valley { background: var(--terrain-valley), #f4f1e8; background-position: center; background-repeat: no-repeat; background-size: 80% auto; }
.map-tool-swatch.terrain.city { background: var(--terrain-image-city), #f4f1e8; background-position: center; background-repeat: no-repeat; background-size: 80% auto; }

.map-tool-swatch.edge::before,
.map-tool-swatch.connect::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  border-top: 3px solid var(--route-road, #f3f0df);
  box-shadow: 0 0 0 1px #7d8c86;
}

.map-tool-swatch.edge.river::before { border-color: var(--route-water, #83cbd4); }
.map-tool-swatch.edge.channel::before { border-color: #175b7a; box-shadow: none; }
.map-tool-swatch.edge.empty::before { border-top: 2px dashed #aeb8b2; box-shadow: none; }
.map-tool-swatch.connect::before { border-top-style: dashed; border-color: #b48a44; box-shadow: none; }

.map-tool-swatch.select,
.map-tool-swatch.move {
  border: 2px solid #b47e30;
  border-radius: 50%;
  width: 15px;
}

.map-tool-swatch.move::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 4px;
  border-left: 5px solid #b47e30;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
}

.map-tool-swatch.territory {
  border: 2px solid #66897e;
  border-radius: 2px;
  background: rgba(102, 137, 126, 0.18);
}

/* the map while editing: the captions take no pointer, a tile tool shows a crosshair */
.map-stage.editing .city-caption-layer {
  pointer-events: none;
}

/* While editing, the roads and water shown are the laid edges (the editor's overlay) only: the routes' own paths, their
   straight guides and caravans are not drawn, so 擦除 takes a road off the map (human 2026-11-08: "current "擦除" can't remove
   the 陆路"), and no route tooltip shows (human 2026-11-08: "in edit mode, don't show the whole window"…点击查看这一条商路"") */
.map-stage.editing :is(.route-path, .connection-guide, .route-merchants) {
  display: none;
}

.map-stage.editing:not(.pan-mode) #map-world,
.map-stage.editing:not(.pan-mode) .periodic-map-projection {
  cursor: crosshair;
}

/* the editor's overlay (map-view.js setEditing drawOverlay): drawn roads and water, the first city of 连路 */
.map-edit-overlay {
  pointer-events: none;
}

.map-edit-edge {
  fill: none;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.map-edit-edge.road {
  stroke: var(--route-road, #f3f0df);
  stroke-width: 2px;
  filter: drop-shadow(0 0 1px rgba(47, 43, 35, 0.88));
}

.map-edit-edge.river {
  stroke: var(--route-water, #83cbd4);
  stroke-width: 2.5px;
}

.map-edit-start {
  fill: rgba(242, 193, 78, 0.25);
  stroke: #b47e30;
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
}

/* a large map's stroke in progress (the map is redrawn when it ends) */
.map-edit-mark {
  opacity: 0.75;
  stroke: #b47e30;
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

.map-edit-mark.territory {
  opacity: 0.45;
}

.map-edit-edge.mark.channel {
  stroke: #175b7a;
  stroke-width: 2.5px;
}

.map-edit-edge.mark.empty {
  stroke: #a23b2a;
  stroke-width: 2px;
  stroke-dasharray: 3 3;
}

/* 圈选 in the editor (map-editor.js; human 2026-11-08: "lasso should be available when edit"): the chosen tiles over the map,
   and the line above the fields that counts them (with the choice for city tiles when one is among them) */
.map-edit-selected {
  fill: rgba(242, 193, 78, 0.28);
  stroke: #c58f12;
  stroke-width: 1.5px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.map-editor-selection {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 4px 8px;
  border: 1px solid #e2c27a;
  border-radius: 3px;
  background: #fbf3dd;
}
.map-editor-selection[hidden],
.map-editor-selection-cities[hidden] { display: none; }
.map-editor-selection-cities {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  cursor: pointer;
}
