:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --fg: #2b2b2b;
  --muted: #8a8a85;
  --line: #e2e2de;
  --accent: #5a6b7b;
  --ok: #4f6b57;
  --err: #8a5050;
  --warn: #7a6a40;
  --wip: #66608f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1c1d;
    --panel: #222324;
    --fg: #c9c9c6;
    --muted: #707270;
    --line: #333536;
    --accent: #8697a6;
    --ok: #86a08c;
    --err: #b08080;
    --warn: #ab9a6e;
    --wip: #9d96c6;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 12px/1.5 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}

header {
  display: flex;
  justify-content: space-between;
  padding: 6px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

main {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 400px;
  gap: 16px;
  padding: 16px;
  max-width: 1700px;
}
@media (max-width: 1000px) {
  main { grid-template-columns: 200px minmax(0, 1fr); }
  #side { grid-column: 1 / -1; }
}
/* side panel: skills / prestige shop / essence shop as tabs (desktop) */
#stabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
#stabs button {
  border: 0; border-bottom: 1px solid transparent; margin-bottom: -1px;
  background: none; color: var(--muted); padding: 2px 10px 3px;
}
#stabs button:first-child { padding-left: 0; }
#stabs button:hover { color: var(--fg); }
#stabs button.on { color: var(--fg); border-bottom-color: var(--accent); }
#s-new, #p-new, #m-pnew { margin-left: 4px; }
#s-new::before, #p-new::before, #m-pnew::before { content: '·'; margin-right: 2px; }
#stabs button[data-stab=prestige][hidden], #mtabs button[hidden], #shop[hidden] { display: none !important; }
@media (min-width: 641px) {
  #side > section { display: none; }
  body[data-stab=skills] #skills, body[data-stab=prestige] #shop, body[data-stab=essence] #essence { display: block; }
}
@media (max-width: 640px) {
  main { grid-template-columns: minmax(0, 1fr); }
}
#p-hpbar .bar { display: block; max-width: none; }
#slot-count { float: right; }
#slots { margin-bottom: 16px; }
.sub { font-size: 11px; }
#skills td { vertical-align: top; white-space: normal; }
#skills td:last-child { text-align: right; }
#skills .grid tr:first-child { border-top: 0; }

h2 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: normal;
  color: var(--muted);
  text-transform: lowercase;
  border-bottom: 1px solid var(--line);
}
h2:not(:first-child) { margin-top: 16px; }

