/* CoopTD Board Planner — forest-night companion theme */

:root {
  --night: #101a14;
  --night-2: #16241b;
  --panel: #1c2b21;
  --panel-edge: #35503d;
  --ink: #e8e6d8;
  --ink-dim: #a8b3a0;
  --amber: #ffb454;
  --amber-deep: #d98324;
  --leaf: #7fc46a;
  --leaf-deep: #3f7a54;
  --danger: #e06c55;
  --r-supreme: #ffcf5e;
  --r-demon: #e08fff;
  --r-legendary: #ff9d5c;
  --r-epic: #b48bff;
  --r-rare: #6fb9ff;
  --r-common: #9aa89b;
  --shadow: 0 8px 24px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 15px/1.5 "Nunito", sans-serif;
  background:
    radial-gradient(1200px 500px at 70% -10%, rgba(127, 196, 106, .10), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(255, 180, 84, .07), transparent 55%),
    linear-gradient(180deg, #142019 0%, var(--night) 55%, #0b120d 100%);
  background-attachment: fixed;
}

/* soft grain */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

h1, h2, .board-name, .stage-chip, button.primary {
  font-family: "Lilita One", "Nunito", sans-serif;
  font-weight: 400;
  letter-spacing: .02em;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 14px 22px 10px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-sprite {
  width: 44px; height: 44px;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.5));
  transform: rotate(-6deg);
}
h1 {
  margin: 0; font-size: 26px; color: var(--amber);
  text-shadow: 0 2px 0 rgba(0,0,0,.55);
}
h1 span { color: var(--ink); }

/* ---------- layout ---------- */
/* 1fr | board | 1fr keeps the board dead-center in the viewport;
   the side panel lives in the right 1fr and never pushes the board. */
main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 20px; align-items: start;
  padding: 6px 22px 30px;
}
#board-wrap {
  grid-column: 2;
  position: relative; /* anchors the quick-find overlay */
  width: min-content; /* caps the deployed chips at board width */
}
#side {
  grid-column: 3; justify-self: start;
  width: min(100%, 460px);
  display: flex; flex-direction: column; gap: 16px;
}

/* ---------- board ---------- */
.board-title {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 4px 6px;
}
.board-name { font-size: 18px; color: var(--leaf); text-shadow: 0 2px 0 rgba(0,0,0,.5); }
.slot-count { color: var(--ink-dim); font-weight: 700; font-size: 13px; }

#board {
  position: relative;
  box-sizing: content-box; /* JS sizes the content box; border-box would shrink the image under the slot grid */
  border: 3px solid var(--panel-edge);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow), inset 0 0 40px rgba(0,0,0,.25);
  background: #2a2419;
  user-select: none;
}
#boardImg { display: block; width: 100%; height: 100%; }

#slots { position: absolute; inset: 0; }

.slot {
  position: absolute;
  border-radius: 6px;
  cursor: pointer;
  transition: box-shadow .12s ease, background-color .12s ease;
}
.slot:hover { box-shadow: inset 0 0 0 2px rgba(255, 214, 130, .9); }
.slot.invite { animation: invite 1.4s ease-in-out infinite; }
@keyframes invite {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 214, 130, .0); }
  50% { box-shadow: inset 0 0 0 2px rgba(255, 214, 130, .55); }
}

