:root {
  --bg: #0a0d14;
  --ink: #eef1f6;
  --mute: #8b93a5;
  --rule: rgba(255, 255, 255, 0.1);
  --loss: #ff7433;
  --gain: #4ea8ff;
}

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

#app {
  position: relative;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 35%, #111725 0%, var(--bg) 70%);
  -webkit-user-select: none;
  user-select: none;
}

#ground, #gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#gl { touch-action: none; cursor: grab; }
#gl.drag { cursor: grabbing; }
#gl.point { cursor: pointer; }

.head {
  position: absolute;
  left: 24px;
  top: 18px;
  right: 280px;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(10, 13, 20, 0.9);
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mute);
}

h1 {
  margin: 6px 0 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
  transition: opacity 0.35s;
}

.sub {
  margin: 6px 0 0;
  max-width: 640px;
  font-size: 14px;
  line-height: 1.45;
  color: #aab2c3;
  transition: opacity 0.35s;
}

.fade { opacity: 0; }

.legend {
  position: absolute;
  right: 24px;
  top: 22px;
  width: 220px;
  font-size: 11px;
  color: var(--mute);
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(10, 13, 20, 0.9);
}

.legend .bar {
  height: 8px;
  border-radius: 2px;
  margin: 6px 0 4px;
}

.legend .ends { display: flex; justify-content: space-between; }
.legend .row { margin-top: 8px; display: flex; align-items: center; gap: 6px; }
.legend .crack { width: 10px; height: 10px; background: linear-gradient(135deg, #2a2420 50%, var(--loss) 50%); flex: none; }
.legend b { color: var(--ink); font-weight: 600; }

.chips {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(10, 13, 20, 0.78);
  max-width: calc(100% - 32px);
  overflow-x: auto;
  scrollbar-width: none;
}

.chips span {
  padding: 0 2px 0 8px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(139, 147, 165, 0.7);
  white-space: nowrap;
}

.chips button {
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  font: 600 12px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--mute);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}

.chips button:hover { color: var(--ink); }
.chips button.on { color: var(--bg); background: var(--ink); }
.chips .sep { width: 1px; height: 18px; margin: 0 2px; background: var(--rule); flex: none; }
.chips button.tour { color: var(--gain); }
.chips button.tour.on { color: var(--bg); background: var(--gain); }

.sel {
  position: absolute;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  padding: 5px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(10, 13, 20, 0.78);
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  max-width: calc(100% - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.sel[hidden] { display: none; }
.sel .m { color: var(--mute); }
.sel .dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--gain); box-shadow: 0 0 8px var(--gain); vertical-align: 1px; }

#gl:focus { outline: none; }

/* Palette swatches in the chips. */
.chips button.sw { flex: none; width: 16px; height: 16px; padding: 0; margin: 0 2px; border-radius: 50%; opacity: 0.5; }
.chips button.sw:hover { opacity: 0.9; }
.chips button.sw.on { opacity: 1; box-shadow: 0 0 0 2px rgba(10, 13, 20, 0.9), 0 0 0 3.5px var(--ink); }
.chips button.help-btn { padding: 6px 10px; }

/* Find: a search popover above the chips. */
.find {
  position: absolute;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: rgba(14, 18, 28, 0.97);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 5;
  overflow: hidden;
}
.find[hidden] { display: none; }
.find input {
  width: 100%;
  box-sizing: border-box;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 11px 14px;
  font: 500 14px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: transparent;
  outline: none;
}
.find ul { list-style: none; margin: 0; padding: 4px; max-height: 300px; overflow-y: auto; }
.find li { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 12.5px; }
.find li .n { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.find li .w { grid-row: 2; color: var(--mute); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.find li .v { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-variant-numeric: tabular-nums; }
.find li .neg { color: var(--loss); }
.find li .pos { color: var(--gain); }
.find li.on, .find li:hover { background: rgba(255, 255, 255, 0.07); }
.find li.none { display: block; color: var(--mute); cursor: default; }
.find li.none:hover { background: none; }

/* Help card. */
.help {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  overflow-y: auto;
  box-sizing: border-box;
  padding: 16px 18px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: rgba(14, 18, 28, 0.97);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  font-size: 12.5px;
  z-index: 6;
}
.help[hidden] { display: none; }
.help-h { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--mute); margin-bottom: 8px; }
.help table { border-collapse: collapse; width: 100%; }
.help td { padding: 3px 0; vertical-align: top; }
.help td:first-child { padding-right: 14px; white-space: nowrap; }
.help kbd {
  font: 600 11px ui-monospace, SFMono-Regular, Consolas, monospace;
  padding: 1px 6px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
}
.help-f { margin-top: 10px; color: var(--mute); line-height: 1.45; }

/* ---- Profit Run (game) ---- */
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#app.gaming .head, #app.gaming .legend, #app.gaming .sel, #app.gaming .foot { display: none; }
.chips button.play { color: var(--bg); background: var(--gain); }
.chips button.play:hover { color: var(--bg); filter: brightness(1.1); }

.game-hud { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.game-hud[hidden], .game-hud [hidden] { display: none !important; }
.gh-top {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  box-sizing: border-box;
  padding: 10px 16px 12px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: rgba(10, 13, 20, 0.82);
  text-align: center;
}
.gh-row { display: flex; justify-content: space-between; font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--mute); }
.gh-score { color: var(--gain); font-weight: 700; }
.gh-t { margin-top: 6px; font-size: 19px; font-weight: 700; line-height: 1.2; }
.gh-s { margin-top: 4px; font-size: 12.5px; color: #aab2c3; }
.gh-bar { margin-top: 9px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.gh-bar i { display: block; height: 100%; width: 100%; background: var(--gain); }
.gh-bar i.low { background: var(--loss); }
.gh-msg {
  position: absolute;
  left: 50%;
  top: 152px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  box-sizing: border-box;
  padding: 9px 14px;
  border-radius: 10px;
  background: rgba(10, 13, 20, 0.85);
  border: 1px solid var(--rule);
  font-size: 13.5px;
  line-height: 1.4;
  text-align: center;
}
.gh-msg.good { border-color: var(--gain); }
.gh-prompt {
  position: absolute;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: rgba(10, 13, 20, 0.8);
  font-size: 12.5px;
  color: #aab2c3;
  white-space: nowrap;
  max-width: calc(100% - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.gh-prompt.near { color: var(--bg); background: var(--gain); border-color: var(--gain); font-weight: 600; }
.gh-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(430px, calc(100% - 32px));
  box-sizing: border-box;
  padding: 20px 22px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: rgba(14, 18, 28, 0.96);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  font-size: 13.5px;
  line-height: 1.5;
}
.gc-k { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--mute); }
.gc-t { margin-top: 4px; font-size: 28px; font-weight: 800; letter-spacing: -0.01em; }
.gh-card p { margin: 10px 0 0; color: #c3cad8; }
.gh-card p.m { color: var(--mute); }
.gh-card p.hs { color: var(--gain); font-weight: 700; }
.gh-card ul { margin: 10px 0 0; padding-left: 18px; color: #c3cad8; }
.gh-card li { margin-top: 4px; }
.gh-card b { color: var(--ink); }
.gc-b { display: flex; gap: 8px; margin-top: 16px; }
.gc-b button {
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  font: 700 13px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
}
.gc-b .go { color: var(--bg); background: var(--gain); }
.gc-b .back { color: var(--ink); background: rgba(255, 255, 255, 0.08); }

@media (max-width: 640px) {
  .gh-t { font-size: 15px; }
  .gh-s { display: none; }
  .gh-msg { top: 112px; font-size: 12.5px; }
  .gh-prompt { bottom: 56px; }
}

/* Toast for key toggles. */
.flash {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(14, 18, 28, 0.9);
  border: 1px solid var(--rule);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 6;
}
.flash.on { opacity: 1; }

.tip {
  position: absolute;
  pointer-events: none;
  padding: 9px 11px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: rgba(14, 18, 28, 0.95);
  font-size: 12px;
  line-height: 1.45;
  max-width: 280px;
  z-index: 3;
}

.tip[hidden] { display: none; }
.tip b { display: block; font-size: 13px; line-height: 1.3; }
.tip .m { color: var(--mute); }
.tip .neg { color: var(--loss); }
.tip .pos { color: var(--gain); }
.tip table { border-collapse: collapse; margin-top: 5px; }
.tip td { padding: 1px 0; white-space: nowrap; }
.tip td + td { padding-left: 14px; text-align: right; font-variant-numeric: tabular-nums; }

.end {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 13, 20, 0.72);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.end[hidden] { display: none; }
.end-in { text-align: center; padding: 0 24px; }
.end-k { font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--mute); }
.end-t { margin-top: 12px; font-size: 34px; font-weight: 700; letter-spacing: -0.01em; }
.end-s { margin-top: 10px; font-size: 14px; color: var(--mute); }

.foot {
  position: absolute;
  right: 24px;
  bottom: 22px;
  font-size: 10px;
  color: rgba(139, 147, 165, 0.6);
  pointer-events: none;
}

.error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--mute);
  font-size: 14px;
  padding: 24px;
  text-align: center;
}

@media (max-width: 1000px) {
  .foot { display: none; }
}

/* Narrow sheets: legend moves above the chips, type shrinks. */
@media (max-width: 640px) {
  .head { left: 16px; right: 16px; top: 14px; }
  h1 { font-size: 20px; }
  .sub { font-size: 12.5px; }
  .kicker { font-size: 10px; letter-spacing: 0.1em; }
  .legend { left: 16px; right: 16px; top: auto; bottom: 62px; width: auto; }
  .legend .row { display: none; }
  .legend .bar { height: 6px; }
  .sel { bottom: 128px; }
  .find { bottom: 128px; }
  .chips { bottom: 12px; gap: 0; }
  .chips span { display: none; }
  .chips button { padding: 6px 8px; font-size: 11.5px; }
}
