/* Palette + top bar live in theme.css, which every page links first. */

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

/* Native number spinners don't fit the theme — strip them everywhere */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

html, body {
  width: 100%; height: 100%;
}

body {
  background: var(--bg0);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(12px, 0.9vw, 16px);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Layout ──────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: clamp(240px, 17vw, 340px) 1fr clamp(260px, 18vw, 360px);
  gap: 0;
  flex: 1;
  overflow: hidden;
}

.panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel:last-child { border-right: none; }

.panel-header {
  padding: clamp(7px,0.6vh,12px) clamp(10px,0.9vw,16px);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: clamp(9px, 0.65vw, 13px);
  letter-spacing: 2px;
  color: var(--gold-dim);
  text-transform: uppercase;
  background: var(--bg1);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: clamp(8px,0.8vw,14px);
  min-height: 0;
}
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: var(--bg1); }
.panel-body::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

/* ── Collection Panel ────────────────────────────────────── */
.left-panel-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Picker section — can be expanded to full height */
.picker-section {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: flex 0.25s ease;
}
.picker-section.expanded {
  flex: 1;
  min-height: 0;
}

.picker-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(5px,0.5vh,9px) clamp(8px,0.8vw,14px);
  background: var(--bg1);
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.picker-section-header:hover { background: var(--bg2); }
.section-label {
  font-size: clamp(9px, 0.6vw, 11px);
  letter-spacing: 1.5px;
  color: var(--text-dim);
  text-transform: uppercase;
}
.picker-section-header .section-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.toggle-btn {
  font-size: clamp(9px, 0.65vw, 12px);
  color: var(--gold-dim);
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 7px;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all 0.15s;
}
.toggle-btn:hover { border-color: var(--gold); color: var(--gold); }
.header-btns {
  display: flex;
  align-items: center;
  gap: clamp(4px,0.4vw,7px);
  flex-shrink: 0;
}

.picker-search-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
  padding: clamp(5px,0.5vh,9px) clamp(8px,0.8vw,14px);
}

.picker-search-container input {
  background: var(--bg0);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(9px, 0.65vw, 12px);
  padding: clamp(3px, 0.3vh, 5px) clamp(4px, 0.35vw, 7px);
  border-radius: 3px;
  width: 100%;
  outline: 0;
}

.picker-search-container input:focus {
  border-color: var(--gold);
}

.tablet-picker-wrap {
  overflow-y: auto;
  padding: clamp(5px,0.5vw,10px);
  flex: 1;
  min-height: 0;
}
.tablet-picker-wrap::-webkit-scrollbar { width: 3px; }
.tablet-picker-wrap::-webkit-scrollbar-thumb { background: var(--border-bright); }

/* Collapsed: show 2 rows fixed; expanded: fills available space */
.picker-section:not(.expanded) .tablet-picker-wrap {
  max-height: calc(var(--cell) * 2 + 20px);
}

.tablet-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(40px,3vw,62px), 1fr));
  gap: clamp(3px, 0.3vw, 6px);
}

.picker-cell {
  aspect-ratio: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}
.picker-cell:hover { border-color: var(--gold); background: var(--bg3); }
.picker-cell img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.picker-cell .fallback {
  font-size: clamp(6px, 0.45vw, 9px);
  text-align: center;
  color: var(--text-dim);
  padding: 2px;
  line-height: 1.2;
  pointer-events: none;
}
.picker-cell .pid {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: clamp(6px,0.4vw,8px);
  color: var(--gold-dim);
  pointer-events: none;
  text-shadow: 0 0 3px #000;
}

/* ── Contribute banner (replaces the old changelog / TODO panels) ── */
.contrib-banner {
  width: 100%;
  max-width: min(100%, 760px);
  margin-top: auto;
  padding: clamp(10px, 0.9vw, 16px);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg2);
  font-size: clamp(10px, 0.68vw, 12px);
  color: var(--text-dim);
  line-height: 1.65;
}
.contrib-banner p { margin: 0; }
.contrib-banner p + p { margin-top: clamp(5px, 0.5vh, 9px); }
.contrib-hello {
  color: var(--text-bright);
  font-family: var(--font-display);
  font-size: clamp(11px, 0.75vw, 14px);
  margin-bottom: clamp(6px, 0.6vh, 10px) !important;
}

/* Rabbit-paw hearts — decorative, so they're aria-hidden and carry no alt text. */
.contrib-paws {
  display: flex;
  justify-content: center;
  gap: clamp(4px, 0.4vw, 8px);
  margin-top: clamp(8px, 0.8vh, 14px);
}
.contrib-paws img {
  width: clamp(14px, 1.15vw, 20px);
  height: clamp(14px, 1.15vw, 20px);
  object-fit: contain;
  image-rendering: pixelated;
  opacity: 0.75;
}
.contrib-banner a {
  color: var(--gold);
  text-decoration: none;
  border-bottom: 1px solid var(--gold-dim);
  word-break: break-word;
}
.contrib-banner a:hover { color: var(--gold-bright); border-bottom-color: var(--gold-bright); }

/* ── Help / Credits dialogs ──────────────────────────────────────── */
/* Reuse the rules dialog shell; only the reading surface inside differs. */
.info-dialog { width: clamp(520px, 56vw, 720px); }

.info-body {
  font-size: clamp(10px, 0.7vw, 13px);
  color: var(--text);
  line-height: 1.7;
}

.info-heading {
  font-family: var(--font-display);
  font-size: clamp(10px, 0.68vw, 13px);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  margin: clamp(14px, 1.3vh, 22px) 0 clamp(6px, 0.6vh, 10px);
  padding-bottom: clamp(4px, 0.4vh, 7px);
  border-bottom: 1px solid var(--border);
}
.info-body > .info-heading:first-child { margin-top: 0; }

.info-p { margin: 0 0 clamp(7px, 0.7vh, 12px); }
.info-p:last-child { margin-bottom: 0; }
.info-p em     { color: var(--text-bright); font-style: italic; }
.info-p strong { color: var(--text-bright); font-weight: normal; }

.info-entry { margin-bottom: clamp(8px, 0.8vh, 14px); }
.info-for {
  color: var(--text-dim);
  font-size: clamp(9px, 0.62vw, 12px);
}
.info-who { color: var(--text-bright); }

.info-list {
  list-style: none;
  padding: 0;
  margin: clamp(3px, 0.3vh, 5px) 0 0;
  display: flex;
  flex-direction: column;
  gap: clamp(2px, 0.2vh, 4px);
  color: var(--text-dim);
}
.info-list li { padding-left: clamp(12px, 1vw, 16px); position: relative; }
.info-list li::before {
  content: '◆';
  position: absolute;
  left: 0;
  color: var(--gold-dim);
  font-size: 0.55em;
  top: 0.55em;
}

