/* Dark theme inspired by the Factorio in-game UI / wiki. Single
   palette, no light variant. */
:root {
  --bg:            #1e1e22;
  --surface:       #2a2a2e;
  --surface-2:     #34343a;
  --surface-hover: #3d3d44;
  --border:        #3a3a40;
  --border-strong: #4a4a52;
  --text:          #e6e6e8;
  --text-dim:      #95959a;
  --text-faint:    #6a6a70;
  --accent:        #4f9eff;
  --accent-hover:  #6fb0ff;
  --accent-bg:     rgba(79, 158, 255, 0.12);
  --error:         #ff6b6b;
  --badge-bg:      #44444a;
  --badge-text:    #c0c0c4;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Titillium Web', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
}

.site-header,
.content,
.site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

.site-header h1 { margin: 0 0 4px; font-size: 26px; font-weight: 600; color: var(--text); }
.site-header .subtitle { margin: 0; color: var(--text-dim); font-size: 16px; }

.site-footer {
  color: var(--text-dim);
  font-size: 14px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}
.site-footer .sep { color: var(--text-faint); margin: 0 6px; }
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { color: var(--accent-hover); text-decoration: underline; }

textarea#bp-input {
  width: 100%;
  min-height: 140px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  padding: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  resize: vertical;
}
textarea#bp-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

