:root {
  --bg: #0a0e16;
  --glass: rgba(12, 17, 28, 0.78);
  --glass-strong: rgba(12, 17, 28, 0.92);
  --panel2: rgba(28, 37, 58, 0.85);
  --line: rgba(120, 140, 180, 0.22);
  --text: #e6ecf5;
  --muted: #93a0b6;
  --accent: #ffd23f;
  --accent-dim: #8a7320;
  --good: #3ddc97;
  --bad: #ff5d5d;
  --warn: #ffb347;
  --blue: #4cc9f0;
  --radius: 12px;
  --panel-w: 390px;
  --top: 62px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
h3 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
button { font-family: inherit; color: inherit; cursor: pointer; }
kbd { font-family: 'JetBrains Mono', monospace; font-size: 11px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }
.pos { color: var(--good) !important; }
.neg { color: var(--bad) !important; }
.warn { color: var(--warn) !important; }

#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; touch-action: none; }

/* ---------- glass HUD ---------- */
.topbar, .hud-left .card, .panel, .hud-map, .hint, .inspect, .ticker, .chip, .toast, .modal-box {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20; height: var(--top);
  display: flex; align-items: center; gap: 14px; padding: 6px 12px;
  background: linear-gradient(180deg, rgba(8, 12, 20, 0.9), rgba(8, 12, 20, 0.65));
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 19px; white-space: nowrap; letter-spacing: -0.02em; }
.bolt { color: var(--accent); filter: drop-shadow(0 0 6px rgba(255, 210, 63, 0.6)); }
.stats { display: flex; gap: 6px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.stat {
  display: flex; flex-direction: column; min-width: 112px; flex: 1;
  background: rgba(20, 28, 44, 0.7); border: 1px solid var(--line); border-radius: 9px; padding: 3px 10px;
}
.stat.wide { flex: 1.6; min-width: 175px; }
.stat .label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.stat .value { font-size: 15px; font-weight: 600; white-space: nowrap; }
.stat .sub { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.meter { height: 3px; background: var(--line); border-radius: 2px; margin-top: 3px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--good); transition: width 0.3s, background 0.3s; }

.hud-chips { position: fixed; top: calc(var(--top) + 8px); left: 324px; right: calc(var(--panel-w) + 24px); z-index: 15; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.hud-chips > * { pointer-events: auto; }
#hud-events { display: contents; }
.chip {
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; font-size: 12px; white-space: nowrap;
}
.chip.event { border-color: rgba(255, 179, 71, 0.6); }
.chip.goal { border-color: rgba(255, 210, 63, 0.5); color: #ffe9a0; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- left column ---------- */
.hud-left {
  position: fixed; top: calc(var(--top) + 8px); left: 10px; width: 304px; z-index: 15;
  display: flex; flex-direction: column; gap: 8px;
  max-height: calc(100vh - var(--top) - 290px); overflow-y: auto; scrollbar-width: thin;
}
.card { background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
details.card > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.card > summary::after { content: '▾'; color: var(--muted); transition: transform 0.2s; }
details.card:not([open]) > summary::after { transform: rotate(-90deg); }
details.card[open] > summary { margin-bottom: 8px; }

.crank-card { display: flex; gap: 12px; align-items: center; padding: 8px 12px; }
.crank {
  width: 64px; height: 64px; flex: none; border-radius: 50%;
  border: 2px solid var(--accent-dim); background: radial-gradient(circle at 35% 30%, #2a3554, #121a2c);
  padding: 0; transition: transform 0.08s, box-shadow 0.2s;
}
.crank:hover { box-shadow: 0 0 18px 2px rgba(255, 210, 63, 0.3); }
.crank:active { transform: scale(0.93); }
.crank svg { width: 100%; height: 100%; }
.crank-ring { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 5; }
.crank-arm { fill: var(--accent); transform-origin: 50px 50px; transition: transform 0.25s cubic-bezier(.3, 1.6, .5, 1); }
.crank-hub { fill: #fff3c4; }
.crank-info h3 { margin: 0; font-size: 14px; }
.crank-info p { margin: 2px 0; }
.float-text {
  position: fixed; pointer-events: none; z-index: 50; font-weight: 700; color: var(--accent);
  font-family: 'JetBrains Mono', monospace; font-size: 14px; text-shadow: 0 1px 4px #000;
  animation: floatUp 0.9s ease-out forwards;
}
@keyframes floatUp { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -50px); } }

.status-line { padding: 7px 9px; border-radius: 8px; background: var(--panel2); margin-bottom: 8px; font-size: 12.5px; line-height: 1.4; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 12.5px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { text-align: right; }

.disp-row { display: grid; grid-template-columns: 20px 1fr 80px; gap: 6px; align-items: center; margin: 4px 0; font-size: 12px; }
.disp-bar { height: 6px; border-radius: 3px; background: var(--line); position: relative; overflow: hidden; margin-top: 2px; }
.disp-bar .avail { position: absolute; inset: 0 auto 0 0; opacity: 0.25; }
.disp-bar .used { position: absolute; inset: 0 auto 0 0; }
.disp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.disp-val { text-align: right; }
.disp-sep { border-top: 1px dashed var(--line); margin: 6px 0; }
.chart { width: 100%; height: 120px; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 3px 8px; margin-top: 4px; font-size: 10.5px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 3px; }

/* ---------- right panel ---------- */
.panel {
  position: fixed; top: calc(var(--top) + 8px); right: 10px; bottom: 44px; width: var(--panel-w); z-index: 18;
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; transition: transform 0.3s ease;
}
.panel.collapsed { transform: translateX(calc(100% + 14px)); }
.panel-toggle {
  position: absolute; left: -34px; top: 10px; width: 28px; height: 44px; border-radius: 8px 0 0 8px;
  background: var(--glass-strong); border: 1px solid var(--line); border-right: none; font-size: 16px;
}
.panel.collapsed .panel-toggle { transform: scaleX(-1); border-radius: 0 8px 8px 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 6px 6px 0; overflow-x: auto; scrollbar-width: none; flex: none; }
.tab { background: none; border: none; padding: 9px 10px; border-radius: 8px 8px 0 0; color: var(--muted); font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.tab:hover { color: var(--text); background: var(--panel2); }
.tab.active { color: var(--text); background: var(--panel2); box-shadow: inset 0 -2px 0 var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #111; font-size: 11px; font-weight: 700; text-align: center; }
.badge:empty { display: none; }
.tab-body { padding: 10px; overflow-y: auto; flex: 1; scrollbar-width: thin; }
.pane { display: none; }
.pane.active { display: block; }
.buy-amt { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.buy-amt button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; font-size: 12px; }
.buy-amt button.active { border-color: var(--accent); color: var(--accent); }
.section-title { margin: 14px 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.item { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin-bottom: 7px; transition: border-color 0.2s; }
.item.can { border-color: rgba(255, 210, 63, 0.45); }
.item.placing { border-color: var(--good); box-shadow: 0 0 0 1px var(--good) inset; }
.item-head { display: flex; align-items: center; gap: 9px; }
.item .ico { font-size: 26px; line-height: 1; width: 34px; text-align: center; flex: none; }
.item .name { font-weight: 600; font-size: 14.5px; flex: 1; }
.item .count { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 13px; background: rgba(255, 255, 255, 0.07); border-radius: 6px; padding: 1px 7px; }
.item .desc { color: var(--muted); font-size: 12px; margin: 5px 0; line-height: 1.35; }
.specs { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 10.5px; padding: 2px 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); color: #c4cede; white-space: nowrap; font-family: 'JetBrains Mono', monospace; }
.tag.green { background: rgba(61, 220, 151, 0.12); color: var(--good); }
.tag.red { background: rgba(255, 93, 93, 0.12); color: #ff9b9b; }
.tag.yellow { background: rgba(255, 210, 63, 0.12); color: var(--accent); }
.tag.blue { background: rgba(76, 201, 240, 0.12); color: var(--blue); }
.item .actions { display: flex; gap: 5px; margin-top: 8px; }
.item .actions .btn { flex: 1; }
.btn {
  background: var(--accent); color: #17130a; border: none; border-radius: 8px; padding: 7px 10px;
  font-weight: 700; font-size: 12.5px; white-space: nowrap; transition: filter 0.15s, transform 0.08s;
}
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { background: #2b3448; color: #6f7b92; cursor: not-allowed; }
.btn.alt { background: #2f6fb0; color: #fff; }
.btn.good { background: var(--good); color: #062; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); font-weight: 500; flex: 0 0 auto !important; }
.btn.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.btn.danger { background: var(--bad); color: #fff; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.item.locked { opacity: 0.55; border-style: dashed; }
.item.locked .ico { filter: grayscale(1); }
.fact { font-size: 11px; color: #7f8ba0; font-style: italic; margin-top: 5px; }

.upg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.upg { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 5px; }
.upg.can { border-color: rgba(255, 210, 63, 0.45); }
.upg.locked { opacity: 0.5; border-style: dashed; }
.upg-head { display: flex; gap: 6px; align-items: center; font-weight: 600; font-size: 13px; }
.upg-head .ico { font-size: 19px; }
.upg .desc { color: var(--muted); font-size: 11.5px; flex: 1; }
.owned-upgs { display: flex; flex-wrap: wrap; gap: 4px; }
.owned-upgs span { font-size: 17px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; cursor: help; }
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.ach { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 11.5px; }
.ach b { display: block; font-size: 12.5px; }
.ach.got { border-color: rgba(61, 220, 151, 0.5); }
.ach.got b::before { content: '🏆 '; }
.ach:not(.got) { opacity: 0.5; }
.stat-table { display: grid; grid-template-columns: 1fr auto; gap: 3px 14px; font-size: 12.5px; }
.stat-table span:nth-child(odd) { color: var(--muted); }
.legacy-box { background: linear-gradient(135deg, rgba(199, 125, 255, 0.14), rgba(76, 201, 240, 0.08)); border: 1px solid rgba(199, 125, 255, 0.35); border-radius: 12px; padding: 14px; }
.legacy-big { font-size: 32px; font-weight: 700; color: #d9a6ff; }
.lm-list { display: grid; gap: 5px; }
.lm { display: flex; gap: 8px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12.5px; }
.lm.got { border-color: rgba(255, 210, 63, 0.4); }
.lm .ico { font-size: 18px; width: 24px; text-align: center; }
.save-text { width: 100%; min-height: 60px; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 11px; resize: vertical; user-select: text; }
.howto { padding-left: 18px; color: #c4cede; line-height: 1.5; font-size: 12.5px; }
.howto li { margin-bottom: 5px; }
.controls-grid { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 12.5px; margin-bottom: 14px; align-items: center; }

/* ---------- minimap ---------- */
.hud-map {
  position: fixed; left: 10px; bottom: 44px; z-index: 15;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px;
}
#minimap { display: block; width: 200px; height: 200px; border-radius: 8px; cursor: crosshair; }
.map-tools { display: flex; gap: 5px; margin-top: 6px; align-items: center; }
.map-btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; font-size: 16px; padding: 3px 8px; }
.map-btn.on { border-color: var(--accent); box-shadow: 0 0 10px rgba(255, 210, 63, 0.4); }
#disc-count { margin-left: auto; }

/* ---------- hint & inspector ---------- */
.hint {
  position: fixed; top: calc(var(--top) + 48px); left: 50%; transform: translateX(-50%); z-index: 25;
  background: var(--glass-strong); border: 1px solid var(--good); border-radius: 10px; padding: 8px 14px;
  font-size: 13px; max-width: min(620px, calc(100vw - 32px)); text-align: center; pointer-events: none;
}
.hint.bad { border-color: var(--bad); }
.hint.hidden, .inspect.hidden { display: none; }
.inspect {
  position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%); z-index: 25;
  width: min(440px, calc(100vw - 24px)); background: var(--glass-strong); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  animation: popIn 0.2s ease-out;
}
.inspect.discovery { border-color: var(--accent); box-shadow: 0 0 40px rgba(255, 210, 63, 0.25); }
.inspect h3 { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.inspect .close { margin-left: auto; background: none; border: none; color: var(--muted); font-size: 18px; }
.inspect p { margin: 6px 0; font-size: 13px; line-height: 1.45; color: #cdd6e4; }
@keyframes popIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- ticker, toasts, modal ---------- */
.ticker {
  position: fixed; bottom: 0; left: 0; right: 0; height: 34px; z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: rgba(8, 12, 20, 0.85); border-top: 1px solid var(--line); font-size: 13px; overflow: hidden;
}
.ticker-tag { background: var(--accent); color: #111; font-weight: 700; font-size: 11px; padding: 2px 6px; border-radius: 4px; flex: none; }
.ticker-track { overflow: hidden; white-space: nowrap; flex: 1; }
#ticker-text { display: inline-block; transition: opacity 0.4s; }
#toasts { position: fixed; right: calc(var(--panel-w) + 26px); bottom: 50px; z-index: 40; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; max-width: min(360px, calc(100vw - 32px)); pointer-events: none; }
body.panel-hidden #toasts { right: 20px; }
body.panel-hidden .hud-chips { right: 20px; }
.toast {
  background: var(--glass-strong); border: 1px solid var(--line); border-left: 4px solid var(--blue);
  border-radius: 8px; padding: 7px 11px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); animation: toastIn 0.3s ease-out;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.toast.event { border-left-color: var(--warn); }
.toast.ach { border-left-color: var(--accent); }
.toast.out { opacity: 0; transform: translateX(20px); transition: all 0.4s; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal.hidden { display: none; }
.modal-box { background: var(--glass-strong); border: 1px solid var(--line); border-radius: 16px; padding: 22px; max-width: 520px; width: 100%; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal-box h2 { margin: 0 0 10px; }
.modal-box p, .modal-box li { line-height: 1.5; color: #cdd6e4; }

#loading { position: fixed; inset: 0; z-index: 100; background: radial-gradient(circle at 50% 40%, #16223a, #070a12); display: flex; flex-direction: column; align-items: center; justify-content: center; transition: opacity 0.6s; }
#loading.done { opacity: 0; pointer-events: none; }
.load-brand { font-size: 42px; font-weight: 700; }
#load-msg { color: var(--muted); }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  :root { --panel-w: 100vw; --top: 54px; }
  .brand { display: none; }
  .stat { min-width: 98px; }
  .stat .value { font-size: 13px; }
  .hud-left { width: auto; right: auto; max-height: none; overflow: visible; }
  .hud-left details { display: none; }
  .crank-card { padding: 6px 10px; }
  .crank-info .tiny { display: none; }
  .hud-chips { left: 10px; right: 10px; top: calc(var(--top) + 90px); }
  .panel { top: auto; left: 0; right: 0; bottom: 34px; height: 46vh; width: auto; border-radius: 14px 14px 0 0; }
  .panel.collapsed { transform: translateY(calc(100% - 44px)); }
  .panel-toggle { left: auto; right: 10px; top: -36px; width: 44px; height: 32px; border-radius: 8px 8px 0 0; border-right: 1px solid var(--line); border-bottom: none; transform: rotate(90deg); }
  .panel.collapsed .panel-toggle { transform: rotate(-90deg); border-radius: 8px 8px 0 0; }
  .hud-map { top: calc(var(--top) + 8px); right: 10px; left: auto; bottom: auto; padding: 4px; }
  #minimap { width: 110px; height: 110px; }
  #toasts { right: 10px; bottom: calc(46vh + 44px); }
  .inspect { bottom: calc(46vh + 44px); }
  .panel.collapsed ~ .inspect { bottom: 90px; }
}
