:root {
  --blue: #0064ad;
  --gray: #888;
  --yellow: #ffd300;
  --red: #da0e15;
  --light-bg: #f7f9fb;
  --text: #333;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--light-bg); font-family: 'Segoe UI', Tahoma, sans-serif; color: var(--text); }
.container { display: flex; min-height: 100vh; }
.sidebar {
  width: 200px; background: #fff; border-right: 1px solid #ddd; padding: 20px;
}
.sidebar h2 { font-size: 1.2rem; color: var(--blue); margin-bottom: 12px; }
.stage-btn {
  display: block; width: 100%; margin-bottom: 8px; padding: 10px;
  border: 2px solid; border-radius: 4px; font-size: 1rem;
  text-align: left; cursor: pointer;
}
.stage-btn.locked { background: var(--gray); color: #fff; border-color: var(--gray); }
.stage-btn.unlocked { background: var(--blue); color: #fff; border-color: var(--blue); }
.stage-btn.buyable { background: var(--yellow); color: var(--text); border-color: var(--yellow); }
.main-content { flex: 1; padding: 20px; }
h1 { text-align: center; color: var(--blue); margin-bottom: 20px; }
.card {
  background: #fff; padding: 15px; margin-bottom: 20px;
  border-radius: 6px; box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.btn.upgrade-btn, .btn.brand-btn, .btn.stock-btn, #prestige-btn {
  background: var(--gray);
  color: #fff;
}
.btn.buyable, #prestige-btn.buyable {
  background: var(--yellow) !important;
  color: var(--text) !important;
  border-color: var(--yellow) !important;
}

.stats.card {
  display: flex; justify-content: space-around;
  position: sticky; top: 0; background: #fff; padding: 10px 0; z-index: 10;
  transition: filter 0.18s;
}
.prestige-container { position: relative; }
.prestige-bonuses {
  margin-top: 6px;
  background: #f0f7fc;
  border-left: 4px solid var(--blue);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.95rem;
  display: none;
  position: absolute;
  left: 0;
  z-index: 20;
  min-width: 210px;
}
.prestige-container:hover .prestige-bonuses,
#prestige-btn:focus + #prestige-bonuses {
  display: block;
}
.prestige-bonuses ul {
  margin: 4px 0 0 20px;
  padding: 0;
}
.tooltip {
  position: fixed; pointer-events: none; background: #fff;
  border: 1px solid var(--blue); padding: 8px; border-radius: 4px;
  white-space: normal; max-width: 200px; display: none;
  box-shadow: 0 2px 6px rgba(0,0,0,.1); font-size: .9rem;
}
.btn { padding: 8px 14px; border: none; border-radius: 6px; cursor: pointer; }
.btn.small { padding: 4px 8px; font-size: .8rem; }
.primary { background: var(--blue); color: #fff; width: 100%; }
.toggle-store {
  display: block; margin: 20px auto; background: var(--yellow); color: var(--text);
}
.customers #queue {
  display: flex; flex-wrap: wrap; gap: 16px;
  height: 200px; overflow-y: auto;
  border: 1px dashed #ccc; padding: 8px; border-radius: 4px;
}
.customer { position: relative; width: 48px; height: 56px; }
.customer-dot {
  width: 32px; height: 32px; background: var(--blue);
  border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; margin: 12px auto 0;
}
.brand-want {
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .8rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 48px;
  text-align: center;
}
.countdown {
  position: absolute; top: 44px; left: 50%; transform: translateX(-50%);
  font-size: .8rem; color: var(--red);
}
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column-reverse; gap: 8px;
}
.toast {
  background: var(--yellow); border-left: 4px solid var(--blue);
  padding: 8px; border-radius: 4px;
  animation: slideIn .3s forwards;
}
@keyframes slideIn { from { opacity:0; transform:translateX(20px);} to{opacity:1;transform:translateX(0);} }
.upgrade, .brand {
  display: flex; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid #eee;
}
.upgrade:last-child, .brand:last-child { border-bottom: none; }
.upgrade .cost, .brand .cost { font-weight: bold; }
.inventory, .phone-support, .save-load { margin-top: 20px; }
input[type="file"] { display: none; }
.modal {
  position: fixed; top:0; left:0; width:100%; height:100%;
  background: rgba(0,0,0,.5); display:flex; align-items:center; justify-content:center;
  z-index: 2000;
}
.modal.hidden { display:none; }
#achievement-modal .modal-content {
  background: #fdf6e4;
  padding: 32px 32px 24px 32px;
  border-radius: 18px;
  min-width: 320px;
  max-width: 95vw;
  box-shadow: 0 6px 36px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 3px solid var(--yellow);
  position: relative;
}
#achievement-modal .modal-icon {
  font-size: 4rem;
  margin-bottom: 14px;
  margin-top: -12px;
  filter: drop-shadow(0 2px 6px #ffd30090);
}
#achievement-modal h3 {
  font-size: 1.3rem;
  color: #c09a24;
  font-weight: bold;
  margin-bottom: 10px;
  letter-spacing: 1px;
  text-shadow: 0 2px 12px #fff4;
}
#achievement-modal p {
  color: #75511b;
  font-size: 1.08rem;
  text-align: center;
  margin-bottom: 20px;
}
#achievement-modal .btn {
  margin-top: 5px;
  background: #fffbe8;
  color: #c09a24;
  border: 1.5px solid #ffe373;
  font-weight: bold;
  transition: background .15s;
}
#achievement-modal .btn:hover {
  background: #fff6cc;
}
#all-achievements-modal .modal-content {
  background: #f4f8fb;
  padding: 30px 30px 18px 30px;
  border-radius: 16px;
  min-width: 320px;
  max-width: 98vw;
  box-shadow: 0 6px 36px rgba(0,0,0,0.11);
  border: 3px solid #c0e2ff;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#all-achievements-modal h3 {
  color: var(--blue);
  margin-bottom: 14px;
  font-size: 1.2rem;
  font-weight: bold;
  letter-spacing: 1px;
}
#achieve-list {
  list-style: none;
  margin: 0 0 10px 0;
  padding: 0;
  width: 100%;
  max-width: 350px;
}
#achieve-list li {
  background: #e9f6ff;
  border-left: 5px solid #89c4ff;
  margin-bottom: 10px;
  padding: 10px 18px 10px 12px;
  border-radius: 8px;
  font-size: 1.04rem;
  color: #15608a;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  position: relative;
  box-shadow: 0 1px 3px #b6e0ff24;
  animation: fadeInUp .35s;
}
#achieve-list li::before {
  content: "🏆";
  font-size: 1.35em;
  margin-right: 6px;
  flex-shrink: 0;
  margin-left: 2px;
  filter: drop-shadow(0 2px 5px #cce7ffad);
  position: absolute;
  left: -36px;
  top: 8px;
}
#achieve-list .achieve-name {
  font-weight: bold;
  font-size: 1.08em;
  color: #155685;
  margin-bottom: 2px;
}
#achieve-list .achieve-desc {
  color: #786311;
  font-size: 0.99em;
  opacity: 0.85;
  margin-left: 3px;
}
#achieve-list li:last-child { margin-bottom: 0; }
#all-achievements-modal .btn {
  margin-top: 8px;
  background: #e9f6ff;
  color: var(--blue);
  border: 1.5px solid #b6eaff;
  font-weight: bold;
  transition: background .15s;
}
#all-achievements-modal .btn:hover {
  background: #d6f1ff;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px);}
  to   { opacity: 1; transform: translateY(0);}
}
.modal-content { background:#fff; padding:20px; border-radius:8px; }
.warning.hidden { display:none; }
#crazy-customer, #crowd-warning { margin-top:10px; }
.trophy-icon { position:fixed; bottom:20px; left:20px; font-size:2rem; cursor:pointer; }

body.modal-open::before {
  content: "";
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  pointer-events: all;
}
body.modal-open .stats.card {
  filter: blur(2.5px) grayscale(0.15) brightness(0.95);
  pointer-events: none;
}
.modal { z-index: 2000; }
.tooltip {
  position: fixed;
  pointer-events: none;
  background: #fff;
  border: 2px solid var(--blue);
  padding: 10px 14px;
  border-radius: 8px;
  white-space: normal;
  max-width: 260px;
  box-shadow: 0 2px 14px rgba(0,0,0,.13);
  font-size: 1rem;
  color: var(--blue);
  z-index: 9999;
  display: none;
  font-family: inherit;
  font-weight: 500;
}
.malin-global { margin-bottom: 12px; }
/* Toggle button at the top right */
/* Minimal emoji-only toggle button (top right) */
#scoreboard-toggle {
  position: fixed;
  top: 22px;
  right: 20px;
  z-index: 5001;
  background: none;
  border: none;
  box-shadow: none;
  font-size: 2.3rem;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0;
  transition: right 0.33s;
}