table { border-collapse: collapse; width: 100%; }
td, th { padding: 2px 6px; text-align: left; white-space: nowrap; }
th { font-weight: normal; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.kv td:first-child { color: var(--muted); }
.grid tbody tr { border-top: 1px solid var(--line); }
.grid tr.active { background: color-mix(in srgb, var(--accent) 10%, transparent); }

button {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 0 8px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { color: var(--muted); cursor: default; }
button.quiet { border-color: transparent; color: var(--muted); }

#proc {
  min-height: 60px;
  padding: 4px 6px;
  background: var(--panel);
  border: 1px solid var(--line);
}
#proc .row { display: flex; gap: 8px; align-items: center; }
#proc .k { width: 40px; color: var(--muted); }
#proc .v { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }

.bar {
  flex: 1;
  max-width: 300px;
  height: 4px;
  background: var(--line);
  position: relative;
}
.bar > span {
  position: absolute; inset: 0 auto 0 0;
  background: var(--accent);
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.controls label { color: var(--muted); }
input[type=checkbox] { accent-color: var(--accent); margin: 0 4px 0 0; vertical-align: -2px; }
.spacer { flex: 1; }

#log {
  height: 220px;
  overflow-y: auto;
  padding: 4px 6px;
  background: var(--panel);
  border: 1px solid var(--line);
}
#log > div { white-space: pre-wrap; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.err { color: var(--err); }
.warn { color: var(--warn); }
/* slots, library and special share the same columns: slot #, id, name, effects, action */
#slots, #library, #special { table-layout: fixed; }
#skills col.c-n { width: 20px; }
#skills col.c-id { width: 40px; }
#skills col.c-name { width: 108px; }
#skills col.c-act { width: 70px; }
#skills td { padding: 2px 4px; }
#skills td:nth-child(3) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Formula tooltip, shown on hover only */
.tip { border-bottom: 1px dotted var(--muted); cursor: help; position: relative; }
.tip:hover::after {
  content: attr(data-tip);
  position: absolute; right: 0; top: 100%; z-index: 10;
  margin-top: 2px; padding: 2px 6px;
  white-space: pre;
  color: var(--fg); background: var(--panel);
  border: 1px solid var(--line);
  font-size: 11px;
}

/* Attribute breakdown */
.q {
  display: inline-block; width: 12px; height: 12px; line-height: 11px;
  font-size: 9px; text-align: center; cursor: help;
  color: var(--muted); border: 1px solid var(--line); border-radius: 50%;
  vertical-align: 1px; margin-left: 2px;
}
.q:hover { color: var(--fg); border-color: var(--accent); }
#popup {
  position: absolute; z-index: 20; min-width: 200px;
  padding: 4px 6px; background: var(--panel);
  border: 1px solid var(--line); font-size: 11px;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
  pointer-events: none;
}
#popup[hidden] { display: none; }
#popup td { padding: 0 4px; }
#popup td:first-child { color: var(--muted); }
#popup tr.sep td, #popup tr.total td { border-top: 1px solid var(--line); }
#popup tr.total td { color: var(--fg); }
#popup tr.head td { color: var(--fg); padding-top: 4px; }
.lvl { line-height: 1.45; display: flex; gap: 1ch; }
.lvl .lv { flex: none; }
.lvl .parts { min-width: 0; }
#popup tr.grp td { color: var(--fg); padding-top: 2px; }
#popup tr.sub td:first-child { padding-left: 14px; }
#p-mpbar .bar { display: block; max-width: none; }
#proc .row > span:last-child.muted { margin-left: 4px; }
#library { margin-bottom: 16px; }
#library button.auto { margin-top: 2px; white-space: nowrap; padding-left: 4px; padding-right: 4px; }
#library button.auto:not(.on) { border-color: transparent; color: var(--muted); }
#special { margin-bottom: 8px; }
.scroll-x { overflow-x: auto; }
#targets td:nth-child(3) { white-space: normal; min-width: 70px; }
#targets tr.tier-start { border-top: 1px solid var(--muted); }

/* ---------- top band ---------- */
header { align-items: center; gap: 0; padding: 0 16px; }
header .logo {
  width: 200px; padding: 6px 0;
  letter-spacing: 0.15em; color: var(--accent);
}
header nav { display: flex; }
header nav a {
  padding: 6px 12px; color: var(--muted); text-decoration: none;
  border-bottom: 1px solid transparent; margin-bottom: -1px;
}
header nav a:hover { color: var(--fg); }
header nav a.on { color: var(--fg); border-bottom-color: var(--accent); }
main[hidden], .dev-view[hidden] { display: none; }
@media (max-width: 640px) { header .logo { width: auto; padding-right: 12px; } }