.info-link {
  color: var(--gold);
  text-decoration: none;
  border-bottom: 1px solid var(--gold-dim);
}
.info-link:hover { color: var(--gold-bright); border-bottom-color: var(--gold-bright); }

.info-foot {
  margin-top: clamp(14px, 1.3vh, 22px);
  padding-top: clamp(8px, 0.8vh, 14px);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
}

/* Little colour keys inline in the Help text, so the mark descriptions
   point at the actual colour rather than just naming it. */
.help-swatch {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border-radius: 2px;
  vertical-align: -0.1em;
  margin-right: 0.15em;
}
.swatch-x2       { border: 2px dashed var(--gold); }
.swatch-target   { box-shadow: inset 0 0 0 2px var(--violet); }
.swatch-exempt   { box-shadow: inset 0 0 0 2px var(--teal); }
.swatch-reserved { border: 1px dashed var(--gold-dim); }

/* ── Merge Open Button ───────────────────────────────────────────── */
.merge-open-btn {
  font-family: var(--font-mono);
  font-size: clamp(8px, 0.58vw, 11px);
  color: var(--teal);
  background: none;
  border: 1px solid var(--teal);
  border-radius: 3px;
  padding: 2px 7px;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.merge-open-btn:hover { opacity: 1; }

/* ── Merge Dialog ────────────────────────────────────────────────── */
.merge-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.merge-dialog {
  background: var(--bg1);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  width: clamp(580px, 78vw, 960px);
  max-height: 84vh;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.merge-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(8px,0.7vh,13px) clamp(12px,1vw,18px);
  border-bottom: 1px solid var(--border);
  background: var(--bg0);
  flex-shrink: 0;
}
.merge-hdr-title {
  font-family: var(--font-display);
  font-size: clamp(10px,0.75vw,14px);
  letter-spacing: 2px;
  color: var(--gold);
  text-transform: uppercase;
}
.merge-close-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: clamp(14px,1.1vw,20px);
  cursor: pointer;
  padding: 0 5px;
  border-radius: 3px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
.merge-close-btn:hover { color: var(--red); border-color: var(--red); }

.merge-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Slot panels (left / right) ──────────────────────────────────── */
.merge-slot {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}
.merge-slot:last-child { border-right: none; border-left: 1px solid var(--border); }

.merge-slot-hdr {
  font-family: var(--font-display);
  font-size: clamp(8px,0.58vw,11px);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold-dim);
  padding: clamp(5px,0.5vh,9px) clamp(8px,0.8vw,13px);
  background: var(--bg0);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.merge-picker-wrap {
  flex: 1;
  overflow-y: auto;
  padding: clamp(5px,0.5vw,9px);
  min-height: 0;
}
.merge-picker-wrap::-webkit-scrollbar { width: 3px; }
.merge-picker-wrap::-webkit-scrollbar-thumb { background: var(--border-bright); }

.merge-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(32px,2.6vw,46px), 1fr));
  gap: clamp(3px,0.28vw,5px);
}

.merge-picker-cell {
  aspect-ratio: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.12s, background 0.12s;
}
.merge-picker-cell img { width:100%;height:100%;object-fit:cover;image-rendering:pixelated; }
.merge-picker-cell:hover { border-color: var(--gold-dim); background: var(--bg3); }
.merge-picker-cell.selected { border-color: var(--teal); background: rgba(78,205,196,0.1); }

.merge-sel-area {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: clamp(7px,0.65vh,11px) clamp(8px,0.8vw,13px);
  background: var(--bg0);
  display: flex;
  flex-direction: column;
  gap: clamp(5px,0.5vh,8px);
  min-height: clamp(80px,9vh,110px);
  justify-content: center;
}

.merge-sel-placeholder {
  font-size: clamp(9px,0.65vw,12px);
  color: var(--text-dim);
  text-align: center;
  font-style: italic;
}

.merge-sel-row {
  display: flex;
  align-items: center;
  gap: clamp(6px,0.6vw,10px);
}
.merge-sel-name {
  font-size: clamp(10px,0.72vw,13px);
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.merge-rot-row {
  display: flex;
  align-items: center;
  gap: clamp(5px,0.5vw,8px);
}
.merge-rot-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--gold-dim);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.65vw,12px);
  padding: 2px 7px;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.merge-rot-btn:hover { border-color: var(--gold); color: var(--gold); }
.merge-rot-label {
  font-size: clamp(10px,0.7vw,13px);
  color: var(--text);
  min-width: clamp(46px,4vw,64px);
  text-align: center;
}
.merge-rot-fixed {
  font-size: clamp(9px,0.62vw,11px);
  color: var(--text-dim);
  font-style: italic;
}

/* ── Center preview column ───────────────────────────────────────── */
.merge-center {
  width: clamp(190px,17vw,260px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px,0.8vh,14px);
  padding: clamp(10px,1vh,16px) clamp(8px,0.8vw,13px);
  background: var(--bg0);
  overflow: hidden;
}

.merge-preview-label {
  font-family: var(--font-display);
  font-size: clamp(8px,0.58vw,10px);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.merge-preview-grid {
  display: grid;
  grid-template-columns: repeat(9, var(--mpc));
  grid-template-rows:    repeat(9, var(--mpc));
  --mpc: clamp(17px,1.45vw,25px);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg2);
}

.mpc {
  width: var(--mpc);
  height: var(--mpc);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(6px,0.5vw,9px);
  font-family: var(--font-mono);
}
.mpc-center { background: var(--bg3); border-color: var(--border-bright); }
.mpc-a      { background: rgba(78,205,196,0.18); border-color: rgba(78,205,196,0.4); color: var(--teal); }
.mpc-a-neg  { background: rgba(224,92,92,0.18);  border-color: rgba(224,92,92,0.4);  color: var(--red);  }
.mpc-b      { background: rgba(200,168,75,0.18); border-color: rgba(200,168,75,0.4); color: var(--gold); }
.mpc-b-neg  { background: rgba(224,92,92,0.26);  border-color: rgba(224,92,92,0.5);  color: var(--red);  }
.mpc-both   { background: rgba(232,236,244,0.18);border-color: rgba(232,236,244,0.45);color: var(--text-bright); }

.merge-legend {
  display: flex;
  gap: clamp(7px,0.7vw,12px);
  font-size: clamp(9px,0.62vw,11px);
}
.ml-a  { color: var(--teal); }
.ml-b  { color: var(--gold); }
.ml-ab { color: var(--text-bright); }