#scoreboard-toggle.open {
  right: 340px; /* Matches panel width when open */
}

/* Slide-out scoreboard panel (right side) */
#scoreboard-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  max-width: 95vw;
  height: 100vh; /* Full window height */
  background: #fff;
  z-index: 5000;
  box-shadow: -4px 0 24px #0002;
  transform: translateX(100%);
  transition: transform 0.33s cubic-bezier(.71,.13,.37,.97);
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

#scoreboard-panel.open {
  transform: translateX(0);
  pointer-events: auto;
}

.scoreboard-content {
  display: flex;
  flex-direction: column;
  height: 100vh;     /* Always fill window vertically */
  min-height: 0;     /* Needed for scrollable flex children */
  padding: 32px 18px 20px 26px;
  position: relative;
  flex: 1 1 auto;
}

/* SCROLLABLE leaderboard area, fills all available space */
#score-list {
  list-style: none;
  padding: 0;
  margin-top: 28px;
  flex: 1 1 auto;    /* Expands to fill available space */
  min-height: 0;
  max-height: unset; /* Let flexbox control height */
  overflow-y: auto;
  border-radius: 10px;
  background: #fafbff;
  box-shadow: 0 2px 6px #0001;
}

#score-list li {
  font-size: 1.09em;
  padding: 7px 0;
  border-bottom: 1px solid #eaeaea;
}

