:root {
  --bg: #0a0710;
  --bg-2: #120a1f;
  --panel: rgba(24, 15, 40, 0.72);
  --panel-solid: #160d26;
  --border: rgba(168, 85, 247, 0.18);
  --border-strong: rgba(168, 85, 247, 0.4);
  --text: #ece7f6;
  --muted: #9c8fb8;
  --purple: #a855f7;
  --purple-2: #7c3aed;
  --purple-soft: #c084fc;
  --ok: #34d399;
  --err: #fb7185;
  --warn: #fbbf24;
  --radius: 16px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 800px at 15% -10%, #1e1030 0%, var(--bg) 55%),
              radial-gradient(1000px 700px at 100% 0%, #180a2e 0%, transparent 60%),
              var(--bg);
  color: var(--text);
  font-family: "Noto Sans Thai", "Sora", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

/* floating background orbs */
.bg-orbs { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bg-orbs span {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.35;
  background: radial-gradient(circle, var(--purple), transparent 70%);
  animation: float 18s ease-in-out infinite;
}
.bg-orbs span:nth-child(1) { width: 420px; height: 420px; top: -80px; left: -60px; }
.bg-orbs span:nth-child(2) { width: 360px; height: 360px; bottom: -120px; right: 10%; animation-delay: -6s; background: radial-gradient(circle, #6d28d9, transparent 70%); }
.bg-orbs span:nth-child(3) { width: 300px; height: 300px; top: 40%; right: -80px; animation-delay: -12s; }
@keyframes float { 0%,100% { transform: translateY(0) translateX(0); } 50% { transform: translateY(-40px) translateX(20px); } }

/* topbar */
.topbar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--purple), var(--purple-2));
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.5);
}
.logo i { width: 26px; height: 26px; color: white; }
.brand-text h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.3px; }
.brand-text h1 span { color: var(--purple-soft); }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; gap: 10px; }
.stat-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--border);
}
.stat-pill b { font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.running { background: var(--purple); box-shadow: 0 0 10px var(--purple); }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }
.stat-pill.code-pill { font-family: "JetBrains Mono", monospace; letter-spacing: 0.5px; border-color: var(--border-strong); }
.stat-pill.code-pill i { width: 14px; height: 14px; color: var(--purple-soft); }

