:root{--uiScale:1}
html,body{height:100%;margin:0;}
body{background:#070d19;color:#e9feff;overflow:hidden;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Arial;font-size:calc(14px*var(--uiScale))}
canvas{display:block;width:100vw;height:100vh}

/* Disable text selection across the game UI */
body, #hud, #title, .chip, .overlay, .modal, .card, #panel, #leaderboard, #changelog {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Re-enable selection for form controls and any explicitly selectable text */
input, textarea, select, button, .selectable {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;    
}

/*.flash {*/
/*  background: rgba(0, 255, 180, 0.15);*/
/*  transition: background 0.8s ease;*/
/*}*/

.flash { background: rgba(0,255,180,.12); transition: background .8s ease; }


/* HUD */
#hud{position:fixed;inset:0;pointer-events:none;display:flex;align-items:flex-start;justify-content:space-between;padding:12px 14px;mix-blend-mode:screen;z-index:5}
.chip{background:linear-gradient(135deg,rgba(0,255,213,.18),rgba(35,130,255,.12));border:1px solid rgba(255,255,255,.18);backdrop-filter:blur(6px) saturate(120%);border-radius:14px;padding:8px 11px;margin-right:8px;box-shadow:0 0 24px rgba(0,200,255,.15),inset 0 0 24px rgba(0,255,170,.08);text-shadow:0 0 6px rgba(0,255,255,.8);color:#e8fbff;font-weight:700;letter-spacing:.4px}
#title{position:fixed;left:50%;transform:translateX(-50%);top:10px;font-weight:900;letter-spacing:.14em;text-transform:uppercase;font-size:clamp(18px,calc(4vw*var(--uiScale)),calc(32px*var(--uiScale)));color:#9be8ff;text-shadow:0 0 24px #00eaff,0 0 48px #00f0ff,0 0 72px rgba(0,255,255,.6)}
#panelToggleWrap{pointer-events:auto}

/* Param Panel */
#panel{position:fixed;right:10px;top:58px;z-index:6;pointer-events:auto;width:min(380px,48vw);max-width:92vw}
#panel.hidden{display:none}
.card{background:rgba(10,25,45,.6);border:1px solid rgba(255,255,255,.18);backdrop-filter:blur(8px) saturate(130%);border-radius:16px;padding:12px 14px;box-shadow:0 12px 40px rgba(0,0,0,.25), inset 0 0 24px rgba(0,255,170,.06)}
.card h3{margin:0 0 8px 0;font-size:13px;letter-spacing:.12em;text-transform:uppercase;color:#c9faff;opacity:.9}
.row{display:flex;align-items:center;gap:8px;margin:8px 0}
.row label{flex:0 0 170px;font-size:12px;opacity:.9}
.row input[type="range"], .row input[type="checkbox"], .row input[type="color"]{flex:1}
.val{width:120px;text-align:right;font-variant-numeric:tabular-nums;opacity:.9}
.mini{font-size:11px;opacity:.75;margin-top:4px}

/* Small buttons */
.btnsm{pointer-events:auto;cursor:pointer;user-select:none;border:1px solid rgba(255,255,255,.25);background:linear-gradient(180deg,rgba(180,255,255,.25),rgba(0,120,160,.25));color:#e9feff;border-radius:10px;padding:6px 10px;font-size:12px;font-weight:700;letter-spacing:.05em;box-shadow:inset 0 -2px 0 rgba(0,0,0,.25);}
.btnsm:active{transform:translateY(1px);} 

/* Modal */
.modal{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,6,16,.55);opacity:0;pointer-events:none;transition:opacity .25s ease;z-index:7}
.modal.show{opacity:1;pointer-events:auto}
.modal .content{width:min(520px,92vw);max-height:80vh;overflow:auto;background:rgba(8,20,36,.9);border:1px solid rgba(255,255,255,.2);backdrop-filter:blur(8px) saturate(130%);border-radius:16px;box-shadow:0 20px 60px rgba(0,0,0,.45), inset 0 0 24px rgba(0,255,170,.06);padding:16px}
.modal h2{margin:6px 0 8px;font-size:20px;letter-spacing:.06em;color:#bffcff}

/* Codex modal layout */
.modal .content.codex{
  width: min(1100px, 94vw);
  height: min(82vh, 820px);
  display: flex;
  flex-direction: column;
  padding: 10px;
}

.codexBar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin: 2px 4px 8px;
}
.codexBody{
  position: relative;
  flex: 1 1 auto;
  border:1px solid rgba(255,255,255,.18);
  border-radius:12px;
  overflow:hidden;
  background:rgba(10,25,45,.5);
}
#codexFrame{
  position:absolute; inset:0;
  width:100%; height:100%;
  border:0; background:transparent;
}
#codexLoading{
  position:absolute; left:12px; top:10px;
  z-index:1; opacity:.9;
}

/* Make each cell layout predictable and prevent text overlap */
.pt-cell{
  position: relative;
  box-sizing: border-box;
  width: 126px;                 /* tune to your grid */
  height: 108px;                /* a bit taller to fit name + qty */
  padding: 10px 12px;
  display: grid;
  grid-template-rows: 18px 1fr auto; /* number, symbol, name */
  overflow: hidden;
}

.pt-cell .num{ font-size: 12px; opacity: .75; line-height: 1; }
.pt-cell .sym{ font-size: 28px; font-weight: 800; line-height: 1; align-self: center; }
.pt-cell .name{
  font-size: 12px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;      /* <- trims long names */
  padding-right: 18px;          /* space for qty badge */
}

/* Put the quantity in a fixed spot so it never overlaps the name */
.pt-cell .qty{
  position: absolute;
  right: 8px;
  bottom: 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: .85;
  pointer-events: none;
}

/* Ensure consistent sizing everywhere */
.pt-cell *{ box-sizing: border-box; }

/* Small screens—shrink typography a touch */
@media (max-width: 820px){
  .pt-cell{ width: 104px; height: 96px; padding: 8px 10px; }
  .pt-cell .sym{ font-size: 24px; }
  .pt-cell .name{ font-size: 11px; }
}

/**/
/* Periodic table cells */
.cell {
  position: relative;
  width: 120px;          /* tune grid size */
  height: 100px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  box-sizing: border-box;
  overflow: hidden;
}

/* Atomic number */
.cell .n {
  font-size: 12px;
  opacity: 0.7;
  margin-bottom: 4px;
}

/* Symbol */
.cell .s {
  font-size: 26px;
  font-weight: bold;
  line-height: 1;
  margin-bottom: 2px;
}

/* Name (never overlaps qty) */
.cell .nm {
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 18px;  /* leave space for qty */
}

/* Quantity pinned bottom-right */
.cell .q {
  position: absolute;
  right: 6px;
  bottom: 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

/* Rare marker star */
.cell .rare {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 14px;
  color: gold;
}

/**/

/*2*/
:root{
  --cell-w: 120px;
  --cell-h: 100px;
}

/* toolbar */
.pt-toolbar{display:flex;align-items:center;gap:10px;margin:8px 0 10px}
.seg{display:inline-flex;background:rgba(255,255,255,.08);border-radius:10px;overflow:hidden;border:1px solid rgba(255,255,255,.15)}
.segbtn{padding:6px 10px;border:0;background:transparent;color:#e9feff;cursor:pointer;font-weight:700}
.segbtn.is-active{background:rgba(255,255,255,.14)}

/* responsive grid */
.pt-grid{
  display:grid;
  gap:10px;
  grid-template-columns: repeat(auto-fit, minmax(var(--cell-w), 1fr));
}
.pt-grid.view-compact{ --cell-w: 96px; --cell-h: 88px; }
.pt-grid.view-normal { --cell-w: 120px; --cell-h: 100px; }
.pt-grid.view-comfy  { --cell-w: 150px; --cell-h: 118px; }

/* cell */
.cell{
  position:relative; box-sizing:border-box;
  width:100%; height:var(--cell-h);
  padding:8px 10px;border-radius:10px;
  background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.12);
  overflow:hidden; cursor:pointer;
}
.cell .n{font-size:12px;opacity:.75;line-height:1;margin-bottom:4px}
.cell .s{font-size:28px;font-weight:800;line-height:1;margin-bottom:2px}
.cell .nm{
  font-size:12px;line-height:1.15;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
  padding-right:18px; /* room for qty */
}
.cell .q{position:absolute;right:6px;bottom:6px;font-size:12px;font-variant-numeric:tabular-nums;opacity:.9}
.cell .rare{position:absolute;top:6px;right:6px;color:gold}

/* compact tweaks */
.pt-grid.view-compact .cell .s{font-size:24px}
.pt-grid.view-compact .cell .nm{display:none}   /* hide long name */
.pt-grid.view-compact .cell .q{bottom:6px}

/* comfy tweaks */
.pt-grid.view-comfy .cell .s{font-size:30px}

/* detail overlay */
.pt-detail{position:fixed;inset:0;background:rgba(0,10,20,.6);display:flex;align-items:center;justify-content:center;z-index:100}
.pt-detail.hide{display:none}
.pt-detail .card{
  width:min(680px,90vw);max-height:80vh;overflow:auto;
  background:rgba(10,25,45,.92);border:1px solid rgba(255,255,255,.18);
  border-radius:14px;box-shadow:0 20px 60px rgba(0,0,0,.4);padding:14px
}
.pt-detail .head{display:flex;align-items:center;gap:12px;margin-bottom:8px}
.pt-detail .sym{font-size:42px;font-weight:900}
.pt-detail .name{font-size:18px;font-weight:800}
.pt-detail .sub{opacity:.85}
.pt-detail .body{margin-top:6px}

/*2*/

.pt-cell .qty::before{
  content: '';
  display:inline-block;
  width:6px;height:6px;border-radius:999px;
  margin-right:4px; vertical-align:middle;
  background: rgba(255,255,255,.4);
}

/* (already present) make modals clickable when shown */
.modal.show{ pointer-events:auto; }

/* Full-screen modal look */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 6, 16, 0.65); /* a bit stronger */
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  z-index: 50;
}
.modal.show { opacity: 1; pointer-events: auto; }