.slot img {
  position: absolute;
  left: 50%; bottom: -4%;
  width: 118%;
  transform: translateX(-50%);
  pointer-events: none;
  filter: drop-shadow(0 3px 2px rgba(0,0,0,.35));
  animation: drop-in .28s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes drop-in {
  from { transform: translateX(-50%) translateY(-10px) scale(.6); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

/* placement preview: the pending unit ghosts onto the hovered slot */
.slot img.ghost {
  opacity: .6;
  filter: drop-shadow(0 3px 2px rgba(0,0,0,.35)) saturate(.8);
  animation: ghost-in .16s ease-out;
}
@keyframes ghost-in {
  from { transform: translateX(-50%) translateY(-8px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0); opacity: .6; }
}

#rangeBox {
  position: absolute;
  pointer-events: none;
  border: 2px solid rgba(120, 210, 255, .85);
  background: rgba(120, 210, 255, .16);
  border-radius: 8px;
  z-index: 40;
}

/* ---------- quick find (type to place) ---------- */
#quickFind {
  position: absolute;
  left: 50%; top: 46px;
  transform: translateX(-50%);
  z-index: 80;
  width: max-content; max-width: 100%;
  background: linear-gradient(180deg, var(--panel), #182619);
  border: 3px solid var(--amber-deep);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  text-align: center;
}
.qf-query {
  font-family: "Lilita One", "Nunito", sans-serif;
  font-size: 19px; color: var(--amber);
  letter-spacing: .04em;
  min-height: 26px; margin-bottom: 8px;
}
.qf-caret {
  display: inline-block;
  width: 2px; height: 17px;
  margin-left: 3px; vertical-align: -2px;
  background: var(--amber);
  animation: qf-blink 1s steps(2) infinite;
}
@keyframes qf-blink { 50% { opacity: 0; } }
.qf-results { display: flex; gap: 8px; justify-content: center; }
.qf-item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 80px; padding: 9px 4px 6px;
  background: var(--night-2);
  border: 2px solid var(--panel-edge);
  border-radius: 10px;
  cursor: pointer;
}
.qf-item img { width: 46px; height: 46px; pointer-events: none; }
.qf-item .qf-name {
  font: 700 11px "Nunito", sans-serif; color: var(--ink);
  max-width: 72px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.qf-item.on {
  border-color: var(--amber);
  box-shadow: 0 0 12px rgba(255, 180, 84, .4);
}
.qf-key {
  position: absolute; top: 2px; left: 5px;
  font-size: 10px; font-weight: 800; color: var(--ink-dim);
}
.qf-empty { color: var(--ink-dim); font-style: italic; padding: 6px 14px; font-size: 13px; }
.qf-hint { margin-top: 8px; font-size: 11px; font-weight: 700; color: var(--ink-dim); }

/* ---------- deployed chips ---------- */
.deployed {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 2px 0;
  min-height: 46px;
}
.chip {
  display: flex; align-items: center; gap: 4px;
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 999px;
  padding: 2px 10px 2px 4px;
  font-weight: 800; font-size: 14px;
}
.chip img { width: 30px; height: 30px; }
.chip .n { color: var(--amber); }

.help { color: var(--ink-dim); font-size: 12.5px; max-width: 520px; margin: 8px 4px; }

/* ---------- panels ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel), #182619);
  border: 3px solid var(--panel-edge);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
}
.panel h2 {
  margin: 0 0 10px; font-size: 17px; color: var(--amber);
  text-shadow: 0 2px 0 rgba(0,0,0,.5);
}

/* ---------- presets ---------- */
.preset-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
#presetSelect {
  flex: 1;
  background: var(--night-2);
  color: var(--ink);
  border: 2px solid var(--panel-edge);
  border-radius: 8px;
  padding: 7px 8px;
  font: 700 14px "Nunito", sans-serif;
}
.stage-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.stage-chip {
  background: var(--night-2);
  border: 2px solid var(--panel-edge);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: transform .1s ease, border-color .1s ease, color .1s ease;
}
.stage-chip:hover { transform: translateY(-1px); border-color: var(--amber-deep); }
.stage-chip.on {
  border-color: var(--amber);
  color: var(--amber);
  box-shadow: 0 0 10px rgba(255, 180, 84, .25);
}
.preset-note { color: var(--ink-dim); font-size: 12.5px; font-style: italic; margin: 4px 0 8px; }

/* ---------- palette ---------- */
.tools-row { display: flex; gap: 8px; margin-bottom: 10px; }
#unitSearch {
  flex: 1;
  background: var(--night-2);
  border: 2px solid var(--panel-edge);
  border-radius: 8px;
  color: var(--ink);
  padding: 7px 10px;
  font: 600 14px "Nunito", sans-serif;
}
#unitSearch::placeholder { color: #6d7a6c; }

.rarity-h {
  font: 400 13px "Lilita One", sans-serif;
  letter-spacing: .05em;
  margin: 10px 0 6px;
  padding-left: 2px;
}
.rarity-Supreme  { color: var(--r-supreme); }
.rarity-Demon    { color: var(--r-demon); }
.rarity-Legendary{ color: var(--r-legendary); }
.rarity-Epic     { color: var(--r-epic); }
.rarity-Rare     { color: var(--r-rare); }
.rarity-Common   { color: var(--r-common); }

.unit-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.unit-btn {
  width: 66px; height: 66px;
  padding: 3px;
  background: var(--night-2);
  border: 2px solid var(--panel-edge);
  border-radius: 10px;
  cursor: pointer;
  transition: transform .1s ease, border-color .1s ease, box-shadow .1s ease;
  position: relative;
}
.unit-btn img { width: 100%; height: 100%; pointer-events: none; }
.unit-btn:hover { transform: translateY(-2px) scale(1.05); border-color: var(--amber-deep); }
.unit-btn.on {
  border-color: var(--amber);
  box-shadow: 0 0 12px rgba(255, 180, 84, .4);
  transform: scale(1.05);
}

/* ---------- buttons ---------- */
button {
  font: 800 13.5px "Nunito", sans-serif;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 9px;
  padding: 7px 13px;
  cursor: pointer;
  transition: transform .1s ease, border-color .1s ease, background-color .1s ease;
}
button:hover { transform: translateY(-1px); border-color: var(--amber-deep); }
button:active { transform: translateY(0); }
button.primary {
  background: linear-gradient(180deg, var(--leaf-deep), #2e5d3f);
  border-color: var(--leaf);
  font-size: 14.5px;
}
button.danger:hover { border-color: var(--danger); color: var(--danger); }
.icon-btn { padding: 6px 10px; }
.icon-btn.on { border-color: var(--amber); box-shadow: 0 0 10px rgba(255,180,84,.35); }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%; top: 132px;
  transform: translateX(-50%);
  background: #253c2b;
  border: 2px solid var(--leaf);
  color: var(--ink);
  font-weight: 800;
  border-radius: 999px;
  padding: 9px 20px;
  box-shadow: var(--shadow);
  z-index: 100;
  animation: toast-in .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes toast-in {
  from { transform: translateX(-50%) translateY(-14px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

@media (max-width: 1000px) {
  main {
    display: flex; flex-direction: column; align-items: center;
    padding: 6px 12px 24px;
  }
  #side { width: 100%; max-width: 560px; }
}