/* ── Footer ──────────────────────────────────────────────────────── */
.merge-footer {
  border-top: 1px solid var(--border);
  padding: clamp(8px,0.75vh,12px) clamp(12px,1vw,18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px,0.6vh,10px);
  justify-content: center;
  background: var(--bg0);
  flex-shrink: 0;
}
.merge-warning {
  font-size: clamp(9px,0.62vw,11px);
  line-height: 1.5;
  color: var(--red);
  text-align: center;
  max-width: 520px;
}
.merge-warning:empty { display: none; }
.merge-confirm-btn {
  padding: clamp(7px,0.65vh,11px) clamp(24px,2vw,38px);
  background: linear-gradient(135deg, rgba(78,205,196,0.25), rgba(78,205,196,0.1));
  border: 1px solid var(--teal);
  color: var(--teal);
  font-family: var(--font-display);
  font-size: clamp(10px,0.75vw,14px);
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s;
}
.merge-confirm-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(78,205,196,0.4), rgba(78,205,196,0.2));
  box-shadow: 0 0 12px rgba(78,205,196,0.3);
}
.merge-confirm-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Rules Dialog ────────────────────────────────────────────────── */
.rules-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.rules-dialog {
  background: var(--bg1);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  width: clamp(520px, 62vw, 780px);
  max-height: 84vh;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.rules-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(8px,0.7vh,13px) clamp(12px,1vw,18px);
  border-bottom: 1px solid var(--border);
  background: var(--bg0);
  flex-shrink: 0;
}
.rules-hdr-title {
  font-family: var(--font-display);
  font-size: clamp(10px,0.75vw,14px);
  letter-spacing: 2px;
  color: var(--gold);
  text-transform: uppercase;
}
.rules-close-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: clamp(14px,1.1vw,20px);
  cursor: pointer;
  padding: 0 5px;
  border-radius: 3px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
.rules-close-btn:hover { color: var(--red); border-color: var(--red); }

.rules-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: clamp(10px,0.9vh,16px) clamp(12px,1vw,18px);
  scrollbar-width: thin;                                  /* Firefox */
  scrollbar-color: var(--border-bright) var(--bg1);
}
.rules-body::-webkit-scrollbar { width: 4px; }
.rules-body::-webkit-scrollbar-track { background: var(--bg1); }
.rules-body::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border-radius: 2px;
}
.rules-body::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }
.rules-list { display: flex; flex-direction: column; gap: clamp(5px,0.5vh,9px); }
.rules-empty {
  color: var(--text-dim);
  font-size: clamp(9px,0.65vw,12px);
  padding: clamp(8px,0.8vh,14px) 0;
  text-align: center;
}

.rules-row {
  display: flex;
  align-items: center;
  gap: clamp(4px,0.4vw,8px);
  padding: clamp(5px,0.5vh,9px) clamp(6px,0.5vw,10px);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.rules-row.dragging { opacity: 0.4; }
.rules-row.drop-above { box-shadow: inset 0 2px 0 var(--gold); }
.rules-row.drop-below { box-shadow: inset 0 -2px 0 var(--gold); }

.rules-handle {
  cursor: grab;
  color: var(--text-dim);
  font-size: clamp(11px,0.85vw,16px);
  line-height: 1;
  padding: 0 2px;
  user-select: none;
}
.rules-handle:active { cursor: grabbing; }

.rules-text {
  color: var(--text-dim);
  font-size: clamp(9px,0.65vw,12px);
  white-space: nowrap;
}

.rules-select, .rules-num {
  background: var(--bg0);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.65vw,12px);
  padding: clamp(3px,0.3vh,5px) clamp(4px,0.35vw,7px);
  border-radius: 3px;
}
.rules-num { width: clamp(46px,3.6vw,62px); }
.rules-select:focus, .rules-num:focus { outline: none; border-color: var(--gold); }

.rules-del-btn {
  margin-left: auto;
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: clamp(10px,0.75vw,14px);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 3px;
  transition: color 0.15s, border-color 0.15s;
}
.rules-del-btn:hover { color: var(--red); border-color: var(--red); }

.rules-add-btn {
  margin-top: clamp(7px,0.7vh,12px);
  width: 100%;
  padding: clamp(5px,0.5vh,9px);
  background: none;
  border: 1px dashed var(--border-bright);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.65vw,12px);
  cursor: pointer;
  border-radius: 3px;
  transition: color 0.15s, border-color 0.15s;
}
.rules-add-btn:hover { color: var(--gold); border-color: var(--gold); }

/* ── Items in the Rules dialog ─────────────────────────────────── */
/* Items are picked, not placed: the solver decides where they go, so this section
   is a roster plus per-item conditions rather than anything grid-shaped. */

.rules-add-row { display: flex; gap: clamp(5px,0.5vw,9px); }
.rules-add-row .rules-add-btn { margin-top: clamp(7px,0.7vh,12px); }

/* Item rules sit under the slot rules; without this they butt straight up against
   whichever list is above them. :empty keeps the gap from appearing when unused. */
#item-rules-list:not(:empty) { margin-top: clamp(5px,0.5vh,9px); }
#rules-list:not(:empty) + #item-rules-list:not(:empty) { margin-top: clamp(5px,0.5vh,9px); }

/* Picker — same tile language as the tablet picker, with the bracket value in the
   badge slot the tablet id occupies there. */
.item-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(58px,4.6vw,84px), 1fr));
  gap: clamp(3px,0.3vw,6px);
  /* Opens directly under the add buttons, so it needs its own gap above as well */
  margin: clamp(8px,0.8vh,14px) 0;
  padding-top: clamp(8px,0.8vh,14px);
  border-top: 1px solid var(--border);
}
.item-picker-cell {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  transition: border-color 0.15s, background 0.15s;
}
.item-picker-cell:hover { border-color: var(--gold); background: var(--bg3); }
.item-picker-cell img {
  width: 100%;
  flex: 1;
  min-height: 0;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}