/* Body scroll lock while a modal is open */
body.modal-open { overflow: hidden; }

/* Fullscreen Codex content */
.modal .content.codex{
  width: 96vw;
  height: 92vh;
  max-width: 1400px;       /* optional clamp */
  display: flex;
  flex-direction: column;
  padding: 10px;
  background: rgba(8, 20, 36, .92);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 16px;
  backdrop-filter: blur(8px) saturate(130%);
  box-shadow: 0 20px 60px rgba(0,0,0,.45), inset 0 0 24px rgba(0,255,170,.06);
}

#marketModal .actions {
  margin-top: 16px;
  display: flex;
  gap: 12px;                  /* add space between buttons */
  justify-content: flex-end;  /* right-align them */
  flex-wrap: wrap;            /* so on smaller screens they stack */
}
#marketModal .btnsm {
  min-width: 120px;           /* consistent button sizing */
  text-align: center;
}

.codexBar{
  display:flex; align-items:center; justify-content:space-between;
  gap:10px; margin: 2px 4px 8px;
}

.codexBody{
  position: relative;
  flex: 1 1 auto;
  border:1px solid rgba(255,255,255,.18);
  border-radius:12px;
  overflow: hidden;         /* iframe handles its own scroll */
  background: rgba(10,25,45,.5);
}

