/* ===== James Happy Smiles ===== */

:root {
  --jhs-sidebar-bg: #2b2352;
  --jhs-sidebar-active: #6c4fd8;
  --jhs-accent: #f7c948;
}

/* ---- Layout: sidebar + main ---- */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  flex: 0 0 220px;
  background: var(--jhs-sidebar-bg);
  color: #fff;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  padding: 0.5rem;
}

.logo-emoji {
  font-size: 1.6rem;
}

.sidebar nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* Beat Pico's nav styling: it gives nav li padding and nav links
   inline-block with negative margins, which misaligns the buttons and
   makes the hover highlight bleed over neighbours. */
.sidebar nav li {
  list-style: none;
  display: block;
  margin: 0;
  padding: 0;
}

.sidebar .nav-button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem;
  color: #e8e4ff;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease;
}

.sidebar .nav-button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar .nav-button.active {
  background: var(--jhs-sidebar-active);
  color: #fff;
  font-weight: 700;
}

.sidebar .nav-button.signout {
  color: #ffb3ab;
}

.nav-emoji {
  width: 1.5rem;
  text-align: center;
}

#nav-burger {
  display: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.page-main {
  flex: 1;
  padding: 2rem;
  max-width: 900px;
}

/* ---- Small screens: sidebar becomes a top bar ---- */
@media (max-width: 700px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    flex: none;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }

  #nav-burger {
    display: block;
  }

  .sidebar nav {
    display: none;
    width: 100%;
  }

  .sidebar.nav-open nav {
    display: block;
  }

  .page-main {
    padding: 1rem;
  }
}

/* ---- Login ---- */
.login-container {
  max-width: 420px;
  padding-top: 3rem;
  text-align: center;
}

.login-container form {
  text-align: left;
}

.login-logo {
  font-size: 4rem;
}

/* ---- Flash banners ---- */
.flash {
  padding: 0.8rem 1rem;
  border-radius: 0.6rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.flash-error {
  background: #ffe3e0;
  color: #8c1d18;
}

.flash-success {
  background: #e2f7e1;
  color: #1d5c20;
}

/* ---- Profile ---- */
.balance-card {
  background: linear-gradient(135deg, var(--jhs-sidebar-active), var(--jhs-sidebar-bg));
  color: #fff;
  border-radius: 1rem;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.stat-label {
  opacity: 0.8;
}

.stat-value {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--jhs-accent);
}

.trophy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.8rem;
}

.trophy-card {
  text-align: center;
  border: 2px solid var(--jhs-accent);
  border-radius: 0.8rem;
  padding: 0.8rem;
}

.trophy-emoji {
  font-size: 2rem;
}

.trophy-name {
  font-weight: 600;
}

/* ---- Music toggle ---- */
#music-toggle {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  font-size: 1.6rem;
  cursor: pointer;
  background: #fff;
  border: 2px solid var(--jhs-sidebar-active);
  border-radius: 50%;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 100;
}

/* ---- Admin ---- */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.admin-card {
  text-align: center;
  border: 2px solid var(--jhs-sidebar-active);
  border-radius: 0.8rem;
  padding: 1.2rem;
  text-decoration: none;
  font-weight: 600;
}

.admin-card:hover {
  background: rgba(108, 79, 216, 0.1);
}

.admin-card-emoji {
  font-size: 2.2rem;
}

.inline-form {
  display: inline-block;
  margin: 0 0.3rem 0 0;
}

.inline-form button,
.inline-form input {
  padding: 0.3rem 0.6rem;
  margin: 0;
  width: auto;
  font-size: 0.85rem;
}

/* ---- Ledger amounts ---- */
.amount-credit {
  color: #1d7a24;
  font-weight: 700;
}

.amount-debit {
  color: #b3261e;
  font-weight: 700;
}

/* ---- Prizes ---- */
.prize-info {
  font-size: 0.85rem;
  min-height: 2.2rem;
  margin-bottom: 0.4rem;
}

.prize-cost {
  font-weight: 800;
  color: var(--jhs-sidebar-active);
  margin-bottom: 0.5rem;
}

.prize-owned {
  font-weight: 700;
  color: #1d7a24;
}

.cashout-stub {
  text-align: center;
  padding: 2rem;
}

/* ---- Analytics leaderboards ---- */
/* Fixed layout so every leaderboard table lines up the same way:
   narrow medal column, name takes the room, right-aligned value. */
.rank-table {
  table-layout: fixed;
  width: 100%;
}

.rank-table .rank-medal {
  width: 3.5rem;
  text-align: center;
}

.rank-table .rank-value {
  width: 7.5rem;
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}

.rank-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Game pages ---- */
/* Below the canvas, with its height reserved so the result banner
   appearing doesn't shift the page. */
