* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 0;
  font-family: 'Consolas', monospace;
  background: #0a0a0a;
  color: white;
  overflow: hidden;
}
canvas#bg {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: -1;
}

/* Header */
header {
  text-align: center;
  padding: 30px 0;
  position: relative;
}
.page-title {
  font-size: 2.4rem;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 0 20px rgba(255,255,255,0.1);
  transition: all 0.3s ease;
}
.page-title:hover {
  text-shadow: 0 0 25px rgba(255,255,255,0.4);
}
.back-btn {
  color: #ccc;
  background: transparent;
  border: none;
  font-size: 16px;
  padding: 8px 16px;
  cursor: pointer;
  transition: 0.3s;
}

.back-btn:hover {
  color: #fff;
  border-bottom: 2px solid #fff;
}


/* Trade layout */
.trade-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 100px;
  margin-top: 40px;
}
.trade-side {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.side-label {
  font-weight: bold;
  margin-bottom: 10px;
  opacity: 0.6;
}
.trade-grid {
  display: grid;
  grid-template-columns: repeat(3, 130px);
  grid-template-rows: repeat(3, 130px);
  gap: 12px;
  background: rgba(255,255,255,0.03);
  padding: 12px;
  border-radius: 14px;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 20px rgba(255,255,255,0.05);
}
.trade-box {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  color: rgba(255,255,255,0.9);
  font-size: 0.9rem;
  cursor: pointer;
  transition: 0.2s;
  flex-direction: column;
}
.trade-box:hover {
  background: rgba(255,255,255,0.15);
  text-shadow: 0 0 8px white;
}
.dino-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.dino-name { font-weight: bold; font-size: 0.95rem; }
.dino-details { font-size: 0.8rem; opacity: 0.75; margin-top: 3px; }
.empty-text { opacity: 0.4; }

input[type="number"] {
  margin-top: 15px;
  padding: 10px 14px;
  width: 230px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: white;
  font-family: inherit;
  text-align: center;
}
input[type="number"]::placeholder { color: rgba(255,255,255,0.4); }

.avg-demand {
  font-size: 0.85rem;
  opacity: 0.6;
  margin-top: 8px;
}

/* Center difference */
.trade-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 260px;
  text-align: center;
}
#difference-text {
  font-size: 1.3rem;
  font-weight: bold;
  text-shadow: 0 0 15px rgba(255,255,255,0.15);
}
#comment-text {
  font-size: 0.85rem;
  margin-top: 6px;
  color: #888;
}

/* Popup */
.popup-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 20;
}
.popup-overlay.active {
  opacity: 1;
  pointer-events: all;
}
.popup {
  width: 80%;
  max-width: 700px;
  padding: 25px;
  border-radius: 14px;
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: 0 0 30px rgba(255,255,255,0.05);
  color: white;
  display: flex;
  flex-direction: column;
  animation: fadeUp 0.3s ease;
}
@keyframes fadeUp {
  from { transform: translateY(15px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
#search {
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: white;
  margin-bottom: 15px;
}
#search::placeholder { color: rgba(255,255,255,0.5); }

#dinoList {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}
.dino-item {
  padding: 10px;
  background: rgba(255,255,255,0.07);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  transition: 0.2s;
}
.dino-item:hover {
  background: rgba(255,255,255,0.15);
}
#closePopup {
  align-self: center;
  margin-top: 15px;
  padding: 8px 16px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.3s;
}
#closePopup:hover {
  background: rgba(255,255,255,0.2);
}
.selection-panel::-webkit-scrollbar {
  width: 10px;
}

.selection-panel::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
}

.selection-panel::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(255,255,255,0.2), rgba(180,180,255,0.3));
  border-radius: 10px;
  backdrop-filter: blur(10px);
}

.selection-panel::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(255,255,255,0.4), rgba(200,200,255,0.5));
}
.side-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0 5px;
  padding: 0 10px;
}

.side-header h3 {
  font-size: 1.1em;
  color: white;
  text-shadow: 0 0 4px rgba(255,255,255,0.4);
}