.item-picker-cell .fallback {
  font-size: clamp(7px,0.5vw,9px);
  color: var(--text-dim);
  text-align: center;
  padding: 2px;
}
.item-picker-cell .item-val {
  position: absolute;
  top: 2px;
  right: 3px;
  font-family: var(--font-mono);
  font-size: clamp(8px,0.58vw,11px);
  color: var(--gold);
  background: rgba(13,15,20,0.8);
  border-radius: 2px;
  padding: 0 3px;
  pointer-events: none;
}
.item-picker-cell .item-nm {
  width: 100%;
  font-size: clamp(6px,0.46vw,9px);
  line-height: 1.2;
  color: var(--text-dim);
  text-align: center;
  padding: 1px 2px 2px;
  background: var(--bg0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* An item rule is a rule — same row language, just taller when it has sub-config. */
.rules-row.item-rule { flex-direction: column; align-items: stretch; }
.item-rule-head {
  display: flex;
  align-items: center;
  gap: clamp(5px,0.45vw,9px);
}
.item-rule-spr {
  width: clamp(18px,1.5vw,26px);
  height: clamp(18px,1.5vw,26px);
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}
.item-rule-nm {
  color: var(--text-bright);
  font-size: clamp(9px,0.65vw,12px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-value-ctl {
  display: inline-flex;
  align-items: center;
  gap: clamp(3px,0.3vw,6px);
  margin-left: auto;
}
.item-sub-row .item-value-ctl { margin-left: 0; }

.item-subcfg {
  margin-top: clamp(5px,0.5vh,9px);
  padding-top: clamp(5px,0.5vh,9px);
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: clamp(4px,0.4vh,7px);
}
.item-sub-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: clamp(4px,0.4vw,8px);
}
.item-glyph {
  color: var(--teal);
  font-size: clamp(11px,0.85vw,15px);
  line-height: 1;
  width: 1.2em;
  text-align: center;
}

/* Two-state segmented control — same active treatment as the Rest buttons */
.item-toggle { display: inline-flex; flex-shrink: 0; }
.item-toggle-btn {
  padding: clamp(2px,0.25vh,4px) clamp(6px,0.5vw,10px);
  background: var(--bg1);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(8px,0.58vw,11px);
  cursor: pointer;
  transition: all 0.15s;
}
.item-toggle-btn:first-child { border-radius: 3px 0 0 3px; }
/* Overlap the seam instead of dropping a border: whichever side is active needs a
   complete outline, and `border-left: none` left the right-hand one open. */
.item-toggle-btn + .item-toggle-btn { border-radius: 0 3px 3px 0; margin-left: -1px; }
.item-toggle-btn:hover { color: var(--text-bright); }
.item-toggle-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(200,168,75,0.1);
  position: relative;
  z-index: 1;                 /* draw the gold edge over its neighbour's */
}

/* Row phases carry their real combo icons, and say which rows they hit on the
   grid as it currently stands. */
.item-phase-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: clamp(3px,0.3vh,5px) clamp(5px,0.45vw,9px);
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(8px,0.58vw,11px);
  cursor: pointer;
  transition: all 0.15s;
}
.item-phase-btn img {
  width: clamp(14px,1.15vw,20px);
  height: clamp(14px,1.15vw,20px);
  object-fit: contain;
  image-rendering: pixelated;
}
.item-phase-btn small { font-size: clamp(6px,0.44vw,9px); opacity: 0.75; }
.item-phase-btn:hover:not(:disabled) { color: var(--text-bright); border-color: var(--border-bright); }
.item-phase-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(200,168,75,0.1);
}
.item-phase-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Grimoire bracket values are fixed and known, so picking the sprite fills the
   number in — two clicks instead of remembering it. */
.item-entities {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  flex-basis: 100%;
}
.item-ent-btn {
  width: clamp(20px,1.6vw,28px);
  height: clamp(20px,1.6vw,28px);
  padding: 1px;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  opacity: 0.5;
  transition: border-color 0.15s, opacity 0.15s;
}
.item-ent-btn img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.item-ent-btn:hover { border-color: var(--gold); opacity: 0.85; }
.item-ent-btn.on { border-color: var(--gold); opacity: 1; background: rgba(200,168,75,0.12); }

.item-hint {
  color: var(--text-dim);
  font-size: clamp(8px,0.55vw,11px);
  line-height: 1.5;
  opacity: 0.85;
}

/* Collection tag, matching the "merged" one */
.tag-item { color: var(--teal); border-color: var(--teal); }

/* How far along a placed item is, without needing a hover. Always present, so the
   colour rather than the presence of the badge is what carries the state. */
.item-slot-badge {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-family: var(--font-mono);
  font-size: clamp(8px,0.62vw,12px);
  background: rgba(13,15,20,0.82);
  border-radius: 2px;
  padding: 0 3px;
  pointer-events: none;
}
.item-slot-badge.inactive { color: var(--red); }
.item-slot-badge.partial  { color: var(--gold-bright); }
.item-slot-badge.full     { color: var(--green); }
/* An inert item has no bracket to fall short of — the badge is just the slot it
   swallowed. Teal when that slot was negative, which is the whole point of it. */
.item-slot-badge.inert      { color: var(--text-dim); }
.item-slot-badge.inert-good { color: var(--teal); }

/* A slot the solver is deliberately holding open for something you named */
.grid-cell.cell-reserved { outline: 1px dashed var(--gold-dim); outline-offset: -3px; }

/* Whatever you said goes here — a Grimoire, Planet or Companion */
.cell-ghost {
  position: absolute;
  width: 62%;
  height: 62%;
  object-fit: contain;
  image-rendering: pixelated;
  opacity: 0.28;
  pointer-events: none;
}

.item-zone-badge {
  color: var(--teal);
  border: 1px solid var(--teal);
  border-radius: 3px;
  padding: 1px clamp(4px,0.35vw,7px);
  font-family: var(--font-mono);
  font-size: clamp(8px,0.55vw,10px);
  white-space: nowrap;
}

/* A solver-placed item on the grid — distinguished from a tablet the player put there */
.cell-item { box-shadow: inset 0 0 0 1px var(--teal); }

/* Rest segment — permanent, non-draggable, always lowest priority */
.rules-rest {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: clamp(4px,0.4vw,8px);
  padding: clamp(8px,0.75vh,13px) clamp(12px,1vw,18px);
  border-top: 1px solid var(--border);
  background: var(--bg0);
  flex-shrink: 0;
}
.rules-rest-btn {
  padding: clamp(4px,0.4vh,7px) clamp(9px,0.75vw,14px);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.65vw,12px);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}
.rules-rest-btn:hover { color: var(--text-bright); }
.rules-rest-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(200,168,75,0.1);
}
.rules-hint {
  flex-basis: 100%;
  color: var(--text-dim);
  font-size: clamp(8px,0.58vw,11px);
  line-height: 1.5;
  opacity: 0.8;
}