button {
  font: inherit;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
button:hover { background: var(--surface-hover); }
button.primary:hover { background: var(--accent-hover); }

/* "Demo" — secondary action: light green, pushed to the right of the row.
   `margin-left: auto` inside the flex .btn-row aligns it to the trailing edge. */
button.btn-demo {
  margin-left: auto;
  background: #6dc789;
  color: #1e1e22;
  border-color: #6dc789;
}
button.btn-demo:hover { background: #82d39c; }
button.btn-demo:disabled:hover { background: #6dc789; }

.error {
  margin-top: 8px;
  color: var(--error);
  font-size: 15px;
}

.input-collapsed {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.input-collapsed .preview {
  flex: 1;
  font-family: ui-monospace, monospace;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary {
  margin-top: 12px;
  padding: 8px 12px;
  background: var(--accent-bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 15px;
  color: var(--text);
}

.tabs { margin-top: 12px; display: flex; gap: 6px; }
.tab {
  font-size: 14px;
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.tab:hover { background: var(--surface-hover); color: var(--text); }
.tab.active { background: var(--accent); color: var(--bg); }

ul.tree, ul.tree ul { list-style: none; padding-left: 16px; margin: 0; }
ul.tree { padding-left: 0; }
.tree-node {
  cursor: pointer;
  padding: 3px 4px;
  border-radius: 3px;
  font-size: 16px;
  color: var(--text);
}
.tree-node:hover { background: var(--surface-hover); }
.tree-node.selected { background: var(--accent); color: var(--bg); }
.tree-node .toggle { display: inline-block; width: 14px; color: var(--text-faint); }
.tree-node .tree-toggle {
  display: inline-block;
  width: 14px;
  margin-right: 4px;
  text-align: center;
  font-size: 10px;
  color: var(--text-faint);
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease;
  vertical-align: -0.1em;
}
.tree-node .tree-toggle.collapsed { transform: rotate(-90deg); }
.tree-node .tree-toggle.empty { cursor: default; visibility: hidden; }
.tree-node .tree-toggle:hover { color: var(--text); }
.tree-node.selected .tree-toggle { color: var(--bg); }
.tree-node.selected .tree-toggle:hover { color: var(--bg); }
.tree-node .badge {
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--badge-bg);
  color: var(--badge-text);
  margin-left: 6px;
}
.tree-node.selected .badge { background: rgba(0, 0, 0, 0.25); color: var(--bg); }

.actions { display: flex; gap: 8px; margin-top: 10px; }

@media (max-width: 480px) {
  .site-header, .content, .site-footer { padding: 16px; }
}

/* Header needs `position: relative` so the absolute switch anchors here. */
.site-header { position: relative; }

.locale-switch {
  position: absolute;
  top: 24px;
  right: 24px;
  font-size: 14px;
  color: var(--text-dim);
  user-select: none;
}
.locale-switch [data-locale] {
  cursor: pointer;
  padding: 2px 4px;
}
.locale-switch [data-locale].active {
  color: var(--accent);
  font-weight: 600;
}
.locale-switch [data-locale]:not(.active):hover {
  color: var(--text);
}
.locale-switch .sep {
  color: var(--text-faint);
  margin: 0 2px;
}

@media (max-width: 480px) {
  .locale-switch { top: 16px; right: 16px; }
}

/* JSON edit mode */
textarea.json-editor {
  width: 100%;
  min-height: 60vh;
  margin-top: 8px;
  padding: 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  white-space: pre;
  overflow: auto;
}
textarea.json-editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.result-panel {
  margin-top: 16px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.result-panel .result-header {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}
.result-panel textarea.result-text {
  width: 100%;
  min-height: 80px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  resize: vertical;
}

input.tree-search {
  width: 100%;
  padding: 6px 10px;
  margin-top: 8px;
  margin-bottom: 8px;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-family: inherit;
}
input.tree-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
input.tree-search::placeholder { color: var(--text-faint); }

p.empty-tree {
  color: var(--text-dim);
  font-size: 15px;
  padding: 12px 4px;
  margin: 0;
}

/* Factorio icons in our `icons/` folder are mipmap sprite sheets:
   the main icon sits in the leftmost height×height square, with smaller
   variants stacked to the right (e.g. 64+32+16+8 = 120 pixels wide for
   a 64-pixel-tall icon). `object-fit: cover` + `object-position: left top`
   tells the browser to display only that leftmost square, scaled to the
   element's dimensions. Works for square icons (no-op) and any aspect
   ratio, including the rare taller-than-wide cases. */
img.bp-icon {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  object-fit: cover;
  object-position: left top;
  vertical-align: -0.2em;
  margin: 0 1px;
}
.tree-node img.bp-icon { width: 1em; height: 1em; vertical-align: -0.15em; }
.summary img.bp-icon { width: 1.05em; height: 1.05em; vertical-align: -0.18em; }

.breadcrumb {
  margin-top: 12px;
  margin-bottom: 4px;
  font-size: 15px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
}
.bc-segment {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--text-dim);
}
.bc-segment:hover { background: var(--surface-hover); color: var(--text); }
.bc-segment.current { color: var(--text); font-weight: 600; }
.bc-sep { color: var(--text-faint); margin: 0 2px; user-select: none; }
.breadcrumb img.bp-icon { height: 1em; vertical-align: -0.15em; }

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
button:disabled:hover { background: var(--surface-2); }
button.primary:disabled:hover { background: var(--accent); }

.spinner {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: -0.15em;
  margin-right: 6px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

::selection { background: var(--accent); color: var(--bg); }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: 6px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--surface-hover); }

.components-panel {
  margin-top: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.components-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.components-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.comp-tile {
  position: relative;
  width: 46px;
  height: 46px;
  padding: 0;
  background: #4a4a52;
  border: none;
  border-radius: 3px;
  /* Faint bevel: light top-left, dark bottom-right — matches the in-game tile look. */
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.06),
    inset -1px -1px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
  overflow: hidden;
}
.comp-tile:hover {
  background: #ff9800;
  box-shadow: none;
}
.comp-tile.active {
  background: #ff9800;
  box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.35);
}
.comp-tile .comp-slot {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.comp-tile img.bp-icon {
  height: 30px;
  width: 30px;
  margin: 0;
  vertical-align: middle;
}
.comp-tile .comp-fallback {
  font-size: 12px;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
}
.comp-tile .comp-count {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-shadow:
    0 0 3px rgba(0, 0, 0, 0.95),
    0 0 3px rgba(0, 0, 0, 0.95),
    0 0 3px rgba(0, 0, 0, 0.95);
  pointer-events: none;
  z-index: 2;
}
.comp-tile .comp-quality {
  position: absolute;
  left: 2px;
  bottom: 2px;
  width: 14px;
  height: 14px;
  pointer-events: none;
  z-index: 2;
}

.entity-editor {
  margin-top: 8px;
  margin-bottom: 4px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.entity-editor-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.entity-editor-tile {
  display: inline-block;
  cursor: default;
}
.entity-editor-tile:hover {
  background: #4a4a52;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.06),
    inset -1px -1px 0 rgba(0, 0, 0, 0.35);
}
.entity-editor-entnum {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}
.entity-editor-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  padding: 3px 0;
  cursor: pointer;
  color: var(--text);
}
.entity-editor-row input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}
.quality-picker {
  display: flex;
  gap: 2px;
  margin-left: auto;
}
.quality-pick-tile {
  width: 32px;
  height: 32px;
  padding: 0;
  background: #4a4a52;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Same bevel as the components-panel tiles. */
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.06),
    inset -1px -1px 0 rgba(0, 0, 0, 0.35);
}
.quality-pick-tile:hover {
  background: #ff9800;
  box-shadow: none;
}
.quality-pick-tile.selected {
  background: #ff9800;
  box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.35);
}
.quality-pick-tile img.bp-icon {
  width: 22px;
  height: 22px;
  margin: 0;
  vertical-align: middle;
}

.entity-editor-bar-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 15px;
  color: var(--text);
  margin-top: 4px;
}
.entity-editor-bar-status {
  font-family: ui-monospace, monospace;
  font-size: 14px;
  color: var(--text-dim);
}
.chest-bar-grid {
  display: grid;
  grid-template-columns: repeat(10, 22px);
  gap: 2px;
  margin: 6px 0 4px;
}
.cb-slot {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid;
  border-radius: 2px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.cb-slot.usable {
  background: #2c2c30;
  border-color: #3a3a3e;
}
.cb-slot.usable:hover { background: #353539; }
.cb-slot.blocked {
  background: #d96d1a;
  border-color: #ff8a3a;
}
.cb-slot.blocked:hover { background: #e07b2c; }
.cb-slot.bar-marker {
  background: #8b2520;
  border-color: #c0382d;
}
.cb-slot.bar-marker::after { content: '×'; }
.cb-slot.bar-marker:hover { background: #a02e28; }
.entity-editor-scope {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-dim);
}
.entity-editor-scope label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.entity-editor-scope input[type="radio"] {
  accent-color: var(--accent);
  cursor: pointer;
}

p.json-too-large {
  margin: 8px 0 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.6;
}

.entity-editor-delete {
  margin-left: auto;
  background: #c0392b;
  border: none;
  padding: 4px;
  border-radius: 3px;
  cursor: pointer;
  color: #000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.entity-editor-delete:hover {
  background: #d24333;
}
.entity-editor-delete svg {
  width: 18px;
  height: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 20px 24px;
  min-width: 320px;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.modal-body {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.modal-actions button {
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}
.modal-actions button:hover {
  background: var(--surface-hover);
}
.modal-actions button.danger {
  background: #c0392b;
  border-color: #a02b1c;
  color: #fff;
}
.modal-actions button.danger:hover {
  background: #d24333;
}