#codexFrame{
  position:absolute; inset:0;
  width:100%; height:100%;
  border:0; background:transparent;
}

#codexLoading{
  position:absolute; left:12px; top:10px;
  z-index:1; opacity:.9;
}


/* Leaderboard modal tweaks */
#leaderboard .content {
  padding: 20px 24px;      /* more breathing room */
}

#leaderboard h2 {
  margin-top: 0;
  margin-bottom: 10px;     /* space below title */
}

#leaderboard .mini {
  margin-bottom: 12px;     /* space after "Your ID" */
}

#leaderboard .row {
  margin: 10px 0 16px;     /* space for Display name input row */
}

#leaderboard ol {
  padding-left: 22px;      /* indent list properly */
  margin: 4px 0 14px;      /* balanced spacing between lists */
}

#leaderboard li {
  padding: 2px 0;          /* vertical spacing between list items */
}

#leaderboard .actions {
  margin-top: 16px;        /* push buttons down a bit */
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Changelog list spacing */
#changelog ul { margin: 6px 0 12px 18px; padding: 0; }
#changelog li { margin: 4px 0; line-height: 1.4; }

#leaderboard .content { padding: 20px 24px; }
#leaderboard h2 { margin-top: 0; margin-bottom: 10px; }
#leaderboard .mini { margin-bottom: 12px; }
#leaderboard .row { margin: 10px 0 16px; }
#leaderboard ol { padding-left: 22px; margin: 4px 0 14px; }
#leaderboard li { padding: 2px 0; }
#leaderboard .actions { margin-top: 16px; display: flex; gap: 10px; justify-content: flex-end; }

/* Overlay (under modal) */
.overlay{position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;background: radial-gradient(1200px 800px at 50% 0%, rgba(0,200,255,.10), rgba(0,0,0,0));text-align:center;opacity:0;pointer-events:none;transition:opacity .5s ease;z-index:4}
.overlay.show{opacity:1;pointer-events:auto}
.overlay h1{margin:0;font-size:clamp(28px,6vw,64px);color:#bffcff;letter-spacing:.06em;text-shadow:0 0 22px #25ffff}
.overlay p{margin:0;opacity:.9}
.overlay .btn{cursor:pointer;padding:12px 18px;border-radius:18px;font-weight:900;letter-spacing:.1em;text-transform:uppercase;border:2px solid rgba(0,255,255,.6);color:#001217;background:linear-gradient(180deg,#79fff5,#29c0ff);box-shadow:0 15px 40px rgba(0,255,255,.3),inset 0 -4px 10px rgba(0,0,0,.25)}

/* Overlay hint line */
.overlay .hint{
  margin: 0;
  opacity: .8;
  font-size: 12px;
}

/* Heat bar */
#heatbarWrap{position:fixed;left:50%;transform:translateX(-50%);bottom:14px;width:min(520px,80vw);height:10px;border-radius:999px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.15);overflow:hidden;box-shadow:0 6px 30px rgba(0,255,255,.15);z-index:5}
#heatbar{height:100%;width:0%;background:linear-gradient(90deg,#6ff,#8ff,#ffb35a,#ff6a6a);transition:width .1s linear}