/* ---------- dev screen ---------- */
.dev-view { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; max-width: 1400px; }
#view-dev-skills, #view-dev-shop { grid-template-columns: minmax(0, 1000px); }
h3.dp-shop { font-size: inherit; font-weight: normal; margin: 12px 0 4px; color: var(--fg); }
h3.dp-shop:first-child { margin-top: 0; }
details.en.retired > summary { color: var(--muted); }
.dev-view input.w-v { width: 70px; }
#dp-list select, #de-power select { max-width: 220px; }
@media (max-width: 1000px) { .dev-view { grid-template-columns: minmax(0, 1fr); } }
.dev-side { position: sticky; top: 8px; align-self: start; background: var(--panel); border: 1px solid var(--line); padding: 4px 8px 8px; }
.dev-side .kv td.num { text-align: right; }
.dev-banner { margin: 8px 16px 0; padding: 4px 8px; border: 1px solid var(--err); color: var(--err); background: var(--panel); }
.dev-banner[hidden] { display: none; }
.gh-bar { margin: 8px 16px 0; padding: 4px 8px; border: 1px solid var(--line); background: var(--panel); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.gh-bar[hidden] { display: none; }
.gh-bar input { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); padding: 0 4px; height: 18px; }
.gh-bar input:focus { outline: none; border-color: var(--accent); }
.gh-bar #gh-message { width: 240px; }
.gh-bar #gh-token { width: 260px; }
.gh-bar #gh-msg { flex-basis: 100%; }
.gh-bar #gh-msg:empty { display: none; }
.dev-status { margin: 6px 0; color: var(--muted); }
.dev-warn > div, .dev-warn { color: var(--warn); }
.dev-warn { margin-bottom: 8px; }
.dev-view input[type=text], .dev-view input[type=number], .dev-view select {
  font: inherit; color: var(--fg); background: var(--panel);
  border: 1px solid var(--line); padding: 0 4px; height: 18px;
}
.dev-view input[type=number] { width: 80px; text-align: right; }
.dev-view input:focus, .dev-view select:focus { outline: none; border-color: var(--accent); }
.dev-view input.w-id { width: 60px; }
.dev-view input.w-name { width: 220px; }
.dev-view input.w-kill { width: 60px; }
details.en {
  background: var(--panel); border: 1px solid var(--line);
  margin-bottom: 4px;
}
details.en > summary { padding: 2px 6px; cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: '+'; display: inline-block; width: 12px; color: var(--muted); }
details[open] > summary::before { content: '−'; }
details.en > .body { padding: 4px 6px 6px 18px; border-top: 1px solid var(--line); }
/* enemies in development (negative tier) */
details.en.wip { border-left: 3px solid var(--wip); }
details.en.wip > summary { color: var(--wip); }
.wip { color: var(--wip); }
/* dev/run */
.dev-run #dr-list td { vertical-align: middle; }
.dev-run #dr-list input[type=number], .dev-run #dr-shop input[type=number] { width: 70px; }
h3.de-tier { font-size: inherit; font-weight: normal; margin: 12px 0 4px; color: var(--fg); }
h3.de-tier:first-child { margin-top: 0; }
details.fld { margin-top: 4px; }
details.fld > summary { cursor: pointer; list-style: none; color: var(--muted); }
details.fld > summary b { font-weight: normal; color: var(--fg); }
details.fld > .body { padding: 2px 0 4px 12px; }
.ident { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ident label { color: var(--muted); }
.dev-table { width: auto; }
.dev-table td { padding: 1px 6px 1px 0; }
.dev-table td.lbl { color: var(--muted); width: 200px; }
.act {
  border-left: 1px solid var(--line); padding: 2px 0 2px 8px; margin: 4px 0 6px;
}
.act .ident { margin-bottom: 2px; }
.addrow { margin-top: 2px; display: flex; gap: 6px; align-items: center; }
button.x { border-color: transparent; color: var(--muted); padding: 0 4px; }
button.x:hover:not(:disabled) { color: var(--err); border-color: transparent; }
button.armed { color: var(--err); border-color: var(--err); }
.calc { color: var(--muted); font-size: 11px; }
.dev-side select { width: 190px; }
.dev-side .dev-table td { padding-right: 4px; }
.dev-side .lbl { width: auto; }
.addrow { flex-wrap: wrap; }
.dev-view button { white-space: nowrap; }
.hov { border-bottom: 1px dotted var(--muted); color: var(--muted); cursor: help; }
.hov:hover { color: var(--fg); border-bottom-color: var(--accent); }

/* prestige shop */
#shop-points { float: right; }
#shop td { vertical-align: top; white-space: normal; padding: 2px 4px; }
#shop td:first-child { width: 40px; }
#shop td:nth-child(2) { white-space: nowrap; }
#shop-items { max-width: 520px; }
#shop td:last-child { text-align: right; white-space: nowrap; }
#shop .grid tr:first-child { border-top: 0; }
#targets tr.locked td:not(:last-child) { color: var(--muted); }
#targets tr.locked .hov { color: var(--muted); }

/* ---------- phones ---------- */
#mtabs, .m-only { display: none; }
.tip:focus { outline: none; }
.tip:focus::after {
  content: attr(data-tip);
  position: absolute; right: 0; top: 100%; z-index: 10;
  margin-top: 2px; padding: 2px 6px;
  white-space: pre;
  color: var(--fg); background: var(--panel);
  border: 1px solid var(--line);
  font-size: 11px;
}
@media (max-width: 640px) {
  header { padding: 0 12px; }
  main { padding: 0 12px 16px; gap: 0; }
  #mtabs {
    display: flex; align-items: stretch;
    position: sticky; top: 0; z-index: 15;
    margin: 0 -12px; padding: 0 6px;
    background: var(--bg); border-bottom: 1px solid var(--line);
  }
  #mtabs button {
    border: 0; border-bottom: 1px solid transparent; margin-bottom: -1px;
    background: none; color: var(--muted); padding: 8px 8px; min-height: 0;
  }
  #mtabs button.on { color: var(--fg); border-bottom-color: var(--accent); }
  #m-hp { margin-left: auto; align-self: center; padding-right: 6px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

  /* one section at a time */
  #view-monitor section { display: none; }
  #stabs { display: none; }
  body[data-mtab=run] #center, body[data-mtab=log] #center { display: flex; flex-direction: column; }
  body[data-mtab=src] #unit, body[data-mtab=skills] #skills, body[data-mtab=shop] #shop, body[data-mtab=shop] #essence { display: block; }
  #essence { margin-top: 8px; }
  body[data-mtab=run] #center .m-log,
  body[data-mtab=log] #center .m-targets, body[data-mtab=log] #center .m-proc { display: none; }
  #center .m-proc { order: -1; }
  #center h2.m-proc { margin-top: 10px; }
  #center h2.m-targets { margin-top: 16px; }
  #view-monitor h2 { margin-top: 12px; }
  #view-monitor section > h2:first-child { margin-top: 12px; }
  body[data-mtab=log] #log { height: calc(100vh - 110px); }

  /* touch-sized controls */
  button { min-height: 30px; padding: 0 10px; }
  input[type=checkbox] { width: 16px; height: 16px; }
  .controls { flex-wrap: wrap; }
  #proc .v { width: 96px; }
  #proc .bar { min-width: 40px; }

  /* targets: tier, unlocks and status columns hidden (unlocks moves under stats) */
  .m-only { display: inline; }
  #targets { font-size: 11px; }
  #targets td, #targets th { padding: 3px 3px; }
  /* (the max kills change column too: on phones it shows under the count) */
  #targets th:nth-child(2), #targets td:nth-child(2),
  #targets th:nth-child(5), #targets td:nth-child(5),
  #targets th:nth-child(8), #targets td:nth-child(8),
  #targets th:nth-child(9), #targets td:nth-child(9) { display: none; }
  /* fixed columns so the table fits the screen; text wraps inside them */
  #targets { table-layout: fixed; }
  #targets th:nth-child(1) { width: 34px; }
  #targets th:nth-child(4) { width: 58px; }
  #targets .hov { white-space: nowrap; }
  #targets th:nth-child(6) { width: 78px; }
  #targets th:nth-child(7) { width: 54px; }
  #targets th:nth-child(10) { width: 56px; }
  #targets td { white-space: normal; overflow-wrap: anywhere; }
  #targets td:nth-child(3) { min-width: 0; }
  #targets td:last-child { text-align: right; }
  #targets button { padding: 0 4px; width: 100%; white-space: normal; line-height: 1.2; }

  /* skills */
  #skills col.c-n { width: 16px; }
  #skills col.c-name { width: 84px; }
  #skills col.c-act { width: 64px; }
  #skills button, #shop button, #essence button { padding: 0 6px; }

  /* tap tooltips and breakdowns stay inside the screen */
  .tip:hover::after, .tip:focus::after { white-space: pre-wrap; width: max-content; max-width: 70vw; }
  #popup { max-width: calc(100vw - 16px); }
}