.rules-footer {
  border-top: 1px solid var(--border);
  padding: clamp(8px,0.75vh,12px) clamp(12px,1vw,18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px,0.6vh,10px);
  background: var(--bg0);
  flex-shrink: 0;
}
.rules-warning {
  font-size: clamp(9px,0.62vw,11px);
  line-height: 1.5;
  color: var(--red);
  text-align: center;
  max-width: 520px;
}
.rules-warning:empty { display: none; }
.rules-btn-row { display: flex; gap: clamp(7px,0.7vw,12px); }
.rules-cancel-btn, .rules-apply-btn {
  padding: clamp(7px,0.65vh,11px) clamp(20px,1.7vw,32px);
  font-family: var(--font-display);
  font-size: clamp(10px,0.75vw,14px);
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s;
}
.rules-cancel-btn {
  background: none;
  border: 1px solid var(--border-bright);
  color: var(--text-dim);
}
.rules-cancel-btn:hover { color: var(--text-bright); border-color: var(--text-dim); }
.rules-apply-btn {
  background: linear-gradient(135deg, rgba(78,205,196,0.25), rgba(78,205,196,0.1));
  border: 1px solid var(--teal);
  color: var(--teal);
}
.rules-apply-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(78,205,196,0.4), rgba(78,205,196,0.2));
  box-shadow: 0 0 12px rgba(78,205,196,0.3);
}
.rules-apply-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Solver panel: engine toggle + rules entry point ─────────────── */
.engine-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(4px,0.4vw,7px);
  margin-bottom: clamp(6px,0.6vh,10px);
}
.engine-btn {
  padding: clamp(4px,0.4vh,7px);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.62vw,11px);
  letter-spacing: 1px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}
.engine-btn:hover { color: var(--text-bright); }
.engine-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(200,168,75,0.1);
}

.rules-open-btn {
  width: 100%;
  margin-bottom: clamp(8px,0.8vh,14px);   /* matches .mode-btns / .target-row */
  padding: clamp(7px,0.7vh,12px);
  background: var(--bg2);
  border: 1px solid var(--border-bright);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.68vw,12px);
  letter-spacing: 1px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}
.rules-open-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ── Search budget & progress ────────────────────────────────────── */
.budget-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(4px,0.4vw,7px);
  margin-bottom: clamp(5px,0.5vh,9px);
}
.budget-btn {
  padding: clamp(4px,0.4vh,7px);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(8px,0.58vw,11px);
  line-height: 1.4;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}
.budget-btn:hover { color: var(--text-bright); }
.budget-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(200,168,75,0.1);
}
.budget-hint {
  color: var(--text-dim);
  font-size: clamp(8px,0.55vw,10px);
  line-height: 1.5;
  opacity: 0.75;
  margin-bottom: clamp(8px,0.8vh,14px);
}

.solve-progress { margin-bottom: clamp(6px,0.7vh,12px); }
.solve-progress-track {
  height: clamp(4px,0.45vh,7px);
  background: var(--bg0);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.solve-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  transition: width 0.2s linear;
}
.solve-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(6px,0.6vw,10px);
  margin-top: clamp(4px,0.4vh,7px);
  color: var(--text-dim);
  font-size: clamp(8px,0.6vw,11px);
}
.solve-cancel-btn {
  background: none;
  border: 1px solid var(--border-bright);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(8px,0.58vw,11px);
  padding: clamp(2px,0.25vh,4px) clamp(6px,0.6vw,10px);
  cursor: pointer;
  border-radius: 3px;
  transition: color 0.15s, border-color 0.15s;
}
.solve-cancel-btn:hover { color: var(--red); border-color: var(--red); }

.browse-btn {
  width: 100%;
  margin-top: clamp(4px,0.4vh,7px);
  padding: clamp(6px,0.6vh,10px);
  background: var(--bg2);
  border: 1px solid var(--border-bright);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.62vw,11px);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}
.browse-btn:hover { border-color: var(--gold); color: var(--gold); }

.applied-note {
  color: var(--teal);
  font-size: clamp(8px,0.6vw,11px);
  margin-bottom: clamp(5px,0.5vh,9px);
}

/* ── Results Table Dialog ────────────────────────────────────────── */
.results-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.results-dialog {
  background: var(--bg1);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  width: clamp(560px, 74vw, 940px);
  max-height: 84vh;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.results-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(8px,0.7vh,13px) clamp(12px,1vw,18px);
  border-bottom: 1px solid var(--border);
  background: var(--bg0);
  flex-shrink: 0;
}
.results-hdr-title {
  font-family: var(--font-display);
  font-size: clamp(10px,0.75vw,14px);
  letter-spacing: 2px;
  color: var(--gold);
  text-transform: uppercase;
}
.results-close-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: clamp(14px,1.1vw,20px);
  cursor: pointer;
  padding: 0 5px;
  border-radius: 3px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
.results-close-btn:hover { color: var(--red); border-color: var(--red); }

.results-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: clamp(8px,0.9vw,16px);
  padding: clamp(7px,0.7vh,12px) clamp(12px,1vw,18px);
  border-bottom: 1px solid var(--border);
  background: var(--bg0);
  flex-shrink: 0;
}
.results-filter {
  display: flex;
  align-items: center;
  gap: clamp(4px,0.4vw,7px);
  color: var(--text-dim);
  font-size: clamp(8px,0.6vw,11px);
  cursor: pointer;
  white-space: nowrap;
}
.results-filter-num {
  width: clamp(48px,3.8vw,66px);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(8px,0.6vw,11px);
  padding: clamp(2px,0.25vh,4px) clamp(4px,0.35vw,7px);
  border-radius: 3px;
}
.results-filter-num.narrow { width: clamp(38px,3vw,52px); }
.results-filter-op {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(8px,0.6vw,11px);
  padding: clamp(2px,0.25vh,4px) clamp(3px,0.3vw,5px);
  border-radius: 3px;
}
.results-slot-filter { gap: clamp(3px,0.3vw,5px); }
.results-filter-num:focus,
.results-filter-op:focus { outline: none; border-color: var(--gold); }

