/* UI skin: Crusenho "Complete GUI Essential Pack" (Flat theme), 9-sliced with border-image. */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #121218;
  color: #eee;
  font-family: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 500;
  font-size: 15px;
  user-select: none;
}

canvas { display: block; }
button, input { font-family: inherit; }
/* Titles, banners and buttons: the same face, heavier. */
.title, .banner, .btn, .legend-badge { font-weight: 800; letter-spacing: 0.5px; }

#ui { position: fixed; inset: 0; pointer-events: none; }
#ui.active { pointer-events: auto; }

.screen {
  position: absolute;
  inset: 0;
  padding: 24px;
  overflow-y: auto;
  background: radial-gradient(ellipse at center, #1d1820 0%, #0e0c10 75%);
}
.screen.dim { background: rgba(10, 8, 12, 0.82); }
.screen.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center; /* tall screens scroll instead of clipping the top */
  gap: 20px;
  text-align: center;
}

h1, h2, h3 { margin: 0; font-weight: 700; }
h3 { font-size: 17px; margin-bottom: 6px; }
.title { font-size: 60px; letter-spacing: 8px; color: #ffe2b0; text-shadow: 0 4px 0 #6b2a12, 0 8px 0 #1a0a06; }
.hint, .muted { color: #9a93a8; }
.small { font-size: 12px; }
.pos { color: #7ef08a; }
.neg { color: #ff7070; }

.row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; align-items: center; }
.row.top { align-items: flex-start; }

/* ---------- banners (screen titles) ---------- */
.banner {
  display: inline-block;
  padding: 2px 26px 4px;
  color: #3b2414;
  font-size: 26px;
  border-style: solid;
  border-width: 6px 6px 10px 10px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Banner03a.png") 3 3 5 5 fill / 6px 6px 10px 10px;
  image-rendering: pixelated;
}
.banner .muted { color: #8a6a4a; font-size: 18px; }

/* ---------- buttons ---------- */
.btn {
  position: relative;
  color: #3b2414;
  background: none;
  padding: 0 16px;
  min-height: 44px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  border-style: solid;
  border-width: 8px 8px 18px 8px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Button01a_3.png") 4 4 9 4 fill / 8px 8px 18px 8px;
  image-rendering: pixelated;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-image-source: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Button01a_4.png"); }
.btn:active:not(:disabled) {
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Button01a_1.png") 8 4 5 4 fill / 16px 8px 10px 8px;
}
.btn:disabled { filter: grayscale(1) brightness(0.65); cursor: default; }
.btn.big { font-size: 22px; padding: 0 30px; min-height: 58px; }
/* Primary action: the orange frame. */
.btn.go {
  color: #fff;
  text-shadow: 0 2px 0 #8a3a00;
  border-width: 6px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Frame03a.png") 3 fill / 6px;
}
.btn.go:hover:not(:disabled) { border-image-source: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Frame03a.png"); filter: brightness(1.12); }
.btn.go:active:not(:disabled) { border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Frame03a.png") 3 fill / 6px; transform: translateY(2px); }
.btn.lock { padding: 0 10px; font-size: 13px; }
.btn.mini-btn { padding: 0 10px; font-size: 13px; min-height: 36px; }

/* ---------- panels, cards, slots ---------- */
.panel, .card, .slot, .chip {
  border-style: solid;
  image-rendering: pixelated;
  background: none;
}
.panel {
  padding: 14px;
  text-align: left;
  border-width: 9px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_FrameSlot02c.png") 3 fill / 9px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.panel h3 { margin-top: 2px; color: #ffe2b0; }
.stats { min-width: 230px; }
.stat-row { display: flex; justify-content: space-between; gap: 20px; font-size: 14px; padding: 1px 0; }

.card {
  position: relative;
  width: 214px;
  min-height: 200px;
  color: #eee;
  padding: 12px 10px 10px;
  text-align: left;
  font-size: 14px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  font-family: inherit;
  border-width: 9px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_FrameSlot02c.png") 3 fill / 9px;
}
/* Rarity stripe across the top; color comes from the inline --tier variable. */
.card::before, .slot::before {
  content: '';
  position: absolute;
  left: -3px; right: -3px; top: -6px;
  height: 4px;
  background: var(--tier, transparent);
  box-shadow: 0 0 8px var(--tier, transparent);
}
/* Selection brackets on hover. */
button.card { cursor: pointer; }
button.card::after, .card.offer::after {
  content: '';
  position: absolute;
  inset: -16px;
  border: 24px solid transparent;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Select01a_1.png") 12 / 24px;
  image-rendering: pixelated;
  opacity: 0;
  transition: opacity 0.1s, inset 0.1s;
  pointer-events: none;
}
button.card:hover::after, .card.offer:hover::after { opacity: 1; inset: -12px; }
.card.sold { align-items: center; justify-content: center; color: #6a6478; }
.card .spacer { flex: 1; }
.card .btn { margin-top: 10px; }
.card.short { min-height: 0; }
.card.locked { outline: 3px solid #ffd23f; outline-offset: 3px; }

.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.card-actions { display: flex; gap: 6px; }
.card-actions .btn:first-child { flex: 1; }
/* Card buttons are narrow: use the compact body face. */
.card .btn { font-size: 15px; padding: 0 8px; min-width: 0; }

/* Legendary weapons: warm glow and a badge. */
.card.legendary, .slot.legendary { animation: legend-glow 1.6s ease-in-out infinite alternate; }
.card.legendary { border-image-source: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_FrameSlot03c.png"); }
@keyframes legend-glow {
  from { box-shadow: 0 0 6px 1px rgba(255, 190, 60, 0.35); }
  to   { box-shadow: 0 0 22px 5px rgba(255, 190, 60, 0.75); }
}
.legend-badge {
  position: absolute;
  top: -20px;
  right: 6px;
  z-index: 1;
  padding: 0 8px;
  color: #3b2414;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-style: solid;
  border-width: 4px 4px 6px 6px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Banner03a.png") 3 3 5 5 fill / 4px 4px 6px 6px;
  image-rendering: pixelated;
}

.bonus { color: #ffd23f; font-size: 13px; }
.cond { color: #9fd3ff; font-size: 12px; margin-top: 4px; }
.panel.stats > .pos, .panel.stats > .neg { font-size: 14px; }
.effect { color: #ffcf7a; font-size: 13px; margin-top: 2px; }

.icon {
  display: inline-block;
  flex-shrink: 0;
  background-image: url("assets/Set/64x64.png");
  background-repeat: no-repeat;
  image-rendering: pixelated;
}
.icon-box { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.portrait { background-color: rgba(0, 0, 0, 0.35); }
.heroes { max-width: 1260px; }
.card.hero { width: 224px; min-height: 0; }

/* Hover tooltip for owned weapons and items. */
.card.tooltip {
  position: fixed; z-index: 50; width: 270px; min-height: 0; pointer-events: none; display: none;
  background: #161927; /* the frame is see-through; the tooltip floats over other UI */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
}
[data-tip] { cursor: help; }

/* "?" random pick cards. */
.random-icon {
  width: 64px; height: 64px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 800; color: #ffd23f;
  background: rgba(0, 0, 0, 0.35);
}
.card.random { justify-content: center; }

/* ---------- weapon slots & item chips ---------- */
.slots { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 10px; }
.slot {
  position: relative;
  min-height: 70px;
  padding: 4px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-width: 9px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_FrameSlot01c.png") 3 fill / 9px;
}
.slot-head { display: flex; align-items: center; gap: 4px; }
.wave-dmg { color: #ffb36b; font-weight: 700; }
.slot.empty { opacity: 0.35; }
.mini {
  color: #3b2414;
  background: none;
  font-size: 11px;
  font-weight: 700;
  padding: 0 2px;
  cursor: pointer;
  border-style: solid;
  border-width: 4px 4px 8px 4px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Button01a_3.png") 4 4 9 4 fill / 4px 4px 8px 4px;
  image-rendering: pixelated;
}
.mini:hover:not(:disabled) { border-image-source: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Button01a_4.png"); }
.mini:disabled { filter: grayscale(1) brightness(0.6); cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  position: relative;
  display: inline-flex;
  padding: 1px;
  border-width: 6px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_FrameSlot01c.png") 3 fill / 6px;
  box-shadow: inset 0 -3px 0 var(--tier, transparent);
}
.chip .count {
  position: absolute;
  right: 0;
  bottom: -4px;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}

/* ---------- shop ---------- */
/* Full-screen grid: header and offers on the left, stats + Go on the right, inventory along the bottom. */
.screen.shop {
  background: linear-gradient(180deg, rgba(14, 10, 20, 0.92), rgba(10, 8, 14, 0.96));
  padding: 22px 28px;
}
.shop-layout {
  max-width: 1560px;
  min-height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: auto auto auto;
  grid-template-areas: "head head" "offers side" "inventory side";
  align-content: center;
  gap: 18px 22px;
}
/* Big screens: scale the whole shop up rather than leaving it small. */
@media (min-width: 1700px) and (min-height: 1000px) { .shop-layout { zoom: 1.08; } }
.shop-head { grid-area: head; display: flex; justify-content: space-between; align-items: center; }
.shop-wallet { display: flex; align-items: center; gap: 18px; }
.bag { color: #5fe0a8; font-size: 15px; font-weight: 700; opacity: 0.85; cursor: help; }
.crystals { font-size: 32px; font-weight: 800; color: #5fe0a8; text-shadow: 0 3px 0 #0b3a28; }

.shop-offers {
  grid-area: offers;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 22px;
  padding-top: 14px; /* room for legendary badges */
}
.shop-offers .card { width: auto; min-height: clamp(330px, 40vh, 440px); font-size: 15px; line-height: 1.5; padding: 16px 14px 12px; }
.shop-offers .card-head { gap: 14px; margin-bottom: 12px; }
.shop-offers .card-head h3 { font-size: 20px; }
.shop-offers .card .btn { min-height: 48px; font-size: 16px; }
.card.sold { opacity: 0.45; }
.card.sold span { font-size: 22px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; }

.shop-inventory { grid-area: inventory; display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 22px; }
.shop-inventory .slots { grid-template-columns: repeat(3, 1fr); margin-bottom: 0; }
.shop-inventory .slot { min-height: 0; font-size: 14px; }
.shop-inventory .slot.empty { min-height: 104px; } /* same height as a filled slot */
.slot-actions { display: flex; gap: 4px; margin-top: 2px; }
.slot-actions .mini { flex: 1; }
.shop-inventory .chips { max-height: 220px; overflow-y: auto; align-content: flex-start; }

.shop-side { grid-area: side; display: flex; flex-direction: column; gap: 18px; padding-top: 14px; }
.shop-side .stats { flex: 1; }
.shop-side .stat-row { font-size: 15px; padding: 2px 0; }
.shop-side .btn.go { width: 100%; min-height: 84px; font-size: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.go-sub { font-size: 13px; font-weight: 600; opacity: 0.9; }

/* Narrow windows: stack the stats under everything else. */
@media (max-width: 1100px) {
  .shop-layout { grid-template-columns: 1fr; grid-template-areas: "head" "offers" "inventory" "side"; }
  .shop-offers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- sound panel & sliders ---------- */
.sound { display: flex; gap: 18px; align-items: center; }
.volume { display: flex; gap: 10px; align-items: center; font-size: 15px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 140px; height: 22px; background: none; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track {
  height: 20px;
  border-style: solid;
  border-width: 6px 6px 8px 6px;
  border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Bar05a.png") 3 3 4 3 fill / 6px 6px 8px 6px;
  image-rendering: pixelated;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 20px;
  margin-top: -6px;
  background: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_Handle03a.png") center / 16px 20px no-repeat;
  image-rendering: pixelated;
}

/* ---------- profile: name, completion, achievements, toasts ---------- */
.greeting { font-size: 18px; }
.name-input {
  width: 320px; padding: 12px 16px; font: inherit; font-size: 22px; font-weight: 700; text-align: center;
  color: #ffe2b0; background: #161927; border: 3px solid #3a3550; outline: none;
}
.name-input:focus { border-color: #ffd23f; }

/* Hero / weapon already beaten on the final wave. */
.card.completed { outline: 3px solid #ffd23f; outline-offset: 3px; }
.done-badge {
  position: absolute; top: -20px; left: 6px; z-index: 1; padding: 0 8px;
  color: #2a1a00; font-size: 11px; font-weight: 800; text-transform: uppercase;
  background: linear-gradient(90deg, #ffcf4a, #ff9a2a); border: 2px solid #1a0a00;
}

.achievements {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px; width: min(1200px, 100%); text-align: left;
}
.achievement {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; opacity: 0.45; filter: grayscale(1);
  border: 9px solid; border-image: url("assets/ui/01_Flat_Theme/Sprites/UI_Flat_FrameSlot02c.png") 3 fill / 9px;
  image-rendering: pixelated;
}
.achievement.done { opacity: 1; filter: none; }
.ach-text { flex: 1; }
.ach-points { font-size: 20px; font-weight: 800; color: #ffd23f; }

#toasts { position: fixed; top: 14px; right: 14px; z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; min-width: 260px;
  background: #161927; color: #eee; border: 2px solid #ffd23f; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  transition: opacity 0.5s, transform 0.5s;
}
.toast.out { opacity: 0; transform: translateX(30px); }

/* ---------- leaderboards ---------- */
.lb-panel { width: min(980px, 100%); min-height: 200px; }
.lb-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.lb-table th { text-align: left; color: #ffe2b0; font-size: 13px; padding: 6px 10px; border-bottom: 2px solid #3a3550; }
.lb-table td { padding: 6px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.lb-table tr.me td { background: rgba(255, 210, 63, 0.14); color: #ffe2b0; font-weight: 700; }
.lb-rank { color: #9a93a8; width: 40px; }
.lb-table tbody tr:nth-child(1) .lb-rank { color: #ffd23f; font-weight: 800; }
.lb-table tbody tr:nth-child(2) .lb-rank { color: #d8d8d8; font-weight: 800; }
.lb-table tbody tr:nth-child(3) .lb-rank { color: #e0914a; font-weight: 800; }
.lb-weapon { display: inline-flex; align-items: center; gap: 6px; }
.hero-filter { font: inherit; font-size: 15px; padding: 8px 10px; background: #161927; color: #eee; border: 2px solid #3a3550; }
.ach-rarity { color: #9fd3ff; }

.version { position: absolute; top: 12px; right: 16px; font-size: 13px; color: #6f6880; }