#game-status {
  min-height: 3.2rem;
  margin-top: 0.8rem;
  display: flex;
  align-items: center;
}

#game-status.flash {
  margin-bottom: 0;
}

/* ---- JamesGPT widget ---- */
#jgpt-widget {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 150;
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  transition: transform 0.7s ease-in, opacity 0.7s ease-in;
}

#jgpt-launcher {
  width: 3.6rem;
  height: 3.6rem;
  border-radius: 50%;
  border: 3px solid var(--jhs-sidebar-active);
  background: #fff;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  flex: none;
  animation: jgpt-bob 3s ease-in-out infinite;
}

#jgpt-launcher:hover {
  transform: scale(1.08);
}

@keyframes jgpt-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

#jgpt-face,
.jgpt-header-face {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#jgpt-face-fallback,
.jgpt-header-fallback {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
}

#jgpt-teaser {
  background: #fff;
  color: #2b2352;
  border: 2px solid var(--jhs-sidebar-active);
  border-radius: 1rem 1rem 1rem 0.2rem;
  padding: 0.6rem 0.9rem;
  max-width: 240px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  display: none;
  order: 2;
}

#jgpt-teaser.visible {
  display: block;
  animation: jgpt-pop 0.35s ease-out;
}

@keyframes jgpt-pop {
  0% { transform: scale(0.6) translateY(10px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

#jgpt-teaser-close {
  margin-left: 0.5rem;
  opacity: 0.5;
  font-weight: 900;
}

#jgpt-widget.panel-open #jgpt-teaser {
  display: none;
}

/* Panel */
#jgpt-panel {
  position: fixed;
  left: 1rem;
  bottom: 5.4rem;
  width: min(330px, calc(100vw - 2rem));
  background: #fff;
  border: 2px solid var(--jhs-sidebar-active);
  border-radius: 1rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  z-index: 151;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#jgpt-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

#jgpt-panel-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: var(--jhs-sidebar-bg);
  color: #fff;
}

.jgpt-header-avatar {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  flex: none;
}

.jgpt-header-fallback {
  font-size: 1.2rem;
}

.jgpt-header-name {
  font-weight: 800;
  line-height: 1.1;
}

.jgpt-header-status {
  font-size: 0.72rem;
  color: #8ee08f;
}

#jgpt-close {
  margin-left: auto;
  cursor: pointer;
  font-size: 1.3rem;
  opacity: 0.8;
  padding: 0 0.3rem;
}

#jgpt-messages {
  height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.7rem;
  background: #faf9ff;
}

.chat-msg {
  max-width: 82%;
  padding: 0.45rem 0.75rem;
  border-radius: 0.9rem;
  font-size: 0.88rem;
  line-height: 1.3;
  color: #2b2352;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--jhs-sidebar-active);
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.chat-msg.bot {
  align-self: flex-start;
  background: rgba(108, 79, 216, 0.12);
  border-bottom-left-radius: 0.25rem;
}

#jgpt-typing {
  display: none;
  gap: 0.3rem;
  padding: 0.3rem 0.8rem;
  background: #faf9ff;
}

#jgpt-typing.visible {
  display: flex;
}

.typing-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--jhs-sidebar-active);
  animation: typing-bounce 1s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-0.3rem); opacity: 1; }
}

#jgpt-form {
  display: flex;
  gap: 0.4rem;
  margin: 0;
  padding: 0.55rem;
  border-top: 1px solid rgba(108, 79, 216, 0.25);
  background: #fff;
}

#jgpt-form input {
  flex: 1;
  margin: 0;
  padding: 0.45rem 0.7rem;
  font-size: 0.88rem;
}

#jgpt-form button {
  width: auto;
  margin: 0;
  padding: 0.45rem 0.9rem;
  font-size: 0.88rem;
}

/* The ejection: flash + shake, then slide off-screen */
#jgpt-panel.doomed {
  animation: jgpt-doom-flash 0.4s infinite, doom-shake 0.45s infinite;
  border-color: #ff5147;
}

@keyframes jgpt-doom-flash {
  0%, 100% { box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3); }
  50% { box-shadow: 0 0 34px rgba(255, 60, 50, 0.95); }
}

@keyframes doom-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 3px) rotate(-0.6deg); }
  40% { transform: translate(5px, -4px) rotate(0.5deg); }
  60% { transform: translate(-4px, -3px) rotate(-0.4deg); }
  80% { transform: translate(6px, 4px) rotate(0.6deg); }
}

#jgpt-panel.dismissed {
  transition: transform 0.8s cubic-bezier(0.5, -0.3, 0.8, 0.6), opacity 0.9s ease;
  transform: translateY(130vh) rotate(8deg);
  opacity: 0;
  pointer-events: none;
}

#jgpt-widget.dismissed {
  transform: translateY(8rem);
  opacity: 0;
  pointer-events: none;
}