#targets .nw { white-space: nowrap; }
/* max kills change indicator: its explanation wraps instead of one long line */
#targets .tip::after { white-space: normal; width: 260px; text-align: left; }

/* new-skill notices */
.badge { color: var(--warn); font-size: 11px; }
.badge[hidden] { display: none; }
#m-new { margin-left: 4px; }
#m-new::before { content: '·'; margin-right: 2px; }
#shop .tip::after { white-space: normal; width: 240px; text-align: left; }

/* essence shop (same layout as the prestige shop); hidden until P13 */
#essence[hidden], #stabs button[hidden], #st-essence-row[hidden] { display: none !important; }
#ess-points { float: right; }
#essence td { vertical-align: top; white-space: normal; padding: 2px 4px; }
#essence td:first-child { width: 40px; }
#essence td:nth-child(2) { white-space: nowrap; }
#essence td:last-child { text-align: right; white-space: nowrap; }
#essence .tip::after { white-space: normal; width: 220px; text-align: left; }

/* targets: max kills change in its own column, so the count never moves */
#targets td.gain { padding-left: 0; width: 7ch; min-width: 7ch; }
#p-xpbar .bar { display: block; max-width: none; }

/* tooltips in the src panel (left edge of the page): open to the right and
   wrap, so they stay on screen */