#score-list li:last-child {
  border-bottom: none;
}

#scoreboard-panel h2 {
  text-align: left;
  font-size: 1.5em;
  margin-bottom: 10px;
  color: #154e8e;
}

/* Username change bar: always at the bottom */
#username-change {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  margin-top: 18px;
  margin-bottom: 5px;
  padding-bottom: 8px;
  background: #f7fafd;
  border-radius: 8px;
  box-shadow: 0 1px 2px #0001;
}

#new-username {
  font-size: 1em;
  flex: 1 1 auto;
  min-width: 0;
}

#change-username-btn {
  font-size: 1em;
  white-space: nowrap;
}

/* Mobile friendly tweaks */
@media (max-width: 500px) {
  #scoreboard-panel {
    width: 98vw;
  }
  #scoreboard-toggle.open {
    right: 97vw;
  }
  .scoreboard-content {
    padding-left: 10px;
    padding-right: 10px;
    height: 100vh;
  }
  #username-change {
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
    padding-bottom: 12px;
  }
  #new-username, #change-username-btn {
    width: 100%;
  }
}
.chat-icon {
  position: fixed;
  bottom: 84px; /* above trophy */
  left: 20px;
  font-size: 2rem;
  z-index: 5050;
  cursor: pointer;
  background: #fff;
  border-radius: 50%;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px #0002;
  border: 2px solid #e0e0e0;
  transition: box-shadow 0.15s;
}
.chat-icon:hover {
  box-shadow: 0 4px 24px #0071b355;
}
.chat-badge {
  position: absolute;
  top: 8px;
  right: 7px;
  background: var(--red, #da0e15);
  color: #fff;
  border-radius: 50%;
  font-size: 0.9em;
  font-weight: bold;
  min-width: 20px;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px #0002;
  pointer-events: none;
}
.chat-badge.hidden {
  display: none;
}
.chat-window {
  position: fixed;
  bottom: 140px;
  left: 22px;
  width: 320px;
  max-width: 98vw;
  background: #fafdff;
  border-radius: 16px;
  box-shadow: 0 6px 36px #0064ad22;
  z-index: 5051;
  display: flex;
  flex-direction: column;
  border: 2px solid #b6eaff;
  transition: opacity 0.22s;
}
.chat-window.hidden {
  display: none;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #e6f0fa;
  font-weight: bold;
  color: var(--blue);
  background: #eaf6ff;
  border-radius: 14px 14px 0 0;
}
#chat-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: #888;
}
.chat-messages {
  flex: 1 1 auto;
  padding: 16px 14px;
  overflow-y: auto;
  font-size: 1.04em;
  min-height: 110px;
  max-height: 260px;
  background: #fff;
}
.chat-message {
  margin-bottom: 10px;
  display: flex;
  gap: 7px;
  align-items: flex-end;
}
.chat-message.you {
  justify-content: flex-end;
}
.chat-message .chat-username {
  color: #1586d6;
  font-weight: bold;
  margin-right: 4px;
  font-size: .99em;
}
.chat-message .chat-text {
  background: #eaf6ff;
  border-radius: 6px;
  padding: 5px 12px;
  display: inline-block;
  max-width: 180px;
  word-break: break-word;
}
.chat-message.you .chat-text {
  background: #d3ffe8;
  color: #156b42;
}
#chat-form {
  display: flex;
  padding: 7px 10px 8px 10px;
  border-top: 1px solid #e6f0fa;
  background: #f4fbff;
  border-radius: 0 0 14px 14px;
  gap: 6px;
}
#chat-input {
  flex: 1 1 auto;
  border: 1.3px solid #b6eaff;
  border-radius: 7px;
  padding: 7px;
  font-size: 1em;
}
#chat-form button {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 7px 16px;
  font-weight: 500;
  cursor: pointer;
}