/* layout */
.layout {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 400px 1fr; gap: 22px;
  padding: 24px 28px; max-width: 1500px; margin: 0 auto;
  align-items: start;
}
@media (max-width: 950px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  overflow: hidden;
}
.panel-head {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { display: flex; align-items: center; gap: 9px; margin: 0; font-size: 15px; font-weight: 700; }
.panel-head h2 i { width: 18px; height: 18px; color: var(--purple-soft); }
.panel-head .hint { font-size: 12px; color: var(--muted); }

/* tool cards */
.tool-list { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.tool-card {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 16px; border-radius: 14px; cursor: pointer;
  background: linear-gradient(180deg, rgba(168,85,247,0.06), rgba(168,85,247,0.02));
  border: 1px solid var(--border); transition: all 0.18s ease;
}
.tool-card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: 0 12px 30px rgba(124,58,237,0.25); }
.tool-card .t-icon {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; color: white;
  background: linear-gradient(135deg, var(--purple), var(--purple-2));
}
.tool-card .t-icon i { width: 22px; height: 22px; }
.tool-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.tool-card p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* a tool this key isn't allowed to run — still clickable so the click can
   explain WHY (a pointer-events:none card would just feel broken) */
.tool-card.locked { position: relative; filter: grayscale(0.85) brightness(0.62); opacity: 0.75; }
.tool-card.locked:hover { transform: none; border-color: var(--border);
  box-shadow: none; filter: grayscale(0.7) brightness(0.72); }
.tool-card.locked .t-lock { position: absolute; right: 12px; top: 12px;
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: rgba(10,7,16,0.75); border: 1px solid var(--border-strong); color: var(--muted); }
.tool-card.locked .t-lock i { width: 14px; height: 14px; }

/* jobs */
.jobs-panel { min-height: 300px; }
.jobs-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.job-list { padding: 14px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 220px); overflow-y: auto; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty i { width: 42px; height: 42px; opacity: 0.5; margin-bottom: 10px; }
.empty p { margin: 0; font-size: 13px; }

.job {
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  background: rgba(10, 6, 18, 0.55);
}
.job-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; cursor: pointer;
}
.job-head .j-left { display: flex; align-items: center; gap: 11px; min-width: 0; }
.job-badge { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, var(--purple), var(--purple-2)); color: white; }
.job-badge i { width: 17px; height: 17px; }
.job-title { min-width: 0; }
.job-title h4 { margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-title .j-meta { font-size: 11.5px; color: var(--muted); font-family: "JetBrains Mono", monospace; }
.j-right { display: flex; align-items: center; gap: 10px; }
.chev { width: 18px; height: 18px; color: var(--muted); transition: transform 0.2s; }
.job.open .chev { transform: rotate(180deg); }
.job-status {
  font-size: 11px; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  display: flex; align-items: center; gap: 6px; letter-spacing: 0.3px;
}
.status-queued { background: rgba(156,143,184,0.15); color: var(--muted); }
.status-running { background: rgba(168,85,247,0.16); color: var(--purple-soft); }
.status-success { background: rgba(52,211,153,0.14); color: var(--ok); }
.status-error { background: rgba(251,113,133,0.14); color: var(--err); }
.status-cancelled { background: rgba(251,191,36,0.14); color: var(--warn); }
.spin, .status-running .spin { display: inline-block; width: 11px; height: 11px; border: 2px solid rgba(192,132,252,0.35); border-top-color: var(--purple-soft); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* progress bar */
.job-progress { padding: 0 14px 12px; }
.pb-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.pb-step { font-size: 12px; color: var(--purple-soft); font-weight: 500; }
.pb-pct { font-size: 12px; color: var(--muted); font-family: "JetBrains Mono", monospace; }
.pb-track { height: 8px; border-radius: 999px; background: #1c1130; overflow: hidden; }
.pb-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--purple-2), var(--purple), var(--purple-soft));
  background-size: 200% 100%; transition: width 0.4s ease; animation: shimmer 2s linear infinite; }