#unit .tip::after { left: 0; right: auto; white-space: normal; width: 260px; max-width: calc(100vw - 32px); text-align: left; }

/* dev/enemies player preview: load toggles left of the skill id */
#de-preview .pv-load { cursor: pointer; }
#de-preview .pv-load input { margin-right: 2px; }
#de-preview input.w-lv { width: 44px; }
#de-preview .pv-skills td { padding: 0 4px 0 0; white-space: nowrap; }
#de-preview .pv-skills td.pv-name { max-width: 104px; overflow: hidden; text-overflow: ellipsis; }

/* process box: small progress bars for each side's attacks and spells
   (and empowered attacks) */
#proc .act-row { font-size: 11px; line-height: 1.3; }
#proc .bar.mini { flex: 0 0 120px; height: 2px; }
#proc .act-row .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
  /* phones: same-width bars, the skill name takes the rest (cut if long) */
  #proc .act-row { font-size: 10px; }
  #proc .bar.mini { flex: 0 0 64px; min-width: 0; }
  #proc .act-row .muted { flex: 1 1 0; min-width: 0; }
}

/* targets: a locked boss's row shows its unlock progress (BOSS_LOCK) */
#targets tr.bosslock td { color: var(--muted); }
#targets .lockbar { display: block; max-width: none; margin-top: 6px; }

/* ---------- phones (v1.28) ---------- */
@media (max-width: 640px) {
  /* header: the page links scroll inside the bar instead of widening the page */
  header { padding: 0 8px 0 12px; }
  header nav { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  header nav::-webkit-scrollbar { display: none; }
  header nav a { padding: 8px 8px; white-space: nowrap; }
  header .spacer { display: none; }
  #version { padding-left: 8px; white-space: nowrap; }

  /* section tabs: tighter, the hp readout drops the enemy id below 380px */
  #mtabs button { padding: 8px 6px; }
  #m-hp { font-size: 11px; }

  /* targets: narrower fixed columns so the enemy name has room */
  #targets th:nth-child(1) { width: 36px; }
  #targets td:nth-child(1) { white-space: nowrap; overflow-wrap: normal; }
  #targets th:nth-child(4) { width: 50px; }
  #targets th:nth-child(6) { width: 70px; }
  #targets th:nth-child(7) { width: 46px; }
  #targets th:nth-child(10) { width: 48px; }
  #targets td:nth-child(3) { overflow-wrap: normal; word-break: normal; }
  #targets tr.bosslock .sub { font-size: 10px; }
  /* rewards: long values wrap inside their column instead of running into the count */
  #targets td:nth-child(6) div { white-space: normal; overflow-wrap: anywhere; }

  /* skills: names wrap instead of being cut off */
  #skills td:nth-child(3) { white-space: normal; overflow: visible; text-overflow: clip; }

  /* shops: item names wrap so the table fits narrow phones */
  #shop td:nth-child(2), #essence td:nth-child(2) { white-space: normal; }
}
@media (max-width: 379px) {
  .m-wide { display: none; }
}