.results-table-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;   /* ~10 buff columns can outrun the dialog on narrow screens */
  min-height: 0;
  scrollbar-width: thin;                                  /* Firefox */
  scrollbar-color: var(--border-bright) var(--bg1);
}
/* Both axes scroll here, so height and the corner need styling too. */
.results-table-wrap::-webkit-scrollbar { width: 4px; height: 4px; }
.results-table-wrap::-webkit-scrollbar-track  { background: var(--bg1); }
.results-table-wrap::-webkit-scrollbar-corner { background: var(--bg1); }
.results-table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border-radius: 2px;
}
.results-table-wrap::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }
.results-empty {
  color: var(--text-dim);
  font-size: clamp(9px,0.65vw,12px);
  text-align: center;
  padding: clamp(20px,2.5vh,40px) 0;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: clamp(8px,0.62vw,11px);
}
.results-table th {
  position: sticky;
  top: 0;
  background: var(--bg2);
  color: var(--text-dim);
  text-align: left;
  font-weight: normal;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: clamp(5px,0.5vh,9px) clamp(6px,0.6vw,11px);
  border-bottom: 1px solid var(--border-bright);
  white-space: nowrap;
}
.results-table th.rt-sortable { cursor: pointer; user-select: none; }
.results-table th.rt-sortable:hover { color: var(--text-bright); }
.results-table th.sorted { color: var(--gold); }
.results-table td {
  padding: clamp(4px,0.4vh,7px) clamp(6px,0.6vw,11px);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
/* Per-buff-value columns: narrow and centred so the distribution reads as a shape. */
.results-table th.rt-buff-col,
.results-table td.rt-buff-col {
  text-align: center;
  padding-left: clamp(3px,0.3vw,6px);
  padding-right: clamp(3px,0.3vw,6px);
  min-width: clamp(24px,2vw,34px);
}
.results-table td.rt-buff-col { color: var(--text-bright); }
.results-table tbody tr:hover { background: var(--bg2); }
.results-table tr.rt-applied { background: rgba(78,205,196,0.09); }
.results-table td.rt-unmet { color: var(--red); }

.rt-tie-badge {
  display: inline-block;
  margin-left: clamp(4px,0.4vw,7px);
  padding: 1px clamp(4px,0.35vw,6px);
  background: var(--bg0);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 0.85em;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.rt-tie-badge:hover { color: var(--gold); border-color: var(--gold); }

.rt-apply-btn {
  background: none;
  border: 1px solid var(--teal);
  color: var(--teal);
  font-family: var(--font-mono);
  font-size: clamp(8px,0.58vw,11px);
  padding: clamp(2px,0.25vh,4px) clamp(6px,0.6vw,10px);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}
.rt-apply-btn:hover { background: rgba(78,205,196,0.15); }

.results-footer {
  border-top: 1px solid var(--border);
  padding: clamp(6px,0.6vh,10px) clamp(12px,1vw,18px);
  background: var(--bg0);
  flex-shrink: 0;
}
.results-count { color: var(--text-dim); font-size: clamp(8px,0.6vw,11px); }

/* Shown when the best layout still misses a rule — the search can only fail to
   find a placement, never prove none exists, so this is a warning not a verdict. */
.rules-banner {
  border: 1px solid var(--red);
  background: rgba(255,107,107,0.08);
  color: var(--text);
  font-size: clamp(9px,0.62vw,11px);
  line-height: 1.6;
  padding: clamp(6px,0.6vh,10px) clamp(8px,0.7vw,12px);
  border-radius: 3px;
  margin-bottom: clamp(6px,0.6vh,10px);
}
.rules-banner b { color: var(--red); }
.rules-banner-hint { color: var(--text-dim); font-style: italic; }

/* Collection (selected tablets) section */
.collection-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.collection-section-header {
  padding: clamp(5px,0.5vh,9px) clamp(8px,0.8vw,14px);
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.collection-scroll {
  flex: 1;
  overflow-y: auto;
  padding: clamp(6px,0.6vw,10px);
  min-height: 0;
}
.collection-scroll::-webkit-scrollbar { width: 4px; }
.collection-scroll::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

.collection-list { display: flex; flex-direction: column; gap: clamp(3px,0.3vh,5px); }

.collection-item {
  display: flex;
  align-items: center;
  gap: clamp(5px,0.5vw,9px);
  padding: clamp(4px,0.4vh,7px) clamp(6px,0.6vw,10px);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.collection-item:hover { border-color: var(--border-bright); }
.collection-item.selected { border-color: var(--gold); background: var(--bg3); }

.collection-item .spr {
  width: clamp(26px,2.2vw,40px);
  height: clamp(26px,2.2vw,40px);
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
}
.collection-item .spr img { width: 100%; height: 100%; image-rendering: pixelated; object-fit: cover; }
.collection-item .spr .fallback-sm {
  font-size: clamp(5px,0.4vw,7px);
  color: var(--text-dim);
  text-align: center;
  line-height: 1.1;
  padding: 1px;
}

.collection-item .info { flex: 1; min-width: 0; }
.collection-item .info .name {
  font-size: clamp(10px,0.75vw,13px);
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.collection-item .info .tags {
  font-size: clamp(8px,0.55vw,10px);
  color: var(--text-dim);
  margin-top: 1px;
}
.tag { color: var(--teal); }

.count-ctrl {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.count-btn {
  width: clamp(16px,1.3vw,22px);
  height: clamp(16px,1.3vw,22px);
  background: var(--bg3);
  border: 1px solid var(--border-bright);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: clamp(11px,0.9vw,15px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: background 0.1s, border-color 0.1s;
  line-height: 1;
  padding-bottom: 1px;
}
.count-btn:hover { background: var(--border-bright); border-color: var(--gold-dim); }
.count-val {
  font-size: clamp(11px,0.8vw,14px);
  color: var(--gold);
  min-width: clamp(14px,1.1vw,20px);
  text-align: center;
}
.remove-btn {
  width: clamp(16px,1.3vw,22px);
  height: clamp(16px,1.3vw,22px);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: clamp(11px,0.9vw,15px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: color 0.1s, border-color 0.1s;
  flex-shrink: 0;
  line-height: 1;
}
.remove-btn:hover { color: var(--red); border-color: var(--red); }

.empty-collection {
  text-align: center;
  color: var(--text-dim);
  font-size: clamp(10px,0.7vw,13px);
  padding: clamp(12px,1.5vh,24px) 0;
  line-height: 1.8;
}

/* ── Grid Panel ──────────────────────────────────────────── */
.grid-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow: auto;
  padding: clamp(12px,1.5vh,28px) clamp(12px,1.5vw,28px);
  gap: clamp(10px,1.2vh,20px);
  background: var(--bg0);
}
.grid-panel::-webkit-scrollbar { width: 4px; height: 4px; }
.grid-panel::-webkit-scrollbar-thumb { background: var(--border-bright); }

.grid-instructions {
  font-size: clamp(10px,0.65vw,12px);
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-align: center;
  line-height: 1.9;
}
.grid-instructions b { color: var(--gold-dim); }

/* Marking toolbar above the grid */
.grid-tools {
  display: flex;
  align-items: center;
  gap: clamp(4px,0.4vw,8px);
  flex-wrap: wrap;
  justify-content: center;
}
.tool-btn {
  padding: clamp(4px,0.4vh,7px) clamp(7px,0.6vw,12px);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.65vw,12px);
  letter-spacing: 0.5px;
  cursor: pointer;
  border-radius: 3px;
  text-transform: uppercase;
  transition: all 0.15s;
}
.tool-btn:hover { border-color: var(--gold-dim); color: var(--text); }
.tool-btn.active { border-color: var(--gold); color: var(--gold); background: rgba(200,168,75,0.1); }
.tool-btn #x2-count { color: var(--text-dim); }

.tool-inline {
  display: inline-flex;
  align-items: center;
  gap: clamp(3px,0.3vw,6px);
}
.tool-inline select,
.tool-inline input {
  background: var(--bg1);
  border: 1px solid var(--border);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: clamp(10px,0.7vw,13px);
  padding: clamp(3px,0.3vh,6px) clamp(4px,0.35vw,7px);
  border-radius: 3px;
}
.tool-inline input { width: clamp(46px,3.6vw,66px); text-align: center; }
.tool-inline select:focus,
.tool-inline input:focus { outline: none; border-color: var(--gold-dim); }
/* custom caret so the select matches the rest of the chrome */
.tool-inline select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: clamp(14px,1.1vw,20px);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'><path d='M0 0h10L5 6z' fill='%237a6530'/></svg>");
  background-repeat: no-repeat;
  background-position: right clamp(4px,0.35vw,7px) center;
  background-size: clamp(6px,0.5vw,9px);
  cursor: pointer;
}
.tool-inline select:hover { border-color: var(--gold-dim); }

.grid-container { position: relative; }

.inv-grid {
  display: inline-grid;
  grid-template-columns: repeat(6, var(--cell));
  gap: clamp(2px,0.2vw,3px);
  background: var(--bg1);
  border: 1px solid var(--border-bright);
  padding: clamp(2px,0.2vw,3px);
  border-radius: 4px;
}

.grid-cell {
  width: var(--cell);
  height: var(--cell);
  background: var(--bg2);
  border: 1px solid var(--border);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  border-radius: 2px;
  overflow: hidden;
  user-select: none;
}
.grid-cell:hover { border-color: var(--gold-dim); background: var(--bg3); }
.grid-cell.highlight { border-color: var(--gold) !important; background: rgba(200,168,75,0.08) !important; }

/* Expand slot: the NEXT slot to click */
.grid-cell.expand-slot {
  background: rgba(200,168,75,0.04);
  border: 1px dashed var(--gold-dim);
  cursor: pointer;
}
.grid-cell.expand-slot:hover {
  background: rgba(200,168,75,0.12);
  border-color: var(--gold);
}
.grid-cell.expand-slot .expand-icon {
  color: var(--gold-dim);
  font-size: clamp(16px,1.4vw,26px);
  font-weight: 300;
  pointer-events: none;
}
.grid-cell.expand-slot:hover .expand-icon { color: var(--gold); }

/* Inactive: beyond expand range — hidden but keeps grid shape */
.grid-cell.inactive {
  background: transparent;
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}

.cell-buff {
  font-family: var(--font-mono);
  font-size: clamp(12px,1.1vw,20px);
  font-weight: bold;
  pointer-events: none;
}
.cell-buff.pos { color: var(--green); }
.cell-buff.neg { color: var(--red); }
.cell-buff.zero { color: var(--border-bright); }

.cell-tablet {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.cell-tablet .img-container {
  width: 100%; height: 100%;
}
.cell-tablet img {
  width: 100%; height: 100%;
  object-fit: cover; image-rendering: pixelated;
  pointer-events: none;
}
.cell-tablet .fallback-grid {
  font-size: clamp(6px,0.5vw,9px);
  text-align: center; color: var(--text-dim);
  padding: 3px; line-height: 1.3;
  pointer-events: none;
}
.cell-tablet .rot-badge {
  position: absolute; top: 2px; right: 2px;
  font-size: clamp(7px,0.55vw,10px);
  color: var(--gold);
  background: rgba(0,0,0,0.75);
  padding: 0 2px; border-radius: 2px;
  pointer-events: none;
}
.cell-tablet .rot-badge.hidden { display: none; }
.cell-tablet.selected-tablet .img-container {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.grid-cell.aoe-pos { background: rgba(92,190,122,0.15) !important; border-color: rgba(92,190,122,0.45) !important; }
.grid-cell.aoe-neg { background: rgba(224,92,92,0.15) !important; border-color: rgba(224,92,92,0.45) !important; }

/* Cell marks — outline/inset shadow so they survive the aoe !important background+border */
.grid-cell.mark-x2     { outline: 2px dashed var(--gold); outline-offset: -2px; }
.grid-cell.mark-target { box-shadow: inset 0 0 0 2px var(--violet); }
/* A slot where a Link / Surge / Hospitality lets an item ignore its restriction. */
.grid-cell.mark-exempt { box-shadow: inset 0 0 0 2px var(--teal); }
.grid-cell.mark-target.mark-exempt {
  box-shadow: inset 0 0 0 2px var(--violet), inset 0 0 0 4px var(--teal);
}

.mark-badge {
  position: absolute;
  left: 2px;
  font-family: var(--font-mono);
  font-size: clamp(7px,0.55vw,10px);
  background: rgba(0,0,0,0.75);
  padding: 0 2px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 2;
}
.mark-badge.x2  { top: 2px;    color: var(--gold-bright); }
.mark-badge.tgt { bottom: 2px; color: var(--violet); }

/* ── Right Panel ─────────────────────────────────────────── */
.mode-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(4px,0.4vw,7px);
  margin-bottom: clamp(8px,0.8vh,14px);
}
.mode-btn {
  padding: clamp(6px,0.55vh,10px) clamp(6px,0.55vw,10px);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: clamp(9px,0.65vw,12px);
  letter-spacing: 0.5px;
  cursor: pointer;
  border-radius: 3px;
  text-transform: uppercase;
  transition: all 0.15s;
  text-align: center;
  line-height: 1.4;
}
.mode-btn:hover { border-color: var(--gold-dim); color: var(--text); }
.mode-btn.active { border-color: var(--gold); color: var(--gold); background: rgba(200,168,75,0.1); }
.mode-btn.full { grid-column: span 2; }

.target-row {
  display: flex; align-items: center;
  gap: clamp(6px,0.6vw,10px);
  margin-bottom: clamp(8px,0.8vh,14px);
}
.target-row label {
  font-size: clamp(9px,0.65vw,12px);
  color: var(--text-dim); letter-spacing: 0.5px; white-space: nowrap;
}
.target-row input {
  flex: 1;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--gold); font-family: var(--font-mono);
  font-size: clamp(12px,0.9vw,16px);
  padding: clamp(3px,0.3vh,6px) clamp(6px,0.6vw,10px);
  border-radius: 3px; width: 60px; text-align: center;
}
.target-row input:focus { outline: none; border-color: var(--gold-dim); }

.solve-btn {
  width: 100%;
  padding: clamp(8px,0.8vh,14px);
  background: linear-gradient(135deg, var(--gold-dim), #5a4920);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: clamp(11px,0.85vw,15px);
  letter-spacing: 3px; text-transform: uppercase;
  cursor: pointer; border-radius: 3px;
  transition: all 0.2s;
  margin-bottom: clamp(6px,0.7vh,12px);
}
.solve-btn:hover { background: linear-gradient(135deg, #8a6d30, #7a5d25); box-shadow: 0 0 12px rgba(200,168,75,0.3); }
.solve-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.solve-btn.running { animation: pulse-gold 0.8s ease-in-out infinite; }

@keyframes pulse-gold {
  0%,100% { box-shadow: 0 0 4px rgba(200,168,75,0.3); }
  50%      { box-shadow: 0 0 16px rgba(200,168,75,0.6); }
}

.clear-btn {
  width: 100%;
  padding: clamp(5px,0.5vh,8px);
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); font-family: var(--font-mono);
  font-size: clamp(9px,0.65vw,12px); letter-spacing: 1px;
  text-transform: uppercase; cursor: pointer; border-radius: 3px;
  transition: all 0.15s;
  margin-bottom: clamp(8px,0.8vh,14px);
}
.clear-btn:hover { border-color: var(--red); color: var(--red); }

/* Grid-preset toggle — clear-btn geometry, but a gold active state instead of a
   destructive red hover. Must follow .clear-btn:hover to win on source order. */
.preset-btn:hover  { border-color: var(--gold-dim); color: var(--text); }
.preset-btn.active { border-color: var(--gold); color: var(--gold); background: rgba(200,168,75,0.1); }

.results-section { display: flex; flex-direction: column; gap: clamp(5px,0.5vh,9px); }

.result-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 4px; padding: clamp(7px,0.7vh,12px);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.result-card:hover { border-color: var(--gold-dim); background: var(--bg3); }
.result-card.applied { border-color: var(--gold); background: rgba(200,168,75,0.06); }

.result-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: clamp(5px,0.5vh,8px);
}
.result-title { font-size: clamp(9px,0.65vw,12px); color: var(--text-dim); letter-spacing: 1px; text-transform: uppercase; }
.result-score { font-size: clamp(14px,1.1vw,20px); color: var(--gold); font-weight: bold; }

.result-meta {
  font-size: clamp(8px,0.6vw,11px);
  color: var(--text-dim);
  margin-bottom: clamp(4px,0.4vh,7px);
  letter-spacing: 0.5px;
}

.result-dist {
  font-size: clamp(8px,0.6vw,11px);
  color: var(--text-dim); line-height: 1.8;
}
.result-dist .d-entry { display: flex; justify-content: space-between; }
.result-dist .d-val { color: var(--text); }

.apply-btn {
  margin-top: clamp(5px,0.5vh,8px);
  width: 100%;
  padding: clamp(4px,0.4vh,7px);
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text-dim); font-family: var(--font-mono);
  font-size: clamp(9px,0.65vw,11px); letter-spacing: 1px;
  cursor: pointer; border-radius: 2px; text-transform: uppercase;
  transition: all 0.15s;
}
.apply-btn:hover { border-color: var(--gold); color: var(--gold); }

.no-results {
  text-align: center; color: var(--text-dim);
  font-size: clamp(9px,0.65vw,12px);
  padding: clamp(14px,2vh,28px) 0; line-height: 2;
}

/* Stats bar */
.stats-bar {
  display: flex; gap: clamp(8px,0.8vw,14px); flex-wrap: wrap;
  padding: clamp(5px,0.55vh,9px) clamp(8px,0.8vw,14px);
  background: var(--bg1); border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.stat { font-size: clamp(9px,0.65vw,12px); color: var(--text-dim); }
.stat b { color: var(--gold-dim); }
.stat span { color: var(--text); }

/* Active tablet bar */
.active-tablet-bar {
  padding: clamp(6px,0.6vh,10px) clamp(10px,1vw,16px);
  border-top: 1px solid var(--border);
  background: var(--bg1);
  display: flex; align-items: center;
  gap: clamp(6px,0.7vw,12px);
  flex-shrink: 0;
  min-height: clamp(42px,4vh,64px);
}
.atb-sprite {
  width: clamp(28px,2.4vw,44px);
  height: clamp(28px,2.4vw,44px);
  border: 1px solid var(--gold-dim); border-radius: 2px;
  overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2);
}
.atb-sprite img { width: 100%; height: 100%; image-rendering: pixelated; }
.atb-info { flex: 1; }
.atb-name { font-size: clamp(10px,0.8vw,14px); color: var(--text-bright); }
.atb-hint { font-size: clamp(8px,0.6vw,11px); color: var(--text-dim); margin-top: 2px; }
.atb-none { font-size: clamp(9px,0.7vw,12px); color: var(--text-dim); }
.atb-rot {
  font-size: clamp(10px,0.75vw,13px);
  color: var(--gold-dim);
  padding: clamp(2px,0.25vh,4px) clamp(6px,0.6vw,10px);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 3px; cursor: pointer;
  transition: border-color 0.1s; flex-shrink: 0;
}
.atb-rot:hover { border-color: var(--gold); color: var(--gold); }
.atb-rot.disabled { opacity: 0.3; cursor: default; }
.atb-rot.disabled:hover { border-color: var(--border); color: var(--text-dim); }

.solver-log {
  font-size: clamp(9px,0.65vw,11px);
  color: var(--text-dim); text-align: center;
  margin-bottom: clamp(5px,0.5vh,9px); min-height: 14px;
}
.solver-log.ok  { color: var(--green); }
.solver-log.err { color: var(--red); }

/* Tooltip */
.tooltip {
  position: fixed;
  background: var(--bg3); border: 1px solid var(--gold-dim);
  border-radius: 4px; padding: clamp(6px,0.6vw,10px) clamp(8px,0.8vw,12px);
  font-size: clamp(10px,0.7vw,13px);
  color: var(--text); pointer-events: none;
  z-index: 1000; max-width: clamp(150px,13vw,220px);
  line-height: 1.7; display: none;
}
.tooltip.visible { display: block; }
.tooltip b { color: var(--gold); font-size: clamp(10px,0.75vw,14px); display: block; margin-bottom: 3px; }

/* Loading overlay */
#loading-overlay {
  position: fixed; inset: 0;
  background: var(--bg0);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; z-index: 9999;
}
#loading-overlay h2 {
  font-family: var(--font-display);
  color: var(--gold); font-size: clamp(18px,1.8vw,30px);
  letter-spacing: 4px;
}
#loading-overlay p { color: var(--text-dim); font-size: clamp(11px,0.8vw,14px); }
#loading-overlay .err { color: var(--red); max-width: 420px; text-align: center; line-height: 1.7; }