.pb-fill.ok { background: linear-gradient(90deg, #059669, var(--ok)); animation: none; }
.pb-fill.err { background: linear-gradient(90deg, #e11d48, var(--err)); animation: none; }
@keyframes shimmer { to { background-position: -200% 0; } }

.job-body { border-top: 1px solid var(--border); display: none; padding: 14px; }
.job.open .job-body { display: block; }
.job-actions { display: flex; gap: 8px; margin-top: 12px; }
.job-note { font-size: 13px; color: var(--muted); padding: 4px 2px; }

/* result UI */
.result-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--purple-soft); margin-bottom: 12px; }
.result-title i { width: 18px; height: 18px; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.result-tile { display: flex; gap: 11px; align-items: center; padding: 12px; border-radius: 12px;
  background: linear-gradient(180deg, rgba(168,85,247,0.08), rgba(168,85,247,0.02)); border: 1px solid var(--border); }
.rt-icon { width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; display: grid; place-items: center; color: white;
  background: linear-gradient(135deg, var(--purple), var(--purple-2)); }
.rt-icon i, .rt-icon svg { width: 18px; height: 18px; }
.rt-body { min-width: 0; }
.rt-label { font-size: 11.5px; color: var(--muted); }
.rt-value { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-tile.wide { grid-column: 1 / -1; }
.rt-value.wrap { white-space: normal; word-break: break-all; font-size: 13.5px; font-family: "JetBrains Mono", monospace; }
.rt-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.result-empty { font-size: 13px; color: var(--muted); }

/* error block inside job */
.je-head { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--err); margin-bottom: 6px; }
.je-head i { width: 18px; height: 18px; }
.je-msg { font-size: 13px; color: var(--text); line-height: 1.5; }

/* pager */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.pg-info { font-size: 12px; color: var(--muted); }
.pg-btns { display: flex; align-items: center; gap: 10px; }
.pg-cur { font-size: 12.5px; font-weight: 600; color: var(--text); min-width: 74px; text-align: center; }
.pg-arrow { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border); background: transparent;
  color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.pg-arrow i { width: 16px; height: 16px; }
.pg-arrow:hover:not(:disabled) { border-color: var(--purple); color: var(--purple-soft); }
.pg-arrow:disabled { opacity: 0.35; cursor: not-allowed; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--text); transition: all 0.15s ease;
}
.btn i { width: 15px; height: 15px; }
.btn.primary { background: linear-gradient(135deg, var(--purple), var(--purple-2)); border-color: transparent; box-shadow: 0 8px 22px rgba(124,58,237,0.4); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost:hover { border-color: var(--border-strong); }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.danger { color: var(--err); border-color: rgba(251,113,133,0.3); }
.btn.danger:hover { background: rgba(251,113,133,0.12); }
.btn.primary.danger-fill { background: linear-gradient(135deg, #f43f5e, #b91c1c); box-shadow: 0 8px 22px rgba(244,63,94,0.4); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; }
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.icon-btn i { width: 20px; height: 20px; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(5,2,10,0.7); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 20px; }
.modal-backdrop[hidden] { display: none !important; }
.modal { width: 100%; max-width: 520px; background: var(--panel-solid); border: 1px solid var(--border-strong); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; animation: pop 0.16s ease; }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 20px 14px; }
.modal-title { display: flex; gap: 13px; }
.modal-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: white; background: linear-gradient(135deg, var(--purple), var(--purple-2)); }
.modal-icon i { width: 22px; height: 22px; }
.modal-title h3 { margin: 0; font-size: 17px; }
.modal-title p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; max-width: 380px; }
.modal-danger { margin: 0 20px 6px; padding: 11px 13px; border-radius: 10px; font-size: 12.5px; line-height: 1.5;
  background: rgba(251,191,36,0.1); border: 1px solid rgba(251,191,36,0.3); color: #fcd34d; }
.tool-form { padding: 8px 20px 4px; display: flex; flex-direction: column; gap: 15px; max-height: 55vh; overflow-y: auto; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field .fhelp { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.field input[type=text], .field input[type=password], .field input[type=number], .field select {
  width: 100%; padding: 11px 13px; border-radius: 10px; font-family: inherit; font-size: 14px;
  background: #0d0718; border: 1px solid var(--border); color: var(--text); outline: none; transition: border 0.15s;
}
.field input:focus, .field select:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(168,85,247,0.15); }
.field .combo { display: flex; gap: 8px; }
.field .combo select { flex: 1; }
.field .combo input { width: 150px; }
.toggle-field { display: flex; align-items: center; justify-content: space-between; }
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { display: none; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: #2a1c40; transition: 0.2s; cursor: pointer; }
.switch .track::after { content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #7a6a95; top: 3px; left: 3px; transition: 0.2s; }
.switch input:checked + .track { background: linear-gradient(135deg, var(--purple), var(--purple-2)); }
.switch input:checked + .track::after { left: 23px; background: white; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px 20px; border-top: 1px solid var(--border); margin-top: 6px; }

/* confirm dialog */
.confirm-box { max-width: 440px; }
.confirm-desc { margin: 0; padding: 4px 20px 8px; font-size: 13.5px; color: var(--text); line-height: 1.6; }

/* error popup */
.err-box { max-width: 460px; }
.err-head { display: flex; align-items: center; gap: 13px; padding: 22px 22px 8px; }
.err-icon { width: 46px; height: 46px; border-radius: 13px; flex-shrink: 0; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #f43f5e, #b91c1c); box-shadow: 0 8px 22px rgba(244,63,94,0.4); }
.err-icon i { width: 24px; height: 24px; }
.err-head h3 { margin: 0; font-size: 18px; }
#err-message { margin: 0; padding: 4px 22px 8px; font-size: 14px; color: var(--text); line-height: 1.6; }
.err-detail { margin: 8px 22px 0; padding: 12px; border-radius: 10px; background: #07040d; border: 1px solid var(--border);
  font-family: "JetBrains Mono", monospace; font-size: 11.5px; color: #cdbfe6; white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto; }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100;
  padding: 12px 20px; border-radius: 12px; font-size: 13px; font-weight: 500;
  background: var(--panel-solid); border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.toast.err { border-color: rgba(251,113,133,0.5); color: var(--err); }
.toast.ok { border-color: rgba(52,211,153,0.5); color: var(--ok); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(168,85,247,0.3); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* device gate */
.gate-screen { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  padding: 20px; background: radial-gradient(1200px 800px at 15% -10%, #1e1030 0%, var(--bg) 55%), var(--bg); }
.gate-screen[hidden] { display: none !important; }
.gate-card { max-width: 420px; width: 100%; text-align: center; padding: 34px 28px;
  background: var(--panel-solid); border: 1px solid var(--border-strong); border-radius: 20px; box-shadow: var(--shadow); }
.gate-icon { width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--purple), var(--purple-2)); box-shadow: 0 8px 22px rgba(124,58,237,0.4); }
.gate-icon i { width: 28px; height: 28px; }
.gate-card h2 { margin: 0 0 8px; font-size: 19px; }
.gate-card p#gate-msg { margin: 0 0 18px; font-size: 13.5px; color: var(--muted); line-height: 1.6; }
.gate-code { font-family: "JetBrains Mono", monospace; font-size: 26px; font-weight: 700; letter-spacing: 2px;
  padding: 14px; border-radius: 12px; background: #0d0718; border: 1px dashed var(--border-strong); margin-bottom: 14px; color: var(--purple-soft); }
.gate-wait { margin: 16px 0 0; font-size: 12px; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 8px; }

/* ====================== treasure picker (treasure_upgrade) ================= */
/* Wider modal, and the form is a fixed-height column: bar + search + picked
   panel never move, and ONLY the grid scrolls. (An earlier version scrolled the
   whole form with the picked panel stuck to the bottom -- on a phone that panel
   covered nearly the entire grid, so you couldn't change your pick.) */
.modal.wide { max-width: 880px; max-height: 92vh; display: flex; flex-direction: column; }
.modal.wide .modal-head, .modal.wide .modal-foot { flex: 0 0 auto; }
/* overflow-y:auto, not hidden: on a very short screen the grid bottoms out at
   its min-height and the form scrolls as a fallback, so nothing is unreachable */
.tool-form.tp-form { max-height: none; flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 12px; padding-bottom: 14px; }

/* account / coin bar */
.tp-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; padding: 10px 12px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(168,85,247,0.16), rgba(124,58,237,0.10));
  border: 1px solid var(--border-strong); backdrop-filter: blur(10px); }
.tp-acct { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.tp-acct b { color: var(--text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.tp-acct i { width: 15px; height: 15px; }
.tp-money { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.tp-coin, .tp-gem { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px;
  font-size: 13px; font-weight: 700; font-family: "JetBrains Mono", monospace; }
.tp-coin { background: rgba(251,191,36,0.14); color: #fcd34d; border: 1px solid rgba(251,191,36,0.3); }
.tp-gem  { background: rgba(34,211,238,0.12); color: #67e8f9; border: 1px solid rgba(34,211,238,0.28); }
.tp-coin i, .tp-gem i { width: 14px; height: 14px; }

/* search */
.tp-searchwrap { flex: 0 0 auto; position: relative; display: flex; align-items: center; }
.tp-searchwrap > i { position: absolute; left: 11px; width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
.tp-searchwrap input { width: 100%; padding: 10px 12px 10px 34px; border-radius: 10px; font: inherit; font-size: 13px;
  background: #0f0a1c; border: 1px solid var(--border); color: var(--text); outline: none; }
.tp-searchwrap input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(168,85,247,0.15); }

/* the grid of in-game slots — the only scrolling region */
.tp-grid { flex: 1 1 auto; min-height: 118px; overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px;
  align-content: start; padding: 2px 4px 2px 2px; }
.tp-none { grid-column: 1 / -1; padding: 26px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.tp-none i { width: 22px; height: 22px; display: block; margin: 0 auto 8px; }

.tp-tile { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 0;
  background: none; border: 0; cursor: pointer; font: inherit; color: var(--text); }
.tp-tile:disabled { cursor: not-allowed; }
.tp-name { font-size: 10.5px; line-height: 1.25; color: var(--muted); text-align: center;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tp-tile.sel .tp-name { color: var(--text); font-weight: 600; }

/* the slot frame — mirrors the game's rarity-tinted rounded square */
.tp-frame { position: relative; width: 100%; aspect-ratio: 1 / 1; border-radius: 14px;
  display: grid; place-items: center; padding: 5px; overflow: hidden;
  border: 2px solid rgba(255,255,255,0.22);
  background: linear-gradient(160deg, #cfd8e8, #eef2f8 45%, #b9c4d8);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.35), 0 3px 10px rgba(0,0,0,0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease; }
.tp-frame.small { width: 54px; flex: 0 0 54px; }
.tp-frame img { width: 100%; height: 100%; object-fit: contain; image-rendering: -webkit-optimize-contrast; }
.tp-ph { font-size: 22px; font-weight: 800; color: #7b6ea8; font-family: "Sora", sans-serif; }

.tp-tile.g-C .tp-frame { background: linear-gradient(160deg, #d7dfe9, #f2f5fa 45%, #c3cddc); }
.tp-tile.g-B .tp-frame { background: linear-gradient(160deg, #bfe3d2, #eafaf2 45%, #a8d8c2); }
.tp-tile.g-A .tp-frame { background: linear-gradient(160deg, #c9d4ff, #eef1ff 45%, #b3c1f8); }
.tp-tile.g-S .tp-frame { background: linear-gradient(140deg, #ffd7f2, #d8f0ff 30%, #e6ffe0 55%, #fff3c9 80%, #ffd7f2); }

/* cookie grades (PCGrade.djb): SS is the in-game "S+", L is Legendary */
.tp-tile.g-SS .tp-frame { background: linear-gradient(140deg, #ffe9a8, #fff8dc 25%, #ffd9f0 55%, #d9f0ff 80%, #ffe9a8); }
.tp-tile.g-L .tp-frame  { background: linear-gradient(150deg, #e9d5ff, #f5e8ff 40%, #c4b5fd 75%, #ddd6fe); }

.tp-tile:not(:disabled):hover .tp-frame { transform: translateY(-2px); box-shadow: inset 0 0 0 3px rgba(255,255,255,0.45), 0 8px 20px rgba(0,0,0,0.45); }
.tp-tile.sel .tp-frame { border-color: var(--purple-soft);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.45), 0 0 0 3px rgba(192,132,252,0.55), 0 8px 22px rgba(124,58,237,0.5); }

/* multi-select tick, top-left, only while picked. The glyph is plain text, not
   a lucide icon -- createIcons() replaces <i> with a 24px <svg> that spilled
   outside this 18px circle. */
.tp-check { position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%;
  display: none; align-items: center; justify-content: center; overflow: hidden;
  color: #fff; border: 1.5px solid rgba(255,255,255,0.9);
  background: linear-gradient(135deg, var(--purple-soft), var(--purple-2));
  box-shadow: 0 2px 5px rgba(0,0,0,0.45);
  font-size: 11px; font-weight: 900; line-height: 1; font-family: "Sora", system-ui, sans-serif;
  text-shadow: 0 1px 1px rgba(0,0,0,0.35); padding-top: 1px; }
.tp-tile.sel .tp-check { display: flex; }

/* "+N" badge, bottom-right like the game */
.tp-plus { position: absolute; right: 3px; bottom: 2px; padding: 1px 5px; border-radius: 7px;
  font-family: "Sora", sans-serif; font-size: 12px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #fb923c, #ef4444);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5); border: 1.5px solid rgba(255,255,255,0.85);
  box-shadow: 0 2px 5px rgba(0,0,0,0.4); }

/* cookie picker extras: grade chip (top-right) + the price line under the name */
.cp-grade { position: absolute; right: 3px; top: 3px; padding: 0 5px; border-radius: 7px;
  font-family: "Sora", sans-serif; font-size: 10px; font-weight: 800; line-height: 16px; color: #fff;
  background: linear-gradient(135deg, #a855f7, #6366f1);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5); border: 1.5px solid rgba(255,255,255,0.8);
  box-shadow: 0 2px 5px rgba(0,0,0,0.4); }
.cp-tile.g-SS .cp-grade { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.cp-cost { font-size: 10px; font-weight: 700; color: #fcd34d; font-family: "Sora", sans-serif; }
.cp-tile.maxed .cp-cost { color: var(--muted); font-weight: 500; }
.cp-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }

/* maxed (+9) — dimmed and not selectable */
.tp-tile.maxed .tp-frame { filter: grayscale(0.55) brightness(0.45); }
.tp-tile.maxed .tp-plus { filter: none; background: linear-gradient(135deg, #64748b, #334155); }
.tp-tile.maxed .tp-name, .tp-tile.locked .tp-name { opacity: 0.5; }
.tp-tile.locked:not(.maxed) .tp-frame { filter: grayscale(0.8) brightness(0.55); }
.tp-lock { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,0.85); }
.tp-lock i { width: 20px; height: 20px; }

/* selected-treasure panel — pinned under the grid, never overlapping it */
#tp-picked-host { flex: 0 0 auto; }
.tp-picked { padding: 12px; border-radius: 13px; background: #0f0a1c; border: 1px solid var(--border-strong); }
.tp-picked.empty { display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); font-size: 12.5px; border-style: dashed; text-align: center; }
.tp-picked.empty i { width: 16px; height: 16px; flex: 0 0 16px; }
.tp-picked-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.tp-picked-head b { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.tp-picked-head b i { width: 15px; height: 15px; color: var(--purple-soft); }

/* clear-all ✕ */
.tp-clear { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 8px; display: grid; place-items: center;
  background: rgba(251,113,133,0.12); border: 1px solid rgba(251,113,133,0.28); color: var(--err);
  cursor: pointer; padding: 0; }
.tp-clear:hover { background: rgba(251,113,133,0.22); }
.tp-clear i { width: 14px; height: 14px; }

/* picked chips — ONE horizontally-scrolling row, so the panel height never
   grows with the number of picks (critical on a phone) */
.tp-chips { display: flex; gap: 7px; overflow-x: auto; overflow-y: hidden; padding-bottom: 5px;
  overscroll-behavior-x: contain; scrollbar-width: thin; }
.tp-chip { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 4px;
  border-radius: 10px; background: #160d26; border: 1px solid var(--border-strong); max-width: 190px; }
.tp-chip .tp-frame.mini { width: 28px; flex: 0 0 28px; border-width: 1.5px; border-radius: 8px;
  padding: 2px; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.3); }
.tp-chip-name { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-chip-plus { font-size: 11px; font-weight: 700; color: var(--purple-soft);
  font-family: "JetBrains Mono", monospace; }
.tp-chip-x { width: 20px; height: 20px; flex: 0 0 20px; border-radius: 6px; display: grid; place-items: center;
  background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 0; }
.tp-chip-x:hover { background: rgba(251,113,133,0.18); color: var(--err); }
.tp-chip-x i { width: 13px; height: 13px; }
.tp-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tp-inputs input { width: 100%; padding: 10px 12px; border-radius: 10px; font: inherit; font-size: 13px;
  background: #140d24; border: 1px solid var(--border); color: var(--text); outline: none; }
.tp-inputs input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(168,85,247,0.15); }
.tp-est { margin-top: 11px; padding: 9px 11px; border-radius: 10px; font-size: 12px; line-height: 1.6;
  background: rgba(168,85,247,0.10); border: 1px solid var(--border); color: var(--muted); }
.tp-est b { color: var(--text); font-family: "JetBrains Mono", monospace; }
.tp-est i { width: 14px; height: 14px; vertical-align: -2px; }
.tp-est.warn { background: rgba(251,191,36,0.10); border-color: rgba(251,191,36,0.32); }
.tp-warn { color: var(--warn); }
.tp-dim { color: var(--muted); opacity: 0.85; }
.tp-hint { display: flex; align-items: flex-start; gap: 7px; }
.tp-hint i { width: 14px; height: 14px; flex: 0 0 14px; margin-top: 2px; }

/* -------------------------------- responsive ------------------------------ */
/* On a phone the picked panel has to stay SMALL, otherwise it eats the grid.
   Keep the two inputs side by side, drop their help lines (the placeholder and
   the min/max already say it), and shrink the header + estimate. */
@media (max-width: 720px) {
  .modal.wide { max-width: 100%; max-height: 94vh; }
  .modal.wide .modal-head { padding: 14px 14px 10px; }
  .modal.wide .modal-title p { display: none; }
  .modal.wide .modal-foot { padding: 12px 14px 14px; }
  .tool-form.tp-form { padding: 6px 14px 12px; gap: 9px; }

  .tp-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; min-height: 96px; }
  .tp-name { font-size: 9.5px; }
  .tp-bar { padding: 8px 10px; gap: 8px; }
  .tp-money { width: 100%; margin-left: 0; }
  .tp-acct b { max-width: 130px; }
  .tp-searchwrap input { padding: 8px 10px 8px 32px; }

  .tp-picked { padding: 9px; }
  .tp-picked-head { margin-bottom: 7px; }
  .tp-picked-head b { font-size: 12px; }
  .tp-chips { gap: 6px; padding-bottom: 4px; }
  .tp-chip { max-width: 150px; }
  .tp-chip-name { font-size: 11px; }
  .tp-inputs { grid-template-columns: 1fr 1fr; gap: 9px; }
  .tp-inputs .fhelp { display: none; }
  .tp-inputs label { margin-bottom: 4px; font-size: 11.5px; }
  .tp-inputs input { padding: 8px 10px; }
  .tp-est { margin-top: 9px; padding: 7px 9px; font-size: 11px; line-height: 1.5; }
}
/* short/landscape phones: trim the panel further, the grid needs the room */
@media (max-height: 620px) {
  .modal.wide .modal-title p { display: none; }
  .tp-picked-head { margin-bottom: 7px; }
  .tp-chip .tp-frame.mini { width: 24px; flex: 0 0 24px; }
  .tp-est { margin-top: 8px; padding: 6px 9px; }
  .tp-inputs .fhelp { display: none; }
}
@media (max-width: 380px) {
  .tp-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .tp-plus { font-size: 10px; padding: 0 4px; }
  .tp-coin, .tp-gem { font-size: 12px; padding: 4px 9px; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 14px 16px; gap: 10px; }
  .topbar-right { flex-wrap: wrap; gap: 6px; }
  .stat-pill { padding: 6px 10px; font-size: 12px; }
  .layout { padding: 14px; gap: 14px; }
  .brand-text h1 { font-size: 17px; }
  .brand-text p { display: none; }
  .modal { max-width: 100%; margin: 0 10px; }
  .result-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .job-head { flex-wrap: wrap; }
  .pager { flex-direction: column; gap: 8px; }
  .gate-card { padding: 26px 18px; }
  .gate-code { font-size: 21px; letter-spacing: 1px; }
}
