:root {
  --bg: rgba(23, 23, 23, 0.94);
  --bg2: rgba(255, 255, 255, 0.05);
  --bg3: rgba(255, 255, 255, 0.09);
  --line: #2a2a2a;
  --line2: #383838;
  --txt: #ffffff;
  --muted: #a3a3a3;
  --dim: #7a7a7a;
  --accent: #eaeaea;
  --accent_text: #171717;
  --warn: #fbbf24;
  --bad: #f47067;
  --good: #4ade80;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0f0f0f; color: var(--txt); font: 13px/1.45 var(--font); -webkit-font-smoothing: antialiased; user-select: none; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #4a4a4a; background-clip: padding-box; border: 2px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }

#cross { position: fixed; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; pointer-events: none !important; }
#cross::before, #cross::after { content: ''; position: absolute; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.55); border-radius: 1px; }
#cross::before { left: 10px; top: 4px; width: 2px; height: 14px; }
#cross::after { top: 10px; left: 4px; height: 2px; width: 14px; }
body.menu-open:not(.is-locked) #cross { display: none; }
body:not(.playing) #cross, body:not(.playing) #toolbar, body:not(.playing) #stats, body:not(.playing) #coords { display: none; }

.chip { position: fixed; background: rgba(23, 23, 23, 0.82); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-size: 12px; color: var(--txt); pointer-events: none !important; font-variant-numeric: tabular-nums; }
#stats { left: 12px; top: 12px; line-height: 1.5; font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
#coords { left: 50%; top: 12px; transform: translateX(-50%); font-family: var(--mono); font-weight: 600; letter-spacing: .2px; }
#pathbar { left: 50%; bottom: 74px; transform: translateX(-50%); border-color: rgba(244, 112, 103, .5); color: #ffd0d0; }
body.hud-off #stats, body.hud-off #coords, body.hud-off #toolbar { display: none; }

#toolbar { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 6px; padding: 6px; background: rgba(23, 23, 23, 0.9); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 10px; }
.tb { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #202020; color: #e9e9e9; padding: 7px 12px; border-radius: 7px; cursor: pointer; font: 600 12px var(--font); transition: background .12s, border-color .12s; }
.tb:hover { background: #282828; border-color: #404040; }
.tb.on { background: var(--accent); color: var(--accent_text); border-color: var(--accent); }
kbd { font: 600 10px var(--mono); padding: 1px 6px; border-radius: 4px; background: #111; color: var(--muted); border: 1px solid var(--line); }
.tb.on kbd { color: var(--accent_text); background: rgba(0,0,0,0.12); border-color: transparent; }

.card { background: var(--bg); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.4); }
#info { position: fixed; left: 14px; bottom: 14px; width: 310px; max-height: 70vh; overflow: auto; padding: 12px 14px; pointer-events: none !important; }
#info .ttl { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
#info .kv { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; font-size: 12px; }
#info .kv span { color: var(--muted); }
#info .badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; background: var(--bg3); margin-left: 6px; vertical-align: 1px; }
#info .minigrid { margin-top: 8px; }
#info .hintline { color: var(--dim); font-size: 11px; margin-top: 8px; }

#toast { position: fixed; top: 56px; left: 50%; transform: translateX(-50%); background: rgba(23,23,23,.96); border: 1px solid var(--line2); padding: 8px 15px; border-radius: 8px; font-weight: 600; pointer-events: none !important; box-shadow: 0 8px 30px rgba(0,0,0,.45); }

.panel { position: fixed; top: 12px; bottom: 12px; display: flex; flex-direction: column; background: var(--bg); backdrop-filter: blur(16px); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 14px 50px rgba(0,0,0,.5); max-width: calc(100vw - 24px); }
.panel.right { right: 12px; }
.panel.left { left: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px 10px; border-bottom: 1px solid var(--line); }
.panel-title { font-size: 14px; font-weight: 700; }
.panel-body { padding: 6px 14px 16px; overflow: auto; flex: 1; user-select: text; }
.icon-btn { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: #202020; color: #e9e9e9; font-size: 17px; line-height: 1; cursor: pointer; }
.icon-btn:hover { background: #282828; border-color: #404040; }

.sec-title { margin: 16px 0 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--dim); }
.note { color: var(--muted); font-size: 12px; margin: 6px 0; line-height: 1.5; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; min-height: 34px; }
.row-label { flex: 1; min-width: 0; }
.hint { color: var(--dim); font-size: 11px; margin-top: 1px; }

.btn { border: 1px solid #343434; background: #202020; color: #e9e9e9; padding: 7px 13px; border-radius: 7px; font: 600 12px var(--font); cursor: pointer; transition: background .12s, border-color .12s; }
.btn:hover { background: #282828; border-color: #404040; }
.btn.primary { background: var(--accent); color: var(--accent_text); border-color: var(--accent); }
.btn.primary:hover { background: #fff; border-color: #fff; }
.btn.danger { background: rgba(244, 112, 103, .12); color: #ff9a92; border-color: rgba(244, 112, 103, .3); }
.btn.danger:hover { background: rgba(244, 112, 103, .22); }
.btn.sm { padding: 4px 9px; font-size: 11px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.switch { width: 38px; height: 21px; border-radius: 99px; border: 1px solid var(--line2); background: #2a2a2a; position: relative; cursor: pointer; transition: background .15s; flex-shrink: 0; padding: 0; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #bbb; transition: transform .15s, background .15s; }
.switch.on { background: var(--accent); border-color: var(--accent); }
.switch.on .knob { transform: translateX(17px); background: #171717; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; }
.cbox { width: 17px; height: 17px; border-radius: 4px; border: 1.5px solid #4a4a4a; background: #1c1c1c; position: relative; flex-shrink: 0; transition: background .12s, border-color .12s; }
.check.on .cbox { background: var(--accent); border-color: var(--accent); }
.check.on .cbox::after { content: ''; position: absolute; left: 5px; top: 1px; width: 4px; height: 9px; border: solid #171717; border-width: 0 2px 2px 0; transform: rotate(45deg); }

.slider-box { display: flex; align-items: center; gap: 10px; }
.range { -webkit-appearance: none; appearance: none; width: 120px; height: 5px; border-radius: 99px; outline: none; background: linear-gradient(to right, var(--accent) var(--p, 50%), #333 var(--p, 50%)); cursor: pointer; }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0,0,0,.6); }
.range::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: #fff; border: 0; }
.num, .txt { background: #141414; color: var(--txt); border: 1px solid var(--line2); border-radius: 6px; padding: 6px 8px; font: 12px var(--font); outline: none; transition: border-color .12s, background .12s; user-select: text; }
.num { width: 62px; text-align: right; -moz-appearance: textfield; font-family: var(--mono); }
.num.wide { width: 110px; }
.txt { width: 170px; }
.txt.full { width: 100%; padding: 9px 11px; font-size: 13px; }
.num::-webkit-outer-spin-button, .num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num:hover, .txt:hover { border-color: #4a4a4a; }
.num:focus, .txt:focus { border-color: #8a8a8a; background: #101010; }
.txt::placeholder { color: var(--dim); }

.select { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 140px; max-width: 220px; background: #141414; border: 1px solid var(--line2); border-radius: 6px; padding: 6px 10px; color: var(--txt); font: 12px var(--font); cursor: pointer; }
.select:hover { border-color: #4a4a4a; }
.sel-cur { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid var(--dim); flex-shrink: 0; }
.menu { position: fixed; z-index: 100; background: #181818; border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 12px 36px rgba(0,0,0,.6); padding: 4px; overflow: auto; pointer-events: auto; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; color: var(--txt); padding: 7px 10px; border-radius: 5px; font: 12px var(--font); cursor: pointer; white-space: nowrap; }
.menu-item:hover { background: var(--bg3); }
.menu-item.sel { color: #fff; font-weight: 700; background: var(--bg2); }

.tabs { display: flex; gap: 4px; padding: 4px; background: #121212; border: 1px solid var(--line); border-radius: 8px; margin: 8px 0 4px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 6px 8px; border-radius: 5px; font: 600 12px var(--font); cursor: pointer; }
.tab:hover { color: var(--txt); }
.tab.on { background: #2a2a2a; color: #fff; }

.results { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.res { display: flex; align-items: center; gap: 10px; padding: 7px 8px; background: #1c1c1c; border: 1px solid var(--line); border-radius: 8px; }
.res:hover { background: #222; }
.res img { width: 32px; height: 32px; image-rendering: pixelated; flex-shrink: 0; }
.res .grow { flex: 1; min-width: 0; }
.res .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res .ct { color: var(--dim); font-size: 11px; }
.res .acts { display: flex; gap: 6px; align-items: center; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; background: var(--bg3); }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; vertical-align: -1px; margin-right: 6px; }
.hl-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.hl-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #1c1c1c; border: 1px solid var(--line); border-radius: 8px; }
.hl-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.stat { background: #1c1c1c; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font-size: 14px; font-family: var(--mono); font-weight: 600; }
.stat span { color: var(--dim); font-size: 11px; }
.progress { height: 4px; background: #2a2a2a; border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .12s; }

.pack-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 6px 0; }
.pack { border: 1px solid var(--line); background: #1c1c1c; border-radius: 8px; padding: 6px; cursor: pointer; text-align: left; color: var(--txt); font: 600 12px var(--font); }
.pack:hover { background: #222; border-color: var(--line2); }
.pack.on { border-color: #fff; }
.pack .pv { width: 100%; aspect-ratio: 16/9; border-radius: 5px; background: #222 center/cover; margin-bottom: 5px; image-rendering: pixelated; }
.pack small { display: block; color: var(--dim); font-weight: 400; }
.keylist { margin: 4px 0 6px; }

#tip { position: fixed; z-index: 200; pointer-events: none !important; min-width: 160px; max-width: 320px; background: rgba(20, 8, 40, 0.96); border: 2px solid #3b1d6b; border-radius: 6px; padding: 8px 11px; box-shadow: 0 6px 24px rgba(0,0,0,.5), inset 0 0 0 1px rgba(160, 110, 255, .25); font-size: 12px; }
.tt-name { font-weight: 700; font-size: 14px; }
.tt-amt { color: var(--muted); font-weight: 600; font-size: 12px; }
.tt-dim { color: var(--muted); }
.tt-desc { margin-top: 3px; color: #d6d6d6; }
.tt-sec { margin-top: 6px; }
.tt-ench { color: #b9a0ff; }
.tt-stat { display: flex; justify-content: space-between; gap: 14px; color: #d6d6d6; }
.tt-stat b { color: #7ee0a0; font-weight: 600; }
.small { font-size: 11px; }

#modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); }
.win { background: #171717; border: 1px solid var(--line2); border-radius: 12px; box-shadow: 0 24px 80px rgba(0,0,0,.7); padding: 16px 18px 18px; max-width: 96vw; max-height: 96vh; overflow: auto; }
.win-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 8px; }
.win-title { font-size: 16px; font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(6, 68px); gap: 4px; padding: 8px; background: #101010; border: 1px solid var(--line); border-radius: 8px; width: max-content; }
.slot { box-sizing: content-box; width: 64px; height: 64px; position: relative; background: #1a1a1a; border: 2px solid #0c0c0c; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05), inset 0 3px 8px rgba(0,0,0,0.4); }
.slot:hover { background: #242424; border-color: #4a4a4a; }
.slot img { position: absolute; left: 0; top: 0; width: 64px; height: 64px; image-rendering: pixelated; pointer-events: none; }
.minigrid { grid-template-columns: repeat(6, 34px) !important; gap: 3px !important; padding: 5px !important; }
.minigrid .slot { width: 32px !important; height: 32px !important; border-width: 1px !important; }
.minigrid .slot img { width: 32px; height: 32px; }
.slot[style*='--tier'] { border-color: color-mix(in srgb, var(--tier) 70%, #0c0c0c); }
.slot.enchanted::after { content: ''; position: absolute; inset: 0; border-radius: 4px; pointer-events: none; background: linear-gradient(115deg, transparent 30%, rgba(190, 140, 255, 0.28) 50%, transparent 70%); background-size: 250% 100%; animation: shimmer 2.6s linear infinite; }
.slot.match { outline: 2px solid var(--warn); outline-offset: -2px; box-shadow: 0 0 14px rgba(251, 191, 36, .6); }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -100% 0; } }
.slot .n { position: absolute; right: 4px; bottom: 2px; font: 800 13px var(--font); color: #fff; text-shadow: 0 0 3px #000, 1px 1px 0 #000, -1px 1px 0 #000; }
.badge-tier { display: inline-block; padding: 2px 9px; border-radius: 99px; font-weight: 800; font-size: 11px; margin-left: 8px; color: #0a0a0a; vertical-align: 2px; }

#start { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(900px 520px at 50% 0%, rgba(255,255,255,.06), transparent), #0f0f0f; z-index: 50; }
.start-card { width: 460px; max-width: 92vw; background: #171717; border: 1px solid var(--line); border-radius: 12px; padding: 26px 26px 20px; box-shadow: 0 30px 90px rgba(0,0,0,.6); }
.logo { font-size: 24px; font-weight: 700; letter-spacing: -.3px; margin-bottom: 4px; }
.logo span { color: var(--dim); }
.start-sub { color: var(--muted); margin-bottom: 18px; font-size: 13px; }
.start-lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); font-weight: 700; margin-bottom: 7px; }
.start-help { color: var(--muted); font-size: 12px; margin: 9px 0 0; line-height: 1.5; }
.start-help.warn { color: var(--warn); }
.start-keys { color: var(--dim); font-size: 11.5px; margin-top: 14px; line-height: 1.55; }
#start .btn.primary { width: 100%; padding: 11px; font-size: 13.5px; margin-top: 14px; }
#loadmsg { color: var(--muted); font-size: 12px; margin-top: 12px; min-height: 16px; }
#loadmsg.err { color: #ff9a92; }
body.playing #start { display: none; }

#tint { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 1; }
body:not(.playing) #tint { display: none; }
.win.insp { width: min(680px, 94vw); max-height: 88vh; display: flex; flex-direction: column; }
.insp-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.insp-icon { width: 48px; height: 48px; image-rendering: pixelated; background: #101010; border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-sizing: content-box; }
.win-sub2 { color: var(--dim); font-size: 12px; margin-top: 2px; }
.insp-body { overflow-y: auto; padding: 4px 2px 6px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.isec { background: #1c1c1c; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-width: 0; }
.isec:has(.grid) { grid-column: 1 / -1; }
.isec-t { font-weight: 700; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); margin-bottom: 6px; }
.kvr { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; font-size: 12.5px; }
.kvr span { color: var(--muted); flex-shrink: 0; }
.kvr b { font-weight: 600; text-align: right; word-break: break-word; }
.idesc { color: #cfcfcf; font-size: 12px; margin-top: 6px; line-height: 1.45; }
@media (max-width: 640px) { .insp-body { grid-template-columns: 1fr; } }

.res.clickable { cursor: pointer; }
.res .chev { color: var(--dim); font-size: 11px; transition: transform .12s; }
.res.open .chev { transform: rotate(90deg); }
.occ-list { margin: -2px 0 6px 18px; display: flex; flex-direction: column; gap: 4px; }
.occ { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #141414; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; }
.occ img { width: 32px; height: 32px; image-rendering: pixelated; flex-shrink: 0; }
.occ .grow { flex: 1; min-width: 0; }
.occ .where { color: var(--dim); font-size: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.chip2 { background: rgba(179, 136, 255, .15); border: 1px solid rgba(179, 136, 255, .35); color: #e2d2ff; border-radius: 999px; padding: 1px 7px; font-size: 11px; font-weight: 600; }
.chip2.t { background: rgba(251, 191, 36, .13); border-color: rgba(251, 191, 36, .4); color: #ffe39a; }
.more-btn { align-self: flex-start; }
.hud-bar { height: 4px; background: #2a2a2a; border-radius: 99px; overflow: hidden; margin: 5px 0 3px; min-width: 140px; }
.hud-bar > div { height: 100%; background: var(--accent); transition: width .25s; }
#hp { position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%); width: 220px; height: 10px; padding: 2px; background: rgba(0,0,0,.55); border-radius: 99px; pointer-events: none; }
#hp > div { height: 100%; background: linear-gradient(90deg, #f47067, #fb9a5d); border-radius: 99px; transition: width .15s; }