.reset-side {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  color: #ddd;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85em;
  transition: 0.2s;
}

.reset-side:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  text-decoration: underline;
}

/* Middle controls between both sides */
.calculator-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin: 20px auto;
}

.calculator-controls button {
  background: rgba(255, 255, 255, 0.07);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 6px 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9em;
  backdrop-filter: blur(8px);
}

.calculator-controls button:hover {
  background: rgba(255, 255, 255, 0.15);
  text-decoration: underline;
}

/* Container grid so columns never collapse into corners */
.trade-container {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 320px minmax(260px, 1fr);
  gap: 28px;
  align-items: start;
  width: 95%;
  max-width: 1200px;
  margin: 34px auto 60px;
}

/* each column */
.trade-side {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  position: relative;
}

/* Side header (title + reset) placed above grid */
.side-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  margin-bottom: 6px;
  pointer-events: auto;
}
.side-header h3 {
  margin: 0;
  font-size: 1.0rem;
  color: rgba(255,255,255,0.95);
  letter-spacing: 0.4px;
}
.reset-side {
  background: rgba(255,255,255,0.04);
  border: none;
  color: rgba(255,255,255,0.9);
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.18s;
  font-size: 0.85rem;
  backdrop-filter: blur(6px);
}
.reset-side:hover {
  background: rgba(255,255,255,0.14);
  color: #fff;
  box-shadow: 0 6px 18px rgba(255,255,255,0.04);
  transform: translateY(-1px);
}

/* Offer box / grid area (where items are appended) */
.offer-box {
  min-height: 420px;           /* big enough to show 3x3 grid or stacked items */
  background: rgba(255,255,255,0.03);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 120px;
  gap: 12px;
  align-items: stretch;
  justify-items: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 0 30px rgba(255,255,255,0.03);
}

/* Each offer item inside the box (or "Empty" placeholders) */
.offer-item, .trade-box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.95);
  font-size: 0.95rem;
  padding: 8px;
  position: relative;
}
.trade-box.empty {
  opacity: 0.45;
}

/* small X remove button top-right of each added item */
.offer-item .remove-item {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}
.offer-item .remove-item:hover {
  color: #fff;
  transform: scale(1.06);
}

/* center column styling */
.trade-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
#difference-text {
  font-size: 1.2rem;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: 12px;
  min-width: 240px;
  background: rgba(255,255,255,0.03);
  backdrop-filter: blur(8px);
  box-shadow: 0 0 18px rgba(255,255,255,0.03);
}

/* controls centered between the columns */
.controls-wrapper {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}
.controls-wrapper button {
  background: rgba(255,255,255,0.06);
  border: none;
  color: white;
  padding: 8px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  backdrop-filter: blur(8px);
  transition: 0.18s;
}
.controls-wrapper button:hover {
  background: rgba(255,255,255,0.16);
  transform: translateY(-2px);
}

/* input and avg-demand under offer boxes */
input[type="number"] {
  margin-top: 8px;
  padding: 10px 12px;
  width: 100%;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  border: none;
  color: white;
  text-align: center;
}
.avg-demand { text-align: center; opacity: 0.66; margin-top: 6px; }

/* Back button (top-right) matching main site button style */
.back-btn {
  position: absolute;
  top: 22px;
  right: 28px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  font-weight: 700;
  padding: 8px 12px;
  cursor: pointer;
  transition: color 0.25s ease;
}
.back-btn::after {
  content: "";
  display: block;
  height: 2px;
  width: 0%;
  background: white;
  margin-top: 6px;
  transition: width 0.25s ease;
}
.back-btn:hover {
  color: white;
}
.back-btn:hover::after {
  width: 100%;
}

/* small responsive adjustments */
@media (max-width: 980px) {
  .trade-container {
    grid-template-columns: 1fr;
  }
  .trade-center { order: 2; margin: 18px 0; }
  .controls-wrapper { justify-content: center; }
}

